2 * Copyright (c) 2017 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.
90 * @param[in] updateBufferIndex The current update buffer index.
91 * @param[in] node The current node of the scene-graph.
92 * @param[in] currentLayer The current layer containing lists of opaque/transparent renderables.
93 * @param[in] renderTask The current render-task.
94 * @param[in] inheritedDrawMode The draw mode of the parent
95 * @param[in] parentDepthIndex The inherited parent node depth index
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 void AddRenderablesForTask( BufferIndex updateBufferIndex,
103 RenderTask& renderTask,
104 int inheritedDrawMode,
105 uint32_t& currentClippingId,
106 uint32_t clippingDepth )
108 // Short-circuit for invisible nodes
109 if( !node.IsVisible( updateBufferIndex ) )
114 // Check whether node is exclusive to a different render-task
115 const RenderTask* exclusiveTo = node.GetExclusiveRenderTask();
116 if( exclusiveTo && ( exclusiveTo != &renderTask ) )
121 // Assume all children go to this layer (if this node is a layer).
122 Layer* layer = node.GetLayer();
125 // Layers do not inherit the DrawMode from their parents
126 inheritedDrawMode = node.GetDrawMode();
130 // This node is not a layer.
131 layer = ¤tLayer;
132 inheritedDrawMode |= node.GetDrawMode();
135 DALI_ASSERT_DEBUG( NULL != layer );
137 // Update the clipping Id and depth for this node (if clipping is enabled).
138 if( DALI_UNLIKELY( node.GetClippingMode() != ClippingMode::DISABLED ) )
140 ++currentClippingId; // This modifies the reference passed in as well as the local value, causing the value to be global to the recursion.
141 ++clippingDepth; // This only modifies the local value (which is passed in when the method recurses).
143 // Set the information in the node.
144 node.SetClippingInformation( currentClippingId, clippingDepth );
146 const unsigned int count = node.GetRendererCount();
147 for( unsigned int i = 0; i < count; ++i )
149 SceneGraph::Renderer* renderer = node.GetRendererAt( i );
151 // Normal is the more-likely draw mode to occur.
152 if( DALI_LIKELY( inheritedDrawMode == DrawMode::NORMAL ) )
154 layer->colorRenderables.PushBack( Renderable( &node, renderer ) );
158 layer->overlayRenderables.PushBack( Renderable( &node, renderer ) );
163 NodeContainer& children = node.GetChildren();
164 const NodeIter endIter = children.End();
165 for( NodeIter iter = children.Begin(); iter != endIter; ++iter )
167 Node& child = **iter;
168 AddRenderablesForTask( updateBufferIndex, child, *layer, renderTask, inheritedDrawMode, currentClippingId, clippingDepth );
172 } // Anonymous namespace.
175 RenderTaskProcessor::RenderTaskProcessor()
179 RenderTaskProcessor::~RenderTaskProcessor()
183 void RenderTaskProcessor::Process( BufferIndex updateBufferIndex,
184 RenderTaskList& renderTasks,
186 SortedLayerPointers& sortedLayers,
187 RenderInstructionContainer& instructions )
189 RenderTaskList::RenderTaskContainer& taskContainer = renderTasks.GetTasks();
191 if( taskContainer.IsEmpty() )
193 // Early-exit if there are no tasks to process
197 // For each render-task:
198 // 1) Prepare the render-task
199 // 2) Clear the layer-stored lists of renderers (TODO check if the layer is not changed and don't clear in this case)
200 // 3) Traverse the scene-graph, filling the lists for the current render-task
201 // 4) Prepare render-instructions
203 DALI_LOG_INFO( gRenderTaskLogFilter, Debug::General, "RenderTaskProcessor::Process() Offscreens first\n" );
205 // First process off screen render tasks - we may need the results of these for the on screen renders
206 uint32_t clippingId = 0u;
207 bool hasClippingNodes = false;
209 RenderTaskList::RenderTaskContainer::ConstIterator endIter = taskContainer.End();
210 for( RenderTaskList::RenderTaskContainer::Iterator iter = taskContainer.Begin(); endIter != iter; ++iter )
212 RenderTask& renderTask = **iter;
215 if( ( renderTask.GetFrameBuffer() == 0 ) || ( !renderTask.ReadyToRender( updateBufferIndex ) ) )
217 // Skip to next task.
221 Node* sourceNode = renderTask.GetSourceNode();
222 DALI_ASSERT_DEBUG( NULL != sourceNode ); // Otherwise Prepare() should return false
224 // Check that the source node is not exclusive to another task.
225 if( ! CheckExclusivity( *sourceNode, renderTask ) )
230 Layer* layer = FindLayer( *sourceNode );
233 // Skip to next task as no layer.
237 if( renderTask.IsRenderRequired() )
239 size_t layerCount( sortedLayers.size() );
240 for( size_t i(0); i<layerCount; ++i )
242 sortedLayers[i]->ClearRenderables();
245 AddRenderablesForTask( updateBufferIndex,
249 sourceNode->GetDrawMode(),
253 // If the clipping Id is still 0 after adding all Renderables, there is no clipping required for this RenderTaskList.
254 hasClippingNodes = clippingId != 0u;
256 mRenderInstructionProcessor.Prepare( updateBufferIndex,
259 renderTask.GetCullMode(),
265 DALI_LOG_INFO( gRenderTaskLogFilter, Debug::General, "RenderTaskProcessor::Process() Onscreen\n" );
267 // Now that the off screen renders are done we can process on screen render tasks.
268 // Reset the clipping Id for the OnScreen render tasks.
270 for ( RenderTaskList::RenderTaskContainer::Iterator iter = taskContainer.Begin(); endIter != iter; ++iter )
272 RenderTask& renderTask = **iter;
275 if( ( renderTask.GetFrameBuffer() != 0 ) || ( !renderTask.ReadyToRender( updateBufferIndex ) ) )
277 // Skip to next task.
281 Node* sourceNode = renderTask.GetSourceNode();
282 DALI_ASSERT_DEBUG( NULL != sourceNode ); // Otherwise Prepare() should return false.
284 // Check that the source node is not exclusive to another task.
285 if( ! CheckExclusivity( *sourceNode, renderTask ) )
290 Layer* layer = FindLayer( *sourceNode );
293 // Skip to next task as no layer.
297 if( renderTask.IsRenderRequired() )
299 size_t layerCount( sortedLayers.size() );
300 for( size_t i(0); i < layerCount; ++i )
302 sortedLayers[i]->ClearRenderables();
305 AddRenderablesForTask( updateBufferIndex,
309 sourceNode->GetDrawMode(),
313 // If the clipping Id is still 0 after adding all Renderables, there is no clipping required for this RenderTaskList.
314 hasClippingNodes = clippingId != 0;
316 mRenderInstructionProcessor.Prepare( updateBufferIndex,
319 renderTask.GetCullMode(),