2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/update/common/property-owner.h>
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
37 PropertyOwner* PropertyOwner::New()
39 return new PropertyOwner();
42 PropertyOwner::~PropertyOwner()
47 void PropertyOwner::AddObserver(Observer& observer)
49 //Check for duplicates in debug builds
50 DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer ) );
52 mObservers.PushBack( &observer );
55 void PropertyOwner::RemoveObserver(Observer& observer)
57 // Find the observer...
58 const ConstObserverIter endIter = mObservers.End();
59 for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
61 if( (*iter) == &observer)
64 mObservers.Erase(iter);
70 bool PropertyOwner::IsObserved()
72 return mObservers.Count() != 0u;
75 void PropertyOwner::Destroy()
77 // Notification for observers
78 const ConstObserverIter endIter = mObservers.End();
79 for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
81 (*iter)->PropertyOwnerDestroyed(*this);
86 // Remove all constraints when disconnected from scene-graph
90 void PropertyOwner::ConnectToSceneGraph()
92 mIsConnectedToSceneGraph = true;
94 // Notification for observers
95 const ConstObserverIter endIter = mObservers.End();
96 for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
98 (*iter)->PropertyOwnerConnected( *this );
102 void PropertyOwner::DisconnectFromSceneGraph( BufferIndex updateBufferIndex )
104 mIsConnectedToSceneGraph = false;
106 // Notification for observers
107 const ConstObserverIter endIter = mObservers.End();
108 for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
110 (*iter)->PropertyOwnerDisconnected( updateBufferIndex, *this );
113 // Remove all constraints when disconnected from scene-graph
114 mConstraints.Clear();
117 void PropertyOwner::InstallCustomProperty( OwnerPointer<PropertyBase>& property )
119 mCustomProperties.PushBack( property.Release() );
123 ConstraintOwnerContainer& PropertyOwner::GetConstraints()
128 void PropertyOwner::ApplyConstraint( OwnerPointer<ConstraintBase>& constraint )
130 constraint->OnConnect();
131 mConstraints.PushBack( constraint.Release() );
134 void PropertyOwner::RemoveConstraint( ConstraintBase* constraint )
136 const ConstraintIter constraintEndIter = mConstraints.End();
137 for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter )
139 if ( *iter == constraint )
141 mConstraints.Erase( iter );
142 return; // We're finished
146 //it may be that the constraint has already been removed e.g. from disconnection from scene graph, so nothing needs to be done
149 PropertyOwner::PropertyOwner()
151 mIsConnectedToSceneGraph(false)
155 void PropertyOwner::AddUniformMapping( OwnerPointer< UniformPropertyMapping >& map )
157 mUniformMaps.Add( map.Release() );
160 void PropertyOwner::RemoveUniformMapping( const std::string& uniformName )
162 mUniformMaps.Remove( uniformName );
165 const UniformMap& PropertyOwner::GetUniformMap() const
170 void PropertyOwner::AddUniformMapObserver( UniformMap::Observer& observer )
172 mUniformMaps.AddObserver( observer );
175 void PropertyOwner::RemoveUniformMapObserver( UniformMap::Observer& observer )
177 mUniformMaps.RemoveObserver( observer );
182 } // namespace SceneGraph
184 } // namespace Internal