52ea3560582a0a50fd1f3fbefd3c65a05e1d3dd4
[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) 2022 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/internal/common/owner-pointer.h>
24 #include <dali/internal/event/actors/layer-impl.h>
25 #include <dali/internal/event/events/event-processor.h>
26 #include <dali/internal/event/render-tasks/render-task-defaults.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/math/vector2.h>
29 #include <dali/public-api/render-tasks/render-task-list.h>
30
31 namespace Dali
32 {
33 namespace Integration
34 {
35 struct Event;
36
37 }
38
39 namespace Internal
40 {
41 namespace SceneGraph
42 {
43 class Scene;
44 } // namespace SceneGraph
45
46 class EventProcessor;
47 class Layer;
48 class LayerList;
49 class CameraActor;
50 class RenderTaskList;
51 class FrameBuffer;
52
53 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
54 using ScenePtr       = IntrusivePtr<Scene>;
55
56 /**
57  * @brief Scene creates a "world" that can be bound to a surface for rendering.
58  */
59 class Scene : public BaseObject, public RenderTaskDefaults
60 {
61 public:
62   /**
63    * @copydoc Dali::Integration::Scene::New
64    */
65   static ScenePtr New(Size size, int32_t windowOrientation = 0, int32_t screenOrientation = 0);
66
67   /**
68    * virtual destructor
69    */
70   ~Scene() override;
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    * Notify the surface has been resized.
119    *
120    * @param[in] width The new width of the set surface
121    * @param[in] height The new height of the set surface
122    */
123   void SurfaceResized(float width, float height);
124
125   /**
126    * @copydoc Dali::Integration::Scene::SurfaceReplaced
127    */
128   void SurfaceReplaced();
129
130   /**
131    * @copydoc Dali::Integration::Scene::Discard
132    */
133   void Discard();
134
135   /**
136    * Retrieve the ordered list of on-scene layers.
137    * @return The layer-list.
138    */
139   LayerList& GetLayerList() const;
140
141   /**
142    * Request that the depth tree is rebuilt
143    */
144   void RequestRebuildDepthTree();
145
146   /**
147    * This function is called when an event is queued.
148    * @param[in] event A event to queue.
149    */
150   void QueueEvent(const Integration::Event& event);
151
152   /**
153    * This function is called by Core when events are processed.
154    */
155   void ProcessEvents();
156
157   /**
158    * Rebuilds the depth tree at the end of the event frame if
159    * it was requested this frame.
160    */
161   void RebuildDepthTree();
162
163   /**
164    * @brief Sets the background color of the render surface.
165    * @param[in] color The new background color
166    */
167   void SetBackgroundColor(const Vector4& color);
168
169   /**
170    * @brief Gets the background color of the render surface.
171    * @return The background color
172    */
173   Vector4 GetBackgroundColor() const;
174
175   /**
176    * @brief Get the Scene scene graph object
177    *
178    * @return the Scene scene graph object
179    */
180   SceneGraph::Scene* GetSceneObject() const;
181
182   /**
183    * Notify the surface has been rotated.
184    * When the device is rotated or the rotation event is received by display manager,
185    * this function will be called by window implementation.
186    *
187    * @param[in] width The width of rotated surface
188    * @param[in] height The height of rotated surface
189    * @param[in] windowOrientation the current window orientation
190    * @param[in] screenOrientation the current screen orientation
191    */
192   void SurfaceRotated(float width, float height, int32_t windowOrientation, int32_t screenOrientation);
193
194   /**
195    * @copydoc Dali::Integration::Scene::SetRotationCompletedAcknowledgement
196    */
197   void SetRotationCompletedAcknowledgement();
198
199   /**
200    * @copydoc Dali::Integration::Scene::IsRotationCompletedAcknowledgementSet
201    */
202   bool IsRotationCompletedAcknowledgementSet() const;
203
204   /**
205    * @copydoc Dali::Integration::Scene::GetCurrentSurfaceOrientation
206    */
207   int32_t GetCurrentSurfaceOrientation() const;
208
209   /**
210    * @copydoc Dali::Integration::Scene::GetCurrentScreenOrientation
211    */
212   int32_t GetCurrentScreenOrientation() const;
213
214   /**
215    * @copydoc Dali::Integration::Scene::GetCurrentSurfaceRect
216    */
217   const Rect<int32_t>& GetCurrentSurfaceRect() const;
218
219   /**
220    * @copydoc Dali::Integration::Scene::IsSurfaceRectChanged
221    */
222   bool IsSurfaceRectChanged() const;
223
224   /**
225    * @copydoc Dali::Integration::Scene::SetSurfaceRenderTarget
226    */
227   void SetSurfaceRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo);
228
229   /**
230    * Used by the EventProcessor to emit key event signals.
231    * @param[in] event The key event.
232    */
233   void EmitKeyEventSignal(const Dali::KeyEvent& event);
234
235   /**
236    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
237    * @param[in] event The key event.
238    * @return The return is true if KeyEvent is consumed, otherwise false.
239    */
240   bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
241
242   /**
243    * Used by the KeyEventProcessor to emit InterceptKeyEventSignal signals.
244    * @param[in] event The key event.
245    * @return The return is true if KeyEvent is consumed, otherwise false.
246    */
247   bool EmitInterceptKeyEventSignal(const Dali::KeyEvent& event);
248
249   /**
250    * Emits the event processing finished signal.
251    *
252    * @see Dali::Scene::SignalEventProcessingFinished()
253    */
254   void EmitEventProcessingFinishedSignal();
255
256   /**
257    * Emits the touched signal.
258    * @param[in] touch The touch event details.
259    */
260   void EmitTouchedSignal(const Dali::TouchEvent& touch);
261
262   /**
263    * Used by the EventProcessor to emit wheel event signals.
264    * @param[in] event The wheel event.
265    */
266   void EmitWheelEventSignal(const Dali::WheelEvent& event);
267
268   /**
269    * Used by the WheelEventProcessor to emit WheelEventGenerated signals.
270    * @param[in] event The wheel event.
271    * @return The return is true if WheelEvent is consumed, otherwise false.
272    */
273   bool EmitWheelEventGeneratedSignal(const Dali::WheelEvent& event);
274
275   /**
276    * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
277    */
278   void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
279
280   /**
281    * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
282    */
283   void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
284
285   /**
286    * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
287    */
288   void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
289
290   /**
291    * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
292    */
293   void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
294
295   /**
296    * @copydoc Integration::Scene::KeyEventSignal()
297    */
298   Integration::Scene::KeyEventSignalType& KeyEventSignal();
299
300   /**
301    * @copydoc Integration::Scene::KeyEventGeneratedSignal()
302    */
303   Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
304
305   /**
306    * @copydoc Integration::Scene::InterceptKeyEventSignal()
307    */
308   Integration::Scene::KeyEventGeneratedSignalType& InterceptKeyEventSignal();
309
310   /**
311    * @copydoc Integration::Scene::SignalEventProcessingFinished()
312    */
313   Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
314
315   /**
316     * @copydoc Integration::Scene::TouchedSignal()
317     */
318   Integration::Scene::TouchEventSignalType& TouchedSignal();
319
320   /**
321    * @copydoc Integration::Scene::sWheelEventSignal()
322    */
323   Integration::Scene::WheelEventSignalType& WheelEventSignal();
324
325   /**
326    * @copydoc Integration::Scene::WheelEventGeneratedSignal()
327    */
328   Integration::Scene::WheelEventGeneratedSignalType& WheelEventGeneratedSignal();
329
330 public:
331   /**
332    * From RenderTaskDefaults; retrieve the default root actor.
333    * @return The default root actor.
334    */
335   Actor& GetDefaultRootActor() override;
336
337   /**
338    * From RenderTaskDefaults; retrieve the default camera actor.
339    * @return The default camera actor.
340    */
341   CameraActor& GetDefaultCameraActor() const override;
342
343 private:
344   // Constructor
345   Scene();
346
347   /**
348    * Second-phase constructor.
349    *
350    * @param[in] size The size of the set surface
351    * @param[in] windowOrientation The rotated angle of the set surface for this scene
352    * @param[in] screenOrientation The rotated angle of the screen
353    */
354   void Initialize(Size size, int32_t windowOrientation, int32_t screenOrientation);
355
356   // Undefined
357   Scene(const Scene&) = delete;
358
359   // Undefined
360   Scene& operator=(const Scene& rhs) = delete;
361
362   /**
363    * Informs the scene that the set surface has been resized or rotated.
364    *
365    * @param[in] width The width of rotated surface
366    * @param[in] height The height of rotated surface
367    * @param[in] windowOrientation the current window orientation
368    * @param[in] screenOrientation the current screen orientation
369    */
370   void ChangedSurface(float width, float height, int32_t windowOrientation, int32_t screenOrientation);
371
372 private:
373   Internal::SceneGraph::Scene* mSceneObject;
374
375   Size mSize;
376
377   Vector2 mDpi;
378
379   Vector4 mBackgroundColor;
380
381   LayerPtr mRootLayer;
382
383   // Ordered list of currently on-stage layers
384   OwnerPointer<LayerList> mLayerList;
385
386   IntrusivePtr<CameraActor> mDefaultCamera;
387
388   // The list of render-tasks
389   IntrusivePtr<RenderTaskList> mRenderTaskList;
390
391   bool mDepthTreeDirty : 1; ///< True if the depth tree needs recalculating
392
393   EventProcessor mEventProcessor;
394
395   // The Surface's orientation
396   int32_t mSurfaceOrientation;
397
398   // The Screen's orientation
399   int32_t mScreenOrientation;
400
401   // The key event signal
402   Integration::Scene::KeyEventSignalType          mKeyEventSignal;
403   Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
404   Integration::Scene::KeyEventGeneratedSignalType mInterceptKeyEventSignal;
405
406   // The event processing finished signal
407   Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
408
409   // The touch signal
410   Integration::Scene::TouchEventSignalType mTouchedSignal;
411
412   // The wheel event signal
413   Integration::Scene::WheelEventSignalType          mWheelEventSignal;
414   Integration::Scene::WheelEventGeneratedSignalType mWheelEventGeneratedSignal;
415 };
416
417 } // namespace Internal
418
419 // Get impl of handle
420 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
421 {
422   DALI_ASSERT_ALWAYS(scene && "Scene handle is empty");
423   Dali::RefObject& object = scene.GetBaseObject();
424   return static_cast<Internal::Scene&>(object);
425 }
426
427 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
428 {
429   DALI_ASSERT_ALWAYS(scene && "Scene handle is empty");
430   const Dali::RefObject& object = scene.GetBaseObject();
431   return static_cast<const Internal::Scene&>(object);
432 }
433
434 } // namespace Dali
435
436 #endif // DALI_INTERNAL_SCENE_H