Add Overlay Layer in scene
[platform/core/uifw/dali-core.git] / dali / integration-api / scene.h
old mode 100755 (executable)
new mode 100644 (file)
index 3e2cbf5..51a8572
@@ -2,7 +2,7 @@
 #define DALI_SCENE_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  */
 
+// EXTERNAL INCLUDES
+#include <memory>
+
 // INTERNAL INCLUDES
-#include <dali/public-api/object/handle.h>
+#include <dali/graphics-api/graphics-controller.h>
+#include <dali/graphics-api/graphics-render-target-create-info.h>
+#include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/math/vector2.h>
+#include <dali/public-api/math/vector4.h>
+#include <dali/public-api/object/handle.h>
 
 namespace Dali
 {
-
 class Actor;
-struct KeyEvent;
+class KeyEvent;
 class Layer;
 class RenderTaskList;
-class TouchData;
-struct WheelEvent;
+class TouchEvent;
+class WheelEvent;
 
 namespace Internal DALI_INTERNAL
 {
-  class Scene;
+class Scene;
 }
 
-namespace Integration
+namespace Graphics
 {
+class RenderTarget;
+}
 
-class RenderSurface;
+namespace Integration
+{
 struct Event;
 
 /**
@@ -52,19 +61,25 @@ struct Event;
 class DALI_CORE_API Scene : public BaseHandle
 {
 public:
-  typedef Signal< void () > EventProcessingFinishedSignalType; ///< Event Processing finished signal type
-  typedef Signal< void (const Dali::KeyEvent&) > KeyEventSignalType; ///< Key event signal type
-  typedef Signal< void (const Dali::TouchData&) > TouchSignalType; ///< Touch signal type
-  typedef Signal< void (const Dali::WheelEvent&) > WheelEventSignalType; ///< Touched signal type
+  using EventProcessingFinishedSignalType = Signal<void()>;                        ///< Event Processing finished signal type
+  using KeyEventSignalType                = Signal<void(const Dali::KeyEvent&)>;   ///< Key event signal type
+  using KeyEventGeneratedSignalType       = Signal<bool(const Dali::KeyEvent&)>;   ///< key event generated signal type
+  using TouchEventSignalType              = Signal<void(const Dali::TouchEvent&)>; ///< Touch signal type
+  using WheelEventSignalType              = Signal<void(const Dali::WheelEvent&)>; ///< WheelEvent signal type
+  using WheelEventGeneratedSignalType     = Signal<bool(const Dali::WheelEvent&)>; ///< WheelEvent generated signal type
+
+  using FrameCallbackContainer = std::vector<std::pair<std::unique_ptr<CallbackBase>, int32_t> >;
 
   /**
    * @brief Create an initialized Scene handle.
    *
-   * @param[in] size The size of the scene in pixels as a Vector
+   * @param[in] size The size of the set surface for this scene
+   * @param[in] windowOrientation The rotated angle of the set surface for this scene
+   * @param[in] screenOrientation The rotated angle of the screen
    *
    * @return a handle to a newly allocated Dali resource.
    */
-  static Scene New( const Size& size );
+  static Scene New(Size size, int32_t windowOrientation = 0, int32_t screenOrientation = 0);
 
   /**
    * @brief Downcast an Object handle to Scene handle.
@@ -74,7 +89,7 @@ public:
    * @param[in] handle to An object
    * @return handle to a Scene object or an uninitialized handle
    */
-  static Scene DownCast( BaseHandle handle );
+  static Scene DownCast(BaseHandle handle);
 
   /**
    * @brief Create an uninitialized Scene handle.
@@ -107,6 +122,21 @@ public:
   Scene& operator=(const Scene& rhs);
 
   /**
+   * @brief This move constructor is required for (smart) pointer semantics.
+   *
+   * @param [in] handle A reference to the moved handle
+   */
+  Scene(Scene&& handle);
+
+  /**
+   * @brief This move assignment operator is required for (smart) pointer semantics.
+   *
+   * @param [in] rhs  A reference to the moved handle
+   * @return A reference to this
+   */
+  Scene& operator=(Scene&& rhs);
+
+  /**
    * @brief Adds a child Actor to the Scene.
    *
    * The child will be referenced.
@@ -114,7 +144,7 @@ public:
    * @pre The actor has been initialized.
    * @pre The actor does not have a parent.
    */
-  void Add(Actor& actor);
+  void Add(Actor actor);
 
   /**
    * @brief Removes a child Actor from the Scene.
@@ -123,7 +153,7 @@ public:
    * @param[in] actor The child
    * @pre The actor has been added to the stage.
    */
-  void Remove(Actor& actor);
+  void Remove(Actor actor);
 
   /**
    * @brief Returns the size of the Scene in pixels as a Vector.
@@ -139,7 +169,7 @@ public:
    * Sets horizontal and vertical pixels per inch value that is used by the display
    * @param[in] dpi Horizontal and vertical dpi value
    */
-  void SetDpi( Vector2 dpi );
+  void SetDpi(Vector2 dpi);
 
   /**
    * @brief Retrieves the DPI of the display device to which the scene is connected.
@@ -149,6 +179,20 @@ public:
   Vector2 GetDpi() const;
 
   /**
+   * @brief Sets the background color.
+   *
+   * @param[in] color The new background color
+   */
+  void SetBackgroundColor(const Vector4& color);
+
+  /**
+   * @brief Gets the background color of the render surface.
+   *
+   * @return The background color
+   */
+  Vector4 GetBackgroundColor() const;
+
+  /**
    * @brief Retrieves the list of render-tasks.
    *
    * @return A valid handle to a RenderTaskList
@@ -163,6 +207,14 @@ public:
   Layer GetRootLayer() const;
 
   /**
+   * @brief Returns the Scene's Overlay Layer.
+   * If there is no overlay layer yet, this creates the layer and an associated render task.
+   *
+   * @return The overlay layer
+   */
+  Layer GetOverlayLayer();
+
+  /**
    * @brief Queries the number of on-stage layers.
    *
    * Note that a default layer is always provided (count >= 1).
@@ -177,27 +229,44 @@ public:
    * @return The layer found at the given depth
    * @pre Depth is less than layer count; see GetLayerCount().
    */
-  Layer GetLayer( uint32_t depth ) const;
+  Layer GetLayer(uint32_t depth) const;
 
   /**
-   * @brief Binds the rendering surface to the scene
+   * @brief Informs the scene that the set surface has been resized.
    *
-   * @return The root layer
+   * @param[in] width The new width of the set surface
+   * @param[in] height The new height of the set surface
    */
-  void SetSurface( Integration::RenderSurface& surface );
+  void SurfaceResized(float width, float height);
 
   /**
-   * @brief Gets the rendering surface bound to the scene
+   * @brief Informs the scene that the surface has been replaced.
+   */
+  void SurfaceReplaced();
+
+  /**
+   * @brief Discards this Scene from the Core.
+   */
+  void Discard();
+
+  /**
+   * @brief Sets the render target for the surface.
    *
-   * @return The render surface
+   * @param[in] renderTarget The render target create info for the surface
+   */
+  void SetSurfaceRenderTarget(const Graphics::RenderTargetCreateInfo& createInfo);
+
+  /**
+   * @brief Retrieve the Scene that the given actor belongs to.
+   * @return The Scene.
    */
-  Integration::RenderSurface* GetSurface() const;
+  static Integration::Scene Get(Actor actor);
 
   /**
    * This function is called when an event is queued.
    * @param[in] event A event to queue.
    */
-  void QueueEvent( const Integration::Event& event );
+  void QueueEvent(const Integration::Event& event);
 
   /**
    * This function is called by Core when events are processed.
@@ -205,6 +274,117 @@ public:
   void ProcessEvents();
 
   /**
+   * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
+   *
+   * @param[in] callback The function to call
+   * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
+   *
+   * @note A callback of the following type may be used:
+   * @code
+   *   void MyFunction( int32_t frameId );
+   * @endcode
+   * This callback will be deleted once it is called.
+   *
+   * @note Ownership of the callback is passed onto this class.
+   */
+  void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
+
+  /**
+   * @brief Adds a callback that is called when the frame is displayed on the display.
+   *
+   * @param[in] callback The function to call
+   * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
+   *
+   * @note A callback of the following type may be used:
+   * @code
+   *   void MyFunction( int32_t frameId );
+   * @endcode
+   * This callback will be deleted once it is called.
+   *
+   * @note Ownership of the callback is passed onto this class.
+   */
+  void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
+
+  /**
+   * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver.
+   *
+   * @param[out] callbacks The callback list
+   *
+   * @note This is called in the update thread.
+   */
+  void GetFrameRenderedCallback(FrameCallbackContainer& callbacks);
+
+  /**
+   * @brief Gets the callback list that is called when the frame is displayed on the display.
+   *
+   * @param[out] callbacks The callback list
+   *
+   * @note This is called in the update thread.
+   */
+  void GetFramePresentedCallback(FrameCallbackContainer& callbacks);
+
+  /**
+   * @brief Informs the scene that the set surface has been rotated.
+   *
+   * @param[in] width The width of rotated surface
+   * @param[in] height The height of rotated surface
+   * @param[in] windowOrientation the current window orientation
+   * @param[in] screenOrientation the current screen orientation
+   */
+  void SurfaceRotated(float width, float height, int32_t windowOrientation, int32_t screenOrientation);
+
+  /**
+   * @brief Gets the current surface orientation. It gets the value from the scene object.
+   *
+   * @return The current surface orientation.
+   */
+  int32_t GetCurrentSurfaceOrientation() const;
+
+  /**
+   * @brief Gets the current screen orientation. It gets the value from the scene object.
+   *
+   * @return The current screen orientation.
+   */
+  int32_t GetCurrentScreenOrientation() const;
+
+  /**
+   * @brief Gets the current surface rectangle. It gets the value from the scene object.
+   *
+   * @return The current surface rectangle
+   */
+  const Rect<int32_t>& GetCurrentSurfaceRect() const;
+
+  /**
+   * Query wheter the surface rect is changed or not.
+   * @return true if the surface rect is changed.
+   */
+  bool IsSurfaceRectChanged() const;
+
+  /**
+   * @brief Send message to acknowledge for completing window rotation with current window orientation.
+   *
+   * If this function is called, the message is sent to render thread, then mSurfaceRectChanged in scene-graph-scene is set with true.
+   * After that, render thread checks whether window rotation event is received, mSurfaceRectChanged and the neccessary flag are set.
+   * If they are all true, rotation done function is called to complete window rotation.
+   */
+  void SetRotationCompletedAcknowledgement();
+
+  /**
+   * @brief Query wheter is set to acknowledge for completing surface rotation.
+   * @return true it should be acknowledged.
+   *
+   * If SetRotationCompletedAcknowledgement() is called and the related message is received to scene-graph-scene,
+   * then mSurfaceRectChanged in scene-graph-scene is set with true.
+   *
+   * When this function is called, the mSurfaceRectChanged in scene-graph-scene is return.
+   * Then, the flag will be reset.
+   *
+   * @note This function should be not called the application's main thread.
+   * Because this function should be called in windwow surface's postrender() function to complete window rotation manually.
+   */
+  bool IsRotationCompletedAcknowledgementSet() const;
+
+  /**
    * @brief This signal is emitted just after the event processing is finished.
    *
    * @return The signal to connect to
@@ -223,6 +403,37 @@ public:
   KeyEventSignalType& KeyEventSignal();
 
   /**
+   * @brief The user would connect to this signal to get a KeyEvent when KeyEvent is generated.
+   *
+   * If the control already consumed key event, KeyEventProcessor do not need to Emit keyEvent.
+   * Therefore, KeyinputManager first checks whether KeyEvent is generated as KeyEventGeneratedSignal.
+   * After that keyEventProcessor must invoke KeyEvent only if KeyEventGeneratedSignal () is not consumed.
+   *
+   * A callback of the following type may be connected:
+   * @code
+   *   bool YourCallbackName(const KeyEvent& event);
+   * @endcode
+   *
+   * @return The return is true if KeyEvent is consumed, otherwise false.
+   */
+  KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
+
+  /**
+   * @brief The user would connect to this signal to intercept a KeyEvent at window.
+   *
+   * Intercepts KeyEvents in the window before dispatching KeyEvents to the control.
+   * If a KeyEvent is consumed, no KeyEvent is delivered to the control.
+   *
+   * A callback of the following type may be connected:
+   * @code
+   *   bool YourCallbackName(const KeyEvent& event);
+   * @endcode
+   *
+   * @return The return is true if KeyEvent is consumed, otherwise false.
+   */
+  KeyEventGeneratedSignalType& InterceptKeyEventSignal();
+
+  /**
    * @brief This signal is emitted when the screen is touched and when the touch ends
    * (i.e. the down & up touch events only).
    *
@@ -231,13 +442,13 @@ public:
    * An interrupted event will also be emitted (if it occurs).
    * A callback of the following type may be connected:
    * @code
-   *   void YourCallbackName( TouchData event );
+   *   void YourCallbackName( TouchEvent event );
    * @endcode
    *
    * @return The touch signal to connect to
    * @note Motion events are not emitted.
    */
-  TouchSignalType& TouchSignal();
+  TouchEventSignalType& TouchedSignal();
 
   /**
    * @brief This signal is emitted when wheel event is received.
@@ -250,8 +461,24 @@ public:
    */
   WheelEventSignalType& WheelEventSignal();
 
-public: // Not intended for application developers
+  /**
+   * @brief When a custom wheel event occurs, it need to process the focused actor first.
+   *
+   * Therefore, KeyboardFocusManager first checks whether WheelEvent is generated as WheelEventGeneratedSignal.
+   * After that wheelEventProcessor must invoke WheelEvent only if wheelEventGeneratedSignal () is not consumed.
+   *
+   * This is only valid for custom wheel events.
+   *
+   * A callback of the following type may be connected:
+   * @code
+   *   bool YourCallbackName(const WheelEvent& event);
+   * @endcode
+   *
+   * @return The return is true if WheelEvent is consumed, otherwise false.
+   */
+  WheelEventGeneratedSignalType& WheelEventGeneratedSignal();
 
+public: // Not intended for application developers
   /**
    * @brief This constructor is used by Dali::New() methods.
    *