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