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/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/animation/scene-graph-constraint-base.h>
31 #include <dali/internal/update/nodes/scene-graph-layer.h>
32 #include <dali/internal/render/renderers/render-renderer.h>
34 #include <dali/integration-api/debug.h>
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gUpdateFilter = Debug::Filter::New(Debug::Concise, false, "LOG_UPDATE_ALGORITHMS");
49 /******************************************************************************
50 *********************** Apply Constraints ************************************
51 ******************************************************************************/
55 * Constrain the local properties of the PropertyOwner.
56 * @param propertyOwner to constrain
57 * @param updateBufferIndex buffer index to use
58 * @return The number of constraints that are still being applied
60 void ConstrainPropertyOwner( PropertyOwner& propertyOwner, BufferIndex updateBufferIndex )
62 ConstraintOwnerContainer& constraints = propertyOwner.GetConstraints();
64 const ConstraintIter endIter = constraints.End();
65 for( ConstraintIter iter = constraints.Begin(); iter != endIter; ++iter )
67 ConstraintBase& constraint = **iter;
68 constraint.Apply( updateBufferIndex );
72 /******************************************************************************
73 ************************** Update node hierarchy *****************************
74 ******************************************************************************/
76 inline void UpdateRootNodeOpacity( Layer& rootNode, int nodeDirtyFlags, BufferIndex updateBufferIndex )
78 if ( nodeDirtyFlags & ColorFlag )
80 rootNode.SetWorldColor( rootNode.GetColor( updateBufferIndex ), updateBufferIndex );
84 // Copy previous value, in case it changed in the previous frame
85 rootNode.CopyPreviousWorldColor( updateBufferIndex );
89 inline void UpdateNodeOpacity( Node& node, int nodeDirtyFlags, BufferIndex updateBufferIndex )
91 // If opacity needs to be recalculated
92 if ( nodeDirtyFlags & ColorFlag )
94 node.InheritWorldColor( updateBufferIndex );
98 // Copy inherited value, if changed in the previous frame
99 node.CopyPreviousWorldColor( updateBufferIndex );
104 * This is called recursively for all children of the root Node
106 inline int UpdateNodes( Node& node,
108 BufferIndex updateBufferIndex,
109 ResourceManager& resourceManager,
110 RenderQueue& renderQueue,
112 int inheritedDrawMode )
114 //Apply constraints to the node
115 ConstrainPropertyOwner( node, updateBufferIndex );
117 // Short-circuit for invisible nodes
118 if ( !node.IsVisible( updateBufferIndex ) )
123 // If the node was not previously visible
124 BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u;
125 if ( !node.IsVisible( previousBuffer ) )
127 // The node was skipped in the previous update; it must recalculate everything
128 node.SetAllDirtyFlags();
131 // Some dirty flags are inherited from parent
132 int nodeDirtyFlags( node.GetDirtyFlags() | ( parentFlags & InheritedDirtyFlags ) );
134 int cumulativeDirtyFlags = nodeDirtyFlags;
136 Layer* layer = ¤tLayer;
137 Layer* nodeIsLayer( node.GetLayer() );
140 // all childs go to this layer
143 // assume layer is clean to begin with
144 layer->SetReuseRenderers( updateBufferIndex, true );
146 // Layers do not inherit the DrawMode from their parents
147 inheritedDrawMode = DrawMode::NORMAL;
149 DALI_ASSERT_DEBUG( NULL != layer );
151 UpdateNodeOpacity( node, nodeDirtyFlags, updateBufferIndex );
153 // Draw mode inheritance is treated as or-ing the modes together (as they are a bit-mask).
154 inheritedDrawMode |= node.GetDrawMode();
156 node.PrepareRender( updateBufferIndex );
158 // if any child node has moved or had its sort modifier changed, layer is not clean and old frame cannot be reused
159 // also if node has been deleted, dont reuse old render items
160 if( nodeDirtyFlags & RenderableUpdateFlags )
162 layer->SetReuseRenderers( updateBufferIndex, false );
166 NodeContainer& children = node.GetChildren();
167 const NodeIter endIter = children.End();
168 for ( NodeIter iter = children.Begin(); iter != endIter; ++iter )
170 Node& child = **iter;
171 cumulativeDirtyFlags |=UpdateNodes( child,
180 return cumulativeDirtyFlags;
184 * The root node is treated separately; it cannot inherit values since it has no parent
186 int UpdateNodeTree( Layer& rootNode,
187 BufferIndex updateBufferIndex,
188 ResourceManager& resourceManager,
189 RenderQueue& renderQueue )
191 DALI_ASSERT_DEBUG( rootNode.IsRoot() );
193 // Short-circuit for invisible nodes
194 if ( DALI_UNLIKELY( !rootNode.IsVisible( updateBufferIndex ) ) ) // almost never ever true
199 // If the root node was not previously visible
200 BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u;
201 if ( DALI_UNLIKELY( !rootNode.IsVisible( previousBuffer ) ) ) // almost never ever true
203 // The node was skipped in the previous update; it must recalculate everything
204 rootNode.SetAllDirtyFlags();
207 int nodeDirtyFlags( rootNode.GetDirtyFlags() );
209 int cumulativeDirtyFlags = nodeDirtyFlags;
211 UpdateRootNodeOpacity( rootNode, nodeDirtyFlags, updateBufferIndex );
213 DrawMode::Type drawMode( rootNode.GetDrawMode() );
216 NodeContainer& children = rootNode.GetChildren();
217 const NodeIter endIter = children.End();
218 for ( NodeIter iter = children.Begin(); iter != endIter; ++iter )
220 Node& child = **iter;
221 cumulativeDirtyFlags |= UpdateNodes( child,
230 return cumulativeDirtyFlags;
233 } // namespace SceneGraph
235 } // namespace Internal