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 PixelBuffer* mStripBuffer; // Blank image buffer used to pad upload
71 Material mMaterial; // material used for atlas texture
72 SizeType mNextFreeBlock; // next free block will be placed here ( actually +1 )
73 Dali::Vector< SizeType > mFreeBlocksList; // unless there are any previously freed blocks
76 struct AtlasSlotDescriptor
78 SizeType mCount; // Reference count for this slot
79 SizeType mImageWidth; // Width of image stored
80 SizeType mImageHeight; // Height of image stored
81 AtlasId mAtlasId; // Image is stored in this Atlas
82 Dali::Vector< SizeType > mBlocksList; // List of blocks within atlas used for image
88 * Create a new AtlasManager
90 static AtlasManagerPtr New();
92 virtual ~AtlasManager();
95 * @copydoc: Toolkit::AtlasManager::CreateAtlas
97 AtlasId CreateAtlas( SizeType width,
100 SizeType blockHeight,
101 Pixel::Format pixelformat );
104 * @copydoc Toolkit::AtlasManager::SetAddPolicy
106 void SetAddPolicy( Toolkit::AtlasManager::AddFailPolicy policy );
109 * @copydoc Toolkit::AtlasManager::Add
111 void Add( const BufferImage& image,
112 Toolkit::AtlasManager::AtlasSlot& slot,
113 Toolkit::AtlasManager::AtlasId atlas );
116 * @copydoc Toolkit::AtlasManager::GenerateMeshData
118 void GenerateMeshData( ImageId id,
119 const Vector2& position,
123 * @copydoc Toolkit::AtlasManager::StitchMesh
125 void StitchMesh( MeshData& first,
126 const MeshData& second,
130 * @copydoc Toolkit::AtlasManager::StitchMesh
132 void StitchMesh( const MeshData& first,
133 const MeshData& second,
134 MeshData& out, bool optimize );
137 * @copydoc Toolkit::AtlasManager::Remove
139 bool Remove( ImageId id );
142 * @copydoc Toolkit::AtlasManager::GetAtlasContainer
144 Dali::Atlas GetAtlasContainer( AtlasId atlas ) const;
147 * @copydoc Toolkit::AtlasManager::GetAtlas
149 AtlasId GetAtlas( ImageId id ) const;
152 * @copydoc Toolkit::AtlasManager::SetNewAtlasSize
154 void SetNewAtlasSize( const Vector2& size,
155 const Vector2& blockSize );
158 * @copydoc Toolkit::AtlasManager::GetAtlasSize
160 Vector2 GetAtlasSize( AtlasId atlas );
163 * @copydoc Toolkit::AtlasManager::GetBlockSize
165 Vector2 GetBlockSize( AtlasId atlas );
168 * @copydoc Toolkit::AtlasManager::GetFreeBlocks
170 SizeType GetFreeBlocks( AtlasId atlas ) const;
173 * @copydoc Toolkit::AtlasManager::GetAtlasCount
175 SizeType GetAtlasCount() const;
178 * @copydoc Toolkit::AtlasManager::GetPixelFormat
180 Pixel::Format GetPixelFormat( AtlasId atlas );
183 * @copydoc Toolkit::AtlasManager::GetMetrics
185 void GetMetrics( Toolkit::AtlasManager::Metrics& metrics );
189 std::vector< AtlasDescriptor > mAtlasList; // List of atlases created
190 std::vector< AtlasSlotDescriptor > mImageList; // List of bitmaps store in atlases
192 SizeType CheckAtlas( SizeType atlas,
195 Pixel::Format pixelFormat,
197 SizeType& totalBlocks );
199 void CreateMesh( SizeType atlas,
201 SizeType imageHeight,
202 const Vector2& position,
203 SizeType widthInBlocks,
204 SizeType heightInBlocks,
205 Dali::MeshData& meshData,
206 AtlasSlotDescriptor& desc );
208 void OptimizeVertices( const MeshData::VertexContainer& in,
209 MeshData::FaceIndices& faces,
210 MeshData::VertexContainer& out );
212 void UploadImage( const BufferImage& image,
213 const AtlasSlotDescriptor& desc );
215 void PrintMeshData( const MeshData& meshData );
217 Vector2 mNewAtlasSize;
218 Vector2 mNewBlockSize;
219 Toolkit::AtlasManager::AddFailPolicy mAddFailPolicy;
222 } // namespace Internal
224 inline const Internal::AtlasManager& GetImplementation(const Toolkit::AtlasManager& manager)
226 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
228 const BaseObject& handle = manager.GetBaseObject();
230 return static_cast<const Internal::AtlasManager&>(handle);
233 inline Internal::AtlasManager& GetImplementation(Toolkit::AtlasManager& manager)
235 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
237 BaseObject& handle = manager.GetBaseObject();
239 return static_cast<Internal::AtlasManager&>(handle);
242 } // namespace Toolkit
247 #endif // __DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H__