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()
65 * Query the type of property input.
66 * @return The property type.
68 virtual Property::Type GetType() const = 0;
71 * Query the input value (for a constraint) has been initialized.
72 * @return True if initialized, otherwise the constraint should be skipped.
74 virtual bool InputInitialized() const = 0;
77 * Query the input value (for a constraint) has changed.
78 * @return True if the input value has changed.
80 virtual bool InputChanged() const = 0;
83 * Retrieve a boolean value.
84 * @pre GetType() returns Property::BOOLEAN.
85 * @param[in] bufferIndex The buffer to read from.
86 * @return The boolean value.
88 virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
90 // the return will never be executed, it's just to keep the compiler happy
91 return reinterpret_cast<const bool&>(*this);
95 * Retrieve an integer value.
96 * @pre GetType() returns Property::INTEGER.
97 * @param[in] bufferIndex The buffer to read from.
98 * @return The integer value.
100 virtual const int& GetInteger( BufferIndex bufferIndex ) const
102 // the return will never be executed, it's just to keep the compiler happy
103 return reinterpret_cast<const int&>(*this);
107 * Retrieve a float value.
108 * @pre GetType() returns Property::FLOAT.
109 * @param[in] bufferIndex The buffer to read from.
110 * @return The float value.
112 virtual const float& GetFloat( BufferIndex bufferIndex ) const
114 // the return will never be executed, it's just to keep the compiler happy
115 return reinterpret_cast<const float&>(*this);
119 * Retrieve a Vector2 value.
120 * @pre GetType() returns Property::VECTOR2.
121 * @param[in] bufferIndex The buffer to read from.
122 * @return The Vector2 value.
124 virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
126 // the return will never be executed, it's just to keep the compiler happy
127 return reinterpret_cast<const Vector2&>(*this);
131 * Retrieve a Vector3 value.
132 * @pre GetType() returns Property::VECTOR3.
133 * @param[in] bufferIndex The buffer to read from.
134 * @return The Vector3 value.
136 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
138 // the return will never be executed, it's just to keep the compiler happy
139 return reinterpret_cast<const Vector3&>(*this);
143 * Retrieve a Vector4 value.
144 * @pre GetType() returns Property::VECTOR4.
145 * @param[in] bufferIndex The buffer to read from.
146 * @return The Vector4 value.
148 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
150 // the return will never be executed, it's just to keep the compiler happy
151 return reinterpret_cast<const Vector4&>(*this);
155 * Retrieve a Quaternion value.
156 * @pre GetType() returns Property::Quaternion.
157 * @param[in] bufferIndex The buffer to read from.
158 * @return The Quaternion value.
160 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
162 // the return will never be executed, it's just to keep the compiler happy
163 return reinterpret_cast<const Quaternion&>(*this);
167 * Retrieve a Matrix value.
168 * @pre GetType() returns Property::Matrix.
169 * @param[in] bufferIndex The buffer to read from.
170 * @return The Matrix value.
172 virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
174 // the return will never be executed, it's just to keep the compiler happy
175 return reinterpret_cast<const Matrix3&>(*this);
179 * Retrieve a Matrix value.
180 * @pre GetType() returns Property::Matrix.
181 * @param[in] bufferIndex The buffer to read from.
182 * @return The Matrix value.
184 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
186 // the return will never be executed, it's just to keep the compiler happy
187 return reinterpret_cast<const Matrix&>(*this);
190 // Accessors for Constraint functions
193 * Retrieve a boolean input for a constraint function.
194 * @note For inherited properties, this method should be overriden to return the value
195 * from the previous frame i.e. not from the current update buffer.
196 * @pre GetType() returns Property::BOOLEAN.
197 * @param[in] updateBufferIndex The current update buffer index.
198 * @return The boolean value.
200 virtual const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
202 return GetBoolean( updateBufferIndex );
206 * Retrieve an integer input for a constraint function.
207 * @note For inherited properties, this method should be overriden to return the value
208 * from the previous frame i.e. not from the current update buffer.
209 * @pre GetType() returns Property::INTEGER.
210 * @param[in] updateBufferIndex The current update buffer index.
211 * @return The integer value.
213 virtual const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const
215 return GetInteger( updateBufferIndex );
219 * Retrieve a float input for a constraint function.
220 * @note For inherited properties, this method should be overriden to return the value
221 * from the previous frame i.e. not from the current update buffer.
222 * @pre GetType() returns Property::FLOAT.
223 * @param[in] updateBufferIndex The current update buffer index.
224 * @return The float value.
226 virtual const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
228 return GetFloat( updateBufferIndex );
232 * Retrieve a Vector2 input for a constraint function.
233 * @note For inherited properties, this method should be overriden to return the value
234 * from the previous frame i.e. not from the current update buffer.
235 * @pre GetType() returns Property::VECTOR2.
236 * @param[in] updateBufferIndex The buffer to read from.
237 * @return The Vector2 value.
239 virtual const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
241 return GetVector2( updateBufferIndex );
245 * Retrieve a Vector3 input for a constraint function.
246 * @note For inherited properties, this method should be overriden to return the value
247 * from the previous frame i.e. not from the current update buffer.
248 * @pre GetType() returns Property::VECTOR3.
249 * @param[in] updateBufferIndex The buffer to read from.
250 * @return The Vector3 value.
252 virtual const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
254 return GetVector3( updateBufferIndex );
258 * Retrieve a Vector4 input for a constraint function.
259 * @note For inherited properties, this method should be overriden to return the value
260 * from the previous frame i.e. not from the current update buffer.
261 * @pre GetType() returns Property::VECTOR4.
262 * @param[in] updateBufferIndex The buffer to read from.
263 * @return The Vector4 value.
265 virtual const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
267 return GetVector4( updateBufferIndex );
271 * Retrieve a Quaternion input for a constraint function.
272 * @note For inherited properties, this method should be overriden to return the value
273 * from the previous frame i.e. not from the current update buffer.
274 * @pre GetType() returns Property::Quaternion.
275 * @param[in] updateBufferIndex The buffer to read from.
276 * @return The Quaternion value.
278 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
280 return GetQuaternion( updateBufferIndex );
284 * Retrieve a Matrix3 input for a constraint function.
285 * @note For inherited properties, this method should be overriden to return the value
286 * from the previous frame i.e. not from the current update buffer.
287 * @pre GetType() returns Property::Matrix.
288 * @param[in] updateBufferIndex The buffer to read from.
289 * @return The Matrix value.
291 virtual const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
293 return GetMatrix3( updateBufferIndex );
297 * Retrieve a Matrix input for a constraint function.
298 * @note For inherited properties, this method should be overriden to return the value
299 * from the previous frame i.e. not from the current update buffer.
300 * @pre GetType() returns Property::Matrix.
301 * @param[in] updateBufferIndex The buffer to read from.
302 * @return The Matrix value.
304 virtual const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
306 return GetMatrix( updateBufferIndex );
310 * Query whether the property belongs to the
311 * transform manager or not.
312 * @return True if it is a transform manager property, false otherwise
314 virtual bool IsTransformManagerProperty() const
319 std::uint64_t Hash(BufferIndex bufferIndex, uint64_t seed) const
323 case Property::BOOLEAN:
325 return std::_Hash_bytes(&GetBoolean(bufferIndex), sizeof(bool), seed);
328 case Property::INTEGER:
330 return std::_Hash_bytes(&GetInteger(bufferIndex), sizeof(int), seed);
333 case Property::FLOAT:
335 return std::_Hash_bytes(&GetFloat(bufferIndex), sizeof(float), seed);
338 case Property::VECTOR2:
340 return std::_Hash_bytes(&GetVector2(bufferIndex), sizeof(Vector2), seed);
343 case Property::VECTOR3:
345 return std::_Hash_bytes(&GetVector3(bufferIndex), sizeof(Vector3), seed);
348 case Property::VECTOR4:
350 return std::_Hash_bytes(&GetVector4(bufferIndex), sizeof(Vector4), seed);
353 case Property::ROTATION:
355 return std::_Hash_bytes(&GetQuaternion(bufferIndex), sizeof(Quaternion), seed);
358 case Property::MATRIX:
360 return std::_Hash_bytes(&GetMatrix(bufferIndex), sizeof(Matrix), seed);
363 case Property::MATRIX3:
365 return std::_Hash_bytes(&GetMatrix3(bufferIndex), sizeof(Matrix3), seed);
369 break; // print nothing
377 * Print the property value using a stream.
378 * @param[in] debugStream The output stream.
379 * @param[in] bufferIndex The buffer to read from.
380 * @todo Place this far-too-large-to-be-inlined function in a cpp and remove <iostream> header dependency from this file.
382 void DebugPrint( std::ostream& debugStream, BufferIndex bufferIndex ) const
386 case Property::BOOLEAN:
388 debugStream << GetBoolean( bufferIndex );
392 case Property::INTEGER:
394 debugStream << GetInteger( bufferIndex );
398 case Property::FLOAT:
400 debugStream << GetFloat( bufferIndex );
404 case Property::VECTOR2:
406 debugStream << GetVector2( bufferIndex );
410 case Property::VECTOR3:
412 debugStream << GetVector3( bufferIndex );
416 case Property::VECTOR4:
418 debugStream << GetVector4( bufferIndex );
422 case Property::ROTATION:
424 debugStream << GetQuaternion( bufferIndex );
428 case Property::MATRIX:
430 debugStream << GetMatrix( bufferIndex );
434 case Property::MATRIX3:
436 debugStream << GetMatrix3( bufferIndex );
441 break; // print nothing
446 } // namespace Internal
450 #endif // DALI_INTERNAL_PROPERTY_INPUT_IMPL_H