Ensuring GL Sync is only used for RefreshOnce render tasks
[platform/core/uifw/dali-core.git] / dali / internal / update / render-tasks / scene-graph-render-task.h
index 7cf2489..698abe6 100644 (file)
@@ -22,9 +22,8 @@
 #include <dali/public-api/math/viewport.h>
 #include <dali/public-api/render-tasks/render-task.h>
 #include <dali/internal/common/buffer-index.h>
-#include <dali/internal/common/event-to-update.h>
 #include <dali/internal/common/message.h>
-#include <dali/internal/update/common/double-buffered.h>
+#include <dali/internal/event/common/event-thread-services.h>
 #include <dali/internal/update/common/property-owner.h>
 #include <dali/internal/update/common/animatable-property.h>
 
@@ -34,13 +33,19 @@ namespace Dali
 namespace Internal
 {
 class FrameBufferTexture;
-class CompleteStatusManager;
+class ResourceManager;
+
+namespace Render
+{
+class RenderTracker;
+}
 
 namespace SceneGraph
 {
 class Node;
 class CameraAttachment;
 class RenderInstruction;
+class RenderMessageDispatcher;
 
 /**
  * RenderTasks describe how the Dali scene should be rendered.
@@ -48,6 +53,7 @@ class RenderInstruction;
 class RenderTask : public PropertyOwner
 {
 public:
+
   enum State
   {
     RENDER_CONTINUOUSLY,               ///< mRefreshRate > 0
@@ -67,6 +73,13 @@ public:
   virtual ~RenderTask();
 
   /**
+   * Initialize the render task. Called in update thread
+   * @param[in] renderMessageDispatcher to send messages to render thread
+   * @param[in] resourceManager to check and update status of FBOs
+   */
+  void Initialize( RenderMessageDispatcher& renderMessageDispatcher, ResourceManager& resourceManager );
+
+  /**
    * Set the nodes to be rendered.
    * @param[in] node This node and its children will be rendered.
    */
@@ -99,8 +112,9 @@ public:
   /**
    * Set the frame-buffer used as a render target.
    * @param[in] resourceId The resource ID of the frame-buffer, or zero if not rendering off-screen.
+   * @param[in] isNativeFBO if this render task is targeting a native FBO
    */
-  void SetFrameBufferId( unsigned int resourceId );
+  void SetFrameBufferId( unsigned int resourceId, bool isNativeFBO );
 
   /**
    * Retrieve the resource ID of the frame-buffer.
@@ -109,7 +123,7 @@ public:
   unsigned int GetFrameBufferId() const;
 
   /**
-   * Set the value of property viewport-position
+   * Set the value of property viewportPosition
    * This value will persist only for the current frame.
    * @param[in] updateBufferIndex The current update buffer index.
    * @param[in] value The value of the property
@@ -117,7 +131,7 @@ public:
   void SetViewportPosition( BufferIndex updateBufferIndex, const Vector2& value );
 
   /**
-   * Get the value of property viewport-position
+   * Get the value of property viewportPosition
    * @warning Should only be called from the Update thread
    * @param[in] bufferIndex The buffer to read from.
    * @return the value of the property.
@@ -125,7 +139,7 @@ public:
   const Vector2& GetViewportPosition( BufferIndex bufferIndex ) const;
 
   /**
-   * Bake the value of the property viewport-position
+   * Bake the value of the property viewportPosition
    * This will also set the base value
    * @param[in] updateBufferIndex The current update buffer index.
    * @param[in] value The new value for property.
@@ -133,7 +147,7 @@ public:
   void BakeViewportPosition( BufferIndex updateBufferIndex, const Vector2& value );
 
   /**
-   * Set the value of property viewport-size
+   * Set the value of property viewportSize
    * This value will persist only for the current frame.
    * @param[in] updateBufferIndex The current update buffer index.
    * @param[in] value The value of the property
@@ -141,7 +155,7 @@ public:
   void SetViewportSize( BufferIndex updateBufferIndex, const Vector2& value );
 
   /**
-   * Get the value of property viewport-size
+   * Get the value of property viewportSize
    * @warning Should only be called from the Update thread
    * @param[in] bufferIndex The buffer to read from.
    * @return the value of the property.
@@ -149,7 +163,7 @@ public:
   const Vector2& GetViewportSize( BufferIndex bufferIndex ) const;
 
   /**
-   * Bake the value of the property viewport-size
+   * Bake the value of the property viewportSize
    * This will also set the base value
    * @param[in] updateBufferIndex The current update buffer index.
    * @param[in] value The new value for property.
@@ -157,7 +171,7 @@ public:
   void BakeViewportSize( BufferIndex updateBufferIndex, const Vector2& value );
 
   /**
-   * Get the value of property viewport-enabled
+   * Get the value of property viewportEnabled
    * @warning Should only be called from the Update thread
    * @param[in] bufferIndex The buffer to read from.
    * @return the value of the property.
@@ -173,7 +187,7 @@ public:
   bool QueryViewport( BufferIndex bufferIndex, Viewport& viewport ) const;
 
   /**
-   * Set the value of property clear-color
+   * Set the value of property clearColor
    * This value will persist only for the current frame.
    * @param[in] updateBufferIndex The current update buffer index.
    * @param[in] value The value of the property
@@ -181,7 +195,7 @@ public:
   void SetClearColor( BufferIndex updateBufferIndex, const Vector4& value );
 
   /**
-   * Get the value of property clear-color
+   * Get the value of property clearColor
    * @warning Should only be called from the Update thread
    * @param[in] bufferIndex The buffer to read from.
    * @return the value of the property.
@@ -189,7 +203,7 @@ public:
   const Vector4& GetClearColor( BufferIndex bufferIndex ) const;
 
   /**
-   * Bake the value of the property clear-color
+   * Bake the value of the property clearColor
    * This will also set the base value
    * @param[in] updateBufferIndex The current update buffer index.
    * @param[in] value The new value for property.
@@ -282,6 +296,14 @@ public:
   const Matrix& GetViewMatrix( BufferIndex bufferIndex ) const;
 
   /**
+   * @brief Retrieve the camera attachment.
+   * @pre GetCameraNode() returns a node with valid CameraAttachment.
+   *
+   * @return The camera attachment.
+   */
+  SceneGraph::CameraAttachment& GetCameraAttachment() const;
+
+  /**
    * Retrieve the projection-matrix; this is double buffered for input handling.
    * @pre GetCameraNode() returns a node with valid CameraAttachment.
    * @param[in] bufferIndex The buffer to read from.
@@ -291,6 +313,11 @@ public:
 
   /**
    * Prepares the render-instruction buffer to be populated with instructions.
+   *
+   * If the render task is a render-once framebuffer backed by a native image,
+   * then this method will ensure that a GL sync object is created to track
+   * when the rendering has finished.
+   *
    * @param[out] instruction to prepare
    * @param[in] updateBufferIndex The current update buffer index.
    */
@@ -302,12 +329,6 @@ public:
   bool ViewMatrixUpdated();
 
   /**
-   * Set the complete status tracker.
-   * @param[in] completeStatusManager The complete status Tracker (not owned)
-   */
-  void SetCompleteStatusManager( CompleteStatusManager* completeStatusManager );
-
-  /**
    * @return A pointer to the camera used by the RenderTask
    */
   Node* GetCamera() const;
@@ -330,12 +351,14 @@ private: // PropertyOwner
   virtual void ResetDefaultProperties( BufferIndex currentBufferIndex );
 
 public: // Animatable Properties
-  AnimatableProperty< Vector2 >   mViewportPosition;    ///< viewport-position
-  AnimatableProperty< Vector2 >   mViewportSize;        ///< viewport-size
-  AnimatableProperty< Vector4 >   mClearColor;          ///< clear-color
+  AnimatableProperty< Vector2 >   mViewportPosition;    ///< viewportPosition
+  AnimatableProperty< Vector2 >   mViewportSize;        ///< viewportSize
+  AnimatableProperty< Vector4 >   mClearColor;          ///< clearColor
 
 private:
-  CompleteStatusManager* mCompleteStatusManager;
+  RenderMessageDispatcher* mRenderMessageDispatcher;
+  ResourceManager* mResourceManager;
+  Render::RenderTracker* mRenderSyncTracker;
   Node* mSourceNode;
   Node* mCameraNode;
   CameraAttachment* mCameraAttachment;
@@ -356,78 +379,79 @@ private:
   unsigned int mFrameCounter;       ///< counter for rendering every N frames
 
   unsigned int mRenderedOnceCounter;  ///< Incremented whenever state changes to RENDERED_ONCE_AND_NOTIFIED
+  bool mTargetIsNativeFramebuffer; ///< Tells if our target is a native framebuffer
 
 };
 
 // Messages for RenderTask
 
-inline void SetFrameBufferIdMessage( EventToUpdate& eventToUpdate, RenderTask& task, unsigned int resourceId )
+inline void SetFrameBufferIdMessage( EventThreadServices& eventThreadServices, RenderTask& task, unsigned int resourceId, bool isNativeFBO )
 {
-  typedef MessageValue1< RenderTask, unsigned int > LocalType;
+  typedef MessageValue2< RenderTask, unsigned int, bool > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &task, &RenderTask::SetFrameBufferId, resourceId );
+  new (slot) LocalType( &task, &RenderTask::SetFrameBufferId, resourceId, isNativeFBO );
 }
 
