Fix error of overlay layer
[platform/core/uifw/dali-core.git] / dali / internal / event / render-tasks / render-task-impl.h
index 8b57800..0969916 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_RENDER_TASK_H__
-#define __DALI_INTERNAL_RENDER_TASK_H__
+#ifndef DALI_INTERNAL_RENDER_TASK_H
+#define DALI_INTERNAL_RENDER_TASK_H
 
 /*
- * Copyright (c) 2018 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.
 
 // INTERNAL INCLUDES
 #include <dali/public-api/object/base-object.h>
+#include <dali/public-api/object/weak-handle.h>
 #include <dali/public-api/render-tasks/render-task.h>
-#include <dali/internal/event/images/frame-buffer-image-impl.h>
+
 #include <dali/internal/event/common/object-impl.h>
+#include <dali/internal/event/events/actor-observer.h>
 #include <dali/internal/event/rendering/frame-buffer-impl.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 class Actor;
 class CameraActor;
 class EventThreadServices;
+class RenderTaskList;
 
 namespace SceneGraph
 {
+class RenderTaskList;
 class RenderTask;
 class Camera;
-}
+} // namespace SceneGraph
+
+using RenderTaskPtr = IntrusivePtr<RenderTask>;
 
 class RenderTask : public Object
 {
 public:
-
-  typedef Dali::RenderTask::ScreenToFrameBufferFunction ScreenToFrameBufferFunction;
+  using ScreenToFrameBufferFunction = Dali::RenderTask::ScreenToFrameBufferFunction;
 
   /**
    * Creates a new RenderTask.
+   *
+   * @param[in] sourceActor The source actor.
+   * @param[in] cameraActor The camera actor.
+   * @param[in] renderTaskList The render task list.
+   * @param[in] isOverlayTask True if this render task is overlay task. default is false.
+   * @return The created render task
    */
-  static RenderTask* New();
+  static RenderTaskPtr New(Actor* sourceActor, CameraActor* cameraActor, RenderTaskList& renderTaskList, bool isOverlayTask = false);
 
   /**
    * @copydoc Dali::RenderTask::SetSourceActor()
    */
-  void SetSourceActor( Actor* actor );
+  void SetSourceActor(Actor* actor);
 
   /**
    * @copydoc Dali::RenderTask::GetSourceActor()
@@ -65,7 +74,7 @@ public:
   /**
    * @copydoc Dali::RenderTask::SetExclusive()
    */
-  void SetExclusive( bool exclusive );
+  void SetExclusive(bool exclusive);
 
   /**
    * @copydoc Dali::RenderTask::IsExclusive()
@@ -75,7 +84,7 @@ public:
   /**
    * @copydoc Dali::RenderTask::SetInputEnabled()
    */
-  void SetInputEnabled( bool enabled );
+  void SetInputEnabled(bool enabled);
 
   /**
    * @copydoc Dali::RenderTask::GetInputEnabled()
@@ -85,7 +94,7 @@ public:
   /**
    * @copydoc Dali::RenderTask::SetCameraActor()
    */
-  void SetCameraActor( CameraActor* cameraActor );
+  void SetCameraActor(CameraActor* cameraActor);
 
   /**
    * @copydoc Dali::RenderTask::GetCameraActor()
@@ -93,29 +102,19 @@ public:
   CameraActor* GetCameraActor() const;
 
   /**
-   * @copydoc Dali::RenderTask::SetTargetFrameBuffer()
-   */
-  void SetTargetFrameBuffer( FrameBufferImagePtr frameBuffer );
-
-  /**
-   * @copydoc Dali::RenderTask::GetTargetFrameBuffer
-   */
-  FrameBufferImage* GetTargetFrameBuffer() const;
-
-  /**
     * @copydoc Dali::RenderTask::SetFrameBuffer()
     */
-   void SetFrameBuffer( FrameBufferPtr frameBuffer );
+  void SetFrameBuffer(FrameBufferPtr frameBuffer);
 
-   /**
+  /**
     * @copydoc Dali::RenderTask::GetFrameBuffer
     */
-   FrameBuffer* GetFrameBuffer() const;
+  FrameBuffer* GetFrameBuffer() const;
 
   /**
    * @copydoc Dali::RenderTask::SetScreenToFrameBufferFunction
    */
