Merge "(Scene) Add frame rendered/presented callback" 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
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    */
127   void SurfaceResized( float width, float height );
128
129   /**
130    * @copydoc Dali::Integration::Scene::SurfaceReplaced
131    */
132   void SurfaceReplaced();
133
134   /**
135    * @copydoc Dali::Integration::Scene::Discard
136    */
137   void Discard();
138
139   /**
140    * Retrieve the ordered list of on-scene layers.
141    * @return The layer-list.
142    */
143   LayerList& GetLayerList() const;
144
145   /**
146    * Request that the depth tree is rebuilt
147    */
148   void RequestRebuildDepthTree();
149
150   /**
151    * This function is called when an event is queued.
152    * @param[in] event A event to queue.
153    */
154   void QueueEvent( const Integration::Event& event );
155
156   /**
157    * This function is called by Core when events are processed.
158    */
159   void ProcessEvents();
160
161   /**
162    * Rebuilds the depth tree at the end of the event frame if
163    * it was requested this frame.
164    */
165   void RebuildDepthTree();
166
167   /**
168    * @brief Sets the background color of the render surface.
169    * @param[in] color The new background color
170    */
171   void SetBackgroundColor( const Vector4& color );
172
173   /**
174    * @brief Gets the background color of the render surface.
175    * @return The background color
176    */
177   Vector4 GetBackgroundColor() const;
178
179   /**
180    * @brief Get the Scene scene graph object
181    *
182    * @return the Scene scene graph object
183    */
184   SceneGraph::Scene* GetSceneObject() const;
185
186   /**
187    * Used by the EventProcessor to emit key event signals.
188    * @param[in] event The key event.
189    */
190   void EmitKeyEventSignal(const KeyEvent& event);
191
192   /**
193    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
194    * @param[in] event The key event.
195    * @return The return is true if KeyEvent is consumed, otherwise false.
196    */
197   bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
198
199   /**
200    * Emits the event processing finished signal.
201    *
202    * @see Dali::Scene::SignalEventProcessingFinished()
203    */
204   void EmitEventProcessingFinishedSignal();
205
206   /**
207    * Emits the touched signal.
208    * @param[in] touchEvent The touch event details (Old API).
209    * @param[in] touch The touch event details.
210    */
211   void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
212
213   /**
214    * Used by the EventProcessor to emit wheel event signals.
215    * @param[in] event The wheel event.
216    */
217   void EmitWheelEventSignal( const WheelEvent& event );
218
219   /**
220    * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
221    */
222   void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
223
224   /**
225    * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
226    */
227   void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
228
229   /**
230    * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
231    */
232   void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
233
234   /**
235    * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
236    */
237   void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
238
239   /**
240    * @copydoc Integration::Scene::KeyEventSignal()
241    */
242   Integration::Scene::KeyEventSignalType& KeyEventSignal();
243
244     /**
245    * @copydoc Integration::Scene::KeyEventGeneratedSignal()
246    */
247   Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
248
249   /**
250    * @copydoc Integration::Scene::SignalEventProcessingFinished()
251    */
252   Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
253
254   // The touched signal, to support Stage touched signal, will be removed when deprecated in public Stage API
255   using TouchedSignalType = Signal< void (const TouchEvent&) >;
256
257   /**
258    * Touched signal to support deprecated stage touched signal.
259    */
260   TouchedSignalType& TouchedSignal();
261
262   /**
263     * @copydoc Integration::Scene::TouchSignal()
264     */
265   Integration::Scene::TouchSignalType& TouchSignal();
266
267   /**
268    * @copydoc Integration::Scene::sWheelEventSignal()
269    */
270   Integration::Scene::WheelEventSignalType& WheelEventSignal();
271
272 public:
273
274   /**
275    * From RenderTaskDefaults; retrieve the default root actor.
276    * @return The default root actor.
277    */
278   virtual Actor& GetDefaultRootActor();
279
280   /**
281    * From RenderTaskDefaults; retrieve the default camera actor.
282    * @return The default camera actor.
283    */
284   virtual CameraActor& GetDefaultCameraActor();
285
286 private:
287
288   // Constructor
289   Scene();
290
291   /**
292    * Second-phase constructor.
293    *
294    * @param[in] size The size of the set surface
295    */
296   void Initialize( Size size );
297
298   // Undefined
299   Scene(const Scene&) = delete;
300
301   // Undefined
302   Scene& operator=(const Scene& rhs) = delete;
303
304 private:
305   Internal::SceneGraph::Scene* mSceneObject;
306
307   Size mSize;
308
309   Vector2 mDpi;
310
311   Vector4 mBackgroundColor;
312
313   LayerPtr mRootLayer;
314
315   // Ordered list of currently on-stage layers
316   OwnerPointer<LayerList> mLayerList;
317
318   IntrusivePtr<CameraActor> mDefaultCamera;
319
320   // The list of render-tasks
321   IntrusivePtr<RenderTaskList> mRenderTaskList;
322
323   bool mDepthTreeDirty:1;  ///< True if the depth tree needs recalculating
324
325   EventProcessor mEventProcessor;
326
327   // The key event signal
328   Integration::Scene::KeyEventSignalType mKeyEventSignal;
329   Integration::Scene::KeyEventGeneratedSignalType   mKeyEventGeneratedSignal;
330
331   // The event processing finished signal
332   Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
333
334   // The touch signal
335   Integration::Scene::TouchSignalType mTouchSignal;
336
337   // The touched signal
338   TouchedSignalType mTouchedSignal;
339
340   // The wheel event signal
341   Integration::Scene::WheelEventSignalType mWheelEventSignal;
342 };
343
344 } // Internal
345
346 // Get impl of handle
347 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
348 {
349   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
350   Dali::RefObject& object = scene.GetBaseObject();
351   return static_cast<Internal::Scene&>(object);
352 }
353
354 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
355 {
356   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
357   const Dali::RefObject& object = scene.GetBaseObject();
358   return static_cast<const Internal::Scene&>(object);
359 }
360
361 } // Dali
362
363 #endif // DALI_INTERNAL_SCENE_H