Merge "Added property to Renderer to specify the depth function" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / update / render-tasks / scene-graph-render-task.h
index 32e6b02..b8d6e2f 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_TASK_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
@@ -33,13 +33,19 @@ namespace Dali
 namespace Internal
 {
 class FrameBufferTexture;
-class CompleteStatusManager;
+class ResourceManager;
+
+namespace Render
+{
+class RenderTracker;
+}
 
 namespace SceneGraph
 {
 class Node;
-class CameraAttachment;
+class Camera;
 class RenderInstruction;
+class RenderMessageDispatcher;
 
 /**
  * RenderTasks describe how the Dali scene should be rendered.
@@ -47,6 +53,7 @@ class RenderInstruction;
 class RenderTask : public PropertyOwner
 {
 public:
+
   enum State
   {
     RENDER_CONTINUOUSLY,               ///< mRefreshRate > 0
@@ -66,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.
    */
@@ -90,16 +104,18 @@ public:
   bool IsExclusive() const;
 
   /**
-   * Set the node from which the scene is viewed.
-   * @param[in] node The scene is viewed from the perspective of this node.
+   * Set the camera from which the scene is viewed.
+   * @param[in] cameraNode that camera is connected with
+   * @param[in] camera to use.
    */
-  void SetCameraNode( Node* node );
+  void SetCamera( Node* cameraNode, Camera* camera );
 
   /**
    * 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.
@@ -274,23 +290,23 @@ public:
 
   /**
    * Retrieve the view-matrix; this is double buffered for input handling.
-   * @pre GetCameraNode() returns a node with valid CameraAttachment.
+   * @pre GetCameraNode() returns a node with valid Camera.
    * @param[in] bufferIndex The buffer to read from.
    * @return The view-matrix.
    */
   const Matrix& GetViewMatrix( BufferIndex bufferIndex ) const;
 
   /**
-   * @brief Retrieve the camera attachment.
-   * @pre GetCameraNode() returns a node with valid CameraAttachment.
+   * @brief Retrieve the camera.
+   * @pre GetCameraNode() returns a node with valid Camera.
    *
-   * @return The camera attachment.
+   * @return The camera.
    */
-  SceneGraph::CameraAttachment& GetCameraAttachment() const;
+  SceneGraph::Camera& GetCamera() const;
 
   /**
    * Retrieve the projection-matrix; this is double buffered for input handling.
-   * @pre GetCameraNode() returns a node with valid CameraAttachment.
+   * @pre GetCameraNode() returns a node with valid Camera.
    * @param[in] bufferIndex The buffer to read from.
    * @return The projection-matrix.
    */
@@ -298,6 +314,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.
    */
@@ -309,15 +330,10 @@ 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
+   * Indicate whether GL sync is required for native render target.
+   * @param[in] requiresSync whether GL sync is required for native render target
    */
-  Node* GetCamera() const;
+  void SetSyncRequired( bool requiresSync );
 
 private:
 
@@ -342,10 +358,12 @@ public: // Animatable Properties
   AnimatableProperty< Vector4 >   mClearColor;          ///< clearColor
 
 private:
-  CompleteStatusManager* mCompleteStatusManager;
+  RenderMessageDispatcher* mRenderMessageDispatcher;
+  ResourceManager* mResourceManager;
+  Render::RenderTracker* mRenderSyncTracker;
   Node* mSourceNode;
   Node* mCameraNode;
-  CameraAttachment* mCameraAttachment;
+  SceneGraph::Camera* mCamera;
   unsigned int mFrameBufferResourceId;
 
   bool mResourcesFinished:1; ///< True if all resources were available when the render-task was processed
@@ -363,20 +381,22 @@ 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
+  bool mRequiresSync;              ///< Whether sync is needed to track the render
 
 };
 
 // Messages for RenderTask
 
-inline void SetFrameBufferIdMessage( EventThreadServices& eventThreadServices, 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 = 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( EventThreadServices& eventThreadServices, RenderTask& task, const Vector4& value )
@@ -448,21 +468,31 @@ inline void SetSourceNodeMessage( EventThreadServices& eventThreadServices, Rend
   new (slot) LocalType( &task, &RenderTask::SetSourceNode, node );
 }
 
-inline void SetCameraNodeMessage( EventThreadServices& eventThreadServices, RenderTask& task, const Node* constNode )
+inline void SetCameraMessage( EventThreadServices& eventThreadServices, RenderTask& task, const Node* constNode, const Camera* constCamera )
 {
-  // Scene graph thread can destroy this object.
+  typedef MessageValue2< RenderTask, Node*, Camera* > LocalType;
+
   Node* node = const_cast< Node* >( constNode );
+  Camera* camera = const_cast< Camera* >( constCamera );
+  // Reserve memory inside the message queue
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
-  typedef MessageValue1< RenderTask, Node* > LocalType;
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &task, &RenderTask::SetCamera, node, camera );
+}
+
+inline void SetExclusiveMessage( EventThreadServices& eventThreadServices, RenderTask& task, bool exclusive )
+{
+  typedef MessageValue1< RenderTask, bool > LocalType;
 
   // Reserve some memory inside the message queue
   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 );
+  new (slot) LocalType( &task, &RenderTask::SetExclusive, exclusive );
 }
 
-inline void SetExclusiveMessage( EventThreadServices& eventThreadServices, RenderTask& task, bool exclusive )
+inline void SetSyncRequiredMessage(EventThreadServices& eventThreadServices, RenderTask& task, bool requiresSync )
 {
   typedef MessageValue1< RenderTask, bool > LocalType;
 
@@ -470,7 +500,7 @@ inline void SetExclusiveMessage( EventThreadServices& eventThreadServices, Rende
   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 );
+  new (slot) LocalType( &task, &RenderTask::SetSyncRequired, requiresSync );
 }
 
 inline void BakeViewportPositionMessage( EventThreadServices& eventThreadServices, const RenderTask& task, const Vector2& value )