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