Merge branch 'devel/master' into tizen
[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    * Retrieve the render surface the scene is binded to.
124    * @return The render surface.
125    */
126   Integration::RenderSurface* GetSurface() const;
127
128   /**
129    * Retrieve the ordered list of on-scene layers.
130    * @return The layer-list.
131    */
132   LayerList& GetLayerList() const;
133
134   /**
135    * Request that the depth tree is rebuilt
136    */
137   void RequestRebuildDepthTree();
138
139   /**
140    * This function is called when an event is queued.
141    * @param[in] event A event to queue.
142    */
143   void QueueEvent( const Integration::Event& event );
144
145   /**
146    * This function is called by Core when events are processed.
147    */
148   void ProcessEvents();
149
150   /**
151    * Rebuilds the depth tree at the end of the event frame if
152    * it was requested this frame.
153    */
154   void RebuildDepthTree();
155
156   /**
157    * @brief Sets the background color of the render surface.
158    * @param[in] color The new background color
159    */
160   void SetBackgroundColor(Vector4 color);
161
162   /**
163    * @brief Gets the background color of the render surface.
164    * @return The background color
165    */
166   Vector4 GetBackgroundColor() const;
167
168   /**
169    * Used by the EventProcessor to emit key event signals.
170    * @param[in] event The key event.
171    */
172   void EmitKeyEventSignal(const KeyEvent& event);
173
174   /**
175    * Emits the event processing finished signal.
176    *
177    * @see Dali::Scene::SignalEventProcessingFinished()
178    */
179   void EmitEventProcessingFinishedSignal();
180
181   /**
182    * Emits the touched signal.
183    * @param[in] touchEvent The touch event details (Old API).
184    * @param[in] touch The touch event details.
185    */
186   void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
187
188   /**
189    * Used by the EventProcessor to emit wheel event signals.
190    * @param[in] event The wheel event.
191    */
192   void EmitWheelEventSignal( const WheelEvent& event );
193
194   /**
195    * @copydoc Integration::Scene::KeyEventSignal()
196    */
197   Integration::Scene::KeyEventSignalType& KeyEventSignal();
198
199   /**
200    * @copydoc Integration::Scene::SignalEventProcessingFinished()
201    */
202   Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
203
204   // The touched signal, to support Stage touched signal, will be removed when deprecated in public Stage API
205   using TouchedSignalType = Signal< void (const TouchEvent&) >;
206
207   /**
208    * Touched signal to support deprecated stage touched signal.
209    */
210   TouchedSignalType& TouchedSignal();
211
212   /**
213     * @copydoc Integration::Scene::TouchSignal()
214     */
215   Integration::Scene::TouchSignalType& TouchSignal();
216
217   /**
218    * @copydoc Integration::Scene::sWheelEventSignal()
219    */
220   Integration::Scene::WheelEventSignalType& WheelEventSignal();
221
222 public:
223
224   /**
225    * From RenderTaskDefaults; retrieve the default root actor.
226    * @return The default root actor.
227    */
228   virtual Actor& GetDefaultRootActor();
229
230   /**
231    * From RenderTaskDefaults; retrieve the default camera actor.
232    * @return The default camera actor.
233    */
234   virtual CameraActor& GetDefaultCameraActor();
235
236 private:
237
238   // Constructor
239   Scene( const Size& size );
240
241   /**
242    * Second-phase constructor.
243    */
244   void Initialize();
245
246   // Undefined
247   Scene(const Scene&) = delete;
248
249   // Undefined
250   Scene& operator=(const Scene& rhs) = delete;
251
252 private:
253   Integration::RenderSurface* mSurface;
254
255   // The scene-size may be different with the surface-size
256   Size mSize;
257   Size mSurfaceSize;
258
259   Vector2 mDpi;
260
261   LayerPtr mRootLayer;
262
263   // Ordered list of currently on-stage layers
264   OwnerPointer<LayerList> mLayerList;
265
266   IntrusivePtr<CameraActor> mDefaultCamera;
267
268   // The list of render-tasks
269   IntrusivePtr<RenderTaskList> mRenderTaskList;
270
271   // The frame buffer
272   FrameBufferPtr mFrameBuffer;
273
274   bool mDepthTreeDirty:1;  ///< True if the depth tree needs recalculating
275
276   EventProcessor mEventProcessor;
277
278   // The key event signal
279   Integration::Scene::KeyEventSignalType mKeyEventSignal;
280
281   // The event processing finished signal
282   Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
283
284   // The touch signal
285   Integration::Scene::TouchSignalType mTouchSignal;
286
287   // The touched signal
288   TouchedSignalType mTouchedSignal;
289
290   // The wheel event signal
291   Integration::Scene::WheelEventSignalType mWheelEventSignal;
292 };
293
294 } // Internal
295
296 // Get impl of handle
297 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
298 {
299   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
300   Dali::RefObject& object = scene.GetBaseObject();
301   return static_cast<Internal::Scene&>(object);
302 }
303
304 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
305 {
306   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
307   const Dali::RefObject& object = scene.GetBaseObject();
308   return static_cast<const Internal::Scene&>(object);
309 }
310
311 } // Dali
312
313 #endif // DALI_INTERNAL_SCENE_H