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 ),
67 FrameCallbackProcessor::~FrameCallbackProcessor()
71 void FrameCallbackProcessor::AddFrameCallback( FrameCallbackInterface* frameCallback, const Node* rootNode )
73 Node& node = const_cast< Node& >( *rootNode ); // Was sent as const from event thread, we need to be able to use non-const version here.
75 FrameCallbackInfo info;
76 info.frameCallback = frameCallback;
77 info.updateProxyImpl = new UpdateProxy( mTransformManager, node );
79 // We want to be notified when the node is destroyed (if we're not observing it already)
80 auto iter = std::find_if( mFrameCallbacks.begin(), mFrameCallbacks.end(), MatchRootNode< FrameCallbackInfo >( node ) );
81 if( iter == mFrameCallbacks.end() )
83 node.AddObserver( *this );
86 mFrameCallbacks.push_back( info );
89 void FrameCallbackProcessor::RemoveFrameCallback( FrameCallbackInterface* frameCallback )
91 auto iter = std::remove_if( mFrameCallbacks.begin(), mFrameCallbacks.end(),
92 [ this, frameCallback ]
93 ( const FrameCallbackInfo& info )
95 info.updateProxyImpl->GetRootNode().RemoveObserver( *this );
96 delete info.updateProxyImpl;
97 return info.frameCallback == frameCallback;
99 mFrameCallbacks.erase( iter, mFrameCallbacks.end() );
102 void FrameCallbackProcessor::Update( BufferIndex bufferIndex, float elapsedSeconds )
104 for( auto&& iter : mFrameCallbacks )
106 UpdateProxy& updateProxyImpl = *iter.updateProxyImpl;
107 updateProxyImpl.SetCurrentBufferIndex( bufferIndex );
108 Dali::UpdateProxy updateProxy( updateProxyImpl );
109 iter.frameCallback->Update( updateProxy, elapsedSeconds );
113 void FrameCallbackProcessor::PropertyOwnerDestroyed( PropertyOwner& owner )
115 auto iter = std::remove_if( mFrameCallbacks.begin(), mFrameCallbacks.end(), MatchRootNode< FrameCallbackInfo >( owner ) );
116 mFrameCallbacks.erase( iter, mFrameCallbacks.end() );
119 } // namespace SceneGraph
121 } // namespace Internal