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