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, public ConnectionTracker
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 Sampler mSampler; // sampler 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( const Toolkit::AtlasManager::AtlasSize& size, Pixel::Format pixelformat );
99 * @copydoc Toolkit::AtlasManager::SetAddPolicy
101 void SetAddPolicy( Toolkit::AtlasManager::AddFailPolicy policy );
104 * @copydoc Toolkit::AtlasManager::Add
106 void Add( const BufferImage& image,
107 Toolkit::AtlasManager::AtlasSlot& slot,
108 Toolkit::AtlasManager::AtlasId atlas );
111 * @copydoc Toolkit::AtlasManager::GenerateMeshData
113 void GenerateMeshData( ImageId id,
114 const Vector2& position,
115 Toolkit::AtlasManager::Mesh2D& mesh,
119 * @copydoc Toolkit::AtlasManager::StitchMesh
121 void StitchMesh( Toolkit::AtlasManager::Mesh2D& first,
122 const Toolkit::AtlasManager::Mesh2D& second,
126 * @copydoc Toolkit::AtlasManager::StitchMesh
128 void StitchMesh( const Toolkit::AtlasManager::Mesh2D& first,
129 const Toolkit::AtlasManager::Mesh2D& second,
130 Toolkit::AtlasManager::Mesh2D& out,
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::SetNewAtlasSize
151 void SetNewAtlasSize( const Toolkit::AtlasManager::AtlasSize& size );
154 * @copydoc Toolkit::AtlasManager::GetAtlasSize
156 const Toolkit::AtlasManager::AtlasSize& GetAtlasSize( AtlasId atlas );
159 * @copydoc Toolkit::AtlasManager::GetBlockSize
161 Vector2 GetBlockSize( AtlasId atlas );
164 * @copydoc Toolkit::AtlasManager::GetFreeBlocks
166 SizeType GetFreeBlocks( AtlasId atlas ) const;
169 * @copydoc Toolkit::AtlasManager::GetAtlasCount
171 SizeType GetAtlasCount() const;
174 * @copydoc Toolkit::AtlasManager::GetPixelFormat
176 Pixel::Format GetPixelFormat( AtlasId atlas );
179 * @copydoc Toolkit::AtlasManager::GetMetrics
181 void GetMetrics( Toolkit::AtlasManager::Metrics& metrics );
184 * @copydoc Toolkit::AtlasManager::GetMaterial
186 Material GetMaterial( AtlasId atlas ) const;
189 * @copydoc Toolkit::AtlasManager::GetSampler
191 Sampler GetSampler( AtlasId atlas ) const;
195 std::vector< AtlasDescriptor > mAtlasList; // List of atlases created
196 std::vector< AtlasSlotDescriptor > mImageList; // List of bitmaps store in atlases
197 Vector< PixelBuffer* > mUploadedImages; // List of PixelBuffers passed to UploadedSignal
198 Toolkit::AtlasManager::AtlasSize mNewAtlasSize; // Atlas size to use in next creation
199 Toolkit::AtlasManager::AddFailPolicy mAddFailPolicy; // Policy for faling to add an Image
200 SizeType mFilledPixel; // 32Bit pixel image for underlining
202 SizeType CheckAtlas( SizeType atlas,
205 Pixel::Format pixelFormat,
207 SizeType& totalBlocks );
209 void CreateMesh( SizeType atlas,
211 SizeType imageHeight,
212 const Vector2& position,
213 SizeType widthInBlocks,
214 SizeType heightInBlocks,
215 Toolkit::AtlasManager::Mesh2D& mesh,
216 AtlasSlotDescriptor& desc );
218 void OptimizeMesh( const Toolkit::AtlasManager::Mesh2D& in,
219 Toolkit::AtlasManager::Mesh2D& out );
221 void UploadImage( const BufferImage& image,
222 const AtlasSlotDescriptor& desc );
224 void PrintMeshData( const Toolkit::AtlasManager::Mesh2D& mesh );
226 void OnUpload( Image image );
233 } // namespace Internal
235 inline const Internal::AtlasManager& GetImplementation(const Toolkit::AtlasManager& manager)
237 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
239 const BaseObject& handle = manager.GetBaseObject();
241 return static_cast<const Internal::AtlasManager&>(handle);
244 inline Internal::AtlasManager& GetImplementation(Toolkit::AtlasManager& manager)
246 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
248 BaseObject& handle = manager.GetBaseObject();
250 return static_cast<Internal::AtlasManager&>(handle);
253 } // namespace Toolkit
258 #endif // __DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H__