2 * Copyright (c) 2021 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/scene-graph-frame-callback.h>
22 #include <dali/devel-api/threading/mutex.h>
23 #include <dali/devel-api/update/frame-callback-interface.h>
24 #include <dali/devel-api/update/update-proxy.h>
25 #include <dali/internal/event/update/frame-callback-interface-impl.h>
33 FrameCallback* FrameCallback::New(FrameCallbackInterface& frameCallbackInterface)
35 return new FrameCallback(&frameCallbackInterface);
38 FrameCallback::~FrameCallback()
42 mUpdateProxy->GetRootNode().RemoveObserver(*this);
46 Mutex::ScopedLock lock(mMutex);
47 if(mFrameCallbackInterface)
49 FrameCallbackInterface::Impl::Get(*mFrameCallbackInterface).DisconnectFromSceneGraphObject();
54 void FrameCallback::ConnectToSceneGraph(UpdateManager& updateManager, TransformManager& transformManager, Node& rootNode)
56 mUpdateProxy = std::unique_ptr<UpdateProxy>(new UpdateProxy(updateManager, transformManager, rootNode));
57 rootNode.AddObserver(*this);
60 bool FrameCallback::Update(BufferIndex bufferIndex, float elapsedSeconds, bool nodeHierarchyChanged)
62 bool continueCalling = false;
65 mUpdateProxy->SetCurrentBufferIndex(bufferIndex);
67 if(nodeHierarchyChanged)
69 mUpdateProxy->NodeHierarchyChanged();
72 Mutex::ScopedLock lock(mMutex);
73 if(mFrameCallbackInterface)
75 Dali::UpdateProxy updateProxy(*mUpdateProxy);
76 mFrameCallbackInterface->Update(updateProxy, elapsedSeconds);
77 continueCalling = true;
80 return continueCalling;
83 void FrameCallback::Invalidate()
85 Mutex::ScopedLock lock(mMutex);
86 if(mFrameCallbackInterface)
88 FrameCallbackInterface::Impl::Get(*mFrameCallbackInterface).DisconnectFromSceneGraphObject();
89 mFrameCallbackInterface = nullptr;
93 void FrameCallback::PropertyOwnerDestroyed(PropertyOwner& owner)
95 mUpdateProxy.reset(); // Root node is being destroyed so no point keeping the update-proxy either
100 FrameCallback::FrameCallback(FrameCallbackInterface* frameCallbackInterface)
102 mFrameCallbackInterface(frameCallbackInterface)
104 if(frameCallbackInterface)
106 FrameCallbackInterface::Impl::Get(*mFrameCallbackInterface).ConnectToSceneGraphObject(*this);
110 } // namespace SceneGraph
112 } // namespace Internal