1 #ifndef DALI_INTERNAL_PROPERTY_INPUT_IMPL_H
2 #define DALI_INTERNAL_PROPERTY_INPUT_IMPL_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <dali/public-api/object/property-input.h>
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/public-api/math/vector4.h>
29 #include <dali/public-api/math/quaternion.h>
30 #include <dali/public-api/math/matrix3.h>
31 #include <dali/public-api/math/matrix.h>
32 #include <dali/internal/common/buffer-index.h>
34 #if defined (ANDROID) || defined(WIN32)
38 uint64_t _Hash_bytes(const void* bytes, uint64_t size, uint64_t seed);
50 * An abstract interface for receiving property values, and for querying whether
51 * a property value has changed i.e. whether a constraint needs to be reapplied.
53 class PropertyInputImpl
60 virtual ~PropertyInputImpl() = default;
63 * Query the type of property input.
64 * @return The property type.
66 virtual Property::Type GetType() const = 0;
69 * Query the input value (for a constraint) has been initialized.
70 * @return True if initialized, otherwise the constraint should be skipped.
72 virtual bool InputInitialized() const = 0;
75 * Query the input value (for a constraint) has changed.
76 * @return True if the input value has changed.
78 virtual bool InputChanged() const = 0;
81 * Retrieve a boolean value.
82 * @pre GetType() returns Property::BOOLEAN.
83 * @param[in] bufferIndex The buffer to read from.
84 * @return The boolean value.
86 virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
88 // the return will never be executed, it's just to keep the compiler happy
89 return reinterpret_cast<const bool&>(*this);
93 * Retrieve an integer value.
94 * @pre GetType() returns Property::INTEGER.
95 * @param[in] bufferIndex The buffer to read from.
96 * @return The integer value.
98 virtual const int& GetInteger( BufferIndex bufferIndex ) const
100 // the return will never be executed, it's just to keep the compiler happy
101 return reinterpret_cast<const int&>(*this);
105 * Retrieve a float value.
106 * @pre GetType() returns Property::FLOAT.
107 * @param[in] bufferIndex The buffer to read from.
108 * @return The float value.
110 virtual const float& GetFloat( BufferIndex bufferIndex ) const
112 // the return will never be executed, it's just to keep the compiler happy
113 return reinterpret_cast<const float&>(*this);
117 * Retrieve a Vector2 value.
118 * @pre GetType() returns Property::VECTOR2.
119 * @param[in] bufferIndex The buffer to read from.
120 * @return The Vector2 value.
122 virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
124 // the return will never be executed, it's just to keep the compiler happy
125 return reinterpret_cast<const Vector2&>(*this);
129 * Retrieve a Vector3 value.
130 * @pre GetType() returns Property::VECTOR3.
131 * @param[in] bufferIndex The buffer to read from.
132 * @return The Vector3 value.
134 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
136 // the return will never be executed, it's just to keep the compiler happy
137 return reinterpret_cast<const Vector3&>(*this);
141 * Retrieve a Vector4 value.
142 * @pre GetType() returns Property::VECTOR4.
143 * @param[in] bufferIndex The buffer to read from.
144 * @return The Vector4 value.
146 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
148 // the return will never be executed, it's just to keep the compiler happy
149 return reinterpret_cast<const Vector4&>(*this);
153 * Retrieve a Quaternion value.
154 * @pre GetType() returns Property::Quaternion.
155 * @param[in] bufferIndex The buffer to read from.
156 * @return The Quaternion value.
158 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
160 // the return will never be executed, it's just to keep the compiler happy
161 return reinterpret_cast<const Quaternion&>(*this);
165 * Retrieve a Matrix value.
166 * @pre GetType() returns Property::Matrix.
167 * @param[in] bufferIndex The buffer to read from.
168 * @return The Matrix value.
170 virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
172 // the return will never be executed, it's just to keep the compiler happy
173 return reinterpret_cast<const Matrix3&>(*this);
177 * Retrieve a Matrix value.
178 * @pre GetType() returns Property::Matrix.
179 * @param[in] bufferIndex The buffer to read from.
180 * @return The Matrix value.
182 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
184 // the return will never be executed, it's just to keep the compiler happy
185 return reinterpret_cast<const Matrix&>(*this);
188 // Accessors for Constraint functions
191 * Retrieve a boolean input for a constraint function.
192 * @note For inherited properties, this method should be overriden to return the value
193 * from the previous frame i.e. not from the current update buffer.
194 * @pre GetType() returns Property::BOOLEAN.
195 * @param[in] updateBufferIndex The current update buffer index.
196 * @return The boolean value.
198 virtual const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
200 return GetBoolean( updateBufferIndex );
204 * Retrieve an integer input for a constraint function.
205 * @note For inherited properties, this method should be overriden to return the value
206 * from the previous frame i.e. not from the current update buffer.
207 * @pre GetType() returns Property::INTEGER.
208 * @param[in] updateBufferIndex The current update buffer index.
209 * @return The integer value.
211 virtual const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const
213 return GetInteger( updateBufferIndex );
217 * Retrieve a float input for a constraint function.
218 * @note For inherited properties, this method should be overriden to return the value
219 * from the previous frame i.e. not from the current update buffer.
220 * @pre GetType() returns Property::FLOAT.
221 * @param[in] updateBufferIndex The current update buffer index.
222 * @return The float value.
224 virtual const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
226 return GetFloat( updateBufferIndex );
230 * Retrieve a Vector2 input for a constraint function.
231 * @note For inherited properties, this method should be overriden to return the value
232 * from the previous frame i.e. not from the current update buffer.
233 * @pre GetType() returns Property::VECTOR2.
234 * @param[in] updateBufferIndex The buffer to read from.
235 * @return The Vector2 value.
237 virtual const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
239 return GetVector2( updateBufferIndex );
243 * Retrieve a Vector3 input for a constraint function.
244 * @note For inherited properties, this method should be overriden to return the value
245 * from the previous frame i.e. not from the current update buffer.
246 * @pre GetType() returns Property::VECTOR3.
247 * @param[in] updateBufferIndex The buffer to read from.
248 * @return The Vector3 value.
250 virtual const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
252 return GetVector3( updateBufferIndex );
256 * Retrieve a Vector4 input for a constraint function.
257 * @note For inherited properties, this method should be overriden to return the value
258 * from the previous frame i.e. not from the current update buffer.
259 * @pre GetType() returns Property::VECTOR4.
260 * @param[in] updateBufferIndex The buffer to read from.
261 * @return The Vector4 value.
263 virtual const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
265 return GetVector4( updateBufferIndex );
269 * Retrieve a Quaternion input for a constraint function.
270 * @note For inherited properties, this method should be overriden to return the value
271 * from the previous frame i.e. not from the current update buffer.
272 * @pre GetType() returns Property::Quaternion.
273 * @param[in] updateBufferIndex The buffer to read from.
274 * @return The Quaternion value.
276 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
278 return GetQuaternion( updateBufferIndex );
282 * Retrieve a Matrix3 input for a constraint function.
283 * @note For inherited properties, this method should be overriden to return the value
284 * from the previous frame i.e. not from the current update buffer.
285 * @pre GetType() returns Property::Matrix.
286 * @param[in] updateBufferIndex The buffer to read from.
287 * @return The Matrix value.
289 virtual const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
291 return GetMatrix3( updateBufferIndex );
295 * Retrieve a Matrix input for a constraint function.
296 * @note For inherited properties, this method should be overriden to return the value
297 * from the previous frame i.e. not from the current update buffer.
298 * @pre GetType() returns Property::Matrix.
299 * @param[in] updateBufferIndex The buffer to read from.
300 * @return The Matrix value.
302 virtual const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
304 return GetMatrix( updateBufferIndex );
308 * Query whether the property belongs to the
309 * transform manager or not.
310 * @return True if it is a transform manager property, false otherwise
312 virtual bool IsTransformManagerProperty() const
317 std::uint64_t Hash(BufferIndex bufferIndex, uint64_t seed) const
321 case Property::BOOLEAN:
323 return std::_Hash_bytes(&GetBoolean(bufferIndex), sizeof(bool), seed);
326 case Property::INTEGER:
328 return std::_Hash_bytes(&GetInteger(bufferIndex), sizeof(int), seed);
331 case Property::FLOAT:
333 return std::_Hash_bytes(&GetFloat(bufferIndex), sizeof(float), seed);
336 case Property::VECTOR2:
338 return std::_Hash_bytes(&GetVector2(bufferIndex), sizeof(Vector2), seed);
341 case Property::VECTOR3:
343 return std::_Hash_bytes(&GetVector3(bufferIndex), sizeof(Vector3), seed);
346 case Property::VECTOR4:
348 return std::_Hash_bytes(&GetVector4(bufferIndex), sizeof(Vector4), seed);
351 case Property::ROTATION:
353 return std::_Hash_bytes(&GetQuaternion(bufferIndex), sizeof(Quaternion), seed);
356 case Property::MATRIX:
358 return std::_Hash_bytes(&GetMatrix(bufferIndex), sizeof(Matrix), seed);
361 case Property::MATRIX3:
363 return std::_Hash_bytes(&GetMatrix3(bufferIndex), sizeof(Matrix3), seed);
367 break; // print nothing
375 * Print the property value using a stream.
376 * @param[in] debugStream The output stream.
377 * @param[in] bufferIndex The buffer to read from.
378 * @todo Place this far-too-large-to-be-inlined function in a cpp and remove <iostream> header dependency from this file.
380 void DebugPrint( std::ostream& debugStream, BufferIndex bufferIndex ) const
384 case Property::BOOLEAN:
386 debugStream << GetBoolean( bufferIndex );
390 case Property::INTEGER:
392 debugStream << GetInteger( bufferIndex );
396 case Property::FLOAT:
398 debugStream << GetFloat( bufferIndex );
402 case Property::VECTOR2:
404 debugStream << GetVector2( bufferIndex );
408 case Property::VECTOR3:
410 debugStream << GetVector3( bufferIndex );
414 case Property::VECTOR4:
416 debugStream << GetVector4( bufferIndex );
420 case Property::ROTATION:
422 debugStream << GetQuaternion( bufferIndex );
426 case Property::MATRIX:
428 debugStream << GetMatrix( bufferIndex );
432 case Property::MATRIX3:
434 debugStream << GetMatrix3( bufferIndex );
439 break; // print nothing
444 } // namespace Internal
448 #endif // DALI_INTERNAL_PROPERTY_INPUT_IMPL_H