1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_BUFFER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_BUFFER_H
5 * Copyright (c) 2018 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.
19 #include <dali/public-api/actors/sampling.h>
20 #include <dali/public-api/common/vector-wrapper.h>
21 #include <dali/public-api/rendering/sampler.h>
22 #include <dali/graphics-api/graphics-api-accessor.h>
23 #include <dali/graphics-api/graphics-api-buffer.h>
24 #include <dali/integration-api/graphics/graphics.h>
25 #include <dali/internal/common/message.h>
26 #include <dali/internal/common/owner-pointer.h>
27 #include <dali/internal/event/common/event-thread-services.h>
28 #include <dali/internal/update/rendering/scene-graph-sampler.h>
58 * Structure that holds the meta-data of the format of PropertyBuffer.
62 std::vector<Component> components;
67 * @brief Default constructor
77 * Initialize the shader object with the Graphics API when added to UpdateManager
79 * @param[in] graphics The Graphics API
81 void Initialize( Integration::Graphics::Graphics& graphics );
84 * @brief Set the format of the buffer
86 * This function takes ownership of the pointer
88 * @param[in] format The format for the PropertyBuffer
90 void SetFormat( OwnerPointer<PropertyBuffer::Format>& format );
94 * @brief Set the data of the PropertyBuffer
96 * This function takes ownership of the pointer
97 * @param[in] data The new data of the PropertyBuffer
98 * @param[in] size The new size of the buffer
100 void SetData( OwnerPointer< Dali::Vector<char> >& data, size_t size );
103 * @brief Set the number of elements
104 * @param[in] size The number of elements
106 void SetSize( unsigned int size );
109 * Perform the upload of the buffer only when required
110 * @param[in] controller
113 bool Update( Dali::Graphics::API::Controller& controller );
116 * Get the number of attributes present in the buffer
117 * @return The number of attributes stored in this buffer
119 inline unsigned int GetAttributeCount() const
121 DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
122 return mFormat->components.size();
126 * Retrieve the i-essim attribute name
127 * @param[in] index The index of the attribute
128 * @return The name of the attribute
130 inline const std::string& GetAttributeName(unsigned int index ) const
132 DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
133 return mFormat->components[index].name;
137 * Retrieve the size of the buffer in bytes
138 * @return The total size of the buffer
140 inline std::size_t GetDataSize() const
142 DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
143 return mFormat->size * mSize;
147 * Retrieve the size of one element of the buffer
148 * @return The size of one element
150 inline std::size_t GetElementSize() const
152 DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
153 return mFormat->size;
157 * Retrieve the number of elements in the buffer
158 * @return The total number of elements
160 inline unsigned int GetElementCount() const
165 inline const PropertyBuffer::Format* GetFormat() const
167 return mFormat.Get();
169 inline Graphics::API::Accessor<Graphics::API::Buffer> GetGfxObject() const
171 return mGraphicsBuffer;
174 void SetUsage( Graphics::API::Buffer::UsageHint usage );
177 Integration::Graphics::Graphics* mGraphics; ///< Graphics interface object
178 OwnerPointer< PropertyBuffer::Format > mFormat; ///< Format of the buffer
179 OwnerPointer< Dali::Vector< char > > mData; ///< Data
181 size_t mSize; ///< Number of Elements in the buffer
182 bool mDataChanged; ///< Flag to know if data has changed in a frame
185 Graphics::API::Accessor<Graphics::API::Buffer> mGraphicsBuffer;
186 Graphics::API::Buffer::UsageHint mGraphicsBufferUsage;
190 inline void SetPropertyBufferFormatMessage( EventThreadServices& eventThreadServices, SceneGraph::PropertyBuffer& propertyBuffer, OwnerPointer< SceneGraph::PropertyBuffer::Format>& format )
192 // Message has ownership of PropertyBuffer::Format while in transit from event -> update
193 typedef MessageValue1< SceneGraph::PropertyBuffer, OwnerPointer< SceneGraph::PropertyBuffer::Format> > LocalType;
195 // Reserve some memory inside the message queue
196 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ), false );
198 // Construct message in the message queue memory; note that delete should not be called on the return value
199 new (slot) LocalType( &propertyBuffer, &PropertyBuffer::SetFormat, format );
202 inline void SetPropertyBufferDataMessage( EventThreadServices& eventThreadServices, SceneGraph::PropertyBuffer& propertyBuffer, OwnerPointer< Vector<char> >& data, size_t size )
204 // Message has ownership of PropertyBuffer data while in transit from event -> update
205 typedef MessageValue2< SceneGraph::PropertyBuffer, OwnerPointer< Vector<char> >, size_t > LocalType;
207 // Reserve some memory inside the message queue
208 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ), false );
210 // Construct message in the message queue memory; note that delete should not be called on the return value
211 new (slot) LocalType( &propertyBuffer, &PropertyBuffer::SetData, data, size );
214 } // namespace SceneGraph
216 } // namespace Internal
221 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_BUFFER_H