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