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