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/render-task-processor.h>
22 #include <dali/internal/update/manager/sorted-layers.h>
23 #include <dali/internal/update/render-tasks/scene-graph-render-task.h>
24 #include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
25 #include <dali/internal/update/nodes/scene-graph-layer.h>
26 #include <dali/internal/render/common/render-item.h>
27 #include <dali/internal/render/common/render-tracker.h>
28 #include <dali/internal/render/common/render-instruction.h>
29 #include <dali/internal/render/common/render-instruction-container.h>
30 #include <dali/internal/render/renderers/render-renderer.h>
31 #include <dali/integration-api/debug.h>
33 #if defined(DEBUG_ENABLED)
34 extern Debug::Filter* gRenderTaskLogFilter;
47 namespace //Unnamed namespace
50 // Return false if the node or it's parents are exclusive to another render-task.
51 bool CheckExclusivity( const Node& node, const RenderTask& task )
53 const RenderTask* exclusiveTo = node.GetExclusiveRenderTask();
56 return ( exclusiveTo == &task );
59 const Node* parent = node.GetParent();
62 return CheckExclusivity( *parent, task );
65 // No exclusive flags set.
69 Layer* FindLayer( Node& node )
71 Node* currentNode( &node );
75 if( ( layer = currentNode->GetLayer() ) != NULL )
80 currentNode = currentNode->GetParent();
87 * Rebuild the Layer::colorRenderables and overlayRenderables members,
88 * including only renderers which are included in the current render-task.
89 * Returns true if all renderers have finished acquiring resources.
91 * @param[in] updateBufferIndex The current update buffer index.
92 * @param[in] node The current node of the scene-graph.
93 * @param[in] currentLayer The current layer containing lists of opaque/transparent renderables.
94 * @param[in] renderTask The current render-task.
95 * @param[in] inheritedDrawMode The draw mode of the parent
96 * @param[in] currentClippingId The current Clipping Id
97 * Note: ClippingId is passed by reference, so it is permanently modified when traversing back up the tree for uniqueness.
98 * @param[in] clippingDepth The current clipping depth
100 bool AddRenderablesForTask( BufferIndex updateBufferIndex,
103 RenderTask& renderTask,
104 int inheritedDrawMode,
105 uint32_t& currentClippingId,
106 uint32_t clippingDepth )
108 bool resourcesFinished = true;
110 // Short-circuit for invisible nodes
111 if( !node.IsVisible( updateBufferIndex ) )
113 return resourcesFinished;
116 // Check whether node is exclusive to a different render-task
117 const RenderTask* exclusiveTo = node.GetExclusiveRenderTask();
118 if( exclusiveTo && ( exclusiveTo != &renderTask ) )
120 return resourcesFinished;
123 // Assume all children go to this layer (if this node is a layer).
124 Layer* layer = node.GetLayer();
127 // Layers do not inherit the DrawMode from their parents
128 inheritedDrawMode = node.GetDrawMode();
132 // This node is not a layer.
133 layer = ¤tLayer;
134 inheritedDrawMode |= node.GetDrawMode();
137 DALI_ASSERT_DEBUG( NULL != layer );
139 // Update the clipping Id and depth for this node (if clipping is enabled).
140 if( DALI_UNLIKELY( node.GetClippingMode() != ClippingMode::DISABLED ) )
142 ++currentClippingId; // This modifies the reference passed in as well as the local value, causing the value to be global to the recursion.
143 ++clippingDepth; // This only modifies the local value (which is passed in when the method recurses).
145 // Set the information in the node.
146 node.SetClippingInformation( currentClippingId, clippingDepth );
148 const unsigned int count = node.GetRendererCount();
149 for( unsigned int i = 0; i < count; ++i )
151 SceneGraph::Renderer* renderer = node.GetRendererAt( i );
153 bool complete = false;
154 renderer->GetReadyAndComplete( ready, complete );
156 DALI_LOG_INFO( gRenderTaskLogFilter, Debug::General, "Testing renderable:%p ready:%s complete:%s\n", renderer, ready ? "T" : "F", complete ? "T" : "F" );
158 resourcesFinished &= complete;
160 if( ready ) // IE. should be rendered (all resources are available)
162 // Normal is the more-likely draw mode to occur.
163 if( DALI_LIKELY( inheritedDrawMode == DrawMode::NORMAL ) )
165 layer->colorRenderables.PushBack( Renderable( &node, renderer ) );
169 layer->overlayRenderables.PushBack( Renderable( &node, renderer ) );
175 NodeContainer& children = node.GetChildren();
176 const NodeIter endIter = children.End();
177 for( NodeIter iter = children.Begin(); iter != endIter; ++iter )
179 Node& child = **iter;
180 bool childResourcesComplete = AddRenderablesForTask( updateBufferIndex, child, *layer, renderTask, inheritedDrawMode, currentClippingId, clippingDepth );
181 resourcesFinished &= childResourcesComplete;
184 return resourcesFinished;
187 } // Anonymous namespace.
190 RenderTaskProcessor::RenderTaskProcessor()
194 RenderTaskProcessor::~RenderTaskProcessor()
198 void RenderTaskProcessor::Process( BufferIndex updateBufferIndex,
199 RenderTaskList& renderTasks,
201 SortedLayerPointers& sortedLayers,
202 GeometryBatcher& geometryBatcher,
203 RenderInstructionContainer& instructions )
205 RenderTaskList::RenderTaskContainer& taskContainer = renderTasks.GetTasks();
207 if( taskContainer.IsEmpty() )
209 // Early-exit if there are no tasks to process
213 // For each render-task:
214 // 1) Prepare the render-task
215 // 2) Clear the layer-stored lists of renderers (TODO check if the layer is not changed and don't clear in this case)
216 // 3) Traverse the scene-graph, filling the lists for the current render-task
217 // 4) Prepare render-instructions
219 DALI_LOG_INFO( gRenderTaskLogFilter, Debug::General, "RenderTaskProcessor::Process() Offscreens first\n" );
221 // First process off screen render tasks - we may need the results of these for the on screen renders
222 uint32_t clippingId = 0u;
223 bool hasClippingNodes = false;
225 RenderTaskList::RenderTaskContainer::ConstIterator endIter = taskContainer.End();
226 for( RenderTaskList::RenderTaskContainer::Iterator iter = taskContainer.Begin(); endIter != iter; ++iter )
228 RenderTask& renderTask = **iter;
231 if( ( ( 0 == renderTask.GetFrameBufferId() ) && ( renderTask.GetFrameBuffer() == 0 ) ) ||
232 ( !renderTask.ReadyToRender( updateBufferIndex ) ) )
234 // Skip to next task.
238 Node* sourceNode = renderTask.GetSourceNode();
239 DALI_ASSERT_DEBUG( NULL != sourceNode ); // Otherwise Prepare() should return false
241 // Check that the source node is not exclusive to another task.
242 if( ! CheckExclusivity( *sourceNode, renderTask ) )
247 Layer* layer = FindLayer( *sourceNode );
250 // Skip to next task as no layer.
254 bool resourcesFinished = false;
255 if( renderTask.IsRenderRequired() )
257 size_t layerCount( sortedLayers.size() );
258 for( size_t i(0); i<layerCount; ++i )
260 sortedLayers[i]->ClearRenderables();
263 resourcesFinished = AddRenderablesForTask( updateBufferIndex,
267 sourceNode->GetDrawMode(),
271 renderTask.SetResourcesFinished( resourcesFinished );
273 // If the clipping Id is still 0 after adding all Renderables, there is no clipping required for this RenderTaskList.
274 hasClippingNodes = clippingId != 0u;
276 mRenderInstructionProcessor.Prepare( updateBufferIndex,
279 renderTask.GetCullMode(),
286 renderTask.SetResourcesFinished( resourcesFinished );
290 DALI_LOG_INFO( gRenderTaskLogFilter, Debug::General, "RenderTaskProcessor::Process() Onscreen\n" );
292 // Now that the off screen renders are done we can process on screen render tasks.
293 // Reset the clipping Id for the OnScreen render tasks.
295 for ( RenderTaskList::RenderTaskContainer::Iterator iter = taskContainer.Begin(); endIter != iter; ++iter )
297 RenderTask& renderTask = **iter;
300 if( ( 0 != renderTask.GetFrameBufferId() ) ||
301 ( renderTask.GetFrameBuffer() != 0 ) ||
302 ( !renderTask.ReadyToRender( updateBufferIndex ) ) )
304 // Skip to next task.
308 Node* sourceNode = renderTask.GetSourceNode();
309 DALI_ASSERT_DEBUG( NULL != sourceNode ); // Otherwise Prepare() should return false.
311 // Check that the source node is not exclusive to another task.
312 if( ! CheckExclusivity( *sourceNode, renderTask ) )
317 Layer* layer = FindLayer( *sourceNode );
320 // Skip to next task as no layer.
324 bool resourcesFinished = false;
325 if( renderTask.IsRenderRequired() )
327 size_t layerCount( sortedLayers.size() );
328 for( size_t i(0); i < layerCount; ++i )
330 sortedLayers[i]->ClearRenderables();
333 resourcesFinished = AddRenderablesForTask( updateBufferIndex,
337 sourceNode->GetDrawMode(),
341 // If the clipping Id is still 0 after adding all Renderables, there is no clipping required for this RenderTaskList.
342 hasClippingNodes = clippingId != 0;
344 mRenderInstructionProcessor.Prepare( updateBufferIndex,
347 renderTask.GetCullMode(),
353 renderTask.SetResourcesFinished( resourcesFinished );