1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H
5 * Copyright (c) 2024 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/devel-api/common/owner-container.h>
23 #include <dali/integration-api/ordered-set.h>
24 #include <dali/internal/common/const-string.h>
25 #include <dali/internal/common/message.h>
26 #include <dali/internal/update/animation/scene-graph-constraint-declarations.h>
27 #include <dali/internal/update/common/property-base.h>
28 #include <dali/internal/update/common/scene-graph-buffers.h>
29 #include <dali/internal/update/common/uniform-map.h>
30 #include <dali/public-api/common/dali-vector.h>
39 class ResetterManager;
41 using OwnedPropertyContainer = OwnerContainer<PropertyBase*>;
42 using OwnedPropertyIter = OwnedPropertyContainer::Iterator;
45 * An update-thread object which own properties.
46 * This allows observers to track the lifetime of the object & its properties.
62 * Called when the observable object is connected to the scene graph.
63 * @param[in] owner A reference to the connected PropertyOwner
65 virtual void PropertyOwnerConnected(PropertyOwner& owner) = 0;
68 * Called when the observable object is disconnected from the scene graph.
69 * @param[in] currentBufferIndex The buffer to reset.
70 * @param[in] owner A reference to the disconnected PropertyOwner
71 * @return NotifyReturnType::STOP_OBSERVING if we will not observe this object after this called
72 * NotifyReturnType::KEEP_OBSERVING if we will observe this object after this called.
74 virtual NotifyReturnType PropertyOwnerDisconnected(BufferIndex updateBufferIndex, PropertyOwner& owner) = 0;
77 * Called shortly before the observable object is destroyed.
79 * @note Cleanup should be done in both this and PropertyOwnerDisconnected as PropertyOwnerDisconnected
80 * may not be called (i.e. when shutting down).
82 virtual void PropertyOwnerDestroyed(PropertyOwner& owner) = 0;
86 * Virtual destructor, no deletion through this interface
88 virtual ~Observer() = default;
92 * Create a property owner.
93 * @return A newly allocated object.
95 static PropertyOwner* New();
98 * Virtual destructor; this is intended as a base class.
100 virtual ~PropertyOwner();
104 * The observer is responsible for calling RemoveObserver(*this) during its own destruction.
105 * Connecting an actor-side object as an observer is not allowed, due to thread-safety issues.
106 * @param[in] observer The observer.
108 void AddObserver(Observer& observer);
111 * Remove an observer.
112 * @param[in] observer The observer.
114 void RemoveObserver(Observer& observer);
117 * This method can be used to determine if there is an animation or
118 * constraint that is using this property owner.
119 * @return true if there are observers.
124 * Called just before destruction to disconnect all observers and remove constraints.
125 * This occurs when the object is in the process of being destroyed.
130 * Notify all observers that the object has been connected
131 * This occurs when the object is connected to the scene-graph during UpdateManager::Update().
133 void ConnectToSceneGraph();
136 * Notify all observers that the object has been disconnected and remove constraints.
137 * This occurs when the object is disconnected from the scene-graph during UpdateManager::Update().
138 * @param[in] currentBufferIndex The current update buffer.
140 void DisconnectFromSceneGraph(BufferIndex updateBufferIndex);
143 * Reserve the given number of properties
145 void ReserveProperties(int propertyCount);
148 * Install a custom property.
149 * @post The PropertyOwner takes ownership of the property.
150 * @param[in] property A pointer to a newly allocated property.
152 void InstallCustomProperty(OwnerPointer<PropertyBase>& property);
155 * Retrieve the custom properties owned by the object.
156 * @return A container of properties.
158 OwnedPropertyContainer& GetCustomProperties()
160 return mCustomProperties;
164 * Retrieve the custom properties owned by the object.
165 * @return A container of properties.
167 const OwnedPropertyContainer& GetCustomProperties() const
169 return mCustomProperties;
173 * Mark an property owner with the updated flag.
174 * @param[in] updated The updated flag
176 void SetUpdated(bool updated)
182 * Retrieve if the property owner is updated due to the property is being animating.
183 * @return An updated flag
193 * Apply a constraint.
194 * @param[in] constraint The constraint to apply.
196 void ApplyConstraint(OwnerPointer<ConstraintBase>& constraint);
199 * Begin removal of constraints.
200 * @param[in] constraint The constraint to remove.
202 void RemoveConstraint(ConstraintBase* constraint);
205 * Apply a post constraint.
206 * @param[in] constraint The constraint to apply.
208 void ApplyPostConstraint(OwnerPointer<ConstraintBase>& constraint);
211 * Begin removal of post constraints.
212 * @param[in] constraint The constraint to remove.
214 void RemovePostConstraint(ConstraintBase* constraint);
217 * Retrieve the constraints that are currently applied.
218 * @return A container of constraints.
220 ConstraintOwnerContainer& GetConstraints();
223 * Retrieve the post constraints that are currently applied.
224 * @return A container of post constraints.
226 ConstraintOwnerContainer& GetPostConstraints();
229 * @copydoc UniformMap::Add
231 virtual void AddUniformMapping(const UniformPropertyMapping& map);
234 * @copydoc UniformMap::Remove
236 virtual void RemoveUniformMapping(const ConstString& uniformName);
239 * Get the mappings table
241 const UniformMap& GetUniformMap() const;
244 * Query whether playing an animation is possible or not.
245 * @return true if playing an animation is possible.
247 virtual bool IsAnimationPossible() const
253 * @brief Install custom resetter messages to resetter manager.
254 * @pre ConnectToSceneGraph() Should be called before this API.
256 * @param[in] manager ResetterManager to add resetter.
258 virtual void AddInitializeResetter(ResetterManager& manager) const
265 * Protected constructor.
270 * Method to inform derived classes when property maps have been modified.
272 virtual void OnMappingChanged()
274 // Default behaviour is to do nothing
279 PropertyOwner(const PropertyOwner&);
282 PropertyOwner& operator=(const PropertyOwner& rhs);
285 OwnedPropertyContainer mCustomProperties; ///< Properties provided with InstallCustomProperty()
286 UniformMap mUniformMaps; ///< Container of owned uniform maps
288 bool mIsConnectedToSceneGraph;
291 using ObserverContainer = Integration::OrderedSet<PropertyOwner::Observer, false>;
292 using ObserverIter = ObserverContainer::Iterator;
293 using ConstObserverIter = ObserverContainer::ConstIterator;
295 ObserverContainer mObservers; ///< Container of observer raw-pointers (not owned)
297 ConstraintOwnerContainer mConstraints; ///< Container of owned constraints
298 ConstraintOwnerContainer mPostConstraints; ///< Container of owned constraints
300 bool mObserverNotifying : 1; ///< Whether we are currently notifying observers.
303 } // namespace SceneGraph
305 } // namespace Internal
309 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H