X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Frender-tasks%2Fscene-graph-render-task.h;h=99ed6c192a35ae96f8c1ebf054d16c97b24682ec;hb=c0893b7d9077a1053150caccb2534f8b12476253;hp=9d64c08367e68ef93491f308829123efc2466275;hpb=ce20e9f082e811130930d13c9e9edc1da4ce1013;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/render-tasks/scene-graph-render-task.h b/dali/internal/update/render-tasks/scene-graph-render-task.h index 9d64c08..99ed6c1 100644 --- a/dali/internal/update/render-tasks/scene-graph-render-task.h +++ b/dali/internal/update/render-tasks/scene-graph-render-task.h @@ -1,45 +1,50 @@ #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDER_TASK_H__ #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_TASK_H__ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ // INTERNAL INCLUDES #include #include #include -#include #include -#include +#include #include #include +#include namespace Dali { namespace Internal { -class FrameBufferTexture; -class CompleteStatusManager; + +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 +52,7 @@ class RenderInstruction; class RenderTask : public PropertyOwner { public: + enum State { RENDER_CONTINUOUSLY, ///< mRefreshRate > 0 @@ -66,6 +72,12 @@ public: virtual ~RenderTask(); /** + * Initialize the render task. Called in update thread + * @param[in] renderMessageDispatcher to send messages to render thread + */ + void Initialize( RenderMessageDispatcher& renderMessageDispatcher ); + + /** * Set the nodes to be rendered. * @param[in] node This node and its children will be rendered. */ @@ -90,31 +102,39 @@ 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 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 SetCameraNode( Node* node ); + void SetFrameBufferId( unsigned int resourceId, bool isNativeFBO ); /** - * Retrieve the camera node. - * @return The scene is viewed from the perspective of this node. + * Retrieve the resource ID of the frame-buffer. + * @return The resource ID, or zero if not rendering off-screen. */ - Node* GetCameraNode() const; + unsigned int GetFrameBufferId() const; /** * 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] frameBuffer The framebuffer */ - void SetFrameBufferId( unsigned int resourceId ); + void SetFrameBuffer( Render::FrameBuffer* frameBuffer ); /** * Retrieve the resource ID of the frame-buffer. * @return The resource ID, or zero if not rendering off-screen. */ - unsigned int GetFrameBufferId() const; + Render::FrameBuffer* GetFrameBuffer(); /** - * 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 @@ -122,7 +142,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. @@ -130,7 +150,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. @@ -138,7 +158,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 @@ -146,7 +166,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. @@ -154,7 +174,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. @@ -162,7 +182,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. @@ -178,7 +198,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 @@ -186,7 +206,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. @@ -194,7 +214,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. @@ -212,6 +232,16 @@ public: bool GetClearEnabled() const; /** + * @copydoc Dali::RenderTask::SetCullMode() + */ + void SetCullMode( bool mode ); + + /** + * @copydoc Dali::RenderTask::GetCullMode() + */ + bool GetCullMode() const; + + /** * Set the refresh-rate of the RenderTask. * @param[in] refreshRate The new refresh rate. */ @@ -240,9 +270,8 @@ public: /** * Process a frame. This method is called each frame for every ready render task, regardless * of whether it needs to render (so that the frame counter can be updated). - * @param[in] resourcesComplete true if the resources of the source tree are completely loaded. */ - void UpdateState( bool resourcesComplete ); + void UpdateState(); /** * Return true only if currently waiting for the render task to @@ -265,15 +294,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. + * @pre GetCameraNode() returns a node with valid Camera. + * + * @return The camera. + */ + 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. */ @@ -281,6 +318,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. */ @@ -292,10 +334,10 @@ public: bool ViewMatrixUpdated(); /** - * Set the complete status tracker. - * @param[in] completeStatusManager The complete status Tracker (not owned) + * Indicate whether GL sync is required for native render target. + * @param[in] requiresSync whether GL sync is required for native render target */ - void SetCompleteStatusManager( CompleteStatusManager* completeStatusManager ); + void SetSyncRequired( bool requiresSync ); private: @@ -315,91 +357,101 @@ 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; + Render::RenderTracker* mRenderSyncTracker; Node* mSourceNode; Node* mCameraNode; - CameraAttachment* mCameraAttachment; - unsigned int mFrameBufferResourceId; + SceneGraph::Camera* mCamera; + Render::FrameBuffer* mFrameBuffer; bool mWaitingToRender:1; ///< True when an render once to FBO is waiting bool mNotifyTrigger:1; ///< True if a render once render task has finished renderering bool mExclusive: 1; ///< Whether the render task has exclusive access to the source actor (node in the scene graph implementation). bool mClearEnabled: 1; ///< Whether previous results are cleared. - - FrameBufferTexture* mRenderTarget; - Viewport mViewport; + bool mCullMode: 1; ///< Whether renderers should be frustum culled State mState; ///< Render state. unsigned int mRefreshRate; ///< REFRESH_ONCE, REFRESH_ALWAYS or render every N frames unsigned int mFrameCounter; ///< counter for rendering every N frames unsigned int mRenderedOnceCounter; ///< Incremented whenever state changes to RENDERED_ONCE_AND_NOTIFIED + bool mRequiresSync; ///< Whether sync is needed to track the render }; // Messages for RenderTask - -inline void SetFrameBufferIdMessage( EventToUpdate& eventToUpdate, RenderTask& task, unsigned int resourceId ) +inline void SetFrameBufferMessage( EventThreadServices& eventThreadServices, RenderTask& task, Render::FrameBuffer* frameBuffer ) { - typedef MessageValue1< RenderTask, unsigned int > LocalType; + typedef MessageValue1< RenderTask, Render::FrameBuffer*> 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::SetFrameBuffer, frameBuffer ); } -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 SetRefreshRateMessage( EventToUpdate& eventToUpdate, RenderTask& task, unsigned int refreshRate ) +inline void SetCullModeMessage( EventThreadServices& eventThreadServices, RenderTask& task, bool mode ) +{ + 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::SetCullMode, mode ); +} + +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 ); @@ -407,54 +459,64 @@ 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 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 = 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 ); + new (slot) LocalType( &task, &RenderTask::SetExclusive, exclusive ); } -inline void SetExclusiveMessage( EventToUpdate& eventToUpdate, RenderTask& task, bool exclusive ) +inline void SetSyncRequiredMessage(EventThreadServices& eventThreadServices, RenderTask& task, bool requiresSync ) { 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 ); + new (slot) LocalType( &task, &RenderTask::SetSyncRequired, requiresSync ); } -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 );