Removal of unnecessary Actor-attachment classes, part I - event thread
[platform/core/uifw/dali-core.git] / dali / internal / event / common / property-buffer-impl.h
1 #ifndef DALI_INTERNAL_PROPERTY_BUFFER_H
2 #define DALI_INTERNAL_PROPERTY_BUFFER_H
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
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>
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34
35 class PropertyBuffer;
36 typedef IntrusivePtr<PropertyBuffer> PropertyBufferPtr;
37
38 /**
39  * PropertyBuffer is an object that contains an array of structures of values that
40  * can be accessed as properties.
41  */
42 class PropertyBuffer : public BaseObject
43 {
44 public:
45
46   /**
47    * @copydoc PropertBuffer::New()
48    */
49   static PropertyBufferPtr New( Dali::Property::Map& format );
50
51   /**
52    * @copydoc PropertBuffer::SetData()
53    */
54   void SetData( const void* data, std::size_t size );
55
56   /**
57    * @copydoc PropertBuffer::GetSize()
58    */
59   std::size_t GetSize() const;
60
61 public: // Default property extensions from Object
62
63   /**
64    * @brief Get the render thread side of the PropertyBuffer
65    *
66    * @return The render thread side of this PropertyBuffer
67    */
68   const Render::PropertyBuffer* GetRenderObject() const;
69
70 protected:
71   /**
72    * @brief Destructor
73    */
74   ~PropertyBuffer();
75
76 private: // implementation
77   /**
78    * @brief Default constructor
79    */
80   PropertyBuffer();
81
82   /**
83    * Second stage initialization
84    */
85   void Initialize( Dali::Property::Map& format );
86
87 private: // unimplemented methods
88   PropertyBuffer( const PropertyBuffer& );
89   PropertyBuffer& operator=( const PropertyBuffer& );
90
91 private: // data
92   EventThreadServices& mEventThreadServices;    ///<Used to send messages to the render thread via update thread
93   Render::PropertyBuffer* mRenderObject; ///<Render side object
94
95   Property::Map mFormat;  ///< Format of the property buffer
96   const Render::PropertyBuffer::Format* mBufferFormat;  ///< Metadata for the format of the property buffer
97   unsigned int mSize; ///< Number of elements in the buffer
98   Dali::Vector< char > mBuffer; // Data of the property-buffer
99 };
100
101 /**
102  * Get the implementation type from a Property::Type
103  */
104 template<Property::Type type> struct PropertyImplementationType
105 {
106   // typedef ... Type; not defined, only support types declared bellow
107 };
108 template<> struct PropertyImplementationType< Property::BOOLEAN > { typedef bool Type; };
109 template<> struct PropertyImplementationType< Property::FLOAT > { typedef float Type; };
110 template<> struct PropertyImplementationType< Property::INTEGER > { typedef int Type; };
111 template<> struct PropertyImplementationType< Property::VECTOR2 > { typedef Vector2 Type; };
112 template<> struct PropertyImplementationType< Property::VECTOR3 > { typedef Vector3 Type; };
113 template<> struct PropertyImplementationType< Property::VECTOR4 > { typedef Vector4 Type; };
114 template<> struct PropertyImplementationType< Property::MATRIX3 > { typedef Matrix3 Type; };
115 template<> struct PropertyImplementationType< Property::MATRIX > { typedef Matrix Type; };
116 template<> struct PropertyImplementationType< Property::RECTANGLE > { typedef Rect<int> Type; };
117 template<> struct PropertyImplementationType< Property::ROTATION > { typedef Quaternion Type; };
118
119 unsigned int GetPropertyImplementationSize( Property::Type& propertyType );
120
121 } // namespace Internal
122
123 // Helpers for public-api forwarding methods
124 inline Internal::PropertyBuffer& GetImplementation(Dali::PropertyBuffer& handle)
125 {
126   DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
127
128   BaseObject& object = handle.GetBaseObject();
129
130   return static_cast<Internal::PropertyBuffer&>(object);
131 }
132
133 inline const Internal::PropertyBuffer& GetImplementation(const Dali::PropertyBuffer& handle)
134 {
135   DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
136
137   const BaseObject& object = handle.GetBaseObject();
138
139   return static_cast<const Internal::PropertyBuffer&>(object);
140 }
141
142 } // namespace Dali
143
144 #endif // DALI_INTERNAL_PROPERTY_BUFFER_H