2 * Copyright (c) 2016 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/update/manager/process-render-tasks.h>
22 #include <dali/internal/update/manager/prepare-render-instructions.h>
23 #include <dali/internal/update/manager/sorted-layers.h>
24 #include <dali/internal/update/render-tasks/scene-graph-render-task.h>
25 #include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
26 #include <dali/internal/update/nodes/scene-graph-layer.h>
27 #include <dali/internal/render/common/render-item.h>
28 #include <dali/internal/render/common/render-tracker.h>
29 #include <dali/internal/render/common/render-instruction.h>
30 #include <dali/internal/render/common/render-instruction-container.h>
31 #include <dali/internal/render/renderers/render-renderer.h>
32 #include <dali/integration-api/debug.h>
34 #if defined(DEBUG_ENABLED)
35 extern Debug::Filter* gRenderTaskLogFilter;
48 namespace //Unnamed namespace
51 // Return false if the node or it's parents are exclusive to another render-task
52 bool CheckExclusivity( const Node& node, const RenderTask& task )
54 const RenderTask* exclusiveTo = node.GetExclusiveRenderTask();
57 if ( exclusiveTo == &task )
59 // Exclusive to the same render-task
64 // Exclusive to another render-task
69 const Node* parent = node.GetParent();
72 return CheckExclusivity( *parent, task );
75 // No exclusive flags set
79 Layer* FindLayer( Node& node )
81 Node* currentNode( &node );
85 if( (layer = currentNode->GetLayer()) != NULL )
90 currentNode = currentNode->GetParent();
97 * Rebuild the Layer::colorRenderables, stencilRenderables and overlayRenderables members,
98 * including only renderers which are included in the current render-task.
99 * Returns true if all renderers have finished acquiring resources.
101 bool AddRenderablesForTask( BufferIndex updateBufferIndex,
104 RenderTask& renderTask,
105 int inheritedDrawMode )
107 bool resourcesFinished = true;
109 // Short-circuit for invisible nodes
110 if ( !node.IsVisible( updateBufferIndex ) )
112 return resourcesFinished;
115 // Check whether node is exclusive to a different render-task
116 const RenderTask* exclusiveTo = node.GetExclusiveRenderTask();
118 exclusiveTo != &renderTask )
120 return resourcesFinished;
123 Layer* layer = ¤tLayer;
124 Layer* nodeIsLayer( node.GetLayer() );
127 // All children go to this layer
130 // Layers do not inherit the DrawMode from their parents
131 inheritedDrawMode = DrawMode::NORMAL;
133 DALI_ASSERT_DEBUG( NULL != layer );
135 inheritedDrawMode |= node.GetDrawMode();
137 const unsigned int count = node.GetRendererCount();
138 for( unsigned int i = 0; i < count; ++i )
140 SceneGraph::Renderer* renderer = node.GetRendererAt( i );
142 bool complete = false;
143 renderer->GetReadyAndComplete( ready, complete );
145 DALI_LOG_INFO(gRenderTaskLogFilter, Debug::General, "Testing renderable:%p ready:%s complete:%s\n", renderer, ready?"T":"F", complete?"T":"F");
147 resourcesFinished &= complete;
149 if( ready ) // i.e. should be rendered (all resources are available)
151 if( DrawMode::STENCIL == inheritedDrawMode )
153 layer->stencilRenderables.PushBack( Renderable(&node, renderer ) );
155 else if( DrawMode::OVERLAY_2D == inheritedDrawMode )
157 layer->overlayRenderables.PushBack( Renderable(&node, renderer ) );
161 layer->colorRenderables.PushBack( Renderable(&node, renderer ) );
167 NodeContainer& children = node.GetChildren();
168 const NodeIter endIter = children.End();
169 for ( NodeIter iter = children.Begin(); iter != endIter; ++iter )
171 Node& child = **iter;
172 bool childResourcesComplete = AddRenderablesForTask( updateBufferIndex, child, *layer, renderTask, inheritedDrawMode );
173 resourcesFinished &= childResourcesComplete;
176 return resourcesFinished;
178 } //Unnamed namespace
180 void ProcessRenderTasks( BufferIndex updateBufferIndex,
181 RenderTaskList& renderTasks,
183 SortedLayerPointers& sortedLayers,
184 RendererSortingHelper& sortingHelper,
185 GeometryBatcher& geometryBatcher,
186 RenderInstructionContainer& instructions )
188 RenderTaskList::RenderTaskContainer& taskContainer = renderTasks.GetTasks();
190 if ( taskContainer.IsEmpty() )
192 // Early-exit if there are no tasks to process
196 // For each render-task:
197 // 1) Prepare the render-task
198 // 2) Clear the layer-stored lists of renderers (TODO check if the layer is not changed and don't clear in this case)
199 // 3) Traverse the scene-graph, filling the lists for the current render-task
200 // 4) Prepare render-instructions
202 DALI_LOG_INFO(gRenderTaskLogFilter, Debug::General, "ProcessRenderTasks() Offscreens first\n");
204 // First process off screen render tasks - we may need the results of these for the on screen renders
205 RenderTaskList::RenderTaskContainer::ConstIterator endIter = taskContainer.End();
206 for ( RenderTaskList::RenderTaskContainer::Iterator iter = taskContainer.Begin(); endIter != iter; ++iter )
208 RenderTask& renderTask = **iter;
211 if(0 == renderTask.GetFrameBufferId() && renderTask.GetFrameBuffer() == 0 )
217 if ( !renderTask.ReadyToRender( updateBufferIndex ) )
223 Node* sourceNode = renderTask.GetSourceNode();
224 DALI_ASSERT_DEBUG( NULL != sourceNode ); // otherwise Prepare() should return false
226 // Check that the source node is not exclusive to another task
227 if ( ! CheckExclusivity( *sourceNode, renderTask ) )
232 Layer* layer = FindLayer( *sourceNode );
235 // Skip to next task as no layer
239 bool resourcesFinished = false;
240 if( renderTask.IsRenderRequired() )
242 size_t layerCount( sortedLayers.size() );
243 for( size_t i(0); i<layerCount; ++i )
245 sortedLayers[i]->ClearRenderables();
248 resourcesFinished = AddRenderablesForTask( updateBufferIndex,
252 sourceNode->GetDrawMode() );
254 renderTask.SetResourcesFinished( resourcesFinished );
255 PrepareRenderInstruction( updateBufferIndex,
259 renderTask.GetCullMode(),
265 renderTask.SetResourcesFinished( resourcesFinished );
269 DALI_LOG_INFO(gRenderTaskLogFilter, Debug::General, "ProcessRenderTasks() Onscreen\n");
271 // Now that the off screen renders are done we can process on screen render tasks
272 for ( RenderTaskList::RenderTaskContainer::Iterator iter = taskContainer.Begin(); endIter != iter; ++iter )
274 RenderTask& renderTask = **iter;
277 if(0 != renderTask.GetFrameBufferId() || renderTask.GetFrameBuffer() != 0 )
282 if ( !renderTask.ReadyToRender( updateBufferIndex ) )
288 Node* sourceNode = renderTask.GetSourceNode();
289 DALI_ASSERT_DEBUG( NULL != sourceNode ); // otherwise Prepare() should return false
291 // Check that the source node is not exclusive to another task
292 if ( ! CheckExclusivity( *sourceNode, renderTask ) )
297 Layer* layer = FindLayer( *sourceNode );
300 // Skip to next task as no layer
304 bool resourcesFinished = false;
305 if( renderTask.IsRenderRequired() )
307 size_t layerCount( sortedLayers.size() );
308 for( size_t i(0); i<layerCount; ++i )
310 sortedLayers[i]->ClearRenderables();
313 resourcesFinished = AddRenderablesForTask( updateBufferIndex,
317 sourceNode->GetDrawMode() );
319 PrepareRenderInstruction( updateBufferIndex,
323 renderTask.GetCullMode(),
328 renderTask.SetResourcesFinished( resourcesFinished );