-  void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
+  void SetScreenToFrameBufferFunction(ScreenToFrameBufferFunction conversionFunction);
 
   /**
    * @copydoc Dali::RenderTask::GetScreenToFrameBufferFunction
@@ -123,14 +122,29 @@ public:
   ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
 
   /**
-   * copydoc Dali::RenderTask::SetScreenToFrameBufferMappingActor
+   * @copydoc Dali::RenderTask::SetScreenToFrameBufferMappingActor
+   */
+  void SetScreenToFrameBufferMappingActor(Dali::Actor& mappingActor);
+
+  /**
+   * @copydoc Dali::RenderTask::GetScreenToFrameBufferMAppingActor
    */
-  void SetScreenToFrameBufferMappingActor( Actor* mappingActor );
+  Dali::Actor GetScreenToFrameBufferMappingActor() const;
 
   /**
-   * copydoc Dali::RenderTask::GetScreenToFrameBufferMAppingActor
+   * @copydoc Dali::RenderTask::SetViewportGuideActor
    */
-  Actor* GetScreenToFrameBufferMappingActor() const;
+  void SetViewportGuideActor(Actor* actor);
+
+  /**
+   * @copydoc Dali::RenderTask::GetViewportGuideActor
+   */
+  Actor* GetViewportGuideActor() const;
+
+  /**
+   * @copydoc Dali::RenderTask::ResetViewportGuideActor
+   */
+  void ResetViewportGuideActor();
 
   /**
    * @copydoc Dali::RenderTask::SetViewportPosition
@@ -155,17 +169,17 @@ public:
   /**
    * @copydoc Dali::RenderTask::SetViewport()
    */
-  void SetViewport( const Viewport& viewport );
+  void SetViewport(const Viewport& viewport);
 
   /**
    * @param[out] viewPort instance to copy the values into
    */
-  void GetViewport( Viewport& viewPort ) const;
+  void GetViewport(Viewport& viewPort) const;
 
   /**
    * @copydoc Dali::RenderTask::SetClearColor()
    */
-  void SetClearColor( const Vector4& color );
+  void SetClearColor(const Vector4& color);
 
   /**
    * @copydoc Dali::RenderTask::GetClearColor()
@@ -176,18 +190,18 @@ public:
    * Indicate whether GL sync is required for native render target.
    * @param[in] requiresSync whether GL sync is required.
    */
-  void SetSyncRequired( bool requiresSync );
+  void SetSyncRequired(bool requiresSync);
 
   /**
    * Query whether the sync object is required for native render target.
    * @return True if the sync object is required, false otherwise.
    */
- bool IsSyncRequired() const;
 bool IsSyncRequired() const;
 
   /**
    * @copydoc Dali::RenderTask::SetClearEnabled()
    */
-  void SetClearEnabled( bool enabled );
+  void SetClearEnabled(bool enabled);
 
   /**
    * @copydoc Dali::RenderTask::GetClearEnabled()
@@ -197,7 +211,7 @@ public:
   /**
    * @copydoc Dali::RenderTask::SetCullMode()
    */
-  void SetCullMode( bool mode );
+  void SetCullMode(bool mode);
 
   /**
    * @copydoc Dali::RenderTask::GetCullMode()
@@ -207,7 +221,7 @@ public:
   /**
    * @copydoc Dali::RenderTask::SetRefreshRate()
    */
-  void SetRefreshRate( uint32_t refreshRate );
+  void SetRefreshRate(uint32_t refreshRate);
 
   /**
    * @copydoc Dali::RenderTask::GetRefreshRate()
@@ -219,124 +233,70 @@ public:
    * @param[in,out] screenCoords The screen coordinate, which may be converted (for hit-testing actors which are rendered off-screen).
    * @return True the render-task can be used for input-handling; otherwise the output parameters are not valid.
    */
-  bool IsHittable( Vector2& screenCoords ) const;
+  bool IsHittable(Vector2& screenCoords) const;
 
   /**
    * Translates screen coordinates to render task coordinates for offscreen render tasks
    * @param[in,out] screenCoords The screen coordinates, which may be converted (for off-screen).
    * @return false if the conversion function decides the coordinates are not inside. returns true if there is no conversion function
    */
-  bool TranslateCoordinates( Vector2& screenCoords ) const;
+  bool TranslateCoordinates(Vector2& screenCoords) const;
 
   /**
    * @copydoc Dali::RenderTask::WorldToViewport()
    */
