1 #ifndef DALI_TOOLKIT_ATLAS_MANAGER_H
2 #define DALI_TOOLKIT_ATLAS_MANAGER_H
5 * Copyright (c) 2016 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-vector.h>
23 #include <dali/public-api/images/buffer-image.h>
24 #include <dali/public-api/rendering/texture-set.h>
32 namespace Internal DALI_INTERNAL
37 } // namespace Internal
39 class AtlasManager : public BaseHandle
43 typedef uint32_t SizeType;
44 typedef SizeType AtlasId;
45 typedef SizeType ImageId;
49 SizeType mWidth; ///< width of the atlas in pixels
50 SizeType mHeight; ///< height of the atlas in pixels
51 SizeType mBlockWidth; ///< width of a block in pixels
52 SizeType mBlockHeight; ///< height of a block in pixels
56 * Metrics structures to describe Atlas Manager state
59 struct AtlasMetricsEntry
61 AtlasSize mSize; ///< size of atlas and blocks
62 SizeType mBlocksUsed; ///< number of blocks used in the atlas
63 SizeType mTotalBlocks; ///< total blocks used by atlas
64 Pixel::Format mPixelFormat; ///< pixel format of the atlas
71 mTextureMemoryUsed( 0u )
77 SizeType mAtlasCount; ///< number of atlases
78 SizeType mTextureMemoryUsed; ///< texture memory used by atlases
79 Dali::Vector< AtlasMetricsEntry > mAtlasMetrics; ///< container of atlas information
84 Vector2 mPosition; ///< Vertex posiiton
85 Vector2 mTexCoords; ///< Vertex texture co-ordinates
86 Vector4 mColor; ///< Vertex color
91 Vector< Vertex2D > mVertices; ///< container of vertices
92 Vector< unsigned short > mIndices; ///< container of indices
96 * Create an AtlasManager handle; this can be initialised with AtlasManager::New()
97 * Calling member functions with an uninitialised handle is not allowed.
102 * @brief Get new instance of AtlasManager object.
104 * @return A handle to the AtlasManager control.
106 static AtlasManager New();
111 * This is non-virtual since derived Handle types must not contain data or virtual methods.
116 * Policy on failing to add an image
125 * @brief Container to hold result of placing texture into atlas
129 ImageId mImageId; ///< Id of stored Image
130 AtlasId mAtlasId; ///< Id of Atlas containing this slot
133 typedef Dali::Vector< AtlasManager::AtlasSlot > slotContainer;
136 * @brief Create a blank atlas of specific dimensions and pixel format with a certain block size
138 * @param[in] size desired atlas dimensions
139 * @param[in] pixelformat format of a pixel in atlas
143 AtlasId CreateAtlas( const AtlasSize& size, Pixel::Format pixelformat = Pixel::RGBA8888 );
146 * @brief Set the policy on failure to add an image to an atlas
148 * @param policy policy to carry out if add fails
150 void SetAddPolicy( AddFailPolicy policy );
153 * @brief Attempts to add an image to the most suitable atlas
155 * @details Add Policy may dictate that a new atlas is created if it can't presently be placed.
156 * If an add is made before an atlas is created under this policy,
157 * then a default size atlas will be created
159 * @param[in] image PixelData object containing the image data
160 * @param[out] slot result of add operation
161 * @param[in] atlas optional preferred atlas
163 * @return true if a new atlas was created
165 bool Add( const PixelData& image,
170 * @brief Remove previously added bitmapimage from atlas
172 * @param[in] id ImageId returned in the AtlasSlot from the add operation
174 * @return if true then image has been removed from the atlas
176 bool Remove( ImageId id );
179 * @brief Generate mesh data for a previously added image
181 * @param[in] id Image Id returned in the AtlasSlot from the add operation
182 * @param[in] position position of the resulting mesh in model space
183 * @param[out] mesh Mesh Data Object to populate with mesh data
184 * @param[in] addReference Whether to increase the internal reference count for image or not
186 void GenerateMeshData( ImageId id,
187 const Vector2& position,
189 bool addReference = true );
192 * @brief Get the BufferImage containing an atlas
194 * @param[in] atlas AtlasId returned when atlas was created
196 * @return Atlas Handle
198 Dali::Texture GetAtlasContainer( AtlasId atlas ) const;
201 * @brief Get the Id of the atlas containing an image
203 * @param[in] id ImageId
207 AtlasId GetAtlas( ImageId id );
209 * @brief Get the current size of an atlas
211 * @param[in] atlas AtlasId
213 * @return AtlasSize structure for the atlas
215 const AtlasSize& GetAtlasSize( AtlasId atlas );
218 * @brief Get the number of blocks available in an atlas
220 * @param[in] atlas AtlasId
222 * @return Number of blocks free in this atlas
224 SizeType GetFreeBlocks( AtlasId atlas );
227 * @brief Sets the pixel area of any new atlas and also the individual block size
229 * @param[in] size Atlas size structure
231 * @param blockSize pixel area in atlas for a block
233 void SetNewAtlasSize( const AtlasSize& size );
236 * @brief Get the number of atlases created
238 * @return number of atlases
240 SizeType GetAtlasCount() const;
243 * @brief Get the pixel format used by an atlas
245 * @param[in] atlas AtlasId
247 * @return Pixel format used by this atlas
249 Pixel::Format GetPixelFormat( AtlasId atlas ) const;
252 * @brief Fill in a metrics structure showing current status of this Atlas Manager
254 * @param[in] metrics metrics structure to be filled
256 void GetMetrics( Metrics& metrics );
259 * @brief Get TextureSet used by atlas
261 * @param[in] atlas AtlasId
263 * @return TextureSet used by atlas
265 TextureSet GetTextures( AtlasId atlas ) const;
268 * @brief Set the texture set used by an atlas
270 * @param[in] atlas AtlasId
271 * @param[in] textureSet The texture set to assign
273 void SetTextures( AtlasId atlas, TextureSet& textureSet );
277 explicit DALI_INTERNAL AtlasManager(Internal::AtlasManager *impl);
281 } // namespace Toolkit
285 #endif // DALI_TOOLKIT_ATLAS_MANAGER_H