-inline void SetClearColorMessage( EventToUpdate& eventToUpdate, RenderTask& task, const Vector4& value )
+inline void SetClearColorMessage( EventThreadServices& eventThreadServices, RenderTask& task, const Vector4& value )
 {
   typedef MessageDoubleBuffered1< RenderTask, Vector4 > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &task, &RenderTask::SetClearColor, value );
 }
 
-inline void BakeClearColorMessage( EventToUpdate& eventToUpdate, const RenderTask& task, const Vector4& value )
+inline void BakeClearColorMessage( EventThreadServices& eventThreadServices, const RenderTask& task, const Vector4& value )
 {
   typedef MessageDoubleBuffered1< RenderTask, Vector4 > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &task, &RenderTask::BakeClearColor, value );
 }
 
-inline void SetClearEnabledMessage( EventToUpdate& eventToUpdate, RenderTask& task, bool enabled )
+inline void SetClearEnabledMessage( EventThreadServices& eventThreadServices, RenderTask& task, bool enabled )
 {
   typedef MessageValue1< RenderTask, bool > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &task, &RenderTask::SetClearEnabled, enabled );
 }
 
-inline void SetCullModeMessage( EventToUpdate& eventToUpdate, RenderTask& task, bool mode )
+inline void SetCullModeMessage( EventThreadServices& eventThreadServices, RenderTask& task, bool mode )
 {
   typedef MessageValue1< RenderTask, bool > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &task, &RenderTask::SetCullMode, mode );
 }
 