-  bool WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const;
+  bool WorldToViewport(const Vector3position, float& viewportX, float& viewportY) const;
 
   /**
    * @copydoc Dali::RenderTask::ViewportToLocal()
    */
-  bool ViewportToLocal(Actor* actor, float viewportX, float viewportY, float &localX, float &localY) const;
+  bool ViewportToLocal(Actor* actor, float viewportX, float viewportY, float& localX, float& localY) const;
 
 public: // Used by RenderTaskList, which owns the SceneGraph::RenderTasks
-
-  /**
-   * Create the scene-graph RenderTask object.
-   * @pre CreateSceneObject has not already been called.
-   * @return A newly allocated scene-graph object; the caller takes ownership.
-   */
-  SceneGraph::RenderTask* CreateSceneObject();
-
   /**
    * Retrieve the scene-graph RenderTask object.
-   * @return The scene-graph object, or NULL if this has been discarded.
+   * @return The scene-graph object
    */
-  SceneGraph::RenderTask* GetRenderTaskSceneObject();
+  const SceneGraph::RenderTask& GetRenderTaskSceneObject() const;
 
   /**
-   * Discard the scene-graph RenderTask object.
+   * Retrieve the render task list RenderTask object belongs to.
+   * @return The render task list
    */
-  void DiscardSceneObject();
+  RenderTaskList& GetRenderTaskList() const;
 
 public: // Implementation of Object
-
-  /**
-   * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
-   */
-  virtual uint32_t GetDefaultPropertyCount() const;
-
-  /**
-   * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
-   */
-  virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
-
-  /**
-   * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
-   */
-  virtual const char* GetDefaultPropertyName(Property::Index index) const;
-
-  /**
-   * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
-   */
-  virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
-
-  /**
-   * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
-   */
-  virtual bool IsDefaultPropertyWritable(Property::Index index) const;
-
-  /**
-   * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
-   */
-  virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
-
-  /**
-   * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
-   */
-  virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
-
-  /**
-   * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
-   */
-  virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
-
   /**
    * @copydoc Dali::Internal::Object::SetDefaultProperty()
    */
-  virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
+  void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
 
   /**
    * @copydoc Dali::Internal::Object::GetDefaultProperty()
    */
-  virtual Property::Value GetDefaultProperty( Property::Index index ) const;
+  Property::Value GetDefaultProperty(Property::Index index) const override;
 
   /**
    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
    */
-  virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
+  Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
 
   /**
    * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
    */
-  virtual void OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType );
-
-  /**
-   * @copydoc Dali::Internal::Object::GetSceneObject()
-   */
-  virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
+  void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
 
   /**
    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
    */
-  virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
+  const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
 
   /**
    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
    */
-  virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
+  const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
 
 public: //signals
-
   /**
    * Query whether a Finished signal should be emitted for this render-task.
    * This should only be called by NotificationManager, before signals are emitted.
@@ -365,99 +325,35 @@ public: //signals
    * @return True if the signal was connected.
    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
    */
-  static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
+  static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
 
 protected:
-
   /**
-   * Construct a new RenderTask.
+   * Constructor.
+   *
+   * @param[in] sceneObject The scene graph object
+   * @param[in] renderTaskList The render task list
    */
-  RenderTask();
+  RenderTask(const SceneGraph::RenderTask* sceneObject, RenderTaskList& renderTaskList);
 
   /**
    * A reference counted object may only be deleted by calling Unreference()
    */
