Merge "[dali-core] add all X11 colors to Color namespace" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / common / scene-impl.h
1 #ifndef DALI_INTERNAL_SCENE_H
2 #define DALI_INTERNAL_SCENE_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/scene.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/render-tasks/render-task-list.h>
26 #include <dali/internal/common/owner-pointer.h>
27 #include <dali/internal/event/actors/layer-impl.h>
28 #include <dali/internal/event/events/event-processor.h>
29 #include <dali/internal/event/render-tasks/render-task-defaults.h>
30
31 namespace Dali
32 {
33
34 namespace Integration
35 {
36
37 struct Event;
38
39 }
40
41 namespace Internal
42 {
43
44 namespace SceneGraph
45 {
46 class Scene;
47
48 struct DirtyRect
49 {
50   DirtyRect(Node* node, Render::Renderer* renderer, int frame, Rect<int>& rect)
51   : node(node),
52     renderer(renderer),
53     frame(frame),
54     rect(rect),
55     visited(true)
56   {
57   }
58
59   DirtyRect()
60   : node(nullptr),
61     renderer(nullptr),
62     frame(0),
63     rect(),
64     visited(true)
65   {
66   }
67
68   bool operator<(const DirtyRect& rhs) const
69   {
70     if (node == rhs.node)
71     {
72       if (renderer == rhs.renderer)
73       {
74         return frame > rhs.frame; // Most recent rects come first
75       }
76       else
77       {
78         return renderer < rhs.renderer;
79       }
80     }
81     else
82     {
83       return node < rhs.node;
84     }
85   }
86
87   Node* node;
88   Render::Renderer* renderer;
89   int frame;
90
91   Rect<int> rect;
92   bool visited;
93 };
94
95 }
96
97 class EventProcessor;
98 class Layer;
99 class LayerList;
100 class CameraActor;
101 class RenderTaskList;
102 class FrameBuffer;
103
104 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
105 using ScenePtr = IntrusivePtr<Scene>;
106
107 /**
108  * @brief Scene creates a "world" that can be bound to a surface for rendering.
109  */
110 class Scene : public BaseObject, public RenderTaskDefaults
111 {
112
113 public:
114   /**
115    * @copydoc Dali::Integration::Scene::New
116    */
117   static ScenePtr New(Size size, int orientation = 0);
118
119   /**
120    * virtual destructor
121    */
122   ~Scene() override;
123
124   /**
125    * @copydoc Dali::Integration::Scene::Add
126    */
127   void Add(Actor& actor);
128
129   /**
130    * @copydoc Dali::Integration::Scene::Remove
131    */
132   void Remove(Actor& actor);
133
134   /**
135    * @copydoc Dali::Integration::Scene::GetSize
136    */
137   Size GetSize() const;
138
139   /**
140    * @copydoc Dali::Integration::Scene::SetDpi
141    */
142   void SetDpi( Vector2 dpi );
143
144   /**
145    * @copydoc Dali::Integration::Scene::GetDpi
146    */
147   Vector2 GetDpi() const;
148
149   /**
150    * @copydoc Dali::Integration::Scene::GetRenderTaskList
151    */
152   RenderTaskList& GetRenderTaskList() const;
153
154   /**
155    * @copydoc Dali::Integration::Scene::GetRootLayer
156    */
157   Dali::Layer GetRootLayer() const;
158
159   /**
160    * @copydoc Dali::Integration::Scene::GetLayerCount
161    */
162   uint32_t GetLayerCount() const;
163
164   /**
165    * @copydoc Dali::Integration::Scene::GetLayer
166    */
167   Dali::Layer GetLayer(uint32_t depth) const;
168
169   /**
170    * Notify the surface has been resized.
171    *
172    * @param[in] width The new width of the set surface
173    * @param[in] height The new height of the set surface
174    */
175   void SurfaceResized( float width, float height );
176
177   /**
178    * @copydoc Dali::Integration::Scene::SurfaceReplaced
179    */
180   void SurfaceReplaced();
181
182   /**
183    * @copydoc Dali::Integration::Scene::Discard
184    */
185   void Discard();
186
187   /**
188    * Retrieve the ordered list of on-scene layers.
189    * @return The layer-list.
190    */
191   LayerList& GetLayerList() const;
192
193   /**
194    * Request that the depth tree is rebuilt
195    */
196   void RequestRebuildDepthTree();
197
198   /**
199    * This function is called when an event is queued.
200    * @param[in] event A event to queue.
201    */
202   void QueueEvent( const Integration::Event& event );
203
204   /**
205    * This function is called by Core when events are processed.
206    */
207   void ProcessEvents();
208
209   /**
210    * Rebuilds the depth tree at the end of the event frame if
211    * it was requested this frame.
212    */
213   void RebuildDepthTree();
214
215   /**
216    * @brief Sets the background color of the render surface.
217    * @param[in] color The new background color
218    */
219   void SetBackgroundColor( const Vector4& color );
220
221   /**
222    * @brief Gets the background color of the render surface.
223    * @return The background color
224    */
225   Vector4 GetBackgroundColor() const;
226
227   /**
228    * @brief Get the Scene scene graph object
229    *
230    * @return the Scene scene graph object
231    */
232   SceneGraph::Scene* GetSceneObject() const;
233
234   /**
235    * Notify the surface has been rotated.
236    * When the device is rotated or the rotation event is received by display manager,
237    * this function will be called by window implementation.
238    *
239    * @param[in] width The width of rotated surface
240    * @param[in] height The height of rotated surface
241    * @param[in] orientation The orientation of rotated surface
242    */
243   void SurfaceRotated(float width, float height, int orientation);
244
245   /**
246    * @brief Get surface's current orientation
247    *
248    * @return surface orientation
249    */
250   int GetSurfaceOrientation();
251
252   /**
253    * Used by the EventProcessor to emit key event signals.
254    * @param[in] event The key event.
255    */
256   void EmitKeyEventSignal(const Dali::KeyEvent& event);
257
258   /**
259    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
260    * @param[in] event The key event.
261    * @return The return is true if KeyEvent is consumed, otherwise false.
262    */
263   bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
264
265   /**
266    * Emits the event processing finished signal.
267    *
268    * @see Dali::Scene::SignalEventProcessingFinished()
269    */
270   void EmitEventProcessingFinishedSignal();
271
272   /**
273    * Emits the touched signal.
274    * @param[in] touch The touch event details.
275    */
276   void EmitTouchedSignal( const Dali::TouchEvent& touch );
277
278   /**
279    * Used by the EventProcessor to emit wheel event signals.
280    * @param[in] event The wheel event.
281    */
282   void EmitWheelEventSignal( const Dali::WheelEvent& event );
283
284   /**
285    * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
286    */
287   void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
288
289   /**
290    * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
291    */
292   void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
293
294   /**
295    * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
296    */
297   void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
298
299   /**
300    * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
301    */
302   void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
303
304   /**
305    * @copydoc Integration::Scene::KeyEventSignal()
306    */
307   Integration::Scene::KeyEventSignalType& KeyEventSignal();
308
309     /**
310    * @copydoc Integration::Scene::KeyEventGeneratedSignal()
311    */
312   Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
313
314   /**
315    * @copydoc Integration::Scene::SignalEventProcessingFinished()
316    */
317   Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
318
319   /**
320     * @copydoc Integration::Scene::TouchedSignal()
321     */
322   Integration::Scene::TouchEventSignalType& TouchedSignal();
323
324   /**
325    * @copydoc Integration::Scene::sWheelEventSignal()
326    */
327   Integration::Scene::WheelEventSignalType& WheelEventSignal();
328
329   /**
330    * @brief Get ItemsDirtyRects
331    *
332    * @return the ItemsDirtyRects
333    */
334   std::vector<Dali::Internal::SceneGraph::DirtyRect>& GetItemsDirtyRects();
335
336 public:
337
338   /**
339    * From RenderTaskDefaults; retrieve the default root actor.
340    * @return The default root actor.
341    */
342   Actor& GetDefaultRootActor() override;
343
344   /**
345    * From RenderTaskDefaults; retrieve the default camera actor.
346    * @return The default camera actor.
347    */
348   CameraActor& GetDefaultCameraActor() override;
349
350 private:
351
352   // Constructor
353   Scene();
354
355   /**
356    * Second-phase constructor.
357    *
358    * @param[in] size The size of the set surface
359    * @param[in] orientation The orientation of the set surface for this scene
360    */
361   void Initialize(Size size, int orientation);
362
363   // Undefined
364   Scene(const Scene&) = delete;
365
366   // Undefined
367   Scene& operator=(const Scene& rhs) = delete;
368
369   /**
370    * Informs the scene that the set surface has been resized or rotated.
371    *
372    * @param[in] width The width of rotated surface
373    * @param[in] height The height of rotated surface
374    * @param[in] orientation The orientation of rotated surface
375    */
376   void ChangedSurface(float width, float height, int orientation);
377
378 private:
379   Internal::SceneGraph::Scene* mSceneObject;
380
381   Size mSize;
382
383   Vector2 mDpi;
384
385   Vector4 mBackgroundColor;
386
387   LayerPtr mRootLayer;
388
389   // Ordered list of currently on-stage layers
390   OwnerPointer<LayerList> mLayerList;
391
392   IntrusivePtr<CameraActor> mDefaultCamera;
393
394   // The list of render-tasks
395   IntrusivePtr<RenderTaskList> mRenderTaskList;
396
397   bool mDepthTreeDirty:1;  ///< True if the depth tree needs recalculating
398
399   EventProcessor mEventProcessor;
400
401   // The Surface's orientation
402   int mSurfaceOrientation;
403
404   // The key event signal
405   Integration::Scene::KeyEventSignalType mKeyEventSignal;
406   Integration::Scene::KeyEventGeneratedSignalType   mKeyEventGeneratedSignal;
407
408   // The event processing finished signal
409   Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
410
411   // The touch signal
412   Integration::Scene::TouchEventSignalType mTouchedSignal;
413
414   // The wheel event signal
415   Integration::Scene::WheelEventSignalType mWheelEventSignal;
416
417   std::vector<Dali::Internal::SceneGraph::DirtyRect>                    mItemsDirtyRects;
418 };
419
420 } // Internal
421
422 // Get impl of handle
423 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
424 {
425   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
426   Dali::RefObject& object = scene.GetBaseObject();
427   return static_cast<Internal::Scene&>(object);
428 }
429
430 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
431 {
432   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
433   const Dali::RefObject& object = scene.GetBaseObject();
434   return static_cast<const Internal::Scene&>(object);
435 }
436
437 } // Dali
438
439 #endif // DALI_INTERNAL_SCENE_H