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