Clean up the code to build successfully on macOS
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / frame-callback-processor.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/update/manager/frame-callback-processor.h>
20
21 // EXTERNAL INCLUDES
22 #include <algorithm>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/update/frame-callback-interface.h>
26 #include <dali/devel-api/update/update-proxy.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace SceneGraph
35 {
36
37 FrameCallbackProcessor::FrameCallbackProcessor( UpdateManager& updateManager, TransformManager& transformManager )
38 : mFrameCallbacks(),
39   mUpdateManager( updateManager ),
40   mTransformManager( transformManager ),
41   mNodeHierarchyChanged( true )
42 {
43 }
44
45 FrameCallbackProcessor::~FrameCallbackProcessor()
46 {
47 }
48
49 void FrameCallbackProcessor::AddFrameCallback( OwnerPointer< FrameCallback >& frameCallback, const Node* rootNode )
50 {
51   Node& node = const_cast< Node& >( *rootNode ); // Was sent as const from event thread, we need to be able to use non-const version here.
52
53   frameCallback->ConnectToSceneGraph( mUpdateManager, mTransformManager, node );
54
55   mFrameCallbacks.emplace_back( frameCallback );
56 }
57
58 void FrameCallbackProcessor::RemoveFrameCallback( FrameCallbackInterface* frameCallback )
59 {
60   // Find and remove all frame-callbacks that use the given frame-callback-interface
61   auto iter = std::remove( mFrameCallbacks.begin(), mFrameCallbacks.end(), frameCallback );
62   mFrameCallbacks.erase( iter, mFrameCallbacks.end() );
63 }
64
65 void FrameCallbackProcessor::Update( BufferIndex bufferIndex, float elapsedSeconds )
66 {
67   // If any of the FrameCallback::Update calls returns false, then they are no longer required & can be removed.
68   auto iter = std::remove_if(
69     mFrameCallbacks.begin(), mFrameCallbacks.end(),
70     [ & ]( OwnerPointer< FrameCallback >& frameCallback )
71     {
72       return ! frameCallback->Update( bufferIndex, elapsedSeconds, mNodeHierarchyChanged );
73     }
74   );
75   mFrameCallbacks.erase( iter, mFrameCallbacks.end() );
76
77   mNodeHierarchyChanged = false;
78 }
79
80 } // namespace SceneGraph
81
82 } // namespace Internal
83
84 } // namespace Dali