1 #ifndef DALI_INTERNAL_UPDATE_PROXY_PROPERTY_MODIFIER_H
2 #define DALI_INTERNAL_UPDATE_PROXY_PROPERTY_MODIFIER_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/internal/common/owner-pointer.h>
23 #include <dali/internal/update/common/property-resetter.h>
24 #include <dali/internal/update/manager/update-manager.h>
25 #include <dali/internal/update/manager/update-proxy-impl.h>
35 } // namespace SceneGraph
38 * Keeps track of any non-transform manager properties that are modified by the UpdateProxy.
40 * This is required so the Update Manager can then reset the value to the base at the start of every frame.
42 class UpdateProxy::PropertyModifier final
45 using Resetter = SceneGraph::Resetter<PropertyModifier>;
48 * Observer to determine when the animator is no longer present
50 class LifecycleObserver
54 * Called shortly before the animator is destroyed.
56 virtual void ObjectDestroyed() = 0;
60 * Virtual destructor, no deletion through this interface
62 virtual ~LifecycleObserver() = default;
66 * Default Constructor.
67 * @param[in] updateManager A reference to the update-manager
69 PropertyModifier(SceneGraph::UpdateManager& updateManager)
71 mLifecycleObservers(),
72 mUpdateManager(&updateManager)
77 * Non-virtual destructor.
81 for(auto& observer : mLifecycleObservers)
83 observer->ObjectDestroyed();
87 // Movable but not copyable
89 PropertyModifier(const PropertyModifier&) = delete; ///< Deleted copy constructor.
90 PropertyModifier& operator=(const PropertyModifier&) = delete; ///< Deleted assignment operator.
95 PropertyModifier(PropertyModifier&& other)
96 : mProperties(std::move(other.mProperties)),
97 mLifecycleObservers(std::move(other.mLifecycleObservers)),
98 mUpdateManager(std::move(other.mUpdateManager))
100 // Clear other so that it does not remove any resetters unintentionally
101 other.mLifecycleObservers.clear();
105 * Move assignment operator.
107 PropertyModifier& operator=(PropertyModifier&& other)
111 mProperties = std::move(other.mProperties);
112 mLifecycleObservers = std::move(other.mLifecycleObservers);
113 mUpdateManager = std::move(other.mUpdateManager);
115 // Clear other so that it does not remove any resetters unintentionally
116 other.mLifecycleObservers.clear();
122 * Allows Resetter to track the life-cycle of this object.
123 * @param[in] observer The observer to add.
125 void AddLifecycleObserver(LifecycleObserver& observer)
127 mLifecycleObservers.push_back(&observer);
131 * The Resetter no longer needs to track the life-cycle of this object.
132 * @param[in] observer The observer that to remove.
134 void RemoveLifecycleObserver(LifecycleObserver& observer)
136 std::remove(mLifecycleObservers.begin(), mLifecycleObservers.end(), &observer);
140 * Adds a resetter to the given node and property if it hasn't already been added previously.
141 * @param[in] node The associated Node
142 * @param[in] propertyBase The associated PropertyBase
144 void AddResetter(SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase)
146 // Check if we've already added a resetter for this node and property to the update-manager
147 NodePropertyPair pair{&node, &propertyBase};
149 (mProperties.end() == std::find(mProperties.begin(), mProperties.end(), pair)))
151 // We haven't, add the pair to our container to ensure we don't add it again
152 // Then create a Resetter which will observe the life of this object
153 // Finally, add the resetter to the Update-Manager
154 // When this object is destroyed, the resetter will be informed and will automatically be removed
156 mProperties.emplace_back(std::move(pair));
157 OwnerPointer<SceneGraph::PropertyResetterBase> resetter(Resetter::New(node, propertyBase, *this));
158 mUpdateManager->AddPropertyResetter(resetter);
164 * Structure to store the Node & property-base pair
166 struct NodePropertyPair
168 SceneGraph::Node* node;
169 SceneGraph::PropertyBase* propertyBase;
171 NodePropertyPair(const NodePropertyPair&) = delete; ///< Deleted copy constructor.
172 NodePropertyPair(NodePropertyPair&&) = default; ///< Default move constructor.
173 NodePropertyPair& operator=(const NodePropertyPair&) = delete; ///< Deleted assignment operator.
174 NodePropertyPair& operator=(NodePropertyPair&&) = default; ///< Default move assignment operator.
177 * Comparison operator
179 bool operator==(const NodePropertyPair& other)
181 return (other.node == node) &&
182 (other.propertyBase == propertyBase);
186 std::vector<NodePropertyPair> mProperties;
187 std::vector<LifecycleObserver*> mLifecycleObservers;
188 SceneGraph::UpdateManager* mUpdateManager;
191 } // namespace Internal
195 #endif // DALI_INTERNAL_UPDATE_PROXY_PROPERTY_MODIFIER_H