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 mEdgeX; // Image used to pad upload
69 BufferImage mEdgeY; // Image used to pad upload
70 Material mMaterial; // material used for atlas texture
71 SizeType mNextFreeBlock; // next free block will be placed here ( actually +1 )
72 Dali::Vector< SizeType > mFreeBlocksList; // unless there are any previously freed blocks
75 struct AtlasSlotDescriptor
77 SizeType mCount; // Reference count for this slot
78 SizeType mImageWidth; // Width of image stored
79 SizeType mImageHeight; // Height of image stored
80 AtlasId mAtlasId; // Image is stored in this Atlas
81 Dali::Vector< SizeType > mBlocksList; // List of blocks within atlas used for image
87 * Create a new AtlasManager
89 static AtlasManagerPtr New();
91 virtual ~AtlasManager();
94 * @copydoc: Toolkit::AtlasManager::CreateAtlas
96 AtlasId CreateAtlas( SizeType width,
100 Pixel::Format pixelformat );
103 * @copydoc Toolkit::AtlasManager::SetAddPolicy
105 void SetAddPolicy( Toolkit::AtlasManager::AddFailPolicy policy );
108 * @copydoc Toolkit::AtlasManager::Add
110 void Add( const BufferImage& image,
111 Toolkit::AtlasManager::AtlasSlot& slot,
112 Toolkit::AtlasManager::AtlasId atlas );
115 * @copydoc Toolkit::AtlasManager::GenerateMeshData
117 void GenerateMeshData( ImageId id,
118 const Vector2& position,
122 * @copydoc Toolkit::AtlasManager::StitchMesh
124 void StitchMesh( MeshData& first,
125 const MeshData& second,
129 * @copydoc Toolkit::AtlasManager::StitchMesh
131 void StitchMesh( const MeshData& first,
132 const MeshData& second,
133 MeshData& out, bool optimize );
136 * @copydoc Toolkit::AtlasManager::Remove
138 bool Remove( ImageId id );
141 * @copydoc Toolkit::AtlasManager::GetAtlasContainer
143 Dali::Atlas GetAtlasContainer( AtlasId atlas ) const;
146 * @copydoc Toolkit::AtlasManager::GetAtlas
148 AtlasId GetAtlas( ImageId id ) const;
151 * @copydoc Toolkit::AtlasManager::SetNewAtlasSize
153 void SetNewAtlasSize( const Vector2& size,
154 const Vector2& blockSize );
157 * @copydoc Toolkit::AtlasManager::GetAtlasSize
159 Vector2 GetAtlasSize( AtlasId atlas );
162 * @copydoc Toolkit::AtlasManager::GetBlockSize
164 Vector2 GetBlockSize( AtlasId atlas );
167 * @copydoc Toolkit::AtlasManager::GetFreeBlocks
169 SizeType GetFreeBlocks( AtlasId atlas ) const;
172 * @copydoc Toolkit::AtlasManager::GetAtlasCount
174 SizeType GetAtlasCount() const;
177 * @copydoc Toolkit::AtlasManager::GetPixelFormat
179 Pixel::Format GetPixelFormat( AtlasId atlas );
182 * @copydoc Toolkit::AtlasManager::GetMetrics
184 void GetMetrics( Toolkit::AtlasManager::Metrics& metrics );
188 std::vector< AtlasDescriptor > mAtlasList; // List of atlases created
189 std::vector< AtlasSlotDescriptor > mImageList; // List of bitmaps store in atlases
191 SizeType CheckAtlas( SizeType atlas,
194 Pixel::Format pixelFormat,
196 SizeType& totalBlocks );
198 void CreateMesh( SizeType atlas,
200 SizeType imageHeight,
201 const Vector2& position,
202 SizeType widthInBlocks,
203 SizeType heightInBlocks,
204 Dali::MeshData& meshData,
205 AtlasSlotDescriptor& desc );
207 void OptimizeVertices( const MeshData::VertexContainer& in,
208 MeshData::FaceIndices& faces,
209 MeshData::VertexContainer& out );
211 void UploadImage( const BufferImage& image,
212 const AtlasSlotDescriptor& desc );
214 void PrintMeshData( const MeshData& meshData );
216 Vector2 mNewAtlasSize;
217 Vector2 mNewBlockSize;
218 Toolkit::AtlasManager::AddFailPolicy mAddFailPolicy;
219 PixelBuffer* mEdgeBuffer;
220 uint32_t mEdgeBufferSize;
223 } // namespace Internal
225 inline const Internal::AtlasManager& GetImplementation(const Toolkit::AtlasManager& manager)
227 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
229 const BaseObject& handle = manager.GetBaseObject();
231 return static_cast<const Internal::AtlasManager&>(handle);
234 inline Internal::AtlasManager& GetImplementation(Toolkit::AtlasManager& manager)
236 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
238 BaseObject& handle = manager.GetBaseObject();
240 return static_cast<Internal::AtlasManager&>(handle);
243 } // namespace Toolkit
248 #endif // __DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H__