2 * Copyright (c) 2014 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/update-algorithms.h>
25 #include <dali/public-api/actors/draw-mode.h>
26 #include <dali/public-api/math/matrix.h>
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/internal/update/resources/resource-manager.h>
29 #include <dali/internal/update/nodes/node.h>
30 #include <dali/internal/update/node-attachments/node-attachment.h>
31 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
32 #include <dali/internal/update/nodes/scene-graph-layer.h>
33 #include <dali/internal/render/renderers/render-renderer.h>
35 #include <dali/integration-api/debug.h>
46 #if defined(DEBUG_ENABLED)
47 Debug::Filter* gUpdateFilter = Debug::Filter::New(Debug::Concise, false, "LOG_UPDATE_ALGORITHMS");
50 /******************************************************************************
51 *********************** Apply Constraints ************************************
52 ******************************************************************************/
56 * Constrain the local properties of the PropertyOwner.
57 * @param propertyOwner to constrain
58 * @param updateBufferIndex buffer index to use
59 * @return The number of constraints that are still being applied
61 void ConstrainPropertyOwner( PropertyOwner& propertyOwner, BufferIndex updateBufferIndex )
63 ConstraintOwnerContainer& constraints = propertyOwner.GetConstraints();
65 const ConstraintIter endIter = constraints.End();
66 for( ConstraintIter iter = constraints.Begin(); iter != endIter; ++iter )
68 ConstraintBase& constraint = **iter;
69 constraint.Apply( updateBufferIndex );
73 /******************************************************************************
74 ************************** Update node hierarchy *****************************
75 ******************************************************************************/
77 inline void UpdateRootNodeOpacity( Layer& rootNode, int nodeDirtyFlags, BufferIndex updateBufferIndex )
79 if ( nodeDirtyFlags & ColorFlag )
81 rootNode.SetWorldColor( rootNode.GetColor( updateBufferIndex ), updateBufferIndex );
85 // Copy previous value, in case it changed in the previous frame
86 rootNode.CopyPreviousWorldColor( updateBufferIndex );
90 inline void UpdateNodeOpacity( Node& node, int nodeDirtyFlags, BufferIndex updateBufferIndex )
92 // If opacity needs to be recalculated
93 if ( nodeDirtyFlags & ColorFlag )
95 node.InheritWorldColor( updateBufferIndex );
99 // Copy inherited value, if changed in the previous frame
100 node.CopyPreviousWorldColor( updateBufferIndex );
105 * This is called recursively for all children of the root Node
107 inline int UpdateNodesAndAttachments( Node& node,
109 BufferIndex updateBufferIndex,
110 ResourceManager& resourceManager,
111 RenderQueue& renderQueue,
113 int inheritedDrawMode )
115 //Apply constraints to the node
116 ConstrainPropertyOwner( node, updateBufferIndex );
118 // Short-circuit for invisible nodes
119 if ( !node.IsVisible( updateBufferIndex ) )
124 // If the node was not previously visible
125 BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u;
126 if ( !node.IsVisible( previousBuffer ) )
128 // The node was skipped in the previous update; it must recalculate everything
129 node.SetAllDirtyFlags();
132 // Some dirty flags are inherited from parent
133 int nodeDirtyFlags( node.GetDirtyFlags() | ( parentFlags & InheritedDirtyFlags ) );
135 int cumulativeDirtyFlags = nodeDirtyFlags;
137 Layer* layer = ¤tLayer;
138 Layer* nodeIsLayer( node.GetLayer() );
141 // all childs go to this layer
144 // assume layer is clean to begin with
145 layer->SetReuseRenderers( updateBufferIndex, true );
147 // Layers do not inherit the DrawMode from their parents
148 inheritedDrawMode = DrawMode::NORMAL;
150 DALI_ASSERT_DEBUG( NULL != layer );
152 UpdateNodeOpacity( node, nodeDirtyFlags, updateBufferIndex );
154 // Setting STENCIL will override OVERLAY_2D, if that would otherwise have been inherited.
155 inheritedDrawMode |= node.GetDrawMode();
157 node.PrepareRender( updateBufferIndex );
159 // if any child node has moved or had its sort modifier changed, layer is not clean and old frame cannot be reused
160 // also if node has been deleted, dont reuse old render items
161 if( nodeDirtyFlags & RenderableUpdateFlags )
163 layer->SetReuseRenderers( updateBufferIndex, false );
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 cumulativeDirtyFlags |=UpdateNodesAndAttachments( child,
181 return cumulativeDirtyFlags;
185 * The root node is treated separately; it cannot inherit values since it has no parent
187 int UpdateNodesAndAttachments( Layer& rootNode,
188 BufferIndex updateBufferIndex,
189 ResourceManager& resourceManager,
190 RenderQueue& renderQueue )
192 DALI_ASSERT_DEBUG( rootNode.IsRoot() );
194 // Short-circuit for invisible nodes
195 if ( DALI_UNLIKELY( !rootNode.IsVisible( updateBufferIndex ) ) ) // almost never ever true
200 // If the root node was not previously visible
201 BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u;
202 if ( DALI_UNLIKELY( !rootNode.IsVisible( previousBuffer ) ) ) // almost never ever true
204 // The node was skipped in the previous update; it must recalculate everything
205 rootNode.SetAllDirtyFlags();
208 int nodeDirtyFlags( rootNode.GetDirtyFlags() );
210 int cumulativeDirtyFlags = nodeDirtyFlags;
212 UpdateRootNodeOpacity( rootNode, nodeDirtyFlags, updateBufferIndex );
214 DrawMode::Type drawMode( rootNode.GetDrawMode() );
217 NodeContainer& children = rootNode.GetChildren();
218 const NodeIter endIter = children.End();
219 for ( NodeIter iter = children.Begin(); iter != endIter; ++iter )
221 Node& child = **iter;
222 cumulativeDirtyFlags |= UpdateNodesAndAttachments( child,
231 return cumulativeDirtyFlags;
234 } // namespace SceneGraph
236 } // namespace Internal