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