[Tizen] Add screen and client rotation itself function
[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 );
118
119   /**
120    * @copydoc Dali::Integration::Scene::New
121    */
122   static ScenePtr New( Size size, int orientation );
123
124   /**
125    * virtual destructor
126    */
127   ~Scene() override;
128
129   /**
130    * @copydoc Dali::Integration::Scene::Add
131    */
132   void Add(Actor& actor);
133
134   /**
135    * @copydoc Dali::Integration::Scene::Remove
136    */
137   void Remove(Actor& actor);
138
139   /**
140    * @copydoc Dali::Integration::Scene::GetSize
141    */
142   Size GetSize() const;
143
144   /**
145    * @copydoc Dali::Integration::Scene::SetDpi
146    */
147   void SetDpi( Vector2 dpi );
148
149   /**
150    * @copydoc Dali::Integration::Scene::GetDpi
151    */
152   Vector2 GetDpi() const;
153
154   /**
155    * @copydoc Dali::Integration::Scene::GetRenderTaskList
156    */
157   RenderTaskList& GetRenderTaskList() const;
158
159   /**
160    * @copydoc Dali::Integration::Scene::GetRootLayer
161    */
162   Dali::Layer GetRootLayer() const;
163
164   /**
165    * @copydoc Dali::Integration::Scene::GetLayerCount
166    */
167   uint32_t GetLayerCount() const;
168
169   /**
170    * @copydoc Dali::Integration::Scene::GetLayer
171    */
172   Dali::Layer GetLayer(uint32_t depth) const;
173
174   /**
175    * Notify the surface has been resized.
176    *
177    * @param[in] width The new width of the set surface
178    * @param[in] height The new height of the set surface
179    * @param[in] orientation The orientation of the surface
180    * @param[in] forceUpdate The flag to update force
181    */
182   void SurfaceResized( float width, float height, int orientation, bool forceUpdate );
183
184   /**
185    * @copydoc Dali::Integration::Scene::SurfaceReplaced
186    */
187   void SurfaceReplaced();
188
189   /**
190    * @copydoc Dali::Integration::Scene::Discard
191    */
192   void Discard();
193
194   /**
195    * Retrieve the ordered list of on-scene layers.
196    * @return The layer-list.
197    */
198   LayerList& GetLayerList() const;
199
200   /**
201    * Request that the depth tree is rebuilt
202    */
203   void RequestRebuildDepthTree();
204
205   /**
206    * This function is called when an event is queued.
207    * @param[in] event A event to queue.
208    */
209   void QueueEvent( const Integration::Event& event );
210
211   /**
212    * This function is called by Core when events are processed.
213    */
214   void ProcessEvents();
215
216   /**
217    * Rebuilds the depth tree at the end of the event frame if
218    * it was requested this frame.
219    */
220   void RebuildDepthTree();
221
222   /**
223    * @brief Sets the background color of the render surface.
224    * @param[in] color The new background color
225    */
226   void SetBackgroundColor( const Vector4& color );
227
228   /**
229    * @brief Gets the background color of the render surface.
230    * @return The background color
231    */
232   Vector4 GetBackgroundColor() const;
233
234   /**
235    * @brief Get the Scene scene graph object
236    *
237    * @return the Scene scene graph object
238    */
239   SceneGraph::Scene* GetSceneObject() const;
240
241   /**
242    * Used by the EventProcessor to emit key event signals.
243    * @param[in] event The key event.
244    */
245   void EmitKeyEventSignal(const Dali::KeyEvent& event);
246
247   /**
248    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
249    * @param[in] event The key event.
250    * @return The return is true if KeyEvent is consumed, otherwise false.
251    */
252   bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
253
254   /**
255    * Emits the event processing finished signal.
256    *
257    * @see Dali::Scene::SignalEventProcessingFinished()
258    */
259   void EmitEventProcessingFinishedSignal();
260
261   /**
262    * Emits the touched signal.
263    * @param[in] touch The touch event details.
264    */
265   void EmitTouchedSignal( const Dali::TouchEvent& touch );
266
267   /**
268    * Used by the EventProcessor to emit wheel event signals.
269    * @param[in] event The wheel event.
270    */
271   void EmitWheelEventSignal( const Dali::WheelEvent& event );
272
273   /**
274    * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
275    */
276   void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
277
278   /**
279    * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
280    */
281   void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
282
283   /**
284    * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
285    */
286   void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
287
288   /**
289    * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
290    */
291   void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
292
293   /**
294    * @copydoc Integration::Scene::KeyEventSignal()
295    */
296   Integration::Scene::KeyEventSignalType& KeyEventSignal();
297
298     /**
299    * @copydoc Integration::Scene::KeyEventGeneratedSignal()
300    */
301   Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
302
303   /**
304    * @copydoc Integration::Scene::SignalEventProcessingFinished()
305    */
306   Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
307
308   /**
309     * @copydoc Integration::Scene::TouchedSignal()
310     */
311   Integration::Scene::TouchEventSignalType& TouchedSignal();
312
313   /**
314    * @copydoc Integration::Scene::sWheelEventSignal()
315    */
316   Integration::Scene::WheelEventSignalType& WheelEventSignal();
317
318   /**
319    * @brief Get ItemsDirtyRects
320    *
321    * @return the ItemsDirtyRects
322    */
323   std::vector<Dali::Internal::SceneGraph::DirtyRect>& GetItemsDirtyRects();
324
325 public:
326
327   /**
328    * From RenderTaskDefaults; retrieve the default root actor.
329    * @return The default root actor.
330    */
331   Actor& GetDefaultRootActor() override;
332
333   /**
334    * From RenderTaskDefaults; retrieve the default camera actor.
335    * @return The default camera actor.
336    */
337   CameraActor& GetDefaultCameraActor() override;
338
339 private:
340
341   // Constructor
342   Scene();
343
344   /**
345    * Second-phase constructor.
346    *
347    * @param[in] size The size of the set surface
348    * @param[in] orientation The orientation of the set surface for this scene
349    */
350   void Initialize( Size size, int orientation );
351
352   // Undefined
353   Scene(const Scene&) = delete;
354
355   // Undefined
356   Scene& operator=(const Scene& rhs) = delete;
357
358 private:
359   Internal::SceneGraph::Scene* mSceneObject;
360
361   Size mSize;
362
363   Vector2 mDpi;
364
365   Vector4 mBackgroundColor;
366
367   // The SurfaceOrientation
368   int mSurfaceOrientation;
369
370   LayerPtr mRootLayer;
371
372   // Ordered list of currently on-stage layers
373   OwnerPointer<LayerList> mLayerList;
374
375   IntrusivePtr<CameraActor> mDefaultCamera;
376
377   // The list of render-tasks
378   IntrusivePtr<RenderTaskList> mRenderTaskList;
379
380   bool mDepthTreeDirty:1;  ///< True if the depth tree needs recalculating
381
382   EventProcessor mEventProcessor;
383
384   // The key event signal
385   Integration::Scene::KeyEventSignalType mKeyEventSignal;
386   Integration::Scene::KeyEventGeneratedSignalType   mKeyEventGeneratedSignal;
387
388   // The event processing finished signal
389   Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
390
391   // The touch signal
392   Integration::Scene::TouchEventSignalType mTouchedSignal;
393
394   // The wheel event signal
395   Integration::Scene::WheelEventSignalType mWheelEventSignal;
396
397   std::vector<Dali::Internal::SceneGraph::DirtyRect>                    mItemsDirtyRects;
398 };
399
400 } // Internal
401
402 // Get impl of handle
403 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
404 {
405   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
406   Dali::RefObject& object = scene.GetBaseObject();
407   return static_cast<Internal::Scene&>(object);
408 }
409
410 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
411 {
412   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
413   const Dali::RefObject& object = scene.GetBaseObject();
414   return static_cast<const Internal::Scene&>(object);
415 }
416
417 } // Dali
418
419 #endif // DALI_INTERNAL_SCENE_H