1 #ifndef __DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H__
2 #define __DALI_TOOLKIT_ATLAS_MANAGER_IMPL_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/vector-wrapper.h>
23 #include <dali/public-api/object/base-object.h>
26 #include <dali-toolkit/internal/atlas-manager/atlas-manager.h>
36 } // namespace Toolkit
44 typedef Dali::Vector< Toolkit::AtlasManager::AtlasSlot > slotContainer;
47 typedef IntrusivePtr<AtlasManager> AtlasManagerPtr;
49 class AtlasManager : public Dali::BaseObject
53 typedef uint32_t SizeType;
54 typedef SizeType AtlasId;
55 typedef SizeType ImageId;
58 * @brief Internal storage of atlas attributes and image upload results
60 struct AtlasDescriptor
62 Dali::Atlas mAtlas; // atlas image
63 SizeType mWidth; // width of atlas
64 SizeType mHeight; // height of atlas
65 SizeType mBlockWidth; // width of a block in atlas
66 SizeType mBlockHeight; // height of a block in atlas
67 Pixel::Format mPixelFormat; // pixel format used by atlas
68 BufferImage mHorizontalStrip; // Image used to pad upload
69 BufferImage mVerticalStrip; // Image used to pad upload
70 BufferImage mFilledPixelImage; // Image used by atlas for operations such as underline
71 PixelBuffer* mStripBuffer; // Blank image buffer used to pad upload
72 Material mMaterial; // material used for atlas texture
73 SizeType mNextFreeBlock; // next free block will be placed here ( actually +1 )
74 Dali::Vector< SizeType > mFreeBlocksList; // unless there are any previously freed blocks
77 struct AtlasSlotDescriptor
79 SizeType mCount; // Reference count for this slot
80 SizeType mImageWidth; // Width of image stored
81 SizeType mImageHeight; // Height of image stored
82 AtlasId mAtlasId; // Image is stored in this Atlas
83 Dali::Vector< SizeType > mBlocksList; // List of blocks within atlas used for image
89 * Create a new AtlasManager
91 static AtlasManagerPtr New();
93 virtual ~AtlasManager();
96 * @copydoc: Toolkit::AtlasManager::CreateAtlas
98 AtlasId CreateAtlas( SizeType width,
101 SizeType blockHeight,
102 Pixel::Format pixelformat );
105 * @copydoc Toolkit::AtlasManager::SetAddPolicy
107 void SetAddPolicy( Toolkit::AtlasManager::AddFailPolicy policy );
110 * @copydoc Toolkit::AtlasManager::Add
112 void Add( const BufferImage& image,
113 Toolkit::AtlasManager::AtlasSlot& slot,
114 Toolkit::AtlasManager::AtlasId atlas );
117 * @copydoc Toolkit::AtlasManager::GenerateMeshData
119 void GenerateMeshData( ImageId id,
120 const Vector2& position,
124 * @copydoc Toolkit::AtlasManager::StitchMesh
126 void StitchMesh( MeshData& first,
127 const MeshData& second,
131 * @copydoc Toolkit::AtlasManager::StitchMesh
133 void StitchMesh( const MeshData& first,
134 const MeshData& second,
135 MeshData& out, bool optimize );
138 * @copydoc Toolkit::AtlasManager::Remove
140 bool Remove( ImageId id );
143 * @copydoc Toolkit::AtlasManager::GetAtlasContainer
145 Dali::Atlas GetAtlasContainer( AtlasId atlas ) const;
148 * @copydoc Toolkit::AtlasManager::GetAtlas
150 AtlasId GetAtlas( ImageId id ) const;
153 * @copydoc Toolkit::AtlasManager::SetNewAtlasSize
155 void SetNewAtlasSize( const Vector2& size,
156 const Vector2& blockSize );
159 * @copydoc Toolkit::AtlasManager::GetAtlasSize
161 Vector2 GetAtlasSize( AtlasId atlas );
164 * @copydoc Toolkit::AtlasManager::GetBlockSize
166 Vector2 GetBlockSize( AtlasId atlas );
169 * @copydoc Toolkit::AtlasManager::GetFreeBlocks
171 SizeType GetFreeBlocks( AtlasId atlas ) const;
174 * @copydoc Toolkit::AtlasManager::GetAtlasCount
176 SizeType GetAtlasCount() const;
179 * @copydoc Toolkit::AtlasManager::GetPixelFormat
181 Pixel::Format GetPixelFormat( AtlasId atlas );
184 * @copydoc Toolkit::AtlasManager::GetMetrics
186 void GetMetrics( Toolkit::AtlasManager::Metrics& metrics );
190 std::vector< AtlasDescriptor > mAtlasList; // List of atlases created
191 std::vector< AtlasSlotDescriptor > mImageList; // List of bitmaps store in atlases
193 SizeType CheckAtlas( SizeType atlas,
196 Pixel::Format pixelFormat,
198 SizeType& totalBlocks );
200 void CreateMesh( SizeType atlas,
202 SizeType imageHeight,
203 const Vector2& position,
204 SizeType widthInBlocks,
205 SizeType heightInBlocks,
206 Dali::MeshData& meshData,
207 AtlasSlotDescriptor& desc );
209 void OptimizeVertices( const MeshData::VertexContainer& in,
210 MeshData::FaceIndices& faces,
211 MeshData::VertexContainer& out );
213 void UploadImage( const BufferImage& image,
214 const AtlasSlotDescriptor& desc );
216 void PrintMeshData( const MeshData& meshData );
218 Vector2 mNewAtlasSize;
219 Vector2 mNewBlockSize;
220 Toolkit::AtlasManager::AddFailPolicy mAddFailPolicy;
221 uint32_t mFilledPixel;
224 } // namespace Internal
226 inline const Internal::AtlasManager& GetImplementation(const Toolkit::AtlasManager& manager)
228 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
230 const BaseObject& handle = manager.GetBaseObject();
232 return static_cast<const Internal::AtlasManager&>(handle);
235 inline Internal::AtlasManager& GetImplementation(Toolkit::AtlasManager& manager)
237 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
239 BaseObject& handle = manager.GetBaseObject();
241 return static_cast<Internal::AtlasManager&>(handle);
244 } // namespace Toolkit
249 #endif // __DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H__