2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/render-tasks/render-task-list-impl.h>
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/event/common/thread-local-storage.h>
25 #include <dali/internal/event/render-tasks/render-task-defaults.h>
26 #include <dali/internal/event/render-tasks/render-task-impl.h>
27 #include <dali/internal/event/actors/camera-actor-impl.h>
28 #include <dali/internal/update/render-tasks/scene-graph-render-task.h>
29 #include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
30 #include <dali/internal/update/manager/update-manager.h>
32 using Dali::Internal::SceneGraph::UpdateManager;
34 #if defined(DEBUG_ENABLED)
37 Debug::Filter* gLogRenderList = Debug::Filter::New(Debug::Concise, false, "LOG_RENDER_TASK_LIST");
46 RenderTaskList* RenderTaskList::New( EventThreadServices& eventServices, RenderTaskDefaults& defaults, bool systemLevel )
48 RenderTaskList* taskList = new RenderTaskList( eventServices, defaults, systemLevel );
50 taskList->Initialize( eventServices.GetUpdateManager() );
55 Dali::RenderTask RenderTaskList::CreateTask()
57 RenderTask* taskImpl = RenderTask::New( mIsSystemLevel );
59 Dali::RenderTask newTask( taskImpl );
60 mTasks.push_back( newTask );
64 SceneGraph::RenderTask* sceneObject = taskImpl->CreateSceneObject();
65 DALI_ASSERT_DEBUG( NULL != sceneObject );
67 // Pass ownership to SceneGraph::RenderTaskList
68 AddTaskMessage( mEventThreadServices, *mSceneObject, *sceneObject );
71 // Set the default source & camera actors
72 taskImpl->SetSourceActor( &mDefaults.GetDefaultRootActor() );
73 taskImpl->SetCameraActor( &mDefaults.GetDefaultCameraActor() );
78 void RenderTaskList::RemoveTask( Dali::RenderTask task )
80 for ( RenderTaskContainer::iterator iter = mTasks.begin(); mTasks.end() != iter; ++iter )
86 RenderTask& taskImpl = GetImplementation( task );
88 SceneGraph::RenderTask* sceneObject = taskImpl.GetRenderTaskSceneObject();
89 DALI_ASSERT_DEBUG( NULL != sceneObject );
91 // Send a message to remove the scene-graph RenderTask
92 RemoveTaskMessage( mEventThreadServices, *mSceneObject, *sceneObject );
94 // The scene-graph RenderTask will be destroyed soon; discard the raw-pointer
95 taskImpl.DiscardSceneObject();
99 break; // we're finished
104 unsigned int RenderTaskList::GetTaskCount() const
106 return mTasks.size();
109 Dali::RenderTask RenderTaskList::GetTask( unsigned int index ) const
111 DALI_ASSERT_ALWAYS( ( index < mTasks.size() ) && "RenderTask index out-of-range" );
113 return mTasks[index];
116 RenderTaskList::RenderTaskList( EventThreadServices& eventThreadServices, RenderTaskDefaults& defaults, bool systemLevel )
117 : mEventThreadServices( eventThreadServices ),
118 mDefaults( defaults ),
119 mIsSystemLevel( systemLevel ),
124 RenderTaskList::~RenderTaskList()
128 void RenderTaskList::Initialize( UpdateManager& updateManager )
130 // This should only be called once, with no existing scene-object
131 DALI_ASSERT_DEBUG( NULL == mSceneObject );
133 // Get raw-pointer to render task list
134 mSceneObject = updateManager.GetRenderTaskList( mIsSystemLevel );
135 // set the callback to call us back when tasks are completed
136 mSceneObject->SetCompleteNotificationInterface( this );
139 void RenderTaskList::NotifyCompleted()
141 DALI_LOG_TRACE_METHOD(gLogRenderList);
143 std::vector< Dali::RenderTask > finishedRenderTasks;
145 // Since render tasks can be unreferenced during the signal emissions, iterators into render tasks pointers may be invalidated.
146 // First copy the finished render tasks, then emit signals
147 for ( std::vector<Dali::RenderTask>::iterator it = mTasks.begin(), endIt = mTasks.end(); it != endIt; ++it )
149 Dali::RenderTask& renderTask( *it );
151 if( GetImplementation( renderTask ).HasFinished() )
153 finishedRenderTasks.push_back( Dali::RenderTask( renderTask ) );
157 // Now it's safe to emit the signals
158 for ( std::vector<Dali::RenderTask>::iterator it = finishedRenderTasks.begin(), endIt = finishedRenderTasks.end(); it != endIt; ++it )
160 Dali::RenderTask& handle( *it );
162 GetImplementation(handle).EmitSignalFinish();
166 void RenderTaskList::RecoverFromContextLoss()
168 for ( RenderTaskContainer::iterator iter = mTasks.begin(); mTasks.end() != iter; ++iter )
170 Dali::RenderTask task = *iter;
172 // If the render target renders only once to an offscreen, re-render the render task
173 if( task.GetRefreshRate() == Dali::RenderTask::REFRESH_ONCE && task.GetTargetFrameBuffer() )
175 task.SetRefreshRate( Dali::RenderTask::REFRESH_ONCE );
180 } // namespace Internal