[dali_2.3.42] Merge branch 'devel/master'
[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) 2023 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::GetOverlayLayer
109    */
110   Dali::Layer GetOverlayLayer();
111
112   /**
113    * @copydoc Dali::Integration::Scene::GetLayerCount
114    */
115   uint32_t GetLayerCount() const;
116
117   /**
118    * @copydoc Dali::Integration::Scene::GetLayer
119    */
120   Dali::Layer GetLayer(uint32_t depth) const;
121
122   /**
123    * Notify the surface has been resized.
124    *
125    * @param[in] width The new width of the set surface
126    * @param[in] height The new height of the set surface
127    */
128   void SurfaceResized(float width, float height);
129
130   /**
131    * @copydoc Dali::Integration::Scene::SurfaceReplaced
132    */
133   void SurfaceReplaced();
134
135   /**
136    * @copydoc Dali::Integration::Scene::RemoveSceneObject
137    */
138   void RemoveSceneObject();
139
140   /**
141    * @copydoc Dali::Integration::Scene::Discard
142    */
143   void Discard();
144
145   /**
146    * Retrieve the ordered list of on-scene layers.
147    * @return The layer-list.
148    */
149   LayerList& GetLayerList() const;
150
151   /**
152    * Request that the depth tree is rebuilt
153    */
154   void RequestRebuildDepthTree();
155
156   /**
157    * This function is called when an event is queued.
158    * @param[in] event A event to queue.
159    */
160   void QueueEvent(const Integration::Event& event);
161
162   /**
163    * This function is called by Core when events are processed.
164    */
165   void ProcessEvents();
166
167   /**
168    * This function is called by Core when sending a interrupted event to a specific actor.
169    * @param[in] actor The actor on which the event should occur.
170    */
171   void SendInterruptedEvents(Dali::Internal::Actor* actor);
172
173   /**
174    * Rebuilds the depth tree at the end of the event frame if
175    * it was requested this frame.
176    */
177   void RebuildDepthTree();
178
179   /**
180    * @brief Sets the background color of the render surface.
181    * @param[in] color The new background color
182    */
183   void SetBackgroundColor(const Vector4& color);
184
185   /**
186    * @brief Gets the background color of the render surface.
187    * @return The background color
188    */
189   Vector4 GetBackgroundColor() const;
190
191   /**
192    * @brief Get the Scene scene graph object
193    *
194    * @return the Scene scene graph object
195    */
196   SceneGraph::Scene* GetSceneObject() const;
197
198   /**
199    * Notify the surface has been rotated.
200    * When the device is rotated or the rotation event is received by display manager,
201    * this function will be called by window implementation.
202    *
203    * @param[in] width The width of rotated surface
204    * @param[in] height The height of rotated surface
205    * @param[in] windowOrientation the current window orientation
206    * @param[in] screenOrientation the current screen orientation
207    */
208   void SurfaceRotated(float width, float height, int32_t windowOrientation, int32_t screenOrientation);
209
210   /**
211    * @copydoc Dali::Integration::Scene::SetRotationCompletedAcknowledgement
212    */
213   void SetRotationCompletedAcknowledgement();
214
215   /**
216    * @copydoc Dali::Integration::Scene::IsRotationCompletedAcknowledgementSet
217    */
218   bool IsRotationCompletedAcknowledgementSet() const;
219
220   /**
221    * @copydoc Dali::Integration::Scene::GetCurrentSurfaceOrientation
222    */
223   int32_t GetCurrentSurfaceOrientation() const;
224
225   /**
226    * @copydoc Dali::Integration::Scene::GetCurrentScreenOrientation
227    */
228   int32_t GetCurrentScreenOrientation() const;
229
230   /**
231    * @copydoc Dali::Integration::Scene::GetCurrentSurfaceRect
232    */
233   const Rect<int32_t>& GetCurrentSurfaceRect() const;
234
235   /**
236    * @copydoc Dali::Integration::Scene::GetSurfaceRectChangedCount
237    */
238   uint32_t GetSurfaceRectChangedCount() const;
239
240   /**
241    * @copydoc Dali::Integration::Scene::SetSurfaceRenderTarget
242    */
243   void SetSurfaceRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo);
244
245   /**
246    * @copydoc Dali::Integration::Scene::SetGeometryHittestEnabled
247    */
248   void SetGeometryHittestEnabled(bool enabled);
249
250   /**
251    * @copydoc Dali::Integration::Scene::IsGeometryHittestEnabled
252    */
253   bool IsGeometryHittestEnabled() const;
254
255   /**
256    * @copydoc Dali::Integration::Scene::SetNativeId
257    */
258   void SetNativeId(int32_t nativeId);
259
260   /**
261    * @copydoc Dali::Integration::Scene::GetNativeId
262    */
263   int32_t GetNativeId() const;
264
265   /**
266    * Used by the EventProcessor to emit key event signals.
267    * @param[in] event The key event.
268    */
269   void EmitKeyEventSignal(const Dali::KeyEvent& event);
270
271   /**
272    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
273    * @param[in] event The key event.
274    * @return The return is true if KeyEvent is consumed, otherwise false.
275    */
276   bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
277
278   /**
279    * Used by the KeyEventProcessor to emit InterceptKeyEventSignal signals.
280    * @param[in] event The key event.
281    * @return The return is true if KeyEvent is consumed, otherwise false.
282    */
283   bool EmitInterceptKeyEventSignal(const Dali::KeyEvent& event);
284
285   /**
286    * Emits the event processing finished signal.
287    *
288    * @see Dali::Scene::SignalEventProcessingFinished()
289    */
290   void EmitEventProcessingFinishedSignal();
291
292   /**
293    * Emits the touched signal.
294    * @param[in] touch The touch event details.
295    */
296   void EmitTouchedSignal(const Dali::TouchEvent& touch);
297
298   /**
299    * Used by the EventProcessor to emit wheel event signals.
300    * @param[in] event The wheel event.
301    */
302   void EmitWheelEventSignal(const Dali::WheelEvent& event);
303
304   /**
305    * Used by the WheelEventProcessor to emit WheelEventGenerated signals.
306    * @param[in] event The wheel event.
307    * @return The return is true if WheelEvent is consumed, otherwise false.
308    */
309   bool EmitWheelEventGeneratedSignal(const Dali::WheelEvent& event);
310
311   /**
312    * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
313    */
314   void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
315
316   /**
317    * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
318    */
319   void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
320
321   /**
322    * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
323    */
324   void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
325
326   /**
327    * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
328    */
329   void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
330
331   /**
332    * @copydoc Dali::Integration::Scene::KeepRendering
333    */
334   void KeepRendering(float durationSeconds);
335
336   /**
337    * @copydoc Dali::Integration::Scene::SetPartialUpdateEnabled()
338    */
339   void SetPartialUpdateEnabled(bool enabled);
340
341   /**
342    * @copydoc Dali::Integration::Scene::IsPartialUpdateEnabled()
343    */
344   bool IsPartialUpdateEnabled() const;
345
346   /**
347    * @copydoc Integration::Scene::KeyEventSignal()
348    */
349   Integration::Scene::KeyEventSignalType& KeyEventSignal();
350
351   /**
352    * @copydoc Integration::Scene::KeyEventGeneratedSignal()
353    */
354   Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
355
356   /**
357    * @copydoc Integration::Scene::InterceptKeyEventSignal()
358    */
359   Integration::Scene::KeyEventGeneratedSignalType& InterceptKeyEventSignal();
360
361   /**
362    * @copydoc Integration::Scene::SignalEventProcessingFinished()
363    */
364   Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
365
366   /**
367     * @copydoc Integration::Scene::TouchedSignal()
368     */
369   Integration::Scene::TouchEventSignalType& TouchedSignal();
370
371   /**
372    * @copydoc Integration::Scene::sWheelEventSignal()
373    */
374   Integration::Scene::WheelEventSignalType& WheelEventSignal();
375
376   /**
377    * @copydoc Integration::Scene::WheelEventGeneratedSignal()
378    */
379   Integration::Scene::WheelEventGeneratedSignalType& WheelEventGeneratedSignal();
380
381 public:
382   /**
383    * From RenderTaskDefaults; retrieve the default root actor.
384    * @return The default root actor.
385    */
386   Actor& GetDefaultRootActor() override;
387
388   /**
389    * From RenderTaskDefaults; retrieve the default camera actor.
390    * @return The default camera actor.
391    */
392   CameraActor& GetDefaultCameraActor() const override;
393
394 private:
395   // Constructor
396   Scene();
397
398   /**
399    * Second-phase constructor.
400    *
401    * @param[in] size The size of the set surface
402    * @param[in] windowOrientation The rotated angle of the set surface for this scene
403    * @param[in] screenOrientation The rotated angle of the screen
404    */
405   void Initialize(Size size, int32_t windowOrientation, int32_t screenOrientation);
406
407   // Undefined
408   Scene(const Scene&) = delete;
409
410   // Undefined
411   Scene& operator=(const Scene& rhs) = delete;
412
413   /**
414    * Informs the scene that the set surface has been resized or rotated.
415    *
416    * @param[in] width The width of rotated surface
417    * @param[in] height The height of rotated surface
418    * @param[in] windowOrientation the current window orientation
419    * @param[in] screenOrientation the current screen orientation
420    */
421   void ChangedSurface(float width, float height, int32_t windowOrientation, int32_t screenOrientation);
422
423 private:
424   Internal::SceneGraph::Scene* mSceneObject;
425
426   Size mSize;
427
428   Vector2 mDpi;
429
430   Vector4 mBackgroundColor;
431
432   LayerPtr mRootLayer;
433
434   LayerPtr mOverlayLayer;
435
436   // Ordered list of currently on-stage layers
437   OwnerPointer<LayerList> mLayerList;
438
439   IntrusivePtr<CameraActor> mDefaultCamera;
440
441   // The list of render-tasks
442   IntrusivePtr<RenderTaskList> mRenderTaskList;
443
444   bool mDepthTreeDirty : 1;       ///< True if the depth tree needs recalculating
445   bool mPartialUpdateEnabled : 1; ///< True if the partial update is enabled
446   bool mGeometryHittest : 1;      ///< True if the geometry hittest is enabled
447
448   EventProcessor mEventProcessor;
449
450   // The Surface's orientation
451   int32_t mSurfaceOrientation;
452
453   // The Screen's orientation
454   int32_t mScreenOrientation;
455
456   // The native window id
457   int32_t mNativeId;
458
459   // The key event signal
460   Integration::Scene::KeyEventSignalType          mKeyEventSignal;
461   Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
462   Integration::Scene::KeyEventGeneratedSignalType mInterceptKeyEventSignal;
463
464   // The event processing finished signal
465   Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
466
467   // The touch signal
468   Integration::Scene::TouchEventSignalType mTouchedSignal;
469
470   // The wheel event signal
471   Integration::Scene::WheelEventSignalType          mWheelEventSignal;
472   Integration::Scene::WheelEventGeneratedSignalType mWheelEventGeneratedSignal;
473 };
474
475 } // namespace Internal
476
477 // Get impl of handle
478 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
479 {
480   DALI_ASSERT_ALWAYS(scene && "Scene handle is empty");
481   Dali::RefObject& object = scene.GetBaseObject();
482   return static_cast<Internal::Scene&>(object);
483 }
484
485 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
486 {
487   DALI_ASSERT_ALWAYS(scene && "Scene handle is empty");
488   const Dali::RefObject& object = scene.GetBaseObject();
489   return static_cast<const Internal::Scene&>(object);
490 }
491
492 } // namespace Dali
493
494 #endif // DALI_INTERNAL_SCENE_H