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