-  virtual ~RenderTask();
-
-  /**
-   * Helper class for connecting Nodes to the scene-graph RenderTask
-   */
-  class Connector : public Object::Observer
-  {
-  public:
-
-    enum Type
-    {
-      SOURCE_CONNECTOR,
-      CAMERA_CONNECTOR,
-      MAPPING_CONNECTOR
-    };
-
-    /**
-     * Create the helper class
-     */
-    Connector( Type type, RenderTask& renderTask );
-
-    /**
-     * Non-virtual destructor; not suitable as a base object.
-     */
-    ~Connector();
-
-    /**
-     * Set the actor to be observed.
-     * @param[in] actor The actor to be observed.
-     */
-    void SetActor( Actor* actor );
-
-    /**
-     * Update the scene-graph RenderTask with a new source/camera Node.
-     */
-    void UpdateRenderTask();
-
-  public: // From Object::Observer
-
-    /**
-     * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded
-     */
-    virtual void SceneObjectAdded( Object& object );
-
-    /**
-     * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded
-     */
-    virtual void SceneObjectRemoved( Object& object );
-
-    /**
-     * @copydoc Dali::Internal::Object::Observer::ObjectDestroyed
-     */
-    virtual void ObjectDestroyed( Object& object );
+  ~RenderTask() override;
 
-  private:
-
-    // Undefined
-    Connector(const Connector&);
-
-    // Undefined
-    Connector& operator=(const Connector& rhs);
-
-  public:
-
-    const Type mType;
-
-    RenderTask& mRenderTask;
-
-    Actor* mActor; ///< Raw-pointer to the actor; not owned.
-    const SceneGraph::Camera* mCamera;    ///< Raw-pointer to camera scene-graph object; not owned.
-  };
+private: // not copyable
+  RenderTask()                  = delete;
+  RenderTask(const RenderTask&) = delete;
+  RenderTask& operator=(const RenderTask&) = delete;
 
 private:
+  ActorObserver           mSourceActor;        ///< Source actor
+  ActorObserver           mCameraActor;        ///< Camera actor
+  ActorObserver           mViewportGuideActor; ///< Actor to matching viewport of this render task to this Actor.
+  WeakHandle<Dali::Actor> mInputMappingActor;  /// used to mapping screen to frame buffer coordinate, not kept alive by rendertask
+  RenderTaskList&         mRenderTaskList;     ///< The render task list
 
-  SceneGraph::RenderTask* mSceneObject; ///< Raw-pointer to the scene-graph object; not owned.
-
-  Connector mSourceConnector; ///< Responsible for connecting/disconnecting source Nodes
-  Connector mCameraConnector; ///< Responsible for connecting/disconnecting camera Nodes
-  Connector mMappingConnector; /// Responsible for connecting/disconnecting actor node, which used to mapping screen to frame buffer coordinate
-
-  Vector4 mClearColor;       ///< Optional clear color
+  Vector4 mClearColor; ///< Optional clear color
 
   Vector2 mViewportPosition; ///< The cached viewport position
   Vector2 mViewportSize;     ///< The cached viewport size
@@ -466,20 +362,18 @@ private:
 
   uint32_t mRefreshOnceCounter;
 
-  FrameBufferImagePtr mFrameBufferImage;  ///< Optional off-screen render target.
-  FrameBufferPtr  mFrameBuffer;
-
+  FrameBufferPtr mFrameBuffer;
 
   Dali::RenderTask::ScreenToFrameBufferFunction mScreenToFrameBufferFunction; ///< Used to convert screen to frame-buffer coordinates
 
-  bool mExclusive     : 1; ///< True if the render-task has exclusive access to the source Nodes.
-  bool mInputEnabled  : 1; ///< True if the render-task should be considered for input handling.
-  bool mClearEnabled  : 1; ///< True if the render-task should be clear the color buffer.
-  bool mCullMode      : 1; ///< True if the render-task's actors should be culled
-  bool mRequiresSync  : 1; ///< True if the GL sync is required to track the render of.
+  bool mExclusive : 1;    ///< True if the render-task has exclusive access to the source Nodes.
+  bool mInputEnabled : 1; ///< True if the render-task should be considered for input handling.
+  bool mClearEnabled : 1; ///< True if the render-task should be clear the color buffer.
+  bool mCullMode : 1;     ///< True if the render-task's actors should be culled
+  bool mRequiresSync : 1; ///< True if the GL sync is required to track the render of.
 
   //Signals
-  Dali::RenderTask::RenderTaskSignalType  mSignalFinished; ///< Signal emmited when the render task has been processed.
+  Dali::RenderTask::RenderTaskSignalType mSignalFinished; ///< Signal emmited when the render task has been processed.
 };
 
 } // namespace Internal
@@ -506,4 +400,4 @@ inline const Internal::RenderTask& GetImplementation(const Dali::RenderTask& tas
 
 } // namespace Dali
 
-#endif //__DALI_INTERNAL_RENDER_TASK_H__
+#endif // DALI_INTERNAL_RENDER_TASK_H