Merge "Addition of build flag "-Wl,-Bsymbolic-functions" for launching performance...
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-property-notification.cpp
1 /*
2  * Copyright (c) 2014 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 {
65   SetNotifyMode(notifyMode);
66
67   switch(mConditionType)
68   {
69     case PropertyCondition::LessThan:
70     {
71       mConditionFunction = LessThan::GetFunction(mPropertyType);
72       break;
73     }
74     case PropertyCondition::GreaterThan:
75     {
76       mConditionFunction = GreaterThan::GetFunction(mPropertyType);
77       break;
78     }
79     case PropertyCondition::Inside:
80     {
81       mConditionFunction = Inside::GetFunction(mPropertyType);
82       break;
83     }
84     case PropertyCondition::Outside:
85     {
86       mConditionFunction = Outside::GetFunction(mPropertyType);
87       break;
88     }
89     case PropertyCondition::Step:
90     {
91       mConditionFunction = Step::GetFunction(mPropertyType);
92       break;
93     }
94     case PropertyCondition::VariableStep:
95     {
96       mConditionFunction = VariableStep::GetFunction(mPropertyType);
97       break;
98     }
99     case PropertyCondition::False:
100     {
101       mConditionFunction = PropertyNotification::EvalFalse;
102       break;
103     }
104   }
105
106   mProperty = mObject->GetSceneObjectInputProperty( mPropertyIndex );
107   int internalComponentIndex = mObject->GetPropertyComponentIndex(mPropertyIndex);
108   if( internalComponentIndex != Property::INVALID_COMPONENT_INDEX )
109   {
110     // override the one passed in
111     mComponentIndex = internalComponentIndex;
112   }
113 }
114
115 PropertyNotification::~PropertyNotification()
116 {
117 }
118
119 bool PropertyNotification::EvalFalse( const Dali::PropertyInput& value, RawArgumentContainer& arg )
120 {
121   return false;
122 }
123
124 void PropertyNotification::SetNotifyMode( NotifyMode notifyMode )
125 {
126   mNotifyMode = notifyMode;
127 }
128
129 bool PropertyNotification::Check( BufferIndex bufferIndex )
130 {
131   bool notifyRequired = false;
132   bool currentValid = false;
133
134   if ( Property::INVALID_COMPONENT_INDEX != mComponentIndex )
135   {
136     // Evaluate Condition
137     const PropertyInputComponentAccessor component( mProperty, mComponentIndex );
138     const PropertyInputIndexer< PropertyInputComponentAccessor > input( bufferIndex, &component );
139     currentValid = mConditionFunction(input, mArguments);
140   }
141   else
142   {
143     // Evaluate Condition
144     const PropertyInputIndexer< PropertyInputImpl > input( bufferIndex, mProperty );
145     currentValid = mConditionFunction(input, mArguments);
146   }
147
148   if( mValid != currentValid
149       || (currentValid && ((mConditionType == PropertyCondition::Step)
150                         || (mConditionType == PropertyCondition::VariableStep))) )
151   {
152     mValid = currentValid;
153     //  means don't notify so notifyRequired stays false
154     switch( mNotifyMode )
155     {
156       case Dali::PropertyNotification::Disabled:
157       {
158         // notify never, already initialized to false
159         break;
160       }
161       case Dali::PropertyNotification::NotifyOnTrue:
162       {
163         notifyRequired = mValid; // notify if value is true
164         break;
165       }
166       case Dali::PropertyNotification::NotifyOnFalse:
167       {
168         notifyRequired = !mValid; // notify when its false
169         break;
170       }
171       case Dali::PropertyNotification::NotifyOnChanged:
172       {
173         notifyRequired = true; // notify whenever changed
174         break;
175       }
176     }
177   }
178
179   return notifyRequired;
180 }
181
182 bool PropertyNotification::GetValidity() const
183 {
184   return mValid;
185 }
186
187 } // namespace SceneGraph
188
189 } // namespace Internal
190
191 } // namespace Dali