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