1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_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/devel-api/common/owner-container.h>
23 #include <dali/internal/common/const-string.h>
24 #include <dali/internal/common/message.h>
25 #include <dali/internal/update/animation/scene-graph-constraint-declarations.h>
26 #include <dali/internal/update/common/property-base.h>
27 #include <dali/internal/update/common/scene-graph-buffers.h>
28 #include <dali/internal/update/common/uniform-map.h>
29 #include <dali/public-api/common/dali-vector.h>
39 using OwnedPropertyContainer = OwnerContainer<PropertyBase*>;
40 using OwnedPropertyIter = OwnedPropertyContainer::Iterator;
43 * An update-thread object which own properties.
44 * This allows observers to track the lifetime of the object & its properties.
53 * Called when the observable object is connected to the scene graph.
54 * @param[in] owner A reference to the connected PropertyOwner
56 virtual void PropertyOwnerConnected(PropertyOwner& owner) = 0;
59 * Called when the observable object is disconnected from the scene graph.
60 * @param[in] currentBufferIndex The buffer to reset.
61 * @param[in] owner A reference to the disconnected PropertyOwner
63 virtual void PropertyOwnerDisconnected(BufferIndex updateBufferIndex, PropertyOwner& owner) = 0;
66 * Called shortly before the observable object is destroyed.
68 * @note Cleanup should be done in both this and PropertyOwnerDisconnected as PropertyOwnerDisconnected
69 * may not be called (i.e. when shutting down).
71 virtual void PropertyOwnerDestroyed(PropertyOwner& owner) = 0;
75 * Virtual destructor, no deletion through this interface
77 virtual ~Observer() = default;
81 * Create a property owner.
82 * @return A newly allocated object.
84 static PropertyOwner* New();
87 * Virtual destructor; this is intended as a base class.
89 virtual ~PropertyOwner();
93 * The observer is responsible for calling RemoveObserver(*this) during its own destruction.
94 * Connecting an actor-side object as an observer is not allowed, due to thread-safety issues.
95 * @param[in] observer The observer.
97 void AddObserver(Observer& observer);
100 * Remove an observer.
101 * @param[in] observer The observer.
103 void RemoveObserver(Observer& observer);
106 * This method can be used to determine if there is an animation or
107 * constraint that is using this property owner.
108 * @return true if there are observers.
113 * Called just before destruction to disconnect all observers and remove constraints.
114 * This occurs when the object is in the process of being destroyed.
119 * Notify all observers that the object has been connected
120 * This occurs when the object is connected to the scene-graph during UpdateManager::Update().
122 void ConnectToSceneGraph();
125 * Notify all observers that the object has been disconnected and remove constraints.
126 * This occurs when the object is disconnected from the scene-graph during UpdateManager::Update().
127 * @param[in] currentBufferIndex The current update buffer.
129 void DisconnectFromSceneGraph(BufferIndex updateBufferIndex);
132 * Install a custom property.
133 * @post The PropertyOwner takes ownership of the property.
134 * @param[in] property A pointer to a newly allocated property.
136 void InstallCustomProperty(OwnerPointer<PropertyBase>& property);
139 * Retrieve the custom properties owned by the object.
140 * @return A container of properties.
142 OwnedPropertyContainer& GetCustomProperties()
144 return mCustomProperties;
148 * Retrieve the custom properties owned by the object.
149 * @return A container of properties.
151 const OwnedPropertyContainer& GetCustomProperties() const
153 return mCustomProperties;
157 * Mark an property owner with the updated flag.
158 * @param[in] updated The updated flag
160 virtual void SetUpdated(bool updated)
166 * Retrieve if the property owner is updated due to the property is being animating.
167 * @return An updated flag
177 * Apply a constraint.
178 * @param[in] constraint The constraint to apply.
180 void ApplyConstraint(OwnerPointer<ConstraintBase>& constraint);
183 * Begin removal of constraints.
184 * @param[in] constraint The constraint to remove.
186 void RemoveConstraint(ConstraintBase* constraint);
189 * Retrieve the constraints that are currently applied.
190 * @return A container of constraints.
192 ConstraintOwnerContainer& GetConstraints();
195 * @copydoc UniformMap::Add
197 virtual void AddUniformMapping(const UniformPropertyMapping& map);
200 * @copydoc UniformMap::Remove
202 virtual void RemoveUniformMapping(const ConstString& uniformName);
205 * Get the mappings table
207 const UniformMap& GetUniformMap() const;
210 * @copydoc UniformMap::AddUniformMapObserver
212 void AddUniformMapObserver(UniformMap::Observer& observer);
215 * @copydoc UniformMap::RemoveUniformMapObserver
217 void RemoveUniformMapObserver(UniformMap::Observer& observer);
220 * Query whether playing an animation is possible or not.
221 * @return true if playing an animation is possible.
223 virtual bool IsAnimationPossible() const
230 * Protected constructor.
236 PropertyOwner(const PropertyOwner&);
239 PropertyOwner& operator=(const PropertyOwner& rhs);
242 OwnedPropertyContainer mCustomProperties; ///< Properties provided with InstallCustomProperty()
243 UniformMap mUniformMaps; ///< Container of owned uniform maps
245 bool mIsConnectedToSceneGraph;
248 using ObserverContainer = Dali::Vector<PropertyOwner::Observer*>;
249 using ObserverIter = ObserverContainer::Iterator;
250 using ConstObserverIter = ObserverContainer::ConstIterator;
252 ObserverContainer mObservers; ///< Container of observer raw-pointers (not owned)
254 ConstraintOwnerContainer mConstraints; ///< Container of owned constraints
257 } // namespace SceneGraph
259 } // namespace Internal
263 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H