Reduce Render::Renderer size
[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) 2021 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/devel-api/common/owner-container.h>
23 #include <dali/internal/event/common/property-notification-impl.h>
24 #include <dali/internal/update/common/property-base.h>
25 #include <dali/public-api/object/property-notification.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 class Object;
32 class PropertyNotification;
33
34 namespace SceneGraph
35 {
36 class PropertyNotification;
37
38 using PropertyNotificationContainer = OwnerContainer<PropertyNotification*>;
39 using PropertyNotificationIter      = PropertyNotificationContainer::Iterator;
40 using PropertyNotificationConstIter = PropertyNotificationContainer::ConstIterator;
41 using ConditionFunction             = bool (*)(const Dali::PropertyInput&, Dali::Internal::PropertyNotification::RawArgumentContainer&);
42
43 /**
44  * PropertyNotifications are used to inspect properties of scene graph objects, as part of a scene
45  * managers "update" phase. When a condition has been met the application receives a notification signal.
46  */
47 class PropertyNotification
48 {
49 public:
50   using NotifyMode           = Dali::PropertyNotification::NotifyMode;
51   using ConditionType        = Dali::Internal::PropertyNotification::ConditionType;
52   using RawArgumentContainer = Dali::Internal::PropertyNotification::RawArgumentContainer;
53   using GetPropertyFunction  = const void* (*)(const SceneGraph::PropertyBase*, int);
54
55   /**
56    * Construct a new PropertyNotification
57    * @param[in] object The event-object for a scene-graph object to inspect.
58    * @param[in] propertyIndex The index of a property provided by the object.
59    * @param[in] propertyType The type of property we're inspecting.
60    * @param[in] componentIndex Index to the component of a complex property such as a Vector
61    * @param[in] condition The condition type (e.g. LessThan, GreaterThan...)
62    * @param[in] arguments The arguments which accompany the condition.
63    * @param[in] notifyMode The notification mode setting
64    * @param[in] compare The flag of comparing the previous and current data.
65    * @return A new PropertyNotification object.
66    */
67   static PropertyNotification* New(Object&               object,
68                                    Property::Index       propertyIndex,
69                                    Property::Type        propertyType,
70                                    int                   componentIndex,
71                                    ConditionType         condition,
72                                    RawArgumentContainer& arguments,
73                                    NotifyMode            notifyMode,
74                                    bool                  compare);
75
76   /**
77    * Virtual destructor
78    */
79   virtual ~PropertyNotification();
80
81   /**
82    * Sets Notify Mode, whether to notify if the condition is true
83    * and if the condition is false.
84    *
85    * @param[in] notifyMode The notification mode setting
86    */
87   void SetNotifyMode(NotifyMode notifyMode);
88
89   /**
90    * Check this property notification condition,
91    * and if true then dispatch notification.
92    * @param[in] bufferIndex The current update buffer index.
93    * @return Whether the validity of this notification has changed.
94    */
95   bool Check(BufferIndex bufferIndex);
96
97   /**
98    * Returns the validity of the last condition check
99    *
100    * @return the validity
101    */
102   bool GetValidity() const;
103
104 protected:
105   /**
106    * Construct the PropertyNotification
107    * @param[in] object The event-object for a scene-graph object to inspect.
108    * @param[in] propertyIndex The index of a property provided by the object.
109    * @param[in] propertyType The type of property we're inspecting.
110    * @param[in] componentIndex Index to the component of a complex property such as a Vector
111    * @param[in] condition The condition type (e.g. LessThan, GreaterThan...)
112    * @param[in] arguments The arguments which accompany the condition.
113    * @param[in] notifyMode The notification mode setting
114    */
115   PropertyNotification(Object&               object,
116                        Property::Index       propertyIndex,
117                        Property::Type        propertyType,
118                        int                   componentIndex,
119                        ConditionType         condition,
120                        RawArgumentContainer& arguments,
121                        NotifyMode            notifyMode,
122                        bool                  compare);
123
124 private:
125   /**
126    * Checks if bool is LessThan
127    * @param[in] value The value being examined.
128    * @param[in] arg The supplied arguments for the condition.
129    * @return Condition result (true if condition met, false if not)
130    */
131   static bool EvalFalse(const Dali::PropertyInput& value, Dali::Internal::PropertyNotification::RawArgumentContainer& arg);
132
133   // Undefined
134   PropertyNotification(const PropertyNotification&);
135
136   // Undefined
137   PropertyNotification& operator=(const PropertyNotification& rhs);
138
139 protected:
140   Object*                  mObject;            ///< Not owned by the property notification. Valid until ObjectDestroyed() is called.
141   Property::Index          mPropertyIndex;     ///< The index of this property.
142   Property::Type           mPropertyType;      ///< The type of property this is.
143   const PropertyInputImpl* mProperty;          ///< The scene graph property
144   int                      mComponentIndex;    ///< Used for accessing float components of Vector3/4
145   ConditionType            mConditionType;     ///< The ConditionType
146   RawArgumentContainer     mArguments;         ///< The arguments.
147   bool                     mValid;             ///< Whether this property notification is currently valid or not.
148   NotifyMode               mNotifyMode;        ///< Whether to notify on invalid and/or valid
149   ConditionFunction        mConditionFunction; ///< The Condition Function pointer to be evaluated.
150 };
151
152 } // namespace SceneGraph
153
154 } // namespace Internal
155
156 } // namespace Dali
157
158 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_NOTIFICATION_H