-inline void SetRefreshRateMessage( EventToUpdate& eventToUpdate, RenderTask& task, unsigned int refreshRate )
+inline void SetRefreshRateMessage( EventThreadServices& eventThreadServices, RenderTask& task, unsigned int refreshRate )
 {
   typedef MessageValue1< RenderTask, unsigned int > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &task, &RenderTask::SetRefreshRate, refreshRate );
 }
 
-inline void SetSourceNodeMessage( EventToUpdate& eventToUpdate, RenderTask& task, const Node* constNode )
+inline void SetSourceNodeMessage( EventThreadServices& eventThreadServices, RenderTask& task, const Node* constNode )
 {
   // Scene graph thread can destroy this object.
   Node* node = const_cast< Node* >( constNode );
@@ -435,13 +459,13 @@ inline void SetSourceNodeMessage( EventToUpdate& eventToUpdate, RenderTask& task
   typedef MessageValue1< RenderTask, Node* > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &task, &RenderTask::SetSourceNode, node );
 }
 
-inline void SetCameraNodeMessage( EventToUpdate& eventToUpdate, RenderTask& task, const Node* constNode )
+inline void SetCameraNodeMessage( EventThreadServices& eventThreadServices, RenderTask& task, const Node* constNode )
 {
   // Scene graph thread can destroy this object.
   Node* node = const_cast< Node* >( constNode );
@@ -449,40 +473,40 @@ inline void SetCameraNodeMessage( EventToUpdate& eventToUpdate, RenderTask& task
   typedef MessageValue1< RenderTask, Node* > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &task, &RenderTask::SetCameraNode, node );
 }
 
-inline void SetExclusiveMessage( EventToUpdate& eventToUpdate, RenderTask& task, bool exclusive )
+inline void SetExclusiveMessage( EventThreadServices& eventThreadServices, RenderTask& task, bool exclusive )
 {
   typedef MessageValue1< RenderTask, bool > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &task, &RenderTask::SetExclusive, exclusive );
 }
 
-inline void BakeViewportPositionMessage( EventToUpdate& eventToUpdate, const RenderTask& task, const Vector2& value )
+inline void BakeViewportPositionMessage( EventThreadServices& eventThreadServices, const RenderTask& task, const Vector2& value )
 {
   typedef MessageDoubleBuffered1< RenderTask, Vector2 > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &task, &RenderTask::BakeViewportPosition, value );
 }
 
-inline void BakeViewportSizeMessage( EventToUpdate& eventToUpdate, const RenderTask& task, const Vector2& value )
+inline void BakeViewportSizeMessage( EventThreadServices& eventThreadServices, const RenderTask& task, const Vector2& value )
 {
   typedef MessageDoubleBuffered1< RenderTask, Vector2 > LocalType;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &task, &RenderTask::BakeViewportSize, value );