1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__
5 * Copyright (c) 2014 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.
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/internal/common/message.h>
26 #include <dali/internal/common/owner-container.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/internal/update/animation/scene-graph-constraint-declarations.h>
44 typedef OwnerContainer< PropertyBase* > OwnedPropertyContainer;
45 typedef OwnedPropertyContainer::Iterator OwnedPropertyIter;
48 * An update-thread object which own properties.
49 * This allows observers to track the lifetime of the object & its properties.
60 * Called when the observable object is connected to the scene graph.
61 * @param[in] owner A reference to the connected PropertyOwner
63 virtual void PropertyOwnerConnected( PropertyOwner& owner ) = 0;
66 * Called when the observable object is disconnected from the scene graph.
67 * @param[in] currentBufferIndex The buffer to reset.
68 * @param[in] owner A reference to the disconnected PropertyOwner
70 virtual void PropertyOwnerDisconnected( BufferIndex updateBufferIndex, PropertyOwner& owner ) = 0;
73 * Called shortly before the observable object is destroyed.
75 * @note Cleanup should be done in both this and PropertyOwnerDisconnected as PropertyOwnerDisconnected
76 * may not be called (i.e. when shutting down).
78 virtual void PropertyOwnerDestroyed( PropertyOwner& owner ) = 0;
82 * Create a property owner.
83 * @return A newly allocated object.
85 static PropertyOwner* New();
88 * Virtual destructor; this is intended as a base class.
90 virtual ~PropertyOwner();
94 * The observer is responsible for calling RemoveObserver(*this) during its own destruction.
95 * Connecting an actor-side object as an observer is not allowed, due to thread-safety issues.
96 * @param[in] observer The observer.
98 void AddObserver(Observer& observer);
101 * Remove an observer.
102 * @param[in] observer The observer.
104 void RemoveObserver(Observer& observer);
107 * This method can be used to determine if there is an animation or
108 * constraint that is using this property owner.
109 * @return true if there are observers.
114 * Called just before destruction to disconnect all observers and remove constraints.
115 * This occurs when the object is in the process of being destroyed.
120 * Notify all observers that the object has been connected
121 * This occurs when the object is connected to the scene-graph during UpdateManager::Update().
123 void ConnectToSceneGraph();
126 * Notify all observers that the object has been disconnected and remove constraints.
127 * This occurs when the object is disconnected from the scene-graph during UpdateManager::Update().
128 * @param[in] currentBufferIndex The current update buffer.
130 void DisconnectFromSceneGraph( BufferIndex updateBufferIndex );
133 * Install a custom property.
134 * @post The PropertyOwner takes ownership of the property.
135 * @param[in] property A pointer to a newly allocated property.
137 void InstallCustomProperty(PropertyBase* property);
140 * Retrieve the custom properties owned by the object.
141 * @return A container of properties.
143 OwnedPropertyContainer& GetCustomProperties()
145 return mCustomProperties;
149 * Retrieve the custom properties owned by the object.
150 * @return A container of properties.
152 const OwnedPropertyContainer& GetCustomProperties() const
154 return mCustomProperties;
158 * Reset animatable properties to the corresponding base values.
159 * @param[in] currentBufferIndex The buffer to reset.
160 * @post The ResetDefaultProperties method is called, during which derived classes can reset default properties.
162 void ResetToBaseValues( BufferIndex updateBufferIndex );
167 * Apply a constraint.
168 * @param[in] constraint The constraint to apply.
170 void ApplyConstraint( ConstraintBase* constraint );
173 * Begin removal of constraints.
174 * @param[in] constraint The constraint to remove.
176 void RemoveConstraint( ConstraintBase* constraint );
179 * Retrieve the constraints that are currently applied.
180 * @return A container of constraints.
182 ConstraintOwnerContainer& GetConstraints();
185 * @copydoc UniformMap::Add
187 virtual void AddUniformMapping( UniformPropertyMapping* map );
190 * @copydoc UniformMap::Remove
192 virtual void RemoveUniformMapping( const std::string& uniformName );
195 * Get the mappings table
197 const UniformMap& GetUniformMap() const;
200 * @copydoc UniformMap::AddUniformMapObserver
202 void AddUniformMapObserver( UniformMap::Observer& observer );
205 * @copydoc UniformMap::RemoveUniformMapObserver
207 void RemoveUniformMapObserver( UniformMap::Observer& observer );
213 * Protected constructor.
220 PropertyOwner(const PropertyOwner&);
223 PropertyOwner& operator=(const PropertyOwner& rhs);
226 * Called after ResetToBaseValues; derived classes should reset any default properties.
227 * @param[in] currentBufferIndex The buffer to reset.
229 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ) {}
233 OwnedPropertyContainer mCustomProperties; ///< Properties provided with InstallCustomProperty()
234 UniformMap mUniformMaps; ///< Container of owned uniform maps
238 typedef Dali::Vector<PropertyOwner::Observer*> ObserverContainer;
239 typedef ObserverContainer::Iterator ObserverIter;
240 typedef ObserverContainer::ConstIterator ConstObserverIter;
242 ObserverContainer mObservers; ///< Container of observer raw-pointers (not owned)
244 ConstraintOwnerContainer mConstraints; ///< Container of owned constraints
247 } // namespace SceneGraph
249 } // namespace Internal
253 #endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__