1 #ifndef __DALI_TOOLKIT_ATLAS_MANAGER_H__
2 #define __DALI_TOOLKIT_ATLAS_MANAGER_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-vector.h>
23 #include <dali/public-api/images/buffer-image.h>
24 #include <dali/devel-api/images/atlas.h>
25 #include <dali/devel-api/rendering/material.h>
33 namespace Internal DALI_INTERNAL
38 } // namespace Internal
40 class AtlasManager : public BaseHandle
44 typedef uint32_t SizeType;
45 typedef SizeType AtlasId;
46 typedef SizeType ImageId;
50 SizeType mWidth; ///< width of the atlas in pixels
51 SizeType mHeight; ///< height of the atlas in pixels
52 SizeType mBlockWidth; ///< width of a block in pixels
53 SizeType mBlockHeight; ///< height of a block in pixels
57 * Metrics structures to describe Atlas Manager state
60 struct AtlasMetricsEntry
62 AtlasSize mSize; ///< size of atlas and blocks
63 SizeType mBlocksUsed; ///< number of blocks used in the atlas
64 SizeType mTotalBlocks; ///< total blocks used by atlas
65 Pixel::Format mPixelFormat; ///< pixel format of the atlas
72 mTextureMemoryUsed( 0u )
78 SizeType mAtlasCount; ///< number of atlases
79 SizeType mTextureMemoryUsed; ///< texture memory used by atlases
80 Dali::Vector< AtlasMetricsEntry > mAtlasMetrics; ///< container of atlas information
85 Vector2 mPosition; ///< Vertex posiiton
86 Vector2 mTexCoords; ///< Vertex texture co-ordinates
91 Vector< Vertex2D > mVertices; ///< container of vertices
92 Vector< SizeType > 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 reference to a bitmapimage
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 BufferImage& 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::Atlas 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 );
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 Material used by atlas
261 * @param[in] atlas AtlasId
263 * @return Material used by atlas
265 Material GetMaterial( AtlasId atlas ) const;
268 * @brief Set the material used by an atlas
270 * @param[in] atlas AtlasId
271 * @param[in] material The Material to assign
273 void SetMaterial( AtlasId atlas, Material& material );
277 explicit DALI_INTERNAL AtlasManager(Internal::AtlasManager *impl);
281 } // namespace Toolkit
285 #endif // __DALI_TOOLKIT_ATLAS_MANAGER_H__