1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H
5 * Copyright (c) 2019 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/public-api/common/dali-vector.h>
23 #include <dali/devel-api/common/owner-container.h>
24 #include <dali/internal/common/message.h>
25 #include <dali/internal/update/common/property-base.h>
26 #include <dali/internal/update/common/scene-graph-buffers.h>
27 #include <dali/internal/update/common/uniform-map.h>
28 #include <dali/internal/update/animation/scene-graph-constraint-declarations.h>
42 typedef OwnerContainer< PropertyBase* > OwnedPropertyContainer;
43 typedef OwnedPropertyContainer::Iterator OwnedPropertyIter;
46 * An update-thread object which own properties.
47 * This allows observers to track the lifetime of the object & its properties.
58 * Called when the observable object is connected to the scene graph.
59 * @param[in] owner A reference to the connected PropertyOwner
61 virtual void PropertyOwnerConnected( PropertyOwner& owner ) = 0;
64 * Called when the observable object is disconnected from the scene graph.
65 * @param[in] currentBufferIndex The buffer to reset.
66 * @param[in] owner A reference to the disconnected PropertyOwner
68 virtual void PropertyOwnerDisconnected( BufferIndex updateBufferIndex, PropertyOwner& owner ) = 0;
71 * Called shortly before the observable object is destroyed.
73 * @note Cleanup should be done in both this and PropertyOwnerDisconnected as PropertyOwnerDisconnected
74 * may not be called (i.e. when shutting down).
76 virtual void PropertyOwnerDestroyed( PropertyOwner& owner ) = 0;
81 * Virtual destructor, no deletion through this interface
83 virtual ~Observer() {}
88 * Create a property owner.
89 * @return A newly allocated object.
91 static PropertyOwner* New();
94 * Virtual destructor; this is intended as a base class.
96 virtual ~PropertyOwner();
100 * The observer is responsible for calling RemoveObserver(*this) during its own destruction.
101 * Connecting an actor-side object as an observer is not allowed, due to thread-safety issues.
102 * @param[in] observer The observer.
104 void AddObserver(Observer& observer);
107 * Remove an observer.
108 * @param[in] observer The observer.
110 void RemoveObserver(Observer& observer);
113 * This method can be used to determine if there is an animation or
114 * constraint that is using this property owner.
115 * @return true if there are observers.
120 * Called just before destruction to disconnect all observers and remove constraints.
121 * This occurs when the object is in the process of being destroyed.
126 * Notify all observers that the object has been connected
127 * This occurs when the object is connected to the scene-graph during UpdateManager::Update().
129 void ConnectToSceneGraph();
132 * Notify all observers that the object has been disconnected and remove constraints.
133 * This occurs when the object is disconnected from the scene-graph during UpdateManager::Update().
134 * @param[in] currentBufferIndex The current update buffer.
136 void DisconnectFromSceneGraph( BufferIndex updateBufferIndex );
139 * Install a custom property.
140 * @post The PropertyOwner takes ownership of the property.
141 * @param[in] property A pointer to a newly allocated property.
143 void InstallCustomProperty( OwnerPointer<PropertyBase>& property );
146 * Retrieve the custom properties owned by the object.
147 * @return A container of properties.
149 OwnedPropertyContainer& GetCustomProperties()
151 return mCustomProperties;
155 * Retrieve the custom properties owned by the object.
156 * @return A container of properties.
158 const OwnedPropertyContainer& GetCustomProperties() const
160 return mCustomProperties;
164 * Mark an property owner with the updated flag.
165 * @param[in] updated The updated flag
167 virtual void SetUpdated(bool updated)
173 * Retrieve if the property owner is updated due to the property is being animating.
174 * @return An updated flag
184 * Apply a constraint.
185 * @param[in] constraint The constraint to apply.
187 void ApplyConstraint( OwnerPointer<ConstraintBase>& constraint );
190 * Begin removal of constraints.
191 * @param[in] constraint The constraint to remove.
193 void RemoveConstraint( ConstraintBase* constraint );
196 * Retrieve the constraints that are currently applied.
197 * @return A container of constraints.
199 ConstraintOwnerContainer& GetConstraints();
202 * @copydoc UniformMap::Add
204 virtual void AddUniformMapping( OwnerPointer< UniformPropertyMapping >& map );
207 * @copydoc UniformMap::Remove
209 virtual void RemoveUniformMapping( const std::string& uniformName );
212 * Get the mappings table
214 const UniformMap& GetUniformMap() const;
217 * @copydoc UniformMap::AddUniformMapObserver
219 void AddUniformMapObserver( UniformMap::Observer& observer );
222 * @copydoc UniformMap::RemoveUniformMapObserver
224 void RemoveUniformMapObserver( UniformMap::Observer& observer );
230 * Protected constructor.
237 PropertyOwner(const PropertyOwner&);
240 PropertyOwner& operator=(const PropertyOwner& rhs);
244 OwnedPropertyContainer mCustomProperties; ///< Properties provided with InstallCustomProperty()
245 UniformMap mUniformMaps; ///< Container of owned uniform maps
250 typedef Dali::Vector<PropertyOwner::Observer*> ObserverContainer;
251 typedef ObserverContainer::Iterator ObserverIter;
252 typedef ObserverContainer::ConstIterator ConstObserverIter;
254 ObserverContainer mObservers; ///< Container of observer raw-pointers (not owned)
256 ConstraintOwnerContainer mConstraints; ///< Container of owned constraints
259 } // namespace SceneGraph
261 } // namespace Internal
265 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H