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 Material mMaterial; // material used for atlas texture
69 SizeType mNextFreeBlock; // next free block will be placed here ( actually +1 )
70 Dali::Vector< SizeType > mFreeBlocksList; // unless there are any previously freed blocks
73 struct AtlasSlotDescriptor
75 SizeType mCount; // Reference count for this slot
76 SizeType mImageWidth; // Width of image stored
77 SizeType mImageHeight; // Height of image stored
78 AtlasId mAtlasId; // Image is stored in this Atlas
79 Dali::Vector< SizeType > mBlocksList; // List of blocks within atlas used for image
85 * Create a new AtlasManager
87 static AtlasManagerPtr New();
89 virtual ~AtlasManager();
92 * @copydoc: Toolkit::AtlasManager::CreateAtlas
94 AtlasId CreateAtlas( SizeType width,
98 Pixel::Format pixelformat );
101 * @copydoc Toolkit::AtlasManager::SetAddPolicy
103 void SetAddPolicy( Toolkit::AtlasManager::AddFailPolicy policy );
106 * @copydoc Toolkit::AtlasManager::Add
108 void Add( const BufferImage& image,
109 Toolkit::AtlasManager::AtlasSlot& slot,
110 Toolkit::AtlasManager::AtlasId atlas );
113 * @copydoc Toolkit::AtlasManager::GenerateMeshData
115 void GenerateMeshData( ImageId id,
116 const Vector2& position,
120 * @copydoc Toolkit::AtlasManager::StitchMesh
122 void StitchMesh( MeshData& first,
123 const MeshData& second,
127 * @copydoc Toolkit::AtlasManager::StitchMesh
129 void StitchMesh( const MeshData& first,
130 const MeshData& second,
131 MeshData& out, bool optimize );
134 * @copydoc Toolkit::AtlasManager::Remove
136 bool Remove( ImageId id );
139 * @copydoc Toolkit::AtlasManager::GetAtlasContainer
141 Dali::Atlas GetAtlasContainer( AtlasId atlas ) const;
144 * @copydoc Toolkit::AtlasManager::GetAtlas
146 AtlasId GetAtlas( ImageId id ) const;
149 * @copydoc Toolkit::AtlasManager::SetAtlasSize
151 void SetAtlasSize( const Vector2& size,
152 const Vector2& blockSize );
155 * @copydoc Toolkit::AtlasManager::GetBlockSize
157 Vector2 GetBlockSize( AtlasId atlas );
160 * @copydoc Toolkit::AtlasManager::GetFreeBlocks
162 SizeType GetFreeBlocks( AtlasId atlas ) const;
165 * @copydoc Toolkit::AtlasManager::GetAtlasCount
167 SizeType GetAtlasCount() const;
170 * @copydoc Toolkit::AtlasManager::GetPixelFormat
172 Pixel::Format GetPixelFormat( AtlasId atlas );
176 std::vector< AtlasDescriptor > mAtlasList; // List of atlases created
177 std::vector< AtlasSlotDescriptor > mImageList; // List of bitmaps store in atlases
179 SizeType CheckAtlas( SizeType atlas,
182 Pixel::Format pixelFormat,
184 SizeType& totalBlocks );
186 void CreateMesh( SizeType atlas,
188 SizeType imageHeight,
189 const Vector2& position,
190 SizeType widthInBlocks,
191 SizeType heightInBlocks,
192 Dali::MeshData& meshData,
193 AtlasSlotDescriptor& desc );
195 void OptimizeVertices( const MeshData::VertexContainer& in,
196 MeshData::FaceIndices& faces,
197 MeshData::VertexContainer& out );
199 void UploadImage( const BufferImage& image,
200 const AtlasSlotDescriptor& desc );
202 void PrintMeshData( const MeshData& meshData );
204 Vector2 mNewAtlasSize;
205 Vector2 mNewBlockSize;
206 Toolkit::AtlasManager::AddFailPolicy mAddFailPolicy;
209 } // namespace Internal
211 inline const Internal::AtlasManager& GetImplementation(const Toolkit::AtlasManager& manager)
213 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
215 const BaseObject& handle = manager.GetBaseObject();
217 return static_cast<const Internal::AtlasManager&>(handle);
220 inline Internal::AtlasManager& GetImplementation(Toolkit::AtlasManager& manager)
222 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
224 BaseObject& handle = manager.GetBaseObject();
226 return static_cast<Internal::AtlasManager&>(handle);
229 } // namespace Toolkit
234 #endif // __DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H__