2 * Copyright (c) 2018 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/frame-callback-processor.h>
22 #include <dali/devel-api/update/frame-callback-interface.h>
23 #include <dali/devel-api/update/update-proxy.h>
24 #include <dali/internal/update/manager/update-proxy-impl.h>
38 template< typename FrameCallbackInfoT >
43 MatchRootNode( PropertyOwner& rootNode )
44 : mRootNode( rootNode )
48 bool operator() ( const FrameCallbackInfoT& info )
50 return &info.updateProxyImpl->GetRootNode() == &mRootNode;
55 PropertyOwner& mRootNode;
58 } // unnamed namespace
60 FrameCallbackProcessor::FrameCallbackProcessor( TransformManager& transformManager, Node& rootNode )
62 mTransformManager( transformManager ),
63 mRootNode( rootNode ),
64 mNodeHierarchyChanged( true )
68 FrameCallbackProcessor::~FrameCallbackProcessor()
72 void FrameCallbackProcessor::AddFrameCallback( FrameCallbackInterface* frameCallback, const Node* rootNode )
74 Node& node = const_cast< Node& >( *rootNode ); // Was sent as const from event thread, we need to be able to use non-const version here.
76 FrameCallbackInfo info;
77 info.frameCallback = frameCallback;
78 info.updateProxyImpl = new UpdateProxy( mTransformManager, node );
80 // We want to be notified when the node is destroyed (if we're not observing it already)
81 auto iter = std::find_if( mFrameCallbacks.begin(), mFrameCallbacks.end(), MatchRootNode< FrameCallbackInfo >( node ) );
82 if( iter == mFrameCallbacks.end() )
84 node.AddObserver( *this );
87 mFrameCallbacks.push_back( info );
90 void FrameCallbackProcessor::RemoveFrameCallback( FrameCallbackInterface* frameCallback )
92 auto iter = std::remove_if( mFrameCallbacks.begin(), mFrameCallbacks.end(),
93 [ this, frameCallback ]
94 ( const FrameCallbackInfo& info )
96 info.updateProxyImpl->GetRootNode().RemoveObserver( *this );
97 delete info.updateProxyImpl;
98 return info.frameCallback == frameCallback;
100 mFrameCallbacks.erase( iter, mFrameCallbacks.end() );
103 void FrameCallbackProcessor::Update( BufferIndex bufferIndex, float elapsedSeconds )
105 for( auto&& iter : mFrameCallbacks )
107 UpdateProxy& updateProxyImpl = *iter.updateProxyImpl;
108 updateProxyImpl.SetCurrentBufferIndex( bufferIndex );
110 if( mNodeHierarchyChanged )
112 updateProxyImpl.NodeHierarchyChanged();
115 Dali::UpdateProxy updateProxy( updateProxyImpl );
116 iter.frameCallback->Update( updateProxy, elapsedSeconds );
118 mNodeHierarchyChanged = false;
121 void FrameCallbackProcessor::PropertyOwnerDestroyed( PropertyOwner& owner )
123 auto iter = std::remove_if( mFrameCallbacks.begin(), mFrameCallbacks.end(), MatchRootNode< FrameCallbackInfo >( owner ) );
124 mFrameCallbacks.erase( iter, mFrameCallbacks.end() );
127 } // namespace SceneGraph
129 } // namespace Internal