1 #ifndef DALI_INTERNAL_PROPERTY_BUFFER_H
2 #define DALI_INTERNAL_PROPERTY_BUFFER_H
5 * Copyright (c) 2015 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.
22 #include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
23 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/object/property-map.h> // Dali::Property::Map
26 #include <dali/devel-api/object/property-buffer.h> // Dali::PropertyBuffer
27 #include <dali/internal/event/common/event-thread-services.h>
28 #include <dali/internal/render/renderers/render-property-buffer.h>
36 typedef IntrusivePtr<PropertyBuffer> PropertyBufferPtr;
39 * PropertyBuffer is an object that contains an array of structures of values that
40 * can be accessed as properties.
42 class PropertyBuffer : public BaseObject
47 * @copydoc PropertBuffer::New()
49 static PropertyBufferPtr New();
52 * @copydoc PropertBuffer::SetSize()
54 void SetSize( std::size_t size );
57 * @copydoc PropertBuffer::GetSize()
59 std::size_t GetSize() const;
62 * @copydoc PropertBuffer::SetData()
64 void SetData( const void* data );
67 * @brief Set the format of the PropertyBuffer
69 * @pre Has not been set yet
71 * @param[in] format of the PropertyBuffer
73 void SetFormat( Dali::Property::Map& format );
75 public: // Default property extensions from Object
78 * @brief Get the render thread side of the PropertyBuffer
80 * @return The render thread side of this PropertyBuffer
82 const Render::PropertyBuffer* GetRenderObject() const;
90 private: // implementation
92 * @brief Default constructor
97 * Second stage initialization
102 * Update the buffer when the format changes
104 void FormatChanged();
107 * Update the buffer when the size changes
111 private: // unimplemented methods
112 PropertyBuffer( const PropertyBuffer& );
113 PropertyBuffer& operator=( const PropertyBuffer& );
116 EventThreadServices& mEventThreadServices; ///<Used to send messages to the render thread via update thread
117 Render::PropertyBuffer* mRenderObject; ///<Render side object
119 Property::Map mFormat; ///< Format of the property buffer
120 const Render::PropertyBuffer::Format* mBufferFormat; ///< Metadata for the format of the property buffer
121 unsigned int mSize; ///< Number of elements in the buffer
122 Dali::Vector< char > mBuffer; // Data of the property-buffer
126 * Get the implementation type from a Property::Type
128 template<Property::Type type> struct PropertyImplementationType
130 // typedef ... Type; not defined, only support types declared bellow
132 template<> struct PropertyImplementationType< Property::BOOLEAN > { typedef bool Type; };
133 template<> struct PropertyImplementationType< Property::FLOAT > { typedef float Type; };
134 template<> struct PropertyImplementationType< Property::INTEGER > { typedef int Type; };
135 template<> struct PropertyImplementationType< Property::VECTOR2 > { typedef Vector2 Type; };
136 template<> struct PropertyImplementationType< Property::VECTOR3 > { typedef Vector3 Type; };
137 template<> struct PropertyImplementationType< Property::VECTOR4 > { typedef Vector4 Type; };
138 template<> struct PropertyImplementationType< Property::MATRIX3 > { typedef Matrix3 Type; };
139 template<> struct PropertyImplementationType< Property::MATRIX > { typedef Matrix Type; };
140 template<> struct PropertyImplementationType< Property::RECTANGLE > { typedef Rect<int> Type; };
141 template<> struct PropertyImplementationType< Property::ROTATION > { typedef Quaternion Type; };
143 unsigned int GetPropertyImplementationSize( Property::Type& propertyType );
145 } // namespace Internal
147 // Helpers for public-api forwarding methods
148 inline Internal::PropertyBuffer& GetImplementation(Dali::PropertyBuffer& handle)
150 DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
152 BaseObject& object = handle.GetBaseObject();
154 return static_cast<Internal::PropertyBuffer&>(object);
157 inline const Internal::PropertyBuffer& GetImplementation(const Dali::PropertyBuffer& handle)
159 DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
161 const BaseObject& object = handle.GetBaseObject();
163 return static_cast<const Internal::PropertyBuffer&>(object);
168 #endif // DALI_INTERNAL_PROPERTY_BUFFER_H