Revert "[Tizen] Modify dirtyRects to have scene for multi window support."
[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
49 class EventProcessor;
50 class Layer;
51 class LayerList;
52 class CameraActor;
53 class RenderTaskList;
54 class FrameBuffer;
55
56 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
57 using ScenePtr = IntrusivePtr<Scene>;
58
59 /**
60  * @brief Scene creates a "world" that can be bound to a surface for rendering.
61  */
62 class Scene : public BaseObject, public RenderTaskDefaults
63 {
64
65 public:
66   /**
67    * @copydoc Dali::Integration::Scene::New
68    */
69   static ScenePtr New( Size size );
70
71   /**
72    * virtual destructor
73    */
74   virtual ~Scene();
75
76   /**
77    * @copydoc Dali::Integration::Scene::Add
78    */
79   void Add(Actor& actor);
80
81   /**
82    * @copydoc Dali::Integration::Scene::Remove
83    */
84   void Remove(Actor& actor);
85
86   /**
87    * @copydoc Dali::Integration::Scene::GetSize
88    */
89   Size GetSize() const;
90
91   /**
92    * @copydoc Dali::Integration::Scene::SetDpi
93    */
94   void SetDpi( Vector2 dpi );
95
96   /**
97    * @copydoc Dali::Integration::Scene::GetDpi
98    */
99   Vector2 GetDpi() const;
100
101   /**
102    * @copydoc Dali::Integration::Scene::GetRenderTaskList
103    */
104   RenderTaskList& GetRenderTaskList() const;
105
106   /**
107    * @copydoc Dali::Integration::Scene::GetRootLayer
108    */
109   Dali::Layer GetRootLayer() const;
110
111   /**
112    * @copydoc Dali::Integration::Scene::GetLayerCount
113    */
114   uint32_t GetLayerCount() const;
115
116   /**
117    * @copydoc Dali::Integration::Scene::GetLayer
118    */
119   Dali::Layer GetLayer(uint32_t depth) const;
120
121   /**
122    * Notify the surface has been resized.
123    *
124    * @param[in] width The new width of the set surface
125    * @param[in] height The new height of the set surface
126    * @param[in] orientation The orientation of the surface
127    * @param[in] forceUpdate The flag to update force
128    */
129   void SurfaceResized( float width, float height, int orientation, bool forceUpdate );
130
131   /**
132    * @copydoc Dali::Integration::Scene::SurfaceReplaced
133    */
134   void SurfaceReplaced();
135
136   /**
137    * @copydoc Dali::Integration::Scene::Discard
138    */
139   void Discard();
140
141   /**
142    * Retrieve the ordered list of on-scene layers.
143    * @return The layer-list.
144    */
145   LayerList& GetLayerList() const;
146
147   /**
148    * Request that the depth tree is rebuilt
149    */
150   void RequestRebuildDepthTree();
151
152   /**
153    * This function is called when an event is queued.
154    * @param[in] event A event to queue.
155    */
156   void QueueEvent( const Integration::Event& event );
157
158   /**
159    * This function is called by Core when events are processed.
160    */
161   void ProcessEvents();
162
163   /**
164    * Rebuilds the depth tree at the end of the event frame if
165    * it was requested this frame.
166    */
167   void RebuildDepthTree();
168
169   /**
170    * @brief Sets the background color of the render surface.
171    * @param[in] color The new background color
172    */
173   void SetBackgroundColor( const Vector4& color );
174
175   /**
176    * @brief Gets the background color of the render surface.
177    * @return The background color
178    */
179   Vector4 GetBackgroundColor() const;
180
181   /**
182    * @brief Get the Scene scene graph object
183    *
184    * @return the Scene scene graph object
185    */
186   SceneGraph::Scene* GetSceneObject() const;
187
188   /**
189    * Used by the EventProcessor to emit key event signals.
190    * @param[in] event The key event.
191    */
192   void EmitKeyEventSignal(const KeyEvent& event);
193
194   /**
195    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
196    * @param[in] event The key event.
197    * @return The return is true if KeyEvent is consumed, otherwise false.
198    */
199   bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
200
201   /**
202    * Emits the event processing finished signal.
203    *
204    * @see Dali::Scene::SignalEventProcessingFinished()
205    */
206   void EmitEventProcessingFinishedSignal();
207
208   /**
209    * Emits the touched signal.
210    * @param[in] touchEvent The touch event details (Old API).
211    * @param[in] touch The touch event details.
212    */
213   void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
214
215   /**
216    * Used by the EventProcessor to emit wheel event signals.
217    * @param[in] event The wheel event.
218    */
219   void EmitWheelEventSignal( const WheelEvent& event );
220
221   /**
222    * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
223    */
224   void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
225
226   /**
227    * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
228    */
229   void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
230
231   /**
232    * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
233    */
234   void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
235
236   /**
237    * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
238    */
239   void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
240
241   /**
242    * @copydoc Integration::Scene::KeyEventSignal()
243    */
244   Integration::Scene::KeyEventSignalType& KeyEventSignal();
245
246     /**
247    * @copydoc Integration::Scene::KeyEventGeneratedSignal()
248    */
249   Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
250
251   /**
252    * @copydoc Integration::Scene::SignalEventProcessingFinished()
253    */
254   Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
255
256   // The touched signal, to support Stage touched signal, will be removed when deprecated in public Stage API
257   using TouchedSignalType = Signal< void (const TouchEvent&) >;
258
259   /**
260    * Touched signal to support deprecated stage touched signal.
261    */
262   TouchedSignalType& TouchedSignal();
263
264   /**
265     * @copydoc Integration::Scene::TouchSignal()
266     */
267   Integration::Scene::TouchSignalType& TouchSignal();
268
269   /**
270    * @copydoc Integration::Scene::sWheelEventSignal()
271    */
272   Integration::Scene::WheelEventSignalType& WheelEventSignal();
273
274 public:
275
276   /**
277    * From RenderTaskDefaults; retrieve the default root actor.
278    * @return The default root actor.
279    */
280   virtual Actor& GetDefaultRootActor();
281
282   /**
283    * From RenderTaskDefaults; retrieve the default camera actor.
284    * @return The default camera actor.
285    */
286   virtual CameraActor& GetDefaultCameraActor();
287
288 private:
289
290   // Constructor
291   Scene();
292
293   /**
294    * Second-phase constructor.
295    *
296    * @param[in] size The size of the set surface
297    */
298   void Initialize( Size size );
299
300   // Undefined
301   Scene(const Scene&) = delete;
302
303   // Undefined
304   Scene& operator=(const Scene& rhs) = delete;
305
306 private:
307   Internal::SceneGraph::Scene* mSceneObject;
308
309   Size mSize;
310
311   Vector2 mDpi;
312
313   Vector4 mBackgroundColor;
314
315   // The SurfaceOrientation
316   int mSurfaceOrientation;
317
318   LayerPtr mRootLayer;
319
320   // Ordered list of currently on-stage layers
321   OwnerPointer<LayerList> mLayerList;
322
323   IntrusivePtr<CameraActor> mDefaultCamera;
324
325   // The list of render-tasks
326   IntrusivePtr<RenderTaskList> mRenderTaskList;
327
328   bool mDepthTreeDirty:1;  ///< True if the depth tree needs recalculating
329
330   EventProcessor mEventProcessor;
331
332   // The key event signal
333   Integration::Scene::KeyEventSignalType mKeyEventSignal;
334   Integration::Scene::KeyEventGeneratedSignalType   mKeyEventGeneratedSignal;
335
336   // The event processing finished signal
337   Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
338
339   // The touch signal
340   Integration::Scene::TouchSignalType mTouchSignal;
341
342   // The touched signal
343   TouchedSignalType mTouchedSignal;
344
345   // The wheel event signal
346   Integration::Scene::WheelEventSignalType mWheelEventSignal;
347 };
348
349 } // Internal
350
351 // Get impl of handle
352 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
353 {
354   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
355   Dali::RefObject& object = scene.GetBaseObject();
356   return static_cast<Internal::Scene&>(object);
357 }
358
359 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
360 {
361   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
362   const Dali::RefObject& object = scene.GetBaseObject();
363   return static_cast<const Internal::Scene&>(object);
364 }
365
366 } // Dali
367
368 #endif // DALI_INTERNAL_SCENE_H