2 * Copyright (c) 2019 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/stage-impl.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 RenderTaskListPtr RenderTaskList::New()
48 RenderTaskListPtr taskList = new RenderTaskList();
50 taskList->Initialize();
55 RenderTaskPtr RenderTaskList::CreateTask()
57 return CreateTask( &mDefaults.GetDefaultRootActor(), &mDefaults.GetDefaultCameraActor() );
60 RenderTaskPtr RenderTaskList::CreateTask( Actor* sourceActor, CameraActor* cameraActor)
62 RenderTaskPtr task = RenderTask::New( sourceActor, cameraActor, *this );
64 mTasks.push_back( task );
69 void RenderTaskList::RemoveTask( Internal::RenderTask& task )
71 for ( RenderTaskContainer::iterator iter = mTasks.begin(); mTasks.end() != iter; ++iter )
73 if ( iter->Get() == &task )
75 const SceneGraph::RenderTask& sceneObject = task.GetRenderTaskSceneObject();
79 // send a message to remove the scene-graph RenderTask
80 RemoveTaskMessage( mEventThreadServices, *mSceneObject, sceneObject );
82 for ( Vector< Exclusive >::Iterator exclusiveIt = mExclusives.Begin(); exclusiveIt != mExclusives.End(); ++exclusiveIt )
84 if ( exclusiveIt->renderTaskPtr == iter->Get() )
86 mExclusives.Erase( exclusiveIt );
90 break; // we're finished
95 uint32_t RenderTaskList::GetTaskCount() const
97 return static_cast<uint32_t>( mTasks.size() ); // only 4,294,967,295 render tasks supported
100 RenderTaskPtr RenderTaskList::GetTask( uint32_t index ) const
102 DALI_ASSERT_ALWAYS( ( index < mTasks.size() ) && "RenderTask index out-of-range" );
104 return mTasks[ index ];
107 void RenderTaskList::SetExclusive( RenderTask* task, bool exclusive )
109 // Check to see if this rendertask has an entry?
110 for ( Vector< Exclusive >::Iterator exclusiveIt = mExclusives.Begin(); exclusiveIt != mExclusives.End(); ++exclusiveIt )
112 if ( exclusiveIt->renderTaskPtr == task )
116 mExclusives.Erase( exclusiveIt );
121 exclusiveIt->actorPtr = task->GetSourceActor();
129 Exclusive exclusiveSlot;
130 exclusiveSlot.renderTaskPtr = task;
131 exclusiveSlot.actorPtr = task->GetSourceActor();
132 mExclusives.PushBack( exclusiveSlot );
136 RenderTaskList::RenderTaskList()
137 : mEventThreadServices( EventThreadServices::Get() ),
138 mDefaults( *Stage::GetCurrent() ),
139 mSceneObject( nullptr )
143 RenderTaskList::~RenderTaskList()
145 if( EventThreadServices::IsCoreRunning() && mSceneObject )
147 // Remove the render task list using a message to the update manager
148 RemoveRenderTaskListMessage( mEventThreadServices.GetUpdateManager(), *mSceneObject );
152 void RenderTaskList::Initialize()
154 // Create a new render task list, Keep a const pointer to the render task list.
155 mSceneObject = SceneGraph::RenderTaskList::New();
157 OwnerPointer< SceneGraph::RenderTaskList > transferOwnership( const_cast< SceneGraph::RenderTaskList* >( mSceneObject ) );
158 AddRenderTaskListMessage( mEventThreadServices.GetUpdateManager(), transferOwnership );
160 // set the callback to call us back when tasks are completed
161 mSceneObject->SetCompleteNotificationInterface( this );
164 void RenderTaskList::NotifyCompleted()
166 DALI_LOG_TRACE_METHOD(gLogRenderList);
168 RenderTaskContainer finishedRenderTasks;
170 // Since render tasks can be unreferenced during the signal emissions, iterators into render tasks pointers may be invalidated.
171 // First copy the finished render tasks, then emit signals
172 for ( RenderTaskContainer::iterator iter = mTasks.begin(), endIt = mTasks.end(); iter != endIt; ++iter )
174 if( (*iter)->HasFinished() )
176 finishedRenderTasks.push_back( *iter );
180 // Now it's safe to emit the signals
181 for ( auto&& item : finishedRenderTasks )
183 item->EmitSignalFinish();
187 void RenderTaskList::RecoverFromContextLoss()
189 for ( auto&& item : mTasks )
191 // If the render target renders only once to an offscreen, re-render the render task
192 if( item->GetRefreshRate() == Dali::RenderTask::REFRESH_ONCE && item->GetTargetFrameBuffer() )
194 item->SetRefreshRate( Dali::RenderTask::REFRESH_ONCE );
199 const SceneGraph::RenderTaskList& RenderTaskList::GetSceneObject() const
201 return *mSceneObject;
204 } // namespace Internal