/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * 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.
// INTERNAL INCLUDES
#include <dali/public-api/math/matrix.h>
-#include <dali/internal/update/resources/resource-manager.h>
-#include <dali/internal/update/resources/complete-status-manager.h>
+#include <dali/internal/update/controllers/render-message-dispatcher.h>
#include <dali/internal/update/nodes/node.h>
-#include <dali/internal/update/node-attachments/scene-graph-camera-attachment.h>
#include <dali/internal/render/common/render-instruction.h>
+#include <dali/internal/render/common/render-tracker.h>
#include <dali/internal/update/render-tasks/scene-graph-render-task-debug.h>
mSourceNode->SetExclusiveRenderTask( NULL );
}
}
- if( mFrameBufferResourceId )
+ if( mRenderSyncTracker )
{
- mCompleteStatusManager->StopTrackingResource( mFrameBufferResourceId );
+ mRenderMessageDispatcher->RemoveRenderTracker( *mRenderSyncTracker );
}
}
+void RenderTask::Initialize( RenderMessageDispatcher& renderMessageDispatcher )
+{
+ mRenderMessageDispatcher = &renderMessageDispatcher;
+}
+
void RenderTask::SetSourceNode( Node* node )
{
// Remove exclusive flag from the old node, if necessary
return mExclusive;
}
-void RenderTask::SetCameraNode( Node* cameraNode )
+void RenderTask::SetCamera( Node* cameraNode, Camera* camera )
{
- // if camera changed
- if( cameraNode != mCameraNode )
- {
- if( cameraNode )
- {
- // get attachment. when camera node is changed we will get a message from event thread object
- // so no need to observe the node here
- mCameraAttachment = dynamic_cast< CameraAttachment* >( &cameraNode->GetAttachment() );
- DALI_ASSERT_DEBUG( mCameraAttachment && "Camera without attachment" );
- }
- mCameraNode = cameraNode;
- }
+ mCameraNode = cameraNode;
+ mCamera = camera;
}
-void RenderTask::SetFrameBufferId( unsigned int resourceId )
+void RenderTask::SetFrameBuffer( Render::FrameBuffer* frameBuffer )
{
- if ( mFrameBufferResourceId != resourceId )
- {
- DALI_ASSERT_DEBUG(mCompleteStatusManager && "Complete status tracker is null");
- if( mCompleteStatusManager )
- {
- if( resourceId && mState == RENDER_ONCE_WAITING_FOR_RESOURCES )
- {
- mCompleteStatusManager->TrackResource( resourceId );
- }
-
- if( mFrameBufferResourceId )
- {
- mCompleteStatusManager->StopTrackingResource( mFrameBufferResourceId );
- }
- }
-
- mFrameBufferResourceId = resourceId;
- }
+ mFrameBuffer = frameBuffer;
}
-unsigned int RenderTask::GetFrameBufferId() const
+Render::FrameBuffer* RenderTask::GetFrameBuffer()
{
- return mFrameBufferResourceId;
+ return mFrameBuffer;
}
bool RenderTask::QueryViewport( BufferIndex bufferIndex, Viewport& viewport ) const
if( mRefreshRate > 0 )
{
mState = RENDER_CONTINUOUSLY;
-
- if( mFrameBufferResourceId )
- {
- // Don't need tracking
- DALI_ASSERT_DEBUG(mCompleteStatusManager && "Ready state tracker is null");
- if( mCompleteStatusManager != NULL )
- {
- mCompleteStatusManager->StopTrackingResource( mFrameBufferResourceId );
- }
- }
}
else
{
mState = RENDER_ONCE_WAITING_FOR_RESOURCES;
mWaitingToRender = true;
mNotifyTrigger = false;
-
- if( mFrameBufferResourceId )
- {
- DALI_ASSERT_DEBUG(mCompleteStatusManager && "Ready state tracker is null");
- if( mCompleteStatusManager != NULL )
- {
- mCompleteStatusManager->TrackResource( mFrameBufferResourceId );
- }
- }
}
mFrameCounter = 0u;
bool RenderTask::ReadyToRender( BufferIndex updateBufferIndex )
{
- if ( NULL == mSourceNode ||
- ( !mSourceNode->IsRoot() && NULL == mSourceNode->GetParent() ) )
- {
- TASK_LOG_FMT(Debug::General, " =F No source actor FC:%d\n", mFrameCounter );
-
- // Source node is missing or disconnected
- return false;
- }
+ // If the source node of the render task is invisible we should still render
+ // We want the render task to complete and possible clear colors to happen
- // Check if the source node (root actor) and all its ancestors are visible.
- if( !mSourceNode->IsFullyVisible( updateBufferIndex ) )
+ // Check the source node.
+ if( NULL == mSourceNode ||
+ ( !mSourceNode->IsRoot() && NULL == mSourceNode->GetParent() ) )
{
- TASK_LOG_FMT(Debug::General, " =F No visible source FC:%d\n", mFrameCounter );
+ TASK_LOG_FMT( Debug::General, " Source actor not on stage. Frame counter: %d\n", mFrameCounter );
+
+ // The source node is missing or disconnected.
return false;
}
- if ( NULL == mCameraNode ||
- NULL == mCameraNode->GetParent() ||
- !mCameraNode->HasAttachment() )
+ // Check camera node
+ if( NULL == mCameraNode ||
+ NULL == mCameraNode->GetParent() ||
+ NULL == mCamera )
{
- // Camera node is missing or disconnected
+ // The camera node is missing or disconnected.
TASK_LOG_FMT(Debug::General, " =F No Camera FC:%d\n", mFrameCounter );
-
return false;
}
- TASK_LOG_FMT(Debug::General, " =T (FBO ID:%d) FC:%d\n", mFrameBufferResourceId , mFrameCounter );
return true;
}
switch( mState )
{
case RENDER_CONTINUOUSLY:
+ {
required = (mFrameCounter == 0);
break;
-
+ }
case RENDER_ONCE_WAITING_FOR_RESOURCES:
+ {
required = true;
break;
-
+ }
default:
+ {
required = false;
break;
+ }
}
TASK_LOG_FMT( Debug::General, " State:%s = %s\n", STATE_STRING(mState), required?"T":"F" );
return required;
}
-void RenderTask::SetResourcesFinished( bool resourcesFinished )
-{
- mResourcesFinished = resourcesFinished;
-}
-
// Called every frame regardless of whether render was required.
// If render was not required, ignore resourcesFinished.
void RenderTask::UpdateState()
{
- TASK_LOG_FMT( Debug::General, "(mResourcesFinished:%s) FC:%d State:%s RR:%d\n", mResourcesFinished?"T":"F", mFrameCounter, STATE_STRING(mState), mRefreshRate );
+ TASK_LOG_FMT( Debug::General, "FC:%d State:%s RR:%d\n", mFrameCounter, STATE_STRING(mState), mRefreshRate );
switch( mState )
{
{
if( mFrameCounter == 0 )
{
- if( mResourcesFinished )
- {
- ++mFrameCounter; // Only start skipping frames when resources are loaded
- }
+ ++mFrameCounter; // Only start skipping frames when resources are loaded
}
else // Continue counting to skip frames
{
case RENDER_ONCE_WAITING_FOR_RESOURCES:
{
- if( mResourcesFinished )
- {
- mState = RENDERED_ONCE;
- }
+ mState = RENDERED_ONCE;
}
break;
case RENDERED_ONCE:
{
- if( mFrameBufferResourceId > 0 )
+ mWaitingToRender = true;
+ mNotifyTrigger = false;
+ if( mFrameBuffer )
{
- // Query if the framebuffer is complete:
- DALI_ASSERT_DEBUG(mCompleteStatusManager && "Complete status tracker is null");
- if( mCompleteStatusManager != NULL &&
- CompleteStatusManager::COMPLETE == mCompleteStatusManager->GetStatus( mFrameBufferResourceId ) )
+ if( !mRenderSyncTracker || (mRenderSyncTracker && mRenderSyncTracker->IsSynced() ))
{
mWaitingToRender = false;
mNotifyTrigger = true;
}
- else
- {
- mWaitingToRender = true;
- }
}
else
{
- mWaitingToRender = false;
mNotifyTrigger = true;
}
}
+
break;
default:
const Matrix& RenderTask::GetViewMatrix( BufferIndex bufferIndex ) const
{
- DALI_ASSERT_DEBUG( NULL != mCameraAttachment );
+ DALI_ASSERT_DEBUG( NULL != mCamera );
+
+ return mCamera->GetViewMatrix( bufferIndex );
+}
- return mCameraAttachment->GetViewMatrix( bufferIndex );
+SceneGraph::Camera& RenderTask::GetCamera() const
+{
+ DALI_ASSERT_DEBUG( NULL != mCamera );
+ return *mCamera;
}
const Matrix& RenderTask::GetProjectionMatrix( BufferIndex bufferIndex ) const
{
- DALI_ASSERT_DEBUG( NULL != mCameraAttachment );
+ DALI_ASSERT_DEBUG( NULL != mCamera );
- return mCameraAttachment->GetProjectionMatrix( bufferIndex );
+ return mCamera->GetProjectionMatrix( bufferIndex );
}
void RenderTask::PrepareRenderInstruction( RenderInstruction& instruction, BufferIndex updateBufferIndex )
{
- DALI_ASSERT_DEBUG( NULL != mCameraAttachment );
+ DALI_ASSERT_DEBUG( NULL != mCamera );
TASK_LOG(Debug::General);
Viewport viewport;
bool viewportSet = QueryViewport( updateBufferIndex, viewport );
- instruction.Reset( mCameraAttachment,
- GetFrameBufferId(),
+ instruction.Reset( mCamera,
+ GetFrameBuffer(),
viewportSet ? &viewport : NULL,
mClearEnabled ? &GetClearColor( updateBufferIndex ) : NULL );
+
+ if( mRequiresSync &&
+ mRefreshRate == Dali::RenderTask::REFRESH_ONCE )
+ {
+ // create tracker if one doesn't yet exist.
+ if( !mRenderSyncTracker )
+ {
+ mRenderSyncTracker = new Render::RenderTracker();
+ mRenderMessageDispatcher->AddRenderTracker( *mRenderSyncTracker );
+ }
+ instruction.mRenderTracker = mRenderSyncTracker;
+ }
+ else
+ {
+ // no sync needed, texture FBOs are "ready" the same frame they are rendered to
+ instruction.mRenderTracker = NULL;
+ }
}
bool RenderTask::ViewMatrixUpdated()
{
bool retval = false;
- if( mCameraAttachment )
+ if( mCamera )
{
- retval = mCameraAttachment->ViewMatrixUpdated();
+ retval = mCamera->ViewMatrixUpdated();
}
return retval;
}
-void RenderTask::SetCompleteStatusManager(CompleteStatusManager* completeStatusManager)
-{
- mCompleteStatusManager = completeStatusManager;
-}
-
void RenderTask::SetViewportPosition( BufferIndex updateBufferIndex, const Vector2& value )
{
mViewportPosition.Set( updateBufferIndex, value );
return false;
}
-Node* RenderTask::GetCamera() const
+void RenderTask::SetSyncRequired( bool requiresSync )
{
- return mCameraNode;
+ mRequiresSync = requiresSync;
}
void RenderTask::ResetDefaultProperties( BufferIndex updateBufferIndex )
: mViewportPosition( Vector2::ZERO),
mViewportSize( Vector2::ZERO),
mClearColor( Dali::RenderTask::DEFAULT_CLEAR_COLOR ),
- mCompleteStatusManager( NULL ),
+ mRenderMessageDispatcher( NULL ),
+ mRenderSyncTracker( NULL ),
mSourceNode( NULL ),
mCameraNode( NULL ),
- mCameraAttachment( NULL ),
- mFrameBufferResourceId( 0 ),
- mResourcesFinished( false ),
+ mCamera( NULL ),
+ mFrameBuffer(0),
mWaitingToRender( false ),
mNotifyTrigger( false ),
mExclusive( Dali::RenderTask::DEFAULT_EXCLUSIVE ),
mClearEnabled( Dali::RenderTask::DEFAULT_CLEAR_ENABLED ),
mCullMode( Dali::RenderTask::DEFAULT_CULL_MODE ),
- mRenderTarget( NULL ),
mState( (Dali::RenderTask::DEFAULT_REFRESH_RATE == Dali::RenderTask::REFRESH_ALWAYS)
? RENDER_CONTINUOUSLY
: RENDER_ONCE_WAITING_FOR_RESOURCES ),
mRefreshRate( Dali::RenderTask::DEFAULT_REFRESH_RATE ),
mFrameCounter( 0u ),
- mRenderedOnceCounter( 0u )
+ mRenderedOnceCounter( 0u ),
+ mRequiresSync( false )
{
}