Add Overlay Layer in scene
[platform/core/uifw/dali-core.git] / dali / integration-api / scene.h
1 #ifndef DALI_SCENE_H
2 #define DALI_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 // EXTERNAL INCLUDES
22 #include <memory>
23
24 // INTERNAL INCLUDES
25 #include <dali/graphics-api/graphics-controller.h>
26 #include <dali/graphics-api/graphics-render-target-create-info.h>
27 #include <dali/public-api/common/vector-wrapper.h>
28 #include <dali/public-api/math/vector2.h>
29 #include <dali/public-api/math/vector4.h>
30 #include <dali/public-api/object/handle.h>
31
32 namespace Dali
33 {
34 class Actor;
35 class KeyEvent;
36 class Layer;
37 class RenderTaskList;
38 class TouchEvent;
39 class WheelEvent;
40
41 namespace Internal DALI_INTERNAL
42 {
43 class Scene;
44 }
45
46 namespace Graphics
47 {
48 class RenderTarget;
49 }
50
51 namespace Integration
52 {
53 struct Event;
54
55 /**
56  * @brief
57  *
58  * Scene creates a "world" that can be bound to a surface for rendering.
59  *
60  */
61 class DALI_CORE_API Scene : public BaseHandle
62 {
63 public:
64   using EventProcessingFinishedSignalType = Signal<void()>;                        ///< Event Processing finished signal type
65   using KeyEventSignalType                = Signal<void(const Dali::KeyEvent&)>;   ///< Key event signal type
66   using KeyEventGeneratedSignalType       = Signal<bool(const Dali::KeyEvent&)>;   ///< key event generated signal type
67   using TouchEventSignalType              = Signal<void(const Dali::TouchEvent&)>; ///< Touch signal type
68   using WheelEventSignalType              = Signal<void(const Dali::WheelEvent&)>; ///< WheelEvent signal type
69   using WheelEventGeneratedSignalType     = Signal<bool(const Dali::WheelEvent&)>; ///< WheelEvent generated signal type
70
71   using FrameCallbackContainer = std::vector<std::pair<std::unique_ptr<CallbackBase>, int32_t> >;
72
73   /**
74    * @brief Create an initialized Scene handle.
75    *
76    * @param[in] size The size of the set surface for this scene
77    * @param[in] windowOrientation The rotated angle of the set surface for this scene
78    * @param[in] screenOrientation The rotated angle of the screen
79    *
80    * @return a handle to a newly allocated Dali resource.
81    */
82   static Scene New(Size size, int32_t windowOrientation = 0, int32_t screenOrientation = 0);
83
84   /**
85    * @brief Downcast an Object handle to Scene handle.
86    *
87    * If handle points to a Scene object the downcast produces
88    * valid handle. If not the returned handle is left uninitialized.
89    * @param[in] handle to An object
90    * @return handle to a Scene object or an uninitialized handle
91    */
92   static Scene DownCast(BaseHandle handle);
93
94   /**
95    * @brief Create an uninitialized Scene handle.
96    *
97    * This can be initialized with Scene::New(). Calling member
98    * functions with an uninitialized Dali::Object is not allowed.
99    */
100   Scene();
101
102   /**
103    * @brief Destructor
104    *
105    * This is non-virtual since derived Handle types must not contain data or virtual methods.
106    */
107   ~Scene();
108
109   /**
110    * @brief This copy constructor is required for (smart) pointer semantics.
111    *
112    * @param [in] handle A reference to the copied handle
113    */
114   Scene(const Scene& handle);
115
116   /**
117    * @brief This assignment operator is required for (smart) pointer semantics.
118    *
119    * @param [in] rhs  A reference to the copied handle
120    * @return A reference to this
121    */
122   Scene& operator=(const Scene& rhs);
123
124   /**
125    * @brief This move constructor is required for (smart) pointer semantics.
126    *
127    * @param [in] handle A reference to the moved handle
128    */
129   Scene(Scene&& handle);
130
131   /**
132    * @brief This move assignment operator is required for (smart) pointer semantics.
133    *
134    * @param [in] rhs  A reference to the moved handle
135    * @return A reference to this
136    */
137   Scene& operator=(Scene&& rhs);
138
139   /**
140    * @brief Adds a child Actor to the Scene.
141    *
142    * The child will be referenced.
143    * @param[in] actor The child
144    * @pre The actor has been initialized.
145    * @pre The actor does not have a parent.
146    */
147   void Add(Actor actor);
148
149   /**
150    * @brief Removes a child Actor from the Scene.
151    *
152    * The child will be unreferenced.
153    * @param[in] actor The child
154    * @pre The actor has been added to the stage.
155    */
156   void Remove(Actor actor);
157
158   /**
159    * @brief Returns the size of the Scene in pixels as a Vector.
160    *
161    * The x component will be the width of the Scene in pixels.
162    * The y component will be the height of the Scene in pixels.
163    *
164    * @return The size of the Scene as a Vector
165    */
166   Size GetSize() const;
167
168   /**
169    * Sets horizontal and vertical pixels per inch value that is used by the display
170    * @param[in] dpi Horizontal and vertical dpi value
171    */
172   void SetDpi(Vector2 dpi);
173
174   /**
175    * @brief Retrieves the DPI of the display device to which the scene is connected.
176    *
177    * @return The horizontal and vertical DPI
178    */
179   Vector2 GetDpi() const;
180
181   /**
182    * @brief Sets the background color.
183    *
184    * @param[in] color The new background color
185    */
186   void SetBackgroundColor(const Vector4& color);
187
188   /**
189    * @brief Gets the background color of the render surface.
190    *
191    * @return The background color
192    */
193   Vector4 GetBackgroundColor() const;
194
195   /**
196    * @brief Retrieves the list of render-tasks.
197    *
198    * @return A valid handle to a RenderTaskList
199    */
200   Dali::RenderTaskList GetRenderTaskList() const;
201
202   /**
203    * @brief Returns the Scene's Root Layer.
204    *
205    * @return The root layer
206    */
207   Layer GetRootLayer() const;
208
209   /**
210    * @brief Returns the Scene's Overlay Layer.
211    * If there is no overlay layer yet, this creates the layer and an associated render task.
212    *
213    * @return The overlay layer
214    */
215   Layer GetOverlayLayer();
216
217   /**
218    * @brief Queries the number of on-stage layers.
219    *
220    * Note that a default layer is always provided (count >= 1).
221    * @return The number of layers
222    */
223   uint32_t GetLayerCount() const;
224
225   /**
226    * @brief Retrieves the layer at a specified depth.
227    *
228    * @param[in] depth The depth
229    * @return The layer found at the given depth
230    * @pre Depth is less than layer count; see GetLayerCount().
231    */
232   Layer GetLayer(uint32_t depth) const;
233
234   /**
235    * @brief Informs the scene that the set surface has been resized.
236    *
237    * @param[in] width The new width of the set surface
238    * @param[in] height The new height of the set surface
239    */
240   void SurfaceResized(float width, float height);
241
242   /**
243    * @brief Informs the scene that the surface has been replaced.
244    */
245   void SurfaceReplaced();
246
247   /**
248    * @brief Discards this Scene from the Core.
249    */
250   void Discard();
251
252   /**
253    * @brief Sets the render target for the surface.
254    *
255    * @param[in] renderTarget The render target create info for the surface
256    */
257   void SetSurfaceRenderTarget(const Graphics::RenderTargetCreateInfo& createInfo);
258
259   /**
260    * @brief Retrieve the Scene that the given actor belongs to.
261    * @return The Scene.
262    */
263   static Integration::Scene Get(Actor actor);
264
265   /**
266    * This function is called when an event is queued.
267    * @param[in] event A event to queue.
268    */
269   void QueueEvent(const Integration::Event& event);
270
271   /**
272    * This function is called by Core when events are processed.
273    */
274   void ProcessEvents();
275
276   /**
277    * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
278    *
279    * @param[in] callback The function to call
280    * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
281    *
282    * @note A callback of the following type may be used:
283    * @code
284    *   void MyFunction( int32_t frameId );
285    * @endcode
286    * This callback will be deleted once it is called.
287    *
288    * @note Ownership of the callback is passed onto this class.
289    */
290   void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
291
292   /**
293    * @brief Adds a callback that is called when the frame is displayed on the display.
294    *
295    * @param[in] callback The function to call
296    * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
297    *
298    * @note A callback of the following type may be used:
299    * @code
300    *   void MyFunction( int32_t frameId );
301    * @endcode
302    * This callback will be deleted once it is called.
303    *
304    * @note Ownership of the callback is passed onto this class.
305    */
306   void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
307
308   /**
309    * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver.
310    *
311    * @param[out] callbacks The callback list
312    *
313    * @note This is called in the update thread.
314    */
315   void GetFrameRenderedCallback(FrameCallbackContainer& callbacks);
316
317   /**
318    * @brief Gets the callback list that is called when the frame is displayed on the display.
319    *
320    * @param[out] callbacks The callback list
321    *
322    * @note This is called in the update thread.
323    */
324   void GetFramePresentedCallback(FrameCallbackContainer& callbacks);
325
326   /**
327    * @brief Informs the scene that the set surface has been rotated.
328    *
329    * @param[in] width The width of rotated surface
330    * @param[in] height The height of rotated surface
331    * @param[in] windowOrientation the current window orientation
332    * @param[in] screenOrientation the current screen orientation
333    */
334   void SurfaceRotated(float width, float height, int32_t windowOrientation, int32_t screenOrientation);
335
336   /**
337    * @brief Gets the current surface orientation. It gets the value from the scene object.
338    *
339    * @return The current surface orientation.
340    */
341   int32_t GetCurrentSurfaceOrientation() const;
342
343   /**
344    * @brief Gets the current screen orientation. It gets the value from the scene object.
345    *
346    * @return The current screen orientation.
347    */
348   int32_t GetCurrentScreenOrientation() const;
349
350   /**
351    * @brief Gets the current surface rectangle. It gets the value from the scene object.
352    *
353    * @return The current surface rectangle
354    */
355   const Rect<int32_t>& GetCurrentSurfaceRect() const;
356
357   /**
358    * Query wheter the surface rect is changed or not.
359    * @return true if the surface rect is changed.
360    */
361   bool IsSurfaceRectChanged() const;
362
363   /**
364    * @brief Send message to acknowledge for completing window rotation with current window orientation.
365    *
366    * If this function is called, the message is sent to render thread, then mSurfaceRectChanged in scene-graph-scene is set with true.
367    * After that, render thread checks whether window rotation event is received, mSurfaceRectChanged and the neccessary flag are set.
368    * If they are all true, rotation done function is called to complete window rotation.
369    */
370   void SetRotationCompletedAcknowledgement();
371
372   /**
373    * @brief Query wheter is set to acknowledge for completing surface rotation.
374    * @return true it should be acknowledged.
375    *
376    * If SetRotationCompletedAcknowledgement() is called and the related message is received to scene-graph-scene,
377    * then mSurfaceRectChanged in scene-graph-scene is set with true.
378    *
379    * When this function is called, the mSurfaceRectChanged in scene-graph-scene is return.
380    * Then, the flag will be reset.
381    *
382    * @note This function should be not called the application's main thread.
383    * Because this function should be called in windwow surface's postrender() function to complete window rotation manually.
384    */
385   bool IsRotationCompletedAcknowledgementSet() const;
386
387   /**
388    * @brief This signal is emitted just after the event processing is finished.
389    *
390    * @return The signal to connect to
391    */
392   EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
393
394   /**
395    * @brief This signal is emitted when key event is received.
396    *
397    * A callback of the following type may be connected:
398    * @code
399    *   void YourCallbackName(const KeyEvent& event);
400    * @endcode
401    * @return The signal to connect to
402    */
403   KeyEventSignalType& KeyEventSignal();
404
405   /**
406    * @brief The user would connect to this signal to get a KeyEvent when KeyEvent is generated.
407    *
408    * If the control already consumed key event, KeyEventProcessor do not need to Emit keyEvent.
409    * Therefore, KeyinputManager first checks whether KeyEvent is generated as KeyEventGeneratedSignal.
410    * After that keyEventProcessor must invoke KeyEvent only if KeyEventGeneratedSignal () is not consumed.
411    *
412    * A callback of the following type may be connected:
413    * @code
414    *   bool YourCallbackName(const KeyEvent& event);
415    * @endcode
416    *
417    * @return The return is true if KeyEvent is consumed, otherwise false.
418    */
419   KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
420
421   /**
422    * @brief The user would connect to this signal to intercept a KeyEvent at window.
423    *
424    * Intercepts KeyEvents in the window before dispatching KeyEvents to the control.
425    * If a KeyEvent is consumed, no KeyEvent is delivered to the control.
426    *
427    * A callback of the following type may be connected:
428    * @code
429    *   bool YourCallbackName(const KeyEvent& event);
430    * @endcode
431    *
432    * @return The return is true if KeyEvent is consumed, otherwise false.
433    */
434   KeyEventGeneratedSignalType& InterceptKeyEventSignal();
435
436   /**
437    * @brief This signal is emitted when the screen is touched and when the touch ends
438    * (i.e. the down & up touch events only).
439    *
440    * If there are multiple touch points, then this will be emitted when the first touch occurs and
441    * then when the last finger is lifted.
442    * An interrupted event will also be emitted (if it occurs).
443    * A callback of the following type may be connected:
444    * @code
445    *   void YourCallbackName( TouchEvent event );
446    * @endcode
447    *
448    * @return The touch signal to connect to
449    * @note Motion events are not emitted.
450    */
451   TouchEventSignalType& TouchedSignal();
452
453   /**
454    * @brief This signal is emitted when wheel event is received.
455    *
456    * A callback of the following type may be connected:
457    * @code
458    *   void YourCallbackName(const WheelEvent& event);
459    * @endcode
460    * @return The signal to connect to
461    */
462   WheelEventSignalType& WheelEventSignal();
463
464   /**
465    * @brief When a custom wheel event occurs, it need to process the focused actor first.
466    *
467    * Therefore, KeyboardFocusManager first checks whether WheelEvent is generated as WheelEventGeneratedSignal.
468    * After that wheelEventProcessor must invoke WheelEvent only if wheelEventGeneratedSignal () is not consumed.
469    *
470    * This is only valid for custom wheel events.
471    *
472    * A callback of the following type may be connected:
473    * @code
474    *   bool YourCallbackName(const WheelEvent& event);
475    * @endcode
476    *
477    * @return The return is true if WheelEvent is consumed, otherwise false.
478    */
479   WheelEventGeneratedSignalType& WheelEventGeneratedSignal();
480
481 public: // Not intended for application developers
482   /**
483    * @brief This constructor is used by Dali::New() methods.
484    *
485    * @param[in] scene A pointer to an internal Scene resource
486    */
487   explicit DALI_INTERNAL Scene(Internal::Scene* scene);
488 };
489
490 } // namespace Integration
491
492 } // namespace Dali
493
494 #endif // DALI_SCENE_H