Merge "Stop heap allocating messages from UpdateManager for Animation and RenderTask...
[platform/core/uifw/dali-core.git] / dali / internal / update / common / scene-graph-property-notification.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_NOTIFICATION_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_NOTIFICATION_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/property-notification.h>
23 #include <dali/internal/event/common/property-notification-impl.h>
24 #include <dali/internal/update/common/property-base.h>
25 #include <dali/internal/common/owner-container.h>
26 #include <dali/internal/common/message.h>
27 #include <dali/internal/update/common/double-buffered.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 class ProxyObject;
36 class PropertyNotification;
37
38 namespace SceneGraph
39 {
40
41 class PropertyNotification;
42
43 typedef OwnerContainer< PropertyNotification* > PropertyNotificationContainer;
44 typedef PropertyNotificationContainer::Iterator PropertyNotificationIter;
45 typedef PropertyNotificationContainer::ConstIterator PropertyNotificationConstIter;
46 typedef bool(*ConditionFunction)(const Dali::PropertyInput& value, Dali::Internal::PropertyNotification::RawArgumentContainer& args);
47
48 /**
49  * PropertyNotifications are used to inspect properties of scene graph objects, as part of a scene
50  * managers "update" phase. When a condition has been met the application receives a notification signal.
51  */
52 class PropertyNotification
53 {
54 public:
55
56   typedef Dali::PropertyNotification::NotifyMode NotifyMode;
57   typedef Dali::Internal::PropertyNotification::ConditionType ConditionType;
58   typedef Dali::Internal::PropertyNotification::RawArgumentContainer RawArgumentContainer;
59   typedef const void *(*GetPropertyFunction)( const SceneGraph::PropertyBase*, int );
60
61   /**
62    * Construct a new PropertyNotification
63    * @param[in] proxy The proxy for a scene-graph object to inspect.
64    * @param[in] propertyIndex The index of a property provided by the object.
65    * @param[in] propertyType The type of property we're inspecting.
66    * @param[in] componentIndex Index to the component of a complex property such as a Vector
67    * @param[in] condition The condition type (e.g. LessThan, GreaterThan...)
68    * @param[in] arguments The arguments which accompany the condition.
69    * @param[in] notifyMode The notification mode setting
70    * @return A new PropertyNotification object.
71    */
72   static PropertyNotification* New(ProxyObject& proxy,
73                                    Property::Index propertyIndex,
74                                    Property::Type propertyType,
75                                    int componentIndex,
76                                    ConditionType condition,
77                                    RawArgumentContainer& arguments,
78                                    NotifyMode notifyMode);
79
80   /**
81    * Virtual destructor
82    */
83   virtual ~PropertyNotification();
84
85   /**
86    * Sets Notify Mode, whether to notify if the condition is true
87    * and if the condition is false.
88    *
89    * @param[in] notifyMode The notification mode setting
90    */
91   void SetNotifyMode( NotifyMode notifyMode );
92
93   /**
94    * Check this property notification condition,
95    * and if true then dispatch notification.
96    * @param[in] bufferIndex The current update buffer index.
97    * @return Whether the validity of this notification has changed.
98    */
99   bool Check( BufferIndex bufferIndex );
100
101   /**
102    * Returns the validity of the last condition check
103    *
104    * @return the validity
105    */
106   bool GetValidity() const;
107
108 protected:
109
110   /**
111    * Construct the PropertyNotification
112    * @param[in] proxy The proxy for a scene-graph object to inspect.
113    * @param[in] propertyIndex The index of a property provided by the object.
114    * @param[in] propertyType The type of property we're inspecting.
115    * @param[in] componentIndex Index to the component of a complex property such as a Vector
116    * @param[in] condition The condition type (e.g. LessThan, GreaterThan...)
117    * @param[in] arguments The arguments which accompany the condition.
118    * @param[in] notifyMode The notification mode setting
119    */
120   PropertyNotification(ProxyObject& proxy,
121                        Property::Index propertyIndex,
122                        Property::Type propertyType,
123                        int componentIndex,
124                        ConditionType condition,
125                        RawArgumentContainer& arguments,
126                        NotifyMode notifyMode);
127
128 private:
129
130   /**
131    * Checks if bool is LessThan
132    * @param[in] value The value being examined.
133    * @param[in] arg The supplied arguments for the condition.
134    * @return Condition result (true if condition met, false if not)
135    */
136   static bool EvalFalse( const Dali::PropertyInput& value, Dali::Internal::PropertyNotification::RawArgumentContainer& arg );
137
138   // Undefined
139   PropertyNotification(const PropertyNotification&);
140
141   // Undefined
142   PropertyNotification& operator=(const PropertyNotification& rhs);
143
144 protected:
145
146   ProxyObject* mProxy;                          ///< Not owned by the property notification. Valid until ProxyDestroyed() is called.
147   Property::Index mPropertyIndex;               ///< The index of this property.
148   Property::Type mPropertyType;                 ///< The type of property this is.
149   const PropertyInputImpl* mProperty;           ///< The scene graph property
150   int mComponentIndex;                          ///< Used for accessing float components of Vector3/4
151   ConditionType mConditionType;                 ///< The ConditionType
152   RawArgumentContainer mArguments;              ///< The arguments.
153   bool mValid;                                  ///< Whether this property notification is currently valid or not.
154   NotifyMode mNotifyMode;                       ///< Whether to notify on invalid and/or valid
155   ConditionFunction mConditionFunction;         ///< The Condition Function pointer to be evaluated.
156 };
157
158 // Messages for PropertyNotification
159
160 } // namespace SceneGraph
161
162 } // namespace Internal
163
164 } // namespace Dali
165
166 #endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_NOTIFICATION_H__