5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
41 namespace Internal DALI_INTERNAL
58 * Scene creates a "world" that can be bound to a surface for rendering.
61 class DALI_CORE_API Scene : public BaseHandle
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
71 using FrameCallbackContainer = std::vector<std::pair<std::unique_ptr<CallbackBase>, int32_t> >;
74 * @brief Create an initialized Scene handle.
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
80 * @return a handle to a newly allocated Dali resource.
82 static Scene New(Size size, int32_t windowOrientation = 0, int32_t screenOrientation = 0);
85 * @brief Downcast an Object handle to Scene handle.
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
92 static Scene DownCast(BaseHandle handle);
95 * @brief Create an uninitialized Scene handle.
97 * This can be initialized with Scene::New(). Calling member
98 * functions with an uninitialized Dali::Object is not allowed.
105 * This is non-virtual since derived Handle types must not contain data or virtual methods.
110 * @brief This copy constructor is required for (smart) pointer semantics.
112 * @param [in] handle A reference to the copied handle
114 Scene(const Scene& handle);
117 * @brief This assignment operator is required for (smart) pointer semantics.
119 * @param [in] rhs A reference to the copied handle
120 * @return A reference to this
122 Scene& operator=(const Scene& rhs);
125 * @brief Adds a child Actor to the Scene.
127 * The child will be referenced.
128 * @param[in] actor The child
129 * @pre The actor has been initialized.
130 * @pre The actor does not have a parent.
132 void Add(Actor actor);
135 * @brief Removes a child Actor from the Scene.
137 * The child will be unreferenced.
138 * @param[in] actor The child
139 * @pre The actor has been added to the stage.
141 void Remove(Actor actor);
144 * @brief Returns the size of the Scene in pixels as a Vector.
146 * The x component will be the width of the Scene in pixels.
147 * The y component will be the height of the Scene in pixels.
149 * @return The size of the Scene as a Vector
151 Size GetSize() const;
154 * Sets horizontal and vertical pixels per inch value that is used by the display
155 * @param[in] dpi Horizontal and vertical dpi value
157 void SetDpi(Vector2 dpi);
160 * @brief Retrieves the DPI of the display device to which the scene is connected.
162 * @return The horizontal and vertical DPI
164 Vector2 GetDpi() const;
167 * @brief Sets the background color.
169 * @param[in] color The new background color
171 void SetBackgroundColor(const Vector4& color);
174 * @brief Gets the background color of the render surface.
176 * @return The background color
178 Vector4 GetBackgroundColor() const;
181 * @brief Retrieves the list of render-tasks.
183 * @return A valid handle to a RenderTaskList
185 Dali::RenderTaskList GetRenderTaskList() const;
188 * @brief Returns the Scene's Root Layer.
190 * @return The root layer
192 Layer GetRootLayer() const;
195 * @brief Queries the number of on-stage layers.
197 * Note that a default layer is always provided (count >= 1).
198 * @return The number of layers
200 uint32_t GetLayerCount() const;
203 * @brief Retrieves the layer at a specified depth.
205 * @param[in] depth The depth
206 * @return The layer found at the given depth
207 * @pre Depth is less than layer count; see GetLayerCount().
209 Layer GetLayer(uint32_t depth) const;
212 * @brief Informs the scene that the set surface has been resized.
214 * @param[in] width The new width of the set surface
215 * @param[in] height The new height of the set surface
217 void SurfaceResized(float width, float height);
220 * @brief Informs the scene that the surface has been replaced.
222 void SurfaceReplaced();
225 * @brief Discards this Scene from the Core.
230 * @brief Sets the render target for the surface.
232 * @param[in] renderTarget The render target create info for the surface
234 void SetSurfaceRenderTarget(const Graphics::RenderTargetCreateInfo& createInfo);
237 * @brief Retrieve the Scene that the given actor belongs to.
240 static Integration::Scene Get(Actor actor);
243 * This function is called when an event is queued.
244 * @param[in] event A event to queue.
246 void QueueEvent(const Integration::Event& event);
249 * This function is called by Core when events are processed.
251 void ProcessEvents();
254 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
256 * @param[in] callback The function to call
257 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
259 * @note A callback of the following type may be used:
261 * void MyFunction( int32_t frameId );
263 * This callback will be deleted once it is called.
265 * @note Ownership of the callback is passed onto this class.
267 void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
270 * @brief Adds a callback that is called when the frame is displayed on the display.
272 * @param[in] callback The function to call
273 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
275 * @note A callback of the following type may be used:
277 * void MyFunction( int32_t frameId );
279 * This callback will be deleted once it is called.
281 * @note Ownership of the callback is passed onto this class.
283 void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
286 * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver.
288 * @param[out] callbacks The callback list
290 * @note This is called in the update thread.
292 void GetFrameRenderedCallback(FrameCallbackContainer& callbacks);
295 * @brief Gets the callback list that is called when the frame is displayed on the display.
297 * @param[out] callbacks The callback list
299 * @note This is called in the update thread.
301 void GetFramePresentedCallback(FrameCallbackContainer& callbacks);
304 * @brief Informs the scene that the set surface has been rotated.
306 * @param[in] width The width of rotated surface
307 * @param[in] height The height of rotated surface
308 * @param[in] windowOrientation the current window orientation
309 * @param[in] screenOrientation the current screen orientation
311 void SurfaceRotated(float width, float height, int32_t windowOrientation, int32_t screenOrientation);
314 * @brief Gets the current surface orientation. It gets the value from the scene object.
316 * @return The current surface orientation.
318 int32_t GetCurrentSurfaceOrientation() const;
321 * @brief Gets the current screen orientation. It gets the value from the scene object.
323 * @return The current screen orientation.
325 int32_t GetCurrentScreenOrientation() const;
328 * @brief Gets the current surface rectangle. It gets the value from the scene object.
330 * @return The current surface rectangle
332 const Rect<int32_t>& GetCurrentSurfaceRect() const;
335 * Query wheter the surface rect is changed or not.
336 * @return true if the surface rect is changed.
338 bool IsSurfaceRectChanged() const;
341 * @brief Send message to acknowledge for completing window rotation with current window orientation.
343 * If this function is called, the message is sent to render thread, then mSurfaceRectChanged in scene-graph-scene is set with true.
344 * After that, render thread checks whether window rotation event is received, mSurfaceRectChanged and the neccessary flag are set.
345 * If they are all true, rotation done function is called to complete window rotation.
347 void SetRotationCompletedAcknowledgement();
350 * @brief Query wheter is set to acknowledge for completing surface rotation.
351 * @return true it should be acknowledged.
353 * If SetRotationCompletedAcknowledgement() is called and the related message is received to scene-graph-scene,
354 * then mSurfaceRectChanged in scene-graph-scene is set with true.
356 * When this function is called, the mSurfaceRectChanged in scene-graph-scene is return.
357 * Then, the flag will be reset.
359 * @note This function should be not called the application's main thread.
360 * Because this function should be called in windwow surface's postrender() function to complete window rotation manually.
362 bool IsRotationCompletedAcknowledgementSet() const;
365 * @brief This signal is emitted just after the event processing is finished.
367 * @return The signal to connect to
369 EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
372 * @brief This signal is emitted when key event is received.
374 * A callback of the following type may be connected:
376 * void YourCallbackName(const KeyEvent& event);
378 * @return The signal to connect to
380 KeyEventSignalType& KeyEventSignal();
383 * @brief The user would connect to this signal to get a KeyEvent when KeyEvent is generated.
385 * If the control already consumed key event, KeyEventProcessor do not need to Emit keyEvent.
386 * Therefore, KeyinputManager first checks whether KeyEvent is generated as KeyEventGeneratedSignal.
387 * After that keyEventProcessor must invoke KeyEvent only if KeyEventGeneratedSignal () is not consumed.
389 * A callback of the following type may be connected:
391 * bool YourCallbackName(const KeyEvent& event);
394 * @return The return is true if KeyEvent is consumed, otherwise false.
396 KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
399 * @brief The user would connect to this signal to intercept a KeyEvent at window.
401 * Intercepts KeyEvents in the window before dispatching KeyEvents to the control.
402 * If a KeyEvent is consumed, no KeyEvent is delivered to the control.
404 * A callback of the following type may be connected:
406 * bool YourCallbackName(const KeyEvent& event);
409 * @return The return is true if KeyEvent is consumed, otherwise false.
411 KeyEventGeneratedSignalType& InterceptKeyEventSignal();
414 * @brief This signal is emitted when the screen is touched and when the touch ends
415 * (i.e. the down & up touch events only).
417 * If there are multiple touch points, then this will be emitted when the first touch occurs and
418 * then when the last finger is lifted.
419 * An interrupted event will also be emitted (if it occurs).
420 * A callback of the following type may be connected:
422 * void YourCallbackName( TouchEvent event );
425 * @return The touch signal to connect to
426 * @note Motion events are not emitted.
428 TouchEventSignalType& TouchedSignal();
431 * @brief This signal is emitted when wheel event is received.
433 * A callback of the following type may be connected:
435 * void YourCallbackName(const WheelEvent& event);
437 * @return The signal to connect to
439 WheelEventSignalType& WheelEventSignal();
442 * @brief When a custom wheel event occurs, it need to process the focused actor first.
444 * Therefore, KeyboardFocusManager first checks whether WheelEvent is generated as WheelEventGeneratedSignal.
445 * After that wheelEventProcessor must invoke WheelEvent only if wheelEventGeneratedSignal () is not consumed.
447 * This is only valid for custom wheel events.
449 * A callback of the following type may be connected:
451 * bool YourCallbackName(const WheelEvent& event);
454 * @return The return is true if WheelEvent is consumed, otherwise false.
456 WheelEventGeneratedSignalType& WheelEventGeneratedSignal();
458 public: // Not intended for application developers
460 * @brief This constructor is used by Dali::New() methods.
462 * @param[in] scene A pointer to an internal Scene resource
464 explicit DALI_INTERNAL Scene(Internal::Scene* scene);
467 } // namespace Integration
471 #endif // DALI_SCENE_H