Merge "Reduce Render::Renderer size" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-property-notification.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <dali/internal/event/animation/property-constraint.h>
19 #include <dali/internal/event/animation/property-input-accessor.h>
20 #include <dali/internal/event/animation/property-input-indexer.h>
21 #include <dali/internal/event/common/object-impl.h>
22 #include <dali/internal/update/common/property-base.h>
23 #include <dali/internal/update/common/property-condition-functions.h>
24 #include <dali/internal/update/common/property-owner.h>
25 #include <dali/internal/update/common/scene-graph-property-notification.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 namespace SceneGraph
32 {
33 PropertyNotification* PropertyNotification::New(const PropertyInputImpl* property,
34                                                 Property::Index          propertyIndex,
35                                                 Property::Type           propertyType,
36                                                 int                      componentIndex,
37                                                 ConditionType            condition,
38                                                 RawArgumentContainer&    arguments,
39                                                 NotifyMode               notifyMode,
40                                                 bool                     compare)
41 {
42   return new PropertyNotification(property, propertyIndex, propertyType, componentIndex, condition, arguments, notifyMode, compare);
43 }
44
45 PropertyNotification::PropertyNotification(const PropertyInputImpl* property,
46                                            Property::Index          propertyIndex,
47                                            Property::Type           propertyType,
48                                            int                      componentIndex,
49                                            ConditionType            condition,
50                                            RawArgumentContainer&    arguments,
51                                            NotifyMode               notifyMode,
52                                            bool                     compare)
53 : mPropertyIndex(propertyIndex),
54   mPropertyType(propertyType),
55   mProperty(property),
56   mComponentIndex(componentIndex),
57   mConditionType(condition),
58   mArguments(arguments),
59   mValid(false),
60   mNotifyMode(Dali::PropertyNotification::DISABLED),
61   mConditionFunction(nullptr)
62 {
63   SetNotifyMode(notifyMode);
64
65   switch(mConditionType)
66   {
67     case PropertyCondition::LessThan:
68     {
69       mConditionFunction = LessThan::GetFunction(mPropertyType);
70       break;
71     }
72     case PropertyCondition::GreaterThan:
73     {
74       mConditionFunction = GreaterThan::GetFunction(mPropertyType);
75       break;
76     }
77     case PropertyCondition::Inside:
78     {
79       mConditionFunction = Inside::GetFunction(mPropertyType);
80       break;
81     }
82     case PropertyCondition::Outside:
83     {
84       mConditionFunction = Outside::GetFunction(mPropertyType);
85       break;
86     }
87     case PropertyCondition::Step:
88     {
89       if(compare == true)
90       {
91         mConditionFunction = Step::GetCompareFunction(mPropertyType);
92       }
93       else
94       {
95         mConditionFunction = Step::GetFunction(mPropertyType);
96       }
97       break;
98     }
99     case PropertyCondition::VariableStep:
100     {
101       mConditionFunction = VariableStep::GetFunction(mPropertyType);
102       break;
103     }
104     case PropertyCondition::False:
105     {
106       mConditionFunction = PropertyNotification::EvalFalse;
107       break;
108     }
109   }
110 }
111
112 PropertyNotification::~PropertyNotification() = default;
113
114 bool PropertyNotification::EvalFalse(const Dali::PropertyInput& value, RawArgumentContainer& arg)
115 {
116   return false;
117 }
118
119 void PropertyNotification::SetNotifyMode(NotifyMode notifyMode)
120 {
121   mNotifyMode = notifyMode;
122 }
123
124 bool PropertyNotification::Check(BufferIndex bufferIndex)
125 {
126   bool notifyRequired = false;
127   bool currentValid   = false;
128
129   if(Property::INVALID_COMPONENT_INDEX != mComponentIndex)
130   {
131     // Evaluate Condition
132     const PropertyInputAccessor                       component(mProperty, mComponentIndex);
133     const PropertyInputIndexer<PropertyInputAccessor> input(bufferIndex, &component);
134     currentValid = mConditionFunction(input, mArguments);
135   }
136   else
137   {
138     // Evaluate Condition
139     const PropertyInputIndexer<PropertyInputImpl> input(bufferIndex, mProperty);
140     currentValid = mConditionFunction(input, mArguments);
141   }
142
143   if(mValid != currentValid || (currentValid && ((mConditionType == PropertyCondition::Step) || (mConditionType == PropertyCondition::VariableStep))))
144   {
145     mValid = currentValid;
146     //  means don't notify so notifyRequired stays false
147     switch(mNotifyMode)
148     {
149       case Dali::PropertyNotification::DISABLED:
150       {
151         // notify never, already initialized to false
152         break;
153       }
154       case Dali::PropertyNotification::NOTIFY_ON_TRUE:
155       {
156         notifyRequired = mValid; // notify if value is true
157         break;
158       }
159       case Dali::PropertyNotification::NOTIFY_ON_FALSE:
160       {
161         notifyRequired = !mValid; // notify when its false
162         break;
163       }
164       case Dali::PropertyNotification::NOTIFY_ON_CHANGED:
165       {
166         notifyRequired = true; // notify whenever changed
167         break;
168       }
169     }
170   }
171
172   return notifyRequired;
173 }
174
175 bool PropertyNotification::GetValidity() const
176 {
177   return mValid;
178 }
179
180 } // namespace SceneGraph
181
182 } // namespace Internal
183
184 } // namespace Dali