1 #ifndef DALI_INTERNAL_PROPERTY_INPUT_IMPL_H
2 #define DALI_INTERNAL_PROPERTY_INPUT_IMPL_H
5 * Copyright (c) 2023 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);
185 * Retrieve the address of the property value. Only for use
186 * when writing uniforms.
188 virtual const void* GetValueAddress(BufferIndex bufferIndex) const = 0;
191 * Retrieve the size of the property value for use in copying.
192 * Only for use when writing uniforms.
194 virtual size_t GetValueSize() const = 0;
196 // Accessors for Constraint functions
199 * Retrieve a boolean input for a constraint function.
200 * @note For inherited properties, this method should be overriden to return the value
201 * from the previous frame i.e. not from the current update buffer.
202 * @pre GetType() returns Property::BOOLEAN.
203 * @param[in] updateBufferIndex The current update buffer index.
204 * @return The boolean value.
206 virtual const bool& GetConstraintInputBoolean(BufferIndex updateBufferIndex) const
208 return GetBoolean(updateBufferIndex);
212 * Retrieve an integer input for a constraint function.
213 * @note For inherited properties, this method should be overriden to return the value
214 * from the previous frame i.e. not from the current update buffer.
215 * @pre GetType() returns Property::INTEGER.
216 * @param[in] updateBufferIndex The current update buffer index.
217 * @return The integer value.
219 virtual const int& GetConstraintInputInteger(BufferIndex updateBufferIndex) const
221 return GetInteger(updateBufferIndex);
225 * Retrieve a float input for a constraint function.
226 * @note For inherited properties, this method should be overriden to return the value
227 * from the previous frame i.e. not from the current update buffer.
228 * @pre GetType() returns Property::FLOAT.
229 * @param[in] updateBufferIndex The current update buffer index.
230 * @return The float value.
232 virtual const float& GetConstraintInputFloat(BufferIndex updateBufferIndex) const
234 return GetFloat(updateBufferIndex);
238 * Retrieve a Vector2 input for a constraint function.
239 * @note For inherited properties, this method should be overriden to return the value
240 * from the previous frame i.e. not from the current update buffer.
241 * @pre GetType() returns Property::VECTOR2.
242 * @param[in] updateBufferIndex The buffer to read from.
243 * @return The Vector2 value.
245 virtual const Vector2& GetConstraintInputVector2(BufferIndex updateBufferIndex) const
247 return GetVector2(updateBufferIndex);
251 * Retrieve a Vector3 input for a constraint function.
252 * @note For inherited properties, this method should be overriden to return the value
253 * from the previous frame i.e. not from the current update buffer.
254 * @pre GetType() returns Property::VECTOR3.
255 * @param[in] updateBufferIndex The buffer to read from.
256 * @return The Vector3 value.
258 virtual const Vector3& GetConstraintInputVector3(BufferIndex updateBufferIndex) const
260 return GetVector3(updateBufferIndex);
264 * Retrieve a Vector4 input for a constraint function.
265 * @note For inherited properties, this method should be overriden to return the value
266 * from the previous frame i.e. not from the current update buffer.
267 * @pre GetType() returns Property::VECTOR4.
268 * @param[in] updateBufferIndex The buffer to read from.
269 * @return The Vector4 value.
271 virtual const Vector4& GetConstraintInputVector4(BufferIndex updateBufferIndex) const
273 return GetVector4(updateBufferIndex);
277 * Retrieve a Quaternion input for a constraint function.
278 * @note For inherited properties, this method should be overriden to return the value
279 * from the previous frame i.e. not from the current update buffer.
280 * @pre GetType() returns Property::Quaternion.
281 * @param[in] updateBufferIndex The buffer to read from.
282 * @return The Quaternion value.
284 virtual const Quaternion& GetConstraintInputQuaternion(BufferIndex updateBufferIndex) const
286 return GetQuaternion(updateBufferIndex);
290 * Retrieve a Matrix3 input for a constraint function.
291 * @note For inherited properties, this method should be overriden to return the value
292 * from the previous frame i.e. not from the current update buffer.
293 * @pre GetType() returns Property::Matrix.
294 * @param[in] updateBufferIndex The buffer to read from.
295 * @return The Matrix value.
297 virtual const Matrix3& GetConstraintInputMatrix3(BufferIndex updateBufferIndex) const
299 return GetMatrix3(updateBufferIndex);
303 * Retrieve a Matrix input for a constraint function.
304 * @note For inherited properties, this method should be overriden to return the value
305 * from the previous frame i.e. not from the current update buffer.
306 * @pre GetType() returns Property::Matrix.
307 * @param[in] updateBufferIndex The buffer to read from.
308 * @return The Matrix value.
310 virtual const Matrix& GetConstraintInputMatrix(BufferIndex updateBufferIndex) const
312 return GetMatrix(updateBufferIndex);
316 * Query whether the property belongs to the
317 * transform manager or not.
318 * @return True if it is a transform manager property, false otherwise
320 virtual bool IsTransformManagerProperty() const
325 std::uint64_t Hash(BufferIndex bufferIndex, uint64_t seed) const
329 case Property::BOOLEAN:
331 return std::_Hash_bytes(&GetBoolean(bufferIndex), sizeof(bool), seed);
334 case Property::INTEGER:
336 return std::_Hash_bytes(&GetInteger(bufferIndex), sizeof(int), seed);
339 case Property::FLOAT:
341 return std::_Hash_bytes(&GetFloat(bufferIndex), sizeof(float), seed);
344 case Property::VECTOR2:
346 return std::_Hash_bytes(&GetVector2(bufferIndex), sizeof(Vector2), seed);
349 case Property::VECTOR3:
351 return std::_Hash_bytes(&GetVector3(bufferIndex), sizeof(Vector3), seed);
354 case Property::VECTOR4:
356 return std::_Hash_bytes(&GetVector4(bufferIndex), sizeof(Vector4), seed);
359 case Property::ROTATION:
361 return std::_Hash_bytes(&GetQuaternion(bufferIndex), sizeof(Quaternion), seed);
364 case Property::MATRIX:
366 return std::_Hash_bytes(&GetMatrix(bufferIndex), sizeof(Matrix), seed);
369 case Property::MATRIX3:
371 return std::_Hash_bytes(&GetMatrix3(bufferIndex), sizeof(Matrix3), seed);
375 break; // print nothing
382 * Print the property value using a stream.
383 * @param[in] debugStream The output stream.
384 * @param[in] bufferIndex The buffer to read from.
385 * @todo Place this far-too-large-to-be-inlined function in a cpp and remove <iostream> header dependency from this file.
387 void DebugPrint(std::ostream& debugStream, BufferIndex bufferIndex) const
391 case Property::BOOLEAN:
393 debugStream << GetBoolean(bufferIndex);
397 case Property::INTEGER:
399 debugStream << GetInteger(bufferIndex);
403 case Property::FLOAT:
405 debugStream << GetFloat(bufferIndex);
409 case Property::VECTOR2:
411 debugStream << GetVector2(bufferIndex);
415 case Property::VECTOR3:
417 debugStream << GetVector3(bufferIndex);
421 case Property::VECTOR4:
423 debugStream << GetVector4(bufferIndex);
427 case Property::ROTATION:
429 debugStream << GetQuaternion(bufferIndex);
433 case Property::MATRIX:
435 debugStream << GetMatrix(bufferIndex);
439 case Property::MATRIX3:
441 debugStream << GetMatrix3(bufferIndex);
446 break; // print nothing
451 } // namespace Internal
455 #endif // DALI_INTERNAL_PROPERTY_INPUT_IMPL_H