(Partial Update) Change damaged rect calcutation
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-property-notification.cpp
1 /*
2  * Copyright (c) 2021 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(Object&               object,
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(object, propertyIndex, propertyType, componentIndex, condition, arguments, notifyMode, compare);
43 }
44
45 PropertyNotification::PropertyNotification(Object&               object,
46                                            Property::Index       propertyIndex,
47                                            Property::Type        propertyType,
48                                            int                   componentIndex,
49                                            ConditionType         condition,
50                                            RawArgumentContainer& arguments,
51                                            NotifyMode            notifyMode,
52                                            bool                  compare)
53 : mObject(&object),
54   mPropertyIndex(propertyIndex),
55   mPropertyType(propertyType),
56   mProperty(nullptr),
57   mComponentIndex(componentIndex),
58   mConditionType(condition),
59   mArguments(arguments),
60   mValid(false),
61   mNotifyMode(Dali::PropertyNotification::DISABLED),
62   mConditionFunction(nullptr)
63 {
64   SetNotifyMode(notifyMode);
65
66   switch(mConditionType)
67   {
68     case PropertyCondition::LessThan:
69     {
70       mConditionFunction = LessThan::GetFunction(mPropertyType);
71       break;
72     }
73     case PropertyCondition::GreaterThan:
74     {
75       mConditionFunction = GreaterThan::GetFunction(mPropertyType);
76       break;
77     }
78     case PropertyCondition::Inside:
79     {
80       mConditionFunction = Inside::GetFunction(mPropertyType);
81       break;
82     }
83     case PropertyCondition::Outside:
84     {
85       mConditionFunction = Outside::GetFunction(mPropertyType);
86       break;
87     }
88     case PropertyCondition::Step:
89     {
90       if(compare == true)
91       {
92         mConditionFunction = Step::GetCompareFunction(mPropertyType);
93       }
94       else
95       {
96         mConditionFunction = Step::GetFunction(mPropertyType);
97       }
98       break;
99     }
100     case PropertyCondition::VariableStep:
101     {
102       mConditionFunction = VariableStep::GetFunction(mPropertyType);
103       break;
104     }
105     case PropertyCondition::False:
106     {
107       mConditionFunction = PropertyNotification::EvalFalse;
108       break;
109     }
110   }
111
112   mProperty                  = mObject->GetSceneObjectInputProperty(mPropertyIndex);
113   int internalComponentIndex = mObject->GetPropertyComponentIndex(mPropertyIndex);
114   if(internalComponentIndex != Property::INVALID_COMPONENT_INDEX)
115   {
116     // override the one passed in
117     mComponentIndex = internalComponentIndex;
118   }
119 }
120
121 PropertyNotification::~PropertyNotification() = default;
122
123 bool PropertyNotification::EvalFalse(const Dali::PropertyInput& value, RawArgumentContainer& arg)
124 {
125   return false;
126 }
127
128 void PropertyNotification::SetNotifyMode(NotifyMode notifyMode)
129 {
130   mNotifyMode = notifyMode;
131 }
132
133 bool PropertyNotification::Check(BufferIndex bufferIndex)
134 {
135   bool notifyRequired = false;
136   bool currentValid   = false;
137
138   if(Property::INVALID_COMPONENT_INDEX != mComponentIndex)
139   {
140     // Evaluate Condition
141     const PropertyInputAccessor                       component(mProperty, mComponentIndex);
142     const PropertyInputIndexer<PropertyInputAccessor> input(bufferIndex, &component);
143     currentValid = mConditionFunction(input, mArguments);
144   }
145   else
146   {
147     // Evaluate Condition
148     const PropertyInputIndexer<PropertyInputImpl> input(bufferIndex, mProperty);
149     currentValid = mConditionFunction(input, mArguments);
150   }
151
152   if(mValid != currentValid || (currentValid && ((mConditionType == PropertyCondition::Step) || (mConditionType == PropertyCondition::VariableStep))))
153   {
154     mValid = currentValid;
155     //  means don't notify so notifyRequired stays false
156     switch(mNotifyMode)
157     {
158       case Dali::PropertyNotification::DISABLED:
159       {
160         // notify never, already initialized to false
161         break;
162       }
163       case Dali::PropertyNotification::NOTIFY_ON_TRUE:
164       {
165         notifyRequired = mValid; // notify if value is true
166         break;
167       }
168       case Dali::PropertyNotification::NOTIFY_ON_FALSE:
169       {
170         notifyRequired = !mValid; // notify when its false
171         break;
172       }
173       case Dali::PropertyNotification::NOTIFY_ON_CHANGED:
174       {
175         notifyRequired = true; // notify whenever changed
176         break;
177       }
178     }
179   }
180
181   return notifyRequired;
182 }
183
184 bool PropertyNotification::GetValidity() const
185 {
186   return mValid;
187 }
188
189 } // namespace SceneGraph
190
191 } // namespace Internal
192
193 } // namespace Dali