Fix a crash of the RenderTask
[platform/core/uifw/dali-core.git] / dali / internal / event / render-tasks / render-task-impl.h
index 0c65e6f..89febf9 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) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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/rendering/frame-buffer-impl.h>
+#include <dali/internal/event/render-tasks/render-task-list-impl.h>
+#include <dali/internal/event/events/actor-observer.h>
 
 namespace Dali
 {
@@ -34,24 +37,32 @@ namespace Internal
 class Actor;
 class CameraActor;
 class EventThreadServices;
+class RenderTaskList;
 
 namespace SceneGraph
 {
+class RenderTaskList;
 class RenderTask;
 class Camera;
 }
 
+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] isSystemLevel Whether the render-task is on the system level task list.
+   *
+   * @param[in] sourceActor The source actor.
+   * @param[in] cameraActor The camera actor.
+   * @param[in] renderTaskList The render task list.
+   * @return The created render task
    */
-  static RenderTask* New( bool isSystemLevel );
+  static RenderTaskPtr New( Actor* sourceActor, CameraActor* cameraActor, RenderTaskList& renderTaskList );
 
   /**
    * @copydoc Dali::RenderTask::SetSourceActor()
@@ -126,12 +137,12 @@ public:
   /**
    * copydoc Dali::RenderTask::SetScreenToFrameBufferMappingActor
    */
-  void SetScreenToFrameBufferMappingActor( Actor* mappingActor );
+  void SetScreenToFrameBufferMappingActor( Dali::Actor& mappingActor );
 
   /**
    * copydoc Dali::RenderTask::GetScreenToFrameBufferMAppingActor
    */
-  Actor* GetScreenToFrameBufferMappingActor() const;
+  Dali::Actor GetScreenToFrameBufferMappingActor() const;
 
   /**
    * @copydoc Dali::RenderTask::SetViewportPosition
@@ -208,12 +219,12 @@ public:
   /**
    * @copydoc Dali::RenderTask::SetRefreshRate()
    */
-  void SetRefreshRate( unsigned int refreshRate );
+  void SetRefreshRate( uint32_t refreshRate );
 
   /**
    * @copydoc Dali::RenderTask::GetRefreshRate()
    */
-  unsigned int GetRefreshRate() const;
+  uint32_t GetRefreshRate() const;
 
   /**
    * Check if the render-task is hittable. If render task is offscreen, the screen coordinates may be translated.
@@ -230,12 +241,6 @@ public:
   bool TranslateCoordinates( Vector2& screenCoords ) const;
 
   /**
-   * Query whether the RenderTask is on the system level render-task list.
-   * @return true, if on the system level task list, false otherwise.
-   */
-  bool IsSystemLevel() const;
-
-  /**
    * @copydoc Dali::RenderTask::WorldToViewport()
    */
   bool WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const;
@@ -248,66 +253,20 @@ public:
 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 unsigned int 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);
@@ -318,9 +277,14 @@ public: // Implementation of Object
   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
 
   /**
-   * @copydoc Dali::Internal::Object::GetSceneObject()
+   * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
+   */
+  virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
+
+  /**
+   * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
    */
-  virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
+  virtual void OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType );
 
   /**
    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
@@ -367,99 +331,39 @@ public: //signals
 protected:
 
   /**
-   * Construct a new RenderTask.
-   * @param[in] isSystemLevel Whether the RenderTask is on the system level task list.
+   * Constructor.
+   *
+   * @param[in] sceneObject The scene graph object
+   * @param[in] renderTaskList The render task list
    */
-  RenderTask( bool isSystemLevel );
+  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 );
+private: // not copyable
 
-    /**
-     * 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 );
-
-  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.
-  };
+  RenderTask() = delete;
+  RenderTask( const RenderTask& ) = delete;
+  RenderTask& operator=( const RenderTask& ) = delete;
 
 private:
 
-  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
+  ActorObserver mSourceActor; ///< Source actor
+  ActorObserver mCameraActor; ///< Camera actor
+  WeakHandle<Dali::Actor> mInputMappingActor; /// used to mapping screen to frame buffer coordinate, not kept alive by rendertask
+  RenderTaskList& mRenderTaskList; ///< The render task list
 
   Vector4 mClearColor;       ///< Optional clear color
 
-  unsigned int mRefreshRate; ///< Determines how often the task is processed.
+  Vector2 mViewportPosition; ///< The cached viewport position
+  Vector2 mViewportSize;     ///< The cached viewport size
+
+  uint32_t mRefreshRate; ///< Determines how often the task is processed.
 
-  unsigned int mRefreshOnceCounter;
+  uint32_t mRefreshOnceCounter;
 
   FrameBufferImagePtr mFrameBufferImage;  ///< Optional off-screen render target.
   FrameBufferPtr  mFrameBuffer;
@@ -471,7 +375,6 @@ private:
   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 mIsSystemLevel : 1; ///< True if the render-task is on the system level task list.
   bool mRequiresSync  : 1; ///< True if the GL sync is required to track the render of.
 
   //Signals
@@ -502,4 +405,4 @@ inline const Internal::RenderTask& GetImplementation(const Dali::RenderTask& tas
 
 } // namespace Dali
 
-#endif //__DALI_INTERNAL_RENDER_TASK_H__
+#endif // DALI_INTERNAL_RENDER_TASK_H