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 Toolkit::AtlasManager::AtlasSize mSize; // size of atlas
64 Pixel::Format mPixelFormat; // pixel format used by atlas
65 BufferImage mHorizontalStrip; // Image used to pad upload
66 BufferImage mVerticalStrip; // Image used to pad upload
67 BufferImage mFilledPixelImage; // Image used by atlas for operations such as underline
68 PixelBuffer* mStripBuffer; // Blank image buffer used to pad upload
69 Material mMaterial; // material used for atlas texture
70 SizeType mNextFreeBlock; // next free block will be placed here ( actually +1 )
71 Dali::Vector< SizeType > mFreeBlocksList; // unless there are any previously freed blocks
74 struct AtlasSlotDescriptor
76 SizeType mCount; // Reference count for this slot
77 SizeType mImageWidth; // Width of image stored
78 SizeType mImageHeight; // Height of image stored
79 AtlasId mAtlasId; // Image is stored in this Atlas
80 Dali::Vector< SizeType > mBlocksList; // List of blocks within atlas used for image
86 * Create a new AtlasManager
88 static AtlasManagerPtr New();
90 virtual ~AtlasManager();
93 * @copydoc: Toolkit::AtlasManager::CreateAtlas
95 AtlasId CreateAtlas( const Toolkit::AtlasManager::AtlasSize& size, Pixel::Format pixelformat );
98 * @copydoc Toolkit::AtlasManager::SetAddPolicy
100 void SetAddPolicy( Toolkit::AtlasManager::AddFailPolicy policy );
103 * @copydoc Toolkit::AtlasManager::Add
105 void Add( const BufferImage& image,
106 Toolkit::AtlasManager::AtlasSlot& slot,
107 Toolkit::AtlasManager::AtlasId atlas );
110 * @copydoc Toolkit::AtlasManager::GenerateMeshData
112 void GenerateMeshData( ImageId id,
113 const Vector2& position,
114 Toolkit::AtlasManager::Mesh2D& mesh );
117 * @copydoc Toolkit::AtlasManager::StitchMesh
119 void StitchMesh( Toolkit::AtlasManager::Mesh2D& first,
120 const Toolkit::AtlasManager::Mesh2D& second,
124 * @copydoc Toolkit::AtlasManager::StitchMesh
126 void StitchMesh( const Toolkit::AtlasManager::Mesh2D& first,
127 const Toolkit::AtlasManager::Mesh2D& second,
128 Toolkit::AtlasManager::Mesh2D& out,
132 * @copydoc Toolkit::AtlasManager::Remove
134 bool Remove( ImageId id );
137 * @copydoc Toolkit::AtlasManager::GetAtlasContainer
139 Dali::Atlas GetAtlasContainer( AtlasId atlas ) const;
142 * @copydoc Toolkit::AtlasManager::GetAtlas
144 AtlasId GetAtlas( ImageId id ) const;
147 * @copydoc Toolkit::AtlasManager::SetNewAtlasSize
149 void SetNewAtlasSize( const Toolkit::AtlasManager::AtlasSize& size );
152 * @copydoc Toolkit::AtlasManager::GetAtlasSize
154 const Toolkit::AtlasManager::AtlasSize& GetAtlasSize( AtlasId atlas );
157 * @copydoc Toolkit::AtlasManager::GetBlockSize
159 Vector2 GetBlockSize( AtlasId atlas );
162 * @copydoc Toolkit::AtlasManager::GetFreeBlocks
164 SizeType GetFreeBlocks( AtlasId atlas ) const;
167 * @copydoc Toolkit::AtlasManager::GetAtlasCount
169 SizeType GetAtlasCount() const;
172 * @copydoc Toolkit::AtlasManager::GetPixelFormat
174 Pixel::Format GetPixelFormat( AtlasId atlas );
177 * @copydoc Toolkit::AtlasManager::GetMetrics
179 void GetMetrics( Toolkit::AtlasManager::Metrics& metrics );
182 * @copydoc Toolkit::AtlasManager::GetMaterial
184 Material GetMaterial( AtlasId atlas ) const;
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 Toolkit::AtlasManager::Mesh2D& mesh,
205 AtlasSlotDescriptor& desc );
207 void OptimizeMesh( const Toolkit::AtlasManager::Mesh2D& in,
208 Toolkit::AtlasManager::Mesh2D& out );
210 void UploadImage( const BufferImage& image,
211 const AtlasSlotDescriptor& desc );
213 void PrintMeshData( const Toolkit::AtlasManager::Mesh2D& mesh );
215 Toolkit::AtlasManager::AtlasSize mNewAtlasSize;
216 Toolkit::AtlasManager::AddFailPolicy mAddFailPolicy;
217 uint32_t mFilledPixel;
220 } // namespace Internal
222 inline const Internal::AtlasManager& GetImplementation(const Toolkit::AtlasManager& manager)
224 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
226 const BaseObject& handle = manager.GetBaseObject();
228 return static_cast<const Internal::AtlasManager&>(handle);
231 inline Internal::AtlasManager& GetImplementation(Toolkit::AtlasManager& manager)
233 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
235 BaseObject& handle = manager.GetBaseObject();
237 return static_cast<Internal::AtlasManager&>(handle);
240 } // namespace Toolkit
245 #endif // __DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H__