Merge "Change RenderTaskList to behave like any other SceneGraph object" into devel...
[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( TransformManager& transformManager )
38 : mFrameCallbacks(),
39   mTransformManager( transformManager ),
40   mNodeHierarchyChanged( true )
41 {
42 }
43
44 FrameCallbackProcessor::~FrameCallbackProcessor()
45 {
46 }
47
48 void FrameCallbackProcessor::AddFrameCallback( OwnerPointer< FrameCallback >& frameCallback, const Node* rootNode )
49 {
50   Node& node = const_cast< Node& >( *rootNode ); // Was sent as const from event thread, we need to be able to use non-const version here.
51
52   frameCallback->ConnectToSceneGraph( mTransformManager, node );
53
54   mFrameCallbacks.emplace_back( frameCallback );
55 }
56
57 void FrameCallbackProcessor::RemoveFrameCallback( FrameCallbackInterface* frameCallback )
58 {
59   // Find and remove all frame-callbacks that use the given frame-callback-interface
60   auto iter = std::remove( mFrameCallbacks.begin(), mFrameCallbacks.end(), frameCallback );
61   mFrameCallbacks.erase( iter, mFrameCallbacks.end() );
62 }
63
64 void FrameCallbackProcessor::Update( BufferIndex bufferIndex, float elapsedSeconds )
65 {
66   // If any of the FrameCallback::Update calls returns false, then they are no longer required & can be removed.
67   auto iter = std::remove_if(
68     mFrameCallbacks.begin(), mFrameCallbacks.end(),
69     [ & ]( OwnerPointer< FrameCallback >& frameCallback )
70     {
71       return ! frameCallback->Update( bufferIndex, elapsedSeconds, mNodeHierarchyChanged );
72     }
73   );
74   mFrameCallbacks.erase( iter, mFrameCallbacks.end() );
75
76   mNodeHierarchyChanged = false;
77 }
78
79 } // namespace SceneGraph
80
81 } // namespace Internal
82
83 } // namespace Dali