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
87 Vector4 mColor; ///< Vertex color
92 Vector< Vertex2D > mVertices; ///< container of vertices
93 Vector< SizeType > mIndices; ///< container of indices
97 * Create an AtlasManager handle; this can be initialised with AtlasManager::New()
98 * Calling member functions with an uninitialised handle is not allowed.
103 * @brief Get new instance of AtlasManager object.
105 * @return A handle to the AtlasManager control.
107 static AtlasManager New();
112 * This is non-virtual since derived Handle types must not contain data or virtual methods.
117 * Policy on failing to add an image
126 * @brief Container to hold result of placing texture into atlas
130 ImageId mImageId; ///< Id of stored Image
131 AtlasId mAtlasId; ///< Id of Atlas containing this slot
134 typedef Dali::Vector< AtlasManager::AtlasSlot > slotContainer;
137 * @brief Create a blank atlas of specific dimensions and pixel format with a certain block size
139 * @param[in] size desired atlas dimensions
140 * @param[in] pixelformat format of a pixel in atlas
144 AtlasId CreateAtlas( const AtlasSize& size, Pixel::Format pixelformat = Pixel::RGBA8888 );
147 * @brief Set the policy on failure to add an image to an atlas
149 * @param policy policy to carry out if add fails
151 void SetAddPolicy( AddFailPolicy policy );
154 * @brief Attempts to add an image to the most suitable atlas
156 * @details Add Policy may dictate that a new atlas is created if it can't presently be placed.
157 * If an add is made before an atlas is created under this policy,
158 * then a default size atlas will be created
160 * @param[in] image reference to a bitmapimage
161 * @param[out] slot result of add operation
162 * @param[in] atlas optional preferred atlas
164 * @return true if a new atlas was created
166 bool Add( const BufferImage& image,
171 * @brief Remove previously added bitmapimage from atlas
173 * @param[in] id ImageId returned in the AtlasSlot from the add operation
175 * @return if true then image has been removed from the atlas
177 bool Remove( ImageId id );
180 * @brief Generate mesh data for a previously added image
182 * @param[in] id Image Id returned in the AtlasSlot from the add operation
183 * @param[in] position position of the resulting mesh in model space
184 * @param[out] mesh Mesh Data Object to populate with mesh data
185 * @param[in] addReference Whether to increase the internal reference count for image or not
187 void GenerateMeshData( ImageId id,
188 const Vector2& position,
190 bool addReference = true );
193 * @brief Get the BufferImage containing an atlas
195 * @param[in] atlas AtlasId returned when atlas was created
197 * @return Atlas Handle
199 Dali::Atlas GetAtlasContainer( AtlasId atlas ) const;
202 * @brief Get the Id of the atlas containing an image
204 * @param[in] id ImageId
208 AtlasId GetAtlas( ImageId id );
210 * @brief Get the current size of an atlas
212 * @param[in] atlas AtlasId
214 * @return AtlasSize structure for the atlas
216 const AtlasSize& GetAtlasSize( AtlasId atlas );
219 * @brief Get the number of blocks available in an atlas
221 * @param[in] atlas AtlasId
223 * @return Number of blocks free in this atlas
225 SizeType GetFreeBlocks( AtlasId atlas );
228 * @brief Sets the pixel area of any new atlas and also the individual block size
230 * @param[in] size Atlas size structure
232 * @param blockSize pixel area in atlas for a block
234 void SetNewAtlasSize( const AtlasSize& size );
237 * @brief Get the number of atlases created
239 * @return number of atlases
241 SizeType GetAtlasCount() const;
244 * @brief Get the pixel format used by an atlas
246 * @param[in] atlas AtlasId
248 * @return Pixel format used by this atlas
250 Pixel::Format GetPixelFormat( AtlasId atlas );
253 * @brief Fill in a metrics structure showing current status of this Atlas Manager
255 * @param[in] metrics metrics structure to be filled
257 void GetMetrics( Metrics& metrics );
260 * @brief Get Material used by atlas
262 * @param[in] atlas AtlasId
264 * @return Material used by atlas
266 Material GetMaterial( AtlasId atlas ) const;
269 * @brief Set the material used by an atlas
271 * @param[in] atlas AtlasId
272 * @param[in] material The Material to assign
274 void SetMaterial( AtlasId atlas, Material& material );
278 explicit DALI_INTERNAL AtlasManager(Internal::AtlasManager *impl);
282 } // namespace Toolkit
286 #endif // __DALI_TOOLKIT_ATLAS_MANAGER_H__