2 * Copyright (c) 2021 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/internal/common/const-string.h>
26 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
27 #include <dali/public-api/common/dali-common.h>
35 PropertyOwner* PropertyOwner::New()
37 return new PropertyOwner();
40 PropertyOwner::~PropertyOwner()
45 void PropertyOwner::AddObserver(Observer& observer)
47 //Check for duplicates in debug builds
48 DALI_ASSERT_DEBUG(mObservers.End() == std::find(mObservers.Begin(), mObservers.End(), &observer));
50 mObservers.PushBack(&observer);
53 void PropertyOwner::RemoveObserver(Observer& observer)
55 // Find the observer...
56 const ConstObserverIter endIter = mObservers.End();
57 for(ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
59 if((*iter) == &observer)
62 mObservers.Erase(iter);
68 bool PropertyOwner::IsObserved()
70 return mObservers.Count() != 0u;
73 void PropertyOwner::Destroy()
75 // Notification for observers
76 const ConstObserverIter endIter = mObservers.End();
77 for(ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
79 (*iter)->PropertyOwnerDestroyed(*this);
84 // Remove all constraints when disconnected from scene-graph
88 void PropertyOwner::ConnectToSceneGraph()
90 mIsConnectedToSceneGraph = true;
92 // Notification for observers
93 const ConstObserverIter endIter = mObservers.End();
94 for(ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
96 (*iter)->PropertyOwnerConnected(*this);
100 void PropertyOwner::DisconnectFromSceneGraph(BufferIndex updateBufferIndex)
102 mIsConnectedToSceneGraph = false;
104 // Notification for observers
105 const ConstObserverIter endIter = mObservers.End();
106 for(ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
108 (*iter)->PropertyOwnerDisconnected(updateBufferIndex, *this);
111 // Remove all constraints when disconnected from scene-graph
112 mConstraints.Clear();
115 void PropertyOwner::InstallCustomProperty(OwnerPointer<PropertyBase>& property)
117 mCustomProperties.PushBack(property.Release());
120 ConstraintOwnerContainer& PropertyOwner::GetConstraints()
125 void PropertyOwner::ApplyConstraint(OwnerPointer<ConstraintBase>& constraint)
127 constraint->OnConnect();
128 mConstraints.PushBack(constraint.Release());
131 void PropertyOwner::RemoveConstraint(ConstraintBase* constraint)
133 const ConstraintIter constraintEndIter = mConstraints.End();
134 for(ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter)
136 if(*iter == constraint)
138 mConstraints.Erase(iter);
139 return; // We're finished
143 //it may be that the constraint has already been removed e.g. from disconnection from scene graph, so nothing needs to be done
146 PropertyOwner::PropertyOwner()
148 mIsConnectedToSceneGraph(false)
152 void PropertyOwner::AddUniformMapping(const UniformPropertyMapping& map)
154 mUniformMaps.Add(map);
157 void PropertyOwner::RemoveUniformMapping(const ConstString& uniformName)
159 mUniformMaps.Remove(uniformName);
162 const UniformMap& PropertyOwner::GetUniformMap() const
167 void PropertyOwner::AddUniformMapObserver(UniformMap::Observer& observer)
169 mUniformMaps.AddObserver(observer);
172 void PropertyOwner::RemoveUniformMapObserver(UniformMap::Observer& observer)
174 mUniformMaps.RemoveObserver(observer);
177 } // namespace SceneGraph
179 } // namespace Internal