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;
93 // Notification for observers
94 const ConstObserverIter endIter = mObservers.End();
95 for(ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
97 (*iter)->PropertyOwnerConnected(*this);
101 void PropertyOwner::DisconnectFromSceneGraph(BufferIndex updateBufferIndex)
103 mIsConnectedToSceneGraph = false;
105 // Notification for observers
106 const ConstObserverIter endIter = mObservers.End();
107 for(ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
109 (*iter)->PropertyOwnerDisconnected(updateBufferIndex, *this);
112 // Remove all constraints when disconnected from scene-graph
113 mConstraints.Clear();
116 void PropertyOwner::InstallCustomProperty(OwnerPointer<PropertyBase>& property)
118 mCustomProperties.PushBack(property.Release());
121 ConstraintOwnerContainer& PropertyOwner::GetConstraints()
126 void PropertyOwner::ApplyConstraint(OwnerPointer<ConstraintBase>& constraint)
128 constraint->OnConnect();
129 mConstraints.PushBack(constraint.Release());
132 void PropertyOwner::RemoveConstraint(ConstraintBase* constraint)
134 const ConstraintIter constraintEndIter = mConstraints.End();
135 for(ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter)
137 if(*iter == constraint)
139 mConstraints.Erase(iter);
140 return; // We're finished
144 //it may be that the constraint has already been removed e.g. from disconnection from scene graph, so nothing needs to be done
147 PropertyOwner::PropertyOwner()
149 mIsConnectedToSceneGraph(false)
153 void PropertyOwner::AddUniformMapping(const UniformPropertyMapping& map)
155 mUniformMaps.Add(map);
158 void PropertyOwner::RemoveUniformMapping(const ConstString& uniformName)
160 mUniformMaps.Remove(uniformName);
163 const UniformMap& PropertyOwner::GetUniformMap() const
168 void PropertyOwner::AddUniformMapObserver(UniformMap::Observer& observer)
170 mUniformMaps.AddObserver(observer);
173 void PropertyOwner::RemoveUniformMapObserver(UniformMap::Observer& observer)
175 mUniformMaps.RemoveObserver(observer);
178 } // namespace SceneGraph
180 } // namespace Internal