[dali_1.9.27] Merge branch '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 Dali::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 Dali::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] touch The touch event details.
209    */
210   void EmitTouchedSignal( const Dali::TouchEvent& touch );
211
212   /**
213    * Used by the EventProcessor to emit wheel event signals.
214    * @param[in] event The wheel event.
215    */
216   void EmitWheelEventSignal( const Dali::WheelEvent& event );
217
218   /**
219    * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
220    */
221   void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
222
223   /**
224    * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
225    */
226   void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
227
228   /**
229    * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
230    */
231   void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
232
233   /**
234    * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
235    */
236   void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
237
238   /**
239    * @copydoc Integration::Scene::KeyEventSignal()
240    */
241   Integration::Scene::KeyEventSignalType& KeyEventSignal();
242
243     /**
244    * @copydoc Integration::Scene::KeyEventGeneratedSignal()
245    */
246   Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
247
248   /**
249    * @copydoc Integration::Scene::SignalEventProcessingFinished()
250    */
251   Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
252
253   /**
254     * @copydoc Integration::Scene::TouchSignal()
255     */
256   Integration::Scene::TouchSignalType& TouchSignal();
257
258   /**
259    * @copydoc Integration::Scene::sWheelEventSignal()
260    */
261   Integration::Scene::WheelEventSignalType& WheelEventSignal();
262
263 public:
264
265   /**
266    * From RenderTaskDefaults; retrieve the default root actor.
267    * @return The default root actor.
268    */
269   virtual Actor& GetDefaultRootActor();
270
271   /**
272    * From RenderTaskDefaults; retrieve the default camera actor.
273    * @return The default camera actor.
274    */
275   virtual CameraActor& GetDefaultCameraActor();
276
277 private:
278
279   // Constructor
280   Scene();
281
282   /**
283    * Second-phase constructor.
284    *
285    * @param[in] size The size of the set surface
286    */
287   void Initialize( Size size );
288
289   // Undefined
290   Scene(const Scene&) = delete;
291
292   // Undefined
293   Scene& operator=(const Scene& rhs) = delete;
294
295 private:
296   Internal::SceneGraph::Scene* mSceneObject;
297
298   Size mSize;
299
300   Vector2 mDpi;
301
302   Vector4 mBackgroundColor;
303
304   LayerPtr mRootLayer;
305
306   // Ordered list of currently on-stage layers
307   OwnerPointer<LayerList> mLayerList;
308
309   IntrusivePtr<CameraActor> mDefaultCamera;
310
311   // The list of render-tasks
312   IntrusivePtr<RenderTaskList> mRenderTaskList;
313
314   bool mDepthTreeDirty:1;  ///< True if the depth tree needs recalculating
315
316   EventProcessor mEventProcessor;
317
318   // The key event signal
319   Integration::Scene::KeyEventSignalType mKeyEventSignal;
320   Integration::Scene::KeyEventGeneratedSignalType   mKeyEventGeneratedSignal;
321
322   // The event processing finished signal
323   Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
324
325   // The touch signal
326   Integration::Scene::TouchSignalType mTouchSignal;
327
328   // The wheel event signal
329   Integration::Scene::WheelEventSignalType mWheelEventSignal;
330 };
331
332 } // Internal
333
334 // Get impl of handle
335 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
336 {
337   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
338   Dali::RefObject& object = scene.GetBaseObject();
339   return static_cast<Internal::Scene&>(object);
340 }
341
342 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
343 {
344   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
345   const Dali::RefObject& object = scene.GetBaseObject();
346   return static_cast<const Internal::Scene&>(object);
347 }
348
349 } // Dali
350
351 #endif // DALI_INTERNAL_SCENE_H