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>
27 #include <dali/internal/common/const-string.h>
38 PropertyOwner* PropertyOwner::New()
40 return new PropertyOwner();
43 PropertyOwner::~PropertyOwner()
48 void PropertyOwner::AddObserver(Observer& observer)
50 //Check for duplicates in debug builds
51 DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer ) );
53 mObservers.PushBack( &observer );
56 void PropertyOwner::RemoveObserver(Observer& observer)
58 // Find the observer...
59 const ConstObserverIter endIter = mObservers.End();
60 for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
62 if( (*iter) == &observer)
65 mObservers.Erase(iter);
71 bool PropertyOwner::IsObserved()
73 return mObservers.Count() != 0u;
76 void PropertyOwner::Destroy()
78 // Notification for observers
79 const ConstObserverIter endIter = mObservers.End();
80 for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
82 (*iter)->PropertyOwnerDestroyed(*this);
87 // Remove all constraints when disconnected from scene-graph
91 void PropertyOwner::ConnectToSceneGraph()
93 mIsConnectedToSceneGraph = true;
95 // Notification for observers
96 const ConstObserverIter endIter = mObservers.End();
97 for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
99 (*iter)->PropertyOwnerConnected( *this );
103 void PropertyOwner::DisconnectFromSceneGraph( BufferIndex updateBufferIndex )
105 mIsConnectedToSceneGraph = false;
107 // Notification for observers
108 const ConstObserverIter endIter = mObservers.End();
109 for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
111 (*iter)->PropertyOwnerDisconnected( updateBufferIndex, *this );
114 // Remove all constraints when disconnected from scene-graph
115 mConstraints.Clear();
118 void PropertyOwner::InstallCustomProperty( OwnerPointer<PropertyBase>& property )
120 mCustomProperties.PushBack( property.Release() );
124 ConstraintOwnerContainer& PropertyOwner::GetConstraints()
129 void PropertyOwner::ApplyConstraint( OwnerPointer<ConstraintBase>& constraint )
131 constraint->OnConnect();
132 mConstraints.PushBack( constraint.Release() );
135 void PropertyOwner::RemoveConstraint( ConstraintBase* constraint )
137 const ConstraintIter constraintEndIter = mConstraints.End();
138 for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter )
140 if ( *iter == constraint )
142 mConstraints.Erase( iter );
143 return; // We're finished
147 //it may be that the constraint has already been removed e.g. from disconnection from scene graph, so nothing needs to be done
150 PropertyOwner::PropertyOwner()
152 mIsConnectedToSceneGraph(false)
156 void PropertyOwner::AddUniformMapping(const UniformPropertyMapping& map)
158 mUniformMaps.Add(map);
161 void PropertyOwner::RemoveUniformMapping( const ConstString& uniformName )
163 mUniformMaps.Remove( uniformName );
166 const UniformMap& PropertyOwner::GetUniformMap() const
171 void PropertyOwner::AddUniformMapObserver( UniformMap::Observer& observer )
173 mUniformMaps.AddObserver( observer );
176 void PropertyOwner::RemoveUniformMapObserver( UniformMap::Observer& observer )
178 mUniformMaps.RemoveObserver( observer );
183 } // namespace SceneGraph
185 } // namespace Internal