2 * Copyright (c) 2023 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::ReserveProperties(int propertyCount)
118 mCustomProperties.Reserve(propertyCount);
121 void PropertyOwner::InstallCustomProperty(OwnerPointer<PropertyBase>& property)
123 mCustomProperties.PushBack(property.Release());
126 ConstraintOwnerContainer& PropertyOwner::GetConstraints()
131 void PropertyOwner::ApplyConstraint(OwnerPointer<ConstraintBase>& constraint)
133 constraint->OnConnect();
134 mConstraints.PushBack(constraint.Release());
137 void PropertyOwner::RemoveConstraint(ConstraintBase* constraint)
139 const ConstraintIter constraintEndIter = mConstraints.End();
140 for(ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter)
142 if(*iter == constraint)
144 mConstraints.Erase(iter);
145 return; // We're finished
149 //it may be that the constraint has already been removed e.g. from disconnection from scene graph, so nothing needs to be done
152 PropertyOwner::PropertyOwner()
154 mIsConnectedToSceneGraph(false)
158 void PropertyOwner::AddUniformMapping(const UniformPropertyMapping& map)
160 mUniformMaps.Add(map);
164 void PropertyOwner::RemoveUniformMapping(const ConstString& uniformName)
166 mUniformMaps.Remove(uniformName);
170 const UniformMap& PropertyOwner::GetUniformMap() const
175 } // namespace SceneGraph
177 } // namespace Internal