Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / event / render-tasks / render-task-list-impl.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 // CLASS HEADER
18 #include <dali/internal/event/render-tasks/render-task-list-impl.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/public-api/common/dali-common.h>
22 #include <dali/internal/common/event-to-update.h>
23 #include <dali/internal/event/common/thread-local-storage.h>
24 #include <dali/internal/event/render-tasks/render-task-defaults.h>
25 #include <dali/internal/event/render-tasks/render-task-impl.h>
26 #include <dali/internal/event/actors/camera-actor-impl.h>
27 #include <dali/internal/update/render-tasks/scene-graph-render-task.h>
28 #include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
29 #include <dali/internal/update/manager/update-manager.h>
30
31 using Dali::Internal::SceneGraph::UpdateManager;
32
33 #if defined(DEBUG_ENABLED)
34 namespace
35 {
36 Debug::Filter* gLogRenderList = Debug::Filter::New(Debug::Concise, false, "LOG_RENDER_TASK_LIST");
37 }
38 #endif
39
40 namespace Dali
41 {
42 namespace Internal
43 {
44
45 RenderTaskList* RenderTaskList::New( UpdateManager& updateManager, RenderTaskDefaults& defaults, bool systemLevel )
46 {
47   RenderTaskList* taskList = new RenderTaskList( updateManager.GetEventToUpdate(), defaults, systemLevel );
48
49   taskList->Initialize( updateManager );
50
51   return taskList;
52 }
53
54 Dali::RenderTask RenderTaskList::CreateTask()
55 {
56   RenderTask* taskImpl = RenderTask::New( mIsSystemLevel );
57
58   Dali::RenderTask newTask( taskImpl );
59   mTasks.push_back( newTask );
60
61   if ( mSceneObject )
62   {
63     SceneGraph::RenderTask* sceneObject = taskImpl->CreateSceneObject();
64     DALI_ASSERT_DEBUG( NULL != sceneObject );
65
66     // Pass ownership to SceneGraph::RenderTaskList
67     AddTaskMessage( mEventToUpdate, *mSceneObject, *sceneObject );
68   }
69
70   // Set the default source & camera actors
71   taskImpl->SetSourceActor( &mDefaults.GetDefaultRootActor() );
72   taskImpl->SetCameraActor( &mDefaults.GetDefaultCameraActor() );
73
74   return newTask;
75 }
76
77 void RenderTaskList::RemoveTask( Dali::RenderTask task )
78 {
79   for ( RenderTaskContainer::iterator iter = mTasks.begin(); mTasks.end() != iter; ++iter )
80   {
81     if ( *iter == task )
82     {
83       if ( mSceneObject )
84       {
85         RenderTask& taskImpl = GetImplementation( task );
86
87         SceneGraph::RenderTask* sceneObject = taskImpl.GetRenderTaskSceneObject();
88         DALI_ASSERT_DEBUG( NULL != sceneObject );
89
90         // Send a message to remove the scene-graph RenderTask
91         RemoveTaskMessage( mEventToUpdate, *mSceneObject, *sceneObject );
92
93         // The scene-graph RenderTask will be destroyed soon; discard the raw-pointer
94         taskImpl.DiscardSceneObject();
95       }
96
97       mTasks.erase( iter );
98       break; // we're finished
99     }
100   }
101 }
102
103 unsigned int RenderTaskList::GetTaskCount() const
104 {
105   return mTasks.size();
106 }
107
108 Dali::RenderTask RenderTaskList::GetTask( unsigned int index ) const
109 {
110   DALI_ASSERT_ALWAYS( ( index < mTasks.size() ) && "RenderTask index out-of-range" );
111
112   return mTasks[index];
113 }
114
115 void RenderTaskList::NotifyFinished()
116 {
117   DALI_LOG_TRACE_METHOD(gLogRenderList);
118
119   std::vector< Dali::RenderTask > finishedRenderTasks;
120
121   // Since render tasks can be unreferenced during the signal emissions, iterators into render tasks pointers may be invalidated.
122   // First copy the finished render tasks, then emit signals
123   for ( std::vector<Dali::RenderTask>::iterator it = mTasks.begin(), endIt = mTasks.end(); it != endIt; ++it )
124   {
125     Dali::RenderTask& renderTask( *it );
126
127     if( GetImplementation( renderTask ).HasFinished() )
128     {
129       finishedRenderTasks.push_back( Dali::RenderTask( renderTask ) );
130     }
131   }
132
133   // Now it's safe to emit the signals
134   for ( std::vector<Dali::RenderTask>::iterator it = finishedRenderTasks.begin(), endIt = finishedRenderTasks.end(); it != endIt; ++it )
135   {
136     Dali::RenderTask& handle( *it );
137
138     GetImplementation(handle).EmitSignalFinish();
139   }
140 }
141
142 RenderTaskList::RenderTaskList( EventToUpdate& eventToUpdate, RenderTaskDefaults& defaults, bool systemLevel )
143 : mEventToUpdate( eventToUpdate ),
144   mDefaults( defaults ),
145   mIsSystemLevel( systemLevel ),
146   mSceneObject( NULL )
147 {
148 }
149
150 RenderTaskList::~RenderTaskList()
151 {
152 }
153
154 void RenderTaskList::Initialize( UpdateManager& updateManager )
155 {
156   // This should only be called once, with no existing scene-object
157   DALI_ASSERT_DEBUG( NULL == mSceneObject );
158
159   // Get raw-pointer to render task list
160   mSceneObject = updateManager.GetRenderTaskList( mIsSystemLevel );
161 }
162
163 } // namespace Internal
164
165 } // namespace Dali