1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__
5 * Copyright (c) 2017 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/devel-api/common/owner-container.h>
26 #include <dali/internal/common/message.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;
83 * Virtual destructor, no deletion through this interface
85 virtual ~Observer() {}
90 * Create a property owner.
91 * @return A newly allocated object.
93 static PropertyOwner* New();
96 * Virtual destructor; this is intended as a base class.
98 virtual ~PropertyOwner();
102 * The observer is responsible for calling RemoveObserver(*this) during its own destruction.
103 * Connecting an actor-side object as an observer is not allowed, due to thread-safety issues.
104 * @param[in] observer The observer.
106 void AddObserver(Observer& observer);
109 * Remove an observer.
110 * @param[in] observer The observer.
112 void RemoveObserver(Observer& observer);
115 * This method can be used to determine if there is an animation or
116 * constraint that is using this property owner.
117 * @return true if there are observers.
122 * Called just before destruction to disconnect all observers and remove constraints.
123 * This occurs when the object is in the process of being destroyed.
128 * Notify all observers that the object has been connected
129 * This occurs when the object is connected to the scene-graph during UpdateManager::Update().
131 void ConnectToSceneGraph();
134 * Notify all observers that the object has been disconnected and remove constraints.
135 * This occurs when the object is disconnected from the scene-graph during UpdateManager::Update().
136 * @param[in] currentBufferIndex The current update buffer.
138 void DisconnectFromSceneGraph( BufferIndex updateBufferIndex );
141 * Install a custom property.
142 * @post The PropertyOwner takes ownership of the property.
143 * @param[in] property A pointer to a newly allocated property.
145 void InstallCustomProperty( OwnerPointer<PropertyBase>& property );
148 * Retrieve the custom properties owned by the object.
149 * @return A container of properties.
151 OwnedPropertyContainer& GetCustomProperties()
153 return mCustomProperties;
157 * Retrieve the custom properties owned by the object.
158 * @return A container of properties.
160 const OwnedPropertyContainer& GetCustomProperties() const
162 return mCustomProperties;
166 * Reset animatable properties to the corresponding base values.
167 * @param[in] currentBufferIndex The buffer to reset.
168 * @post The ResetDefaultProperties method is called, during which derived classes can reset default properties.
170 void ResetToBaseValues( BufferIndex updateBufferIndex );
175 * Apply a constraint.
176 * @param[in] constraint The constraint to apply.
178 void ApplyConstraint( OwnerPointer<ConstraintBase>& constraint );
181 * Begin removal of constraints.
182 * @param[in] constraint The constraint to remove.
184 void RemoveConstraint( ConstraintBase* constraint );
187 * Retrieve the constraints that are currently applied.
188 * @return A container of constraints.
190 ConstraintOwnerContainer& GetConstraints();
193 * @copydoc UniformMap::Add
195 virtual void AddUniformMapping( OwnerPointer< UniformPropertyMapping >& map );
198 * @copydoc UniformMap::Remove
200 virtual void RemoveUniformMapping( const std::string& uniformName );
203 * Get the mappings table
205 const UniformMap& GetUniformMap() const;
208 * @copydoc UniformMap::AddUniformMapObserver
210 void AddUniformMapObserver( UniformMap::Observer& observer );
213 * @copydoc UniformMap::RemoveUniformMapObserver
215 void RemoveUniformMapObserver( UniformMap::Observer& observer );
221 * Protected constructor.
228 PropertyOwner(const PropertyOwner&);
231 PropertyOwner& operator=(const PropertyOwner& rhs);
234 * Called after ResetToBaseValues; derived classes should reset any default properties.
235 * @param[in] currentBufferIndex The buffer to reset.
237 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ) {}
241 OwnedPropertyContainer mCustomProperties; ///< Properties provided with InstallCustomProperty()
242 UniformMap mUniformMaps; ///< Container of owned uniform maps
246 typedef Dali::Vector<PropertyOwner::Observer*> ObserverContainer;
247 typedef ObserverContainer::Iterator ObserverIter;
248 typedef ObserverContainer::ConstIterator ConstObserverIter;
250 ObserverContainer mObservers; ///< Container of observer raw-pointers (not owned)
252 ConstraintOwnerContainer mConstraints; ///< Container of owned constraints
255 } // namespace SceneGraph
257 } // namespace Internal
261 #endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__