1 #ifndef DALI_INTERNAL_PROPERTY_INPUT_IMPL_H
2 #define DALI_INTERNAL_PROPERTY_INPUT_IMPL_H
5 * Copyright (c) 2021 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/internal/common/buffer-index.h>
26 #include <dali/public-api/math/matrix.h>
27 #include <dali/public-api/math/matrix3.h>
28 #include <dali/public-api/math/quaternion.h>
29 #include <dali/public-api/math/vector2.h>
30 #include <dali/public-api/math/vector3.h>
31 #include <dali/public-api/math/vector4.h>
32 #include <dali/public-api/object/property-input.h>
34 #if defined(ANDROID) || defined(WIN32) || defined(__APPLE__)
37 uint64_t _Hash_bytes(const void* bytes, uint64_t size, uint64_t seed);
47 * An abstract interface for receiving property values, and for querying whether
48 * a property value has changed i.e. whether a constraint needs to be reapplied.
50 class PropertyInputImpl
56 virtual ~PropertyInputImpl() = default;
59 * Query the type of property input.
60 * @return The property type.
62 virtual Property::Type GetType() const = 0;
65 * Query the input value (for a constraint) has been initialized.
66 * @return True if initialized, otherwise the constraint should be skipped.
68 virtual bool InputInitialized() const = 0;
71 * Query the input value (for a constraint) has changed.
72 * @return True if the input value has changed.
74 virtual bool InputChanged() const = 0;
77 * Retrieve a boolean value.
78 * @pre GetType() returns Property::BOOLEAN.
79 * @param[in] bufferIndex The buffer to read from.
80 * @return The boolean value.
82 virtual const bool& GetBoolean(BufferIndex bufferIndex) const
84 // the return will never be executed, it's just to keep the compiler happy
85 return reinterpret_cast<const bool&>(*this);
89 * Retrieve an integer value.
90 * @pre GetType() returns Property::INTEGER.
91 * @param[in] bufferIndex The buffer to read from.
92 * @return The integer value.
94 virtual const int& GetInteger(BufferIndex bufferIndex) const
96 // the return will never be executed, it's just to keep the compiler happy
97 return reinterpret_cast<const int&>(*this);
101 * Retrieve a float value.
102 * @pre GetType() returns Property::FLOAT.
103 * @param[in] bufferIndex The buffer to read from.
104 * @return The float value.
106 virtual const float& GetFloat(BufferIndex bufferIndex) const
108 // the return will never be executed, it's just to keep the compiler happy
109 return reinterpret_cast<const float&>(*this);
113 * Retrieve a Vector2 value.
114 * @pre GetType() returns Property::VECTOR2.
115 * @param[in] bufferIndex The buffer to read from.
116 * @return The Vector2 value.
118 virtual const Vector2& GetVector2(BufferIndex bufferIndex) const
120 // the return will never be executed, it's just to keep the compiler happy
121 return reinterpret_cast<const Vector2&>(*this);
125 * Retrieve a Vector3 value.
126 * @pre GetType() returns Property::VECTOR3.
127 * @param[in] bufferIndex The buffer to read from.
128 * @return The Vector3 value.
130 virtual const Vector3& GetVector3(BufferIndex bufferIndex) const
132 // the return will never be executed, it's just to keep the compiler happy
133 return reinterpret_cast<const Vector3&>(*this);
137 * Retrieve a Vector4 value.
138 * @pre GetType() returns Property::VECTOR4.
139 * @param[in] bufferIndex The buffer to read from.
140 * @return The Vector4 value.
142 virtual const Vector4& GetVector4(BufferIndex bufferIndex) const
144 // the return will never be executed, it's just to keep the compiler happy
145 return reinterpret_cast<const Vector4&>(*this);
149 * Retrieve a Quaternion value.
150 * @pre GetType() returns Property::Quaternion.
151 * @param[in] bufferIndex The buffer to read from.
152 * @return The Quaternion value.
154 virtual const Quaternion& GetQuaternion(BufferIndex bufferIndex) const
156 // the return will never be executed, it's just to keep the compiler happy
157 return reinterpret_cast<const Quaternion&>(*this);
161 * Retrieve a Matrix value.
162 * @pre GetType() returns Property::Matrix.
163 * @param[in] bufferIndex The buffer to read from.
164 * @return The Matrix value.
166 virtual const Matrix3& GetMatrix3(BufferIndex bufferIndex) const
168 // the return will never be executed, it's just to keep the compiler happy
169 return reinterpret_cast<const Matrix3&>(*this);
173 * Retrieve a Matrix value.
174 * @pre GetType() returns Property::Matrix.
175 * @param[in] bufferIndex The buffer to read from.
176 * @return The Matrix value.
178 virtual const Matrix& GetMatrix(BufferIndex bufferIndex) const
180 // the return will never be executed, it's just to keep the compiler happy
181 return reinterpret_cast<const Matrix&>(*this);
184 // Accessors for Constraint functions
187 * Retrieve a boolean input for a constraint function.
188 * @note For inherited properties, this method should be overriden to return the value
189 * from the previous frame i.e. not from the current update buffer.
190 * @pre GetType() returns Property::BOOLEAN.
191 * @param[in] updateBufferIndex The current update buffer index.
192 * @return The boolean value.
194 virtual const bool& GetConstraintInputBoolean(BufferIndex updateBufferIndex) const
196 return GetBoolean(updateBufferIndex);
200 * Retrieve an integer input for a constraint function.
201 * @note For inherited properties, this method should be overriden to return the value
202 * from the previous frame i.e. not from the current update buffer.
203 * @pre GetType() returns Property::INTEGER.
204 * @param[in] updateBufferIndex The current update buffer index.
205 * @return The integer value.
207 virtual const int& GetConstraintInputInteger(BufferIndex updateBufferIndex) const
209 return GetInteger(updateBufferIndex);
213 * Retrieve a float input for a constraint function.
214 * @note For inherited properties, this method should be overriden to return the value
215 * from the previous frame i.e. not from the current update buffer.
216 * @pre GetType() returns Property::FLOAT.
217 * @param[in] updateBufferIndex The current update buffer index.
218 * @return The float value.
220 virtual const float& GetConstraintInputFloat(BufferIndex updateBufferIndex) const
222 return GetFloat(updateBufferIndex);
226 * Retrieve a Vector2 input for a constraint function.
227 * @note For inherited properties, this method should be overriden to return the value
228 * from the previous frame i.e. not from the current update buffer.
229 * @pre GetType() returns Property::VECTOR2.
230 * @param[in] updateBufferIndex The buffer to read from.
231 * @return The Vector2 value.
233 virtual const Vector2& GetConstraintInputVector2(BufferIndex updateBufferIndex) const
235 return GetVector2(updateBufferIndex);
239 * Retrieve a Vector3 input for a constraint function.
240 * @note For inherited properties, this method should be overriden to return the value
241 * from the previous frame i.e. not from the current update buffer.
242 * @pre GetType() returns Property::VECTOR3.
243 * @param[in] updateBufferIndex The buffer to read from.
244 * @return The Vector3 value.
246 virtual const Vector3& GetConstraintInputVector3(BufferIndex updateBufferIndex) const
248 return GetVector3(updateBufferIndex);
252 * Retrieve a Vector4 input for a constraint function.
253 * @note For inherited properties, this method should be overriden to return the value
254 * from the previous frame i.e. not from the current update buffer.
255 * @pre GetType() returns Property::VECTOR4.
256 * @param[in] updateBufferIndex The buffer to read from.
257 * @return The Vector4 value.
259 virtual const Vector4& GetConstraintInputVector4(BufferIndex updateBufferIndex) const
261 return GetVector4(updateBufferIndex);
265 * Retrieve a Quaternion input for a constraint function.
266 * @note For inherited properties, this method should be overriden to return the value
267 * from the previous frame i.e. not from the current update buffer.
268 * @pre GetType() returns Property::Quaternion.
269 * @param[in] updateBufferIndex The buffer to read from.
270 * @return The Quaternion value.
272 virtual const Quaternion& GetConstraintInputQuaternion(BufferIndex updateBufferIndex) const
274 return GetQuaternion(updateBufferIndex);
278 * Retrieve a Matrix3 input for a constraint function.
279 * @note For inherited properties, this method should be overriden to return the value
280 * from the previous frame i.e. not from the current update buffer.
281 * @pre GetType() returns Property::Matrix.
282 * @param[in] updateBufferIndex The buffer to read from.
283 * @return The Matrix value.
285 virtual const Matrix3& GetConstraintInputMatrix3(BufferIndex updateBufferIndex) const
287 return GetMatrix3(updateBufferIndex);
291 * Retrieve a Matrix input for a constraint function.
292 * @note For inherited properties, this method should be overriden to return the value
293 * from the previous frame i.e. not from the current update buffer.
294 * @pre GetType() returns Property::Matrix.
295 * @param[in] updateBufferIndex The buffer to read from.
296 * @return The Matrix value.
298 virtual const Matrix& GetConstraintInputMatrix(BufferIndex updateBufferIndex) const
300 return GetMatrix(updateBufferIndex);
304 * Query whether the property belongs to the
305 * transform manager or not.
306 * @return True if it is a transform manager property, false otherwise
308 virtual bool IsTransformManagerProperty() const
313 std::uint64_t Hash(BufferIndex bufferIndex, uint64_t seed) const
317 case Property::BOOLEAN:
319 return std::_Hash_bytes(&GetBoolean(bufferIndex), sizeof(bool), seed);
322 case Property::INTEGER:
324 return std::_Hash_bytes(&GetInteger(bufferIndex), sizeof(int), seed);
327 case Property::FLOAT:
329 return std::_Hash_bytes(&GetFloat(bufferIndex), sizeof(float), seed);
332 case Property::VECTOR2:
334 return std::_Hash_bytes(&GetVector2(bufferIndex), sizeof(Vector2), seed);
337 case Property::VECTOR3:
339 return std::_Hash_bytes(&GetVector3(bufferIndex), sizeof(Vector3), seed);
342 case Property::VECTOR4:
344 return std::_Hash_bytes(&GetVector4(bufferIndex), sizeof(Vector4), seed);
347 case Property::ROTATION:
349 return std::_Hash_bytes(&GetQuaternion(bufferIndex), sizeof(Quaternion), seed);
352 case Property::MATRIX:
354 return std::_Hash_bytes(&GetMatrix(bufferIndex), sizeof(Matrix), seed);
357 case Property::MATRIX3:
359 return std::_Hash_bytes(&GetMatrix3(bufferIndex), sizeof(Matrix3), seed);
363 break; // print nothing
370 * Print the property value using a stream.
371 * @param[in] debugStream The output stream.
372 * @param[in] bufferIndex The buffer to read from.
373 * @todo Place this far-too-large-to-be-inlined function in a cpp and remove <iostream> header dependency from this file.
375 void DebugPrint(std::ostream& debugStream, BufferIndex bufferIndex) const
379 case Property::BOOLEAN:
381 debugStream << GetBoolean(bufferIndex);
385 case Property::INTEGER:
387 debugStream << GetInteger(bufferIndex);
391 case Property::FLOAT:
393 debugStream << GetFloat(bufferIndex);
397 case Property::VECTOR2:
399 debugStream << GetVector2(bufferIndex);
403 case Property::VECTOR3:
405 debugStream << GetVector3(bufferIndex);
409 case Property::VECTOR4:
411 debugStream << GetVector4(bufferIndex);
415 case Property::ROTATION:
417 debugStream << GetQuaternion(bufferIndex);
421 case Property::MATRIX:
423 debugStream << GetMatrix(bufferIndex);
427 case Property::MATRIX3:
429 debugStream << GetMatrix3(bufferIndex);
434 break; // print nothing
439 } // namespace Internal
443 #endif // DALI_INTERNAL_PROPERTY_INPUT_IMPL_H