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/nodes/node.h>
29 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
30 #include <dali/internal/update/nodes/scene-graph-layer.h>
31 #include <dali/internal/render/renderers/render-renderer.h>
33 #include <dali/integration-api/debug.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gUpdateFilter = Debug::Filter::New(Debug::Concise, false, "LOG_UPDATE_ALGORITHMS");
48 /******************************************************************************
49 *********************** Apply Constraints ************************************
50 ******************************************************************************/
54 * Constrain the local properties of the PropertyOwner.
55 * @param propertyOwner to constrain
56 * @param updateBufferIndex buffer index to use
57 * @return The number of constraints that are still being applied
59 void ConstrainPropertyOwner( PropertyOwner& propertyOwner, BufferIndex updateBufferIndex )
61 ConstraintOwnerContainer& constraints = propertyOwner.GetConstraints();
63 const ConstraintIter endIter = constraints.End();
64 for( ConstraintIter iter = constraints.Begin(); iter != endIter; ++iter )
66 ConstraintBase& constraint = **iter;
67 constraint.Apply( updateBufferIndex );
71 /******************************************************************************
72 ************************** Update node hierarchy *****************************
73 ******************************************************************************/
75 inline void UpdateRootNodeOpacity( Layer& rootNode, int nodeDirtyFlags, BufferIndex updateBufferIndex )
77 if ( nodeDirtyFlags & ColorFlag )
79 rootNode.SetWorldColor( rootNode.GetColor( updateBufferIndex ), updateBufferIndex );
83 // Copy previous value, in case it changed in the previous frame
84 rootNode.CopyPreviousWorldColor( updateBufferIndex );
88 inline void UpdateNodeOpacity( Node& node, int nodeDirtyFlags, BufferIndex updateBufferIndex )
90 // If opacity needs to be recalculated
91 if ( nodeDirtyFlags & ColorFlag )
93 node.InheritWorldColor( updateBufferIndex );
97 // Copy inherited value, if changed in the previous frame
98 node.CopyPreviousWorldColor( updateBufferIndex );
103 * This is called recursively for all children of the root Node
105 inline int UpdateNodes( Node& node,
107 BufferIndex updateBufferIndex,
108 RenderQueue& renderQueue,
110 int inheritedDrawMode )
112 //Apply constraints to the node
113 ConstrainPropertyOwner( node, updateBufferIndex );
115 // Short-circuit for invisible nodes
116 if ( !node.IsVisible( updateBufferIndex ) )
121 // If the node was not previously visible
122 BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u;
123 if ( !node.IsVisible( previousBuffer ) )
125 // The node was skipped in the previous update; it must recalculate everything
126 node.SetAllDirtyFlags();
129 // Some dirty flags are inherited from parent
130 int nodeDirtyFlags( node.GetDirtyFlags() | ( parentFlags & InheritedDirtyFlags ) );
132 int cumulativeDirtyFlags = nodeDirtyFlags;
134 Layer* layer = ¤tLayer;
135 Layer* nodeIsLayer( node.GetLayer() );
138 // all childs go to this layer
141 // assume layer is clean to begin with
142 layer->SetReuseRenderers( updateBufferIndex, true );
144 // Layers do not inherit the DrawMode from their parents
145 inheritedDrawMode = DrawMode::NORMAL;
147 DALI_ASSERT_DEBUG( NULL != layer );
149 UpdateNodeOpacity( node, nodeDirtyFlags, updateBufferIndex );
151 // Draw mode inheritance is treated as or-ing the modes together (as they are a bit-mask).
152 inheritedDrawMode |= node.GetDrawMode();
154 node.PrepareRender( updateBufferIndex );
156 // if any child node has moved or had its sort modifier changed, layer is not clean and old frame cannot be reused
157 // also if node has been deleted, dont reuse old render items
158 if( nodeDirtyFlags & RenderableUpdateFlags )
160 layer->SetReuseRenderers( updateBufferIndex, false );
164 NodeContainer& children = node.GetChildren();
165 const NodeIter endIter = children.End();
166 for ( NodeIter iter = children.Begin(); iter != endIter; ++iter )
168 Node& child = **iter;
169 cumulativeDirtyFlags |=UpdateNodes( child,
177 return cumulativeDirtyFlags;
181 * The root node is treated separately; it cannot inherit values since it has no parent
183 int UpdateNodeTree( Layer& rootNode,
184 BufferIndex updateBufferIndex,
185 RenderQueue& renderQueue )
187 DALI_ASSERT_DEBUG( rootNode.IsRoot() );
189 // Short-circuit for invisible nodes
190 if ( DALI_UNLIKELY( !rootNode.IsVisible( updateBufferIndex ) ) ) // almost never ever true
195 // If the root node was not previously visible
196 BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u;
197 if ( DALI_UNLIKELY( !rootNode.IsVisible( previousBuffer ) ) ) // almost never ever true
199 // The node was skipped in the previous update; it must recalculate everything
200 rootNode.SetAllDirtyFlags();
203 int nodeDirtyFlags( rootNode.GetDirtyFlags() );
205 int cumulativeDirtyFlags = nodeDirtyFlags;
207 UpdateRootNodeOpacity( rootNode, nodeDirtyFlags, updateBufferIndex );
209 DrawMode::Type drawMode( rootNode.GetDrawMode() );
212 NodeContainer& children = rootNode.GetChildren();
213 const NodeIter endIter = children.End();
214 for ( NodeIter iter = children.Begin(); iter != endIter; ++iter )
216 Node& child = **iter;
217 cumulativeDirtyFlags |= UpdateNodes( child,
225 return cumulativeDirtyFlags;
228 } // namespace SceneGraph
230 } // namespace Internal