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