1 #ifndef DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H
2 #define DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H
5 * Copyright (c) 2019 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/text/rendering/atlas/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::Texture mAtlas; // atlas image
63 Toolkit::AtlasManager::AtlasSize mSize; // size of atlas
64 Pixel::Format mPixelFormat; // pixel format used by atlas
65 PixelData mHorizontalStrip; // Image used to pad upload
66 PixelData mVerticalStrip; // Image used to pad upload
67 TextureSet mTextureSet; // Texture set used for atlas texture
68 SizeType mTotalBlocks; // total number of blocks in atlas
69 SizeType mAvailableBlocks; // number of blocks available in atlas
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 SizeType mBlock; // Block 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( const Toolkit::AtlasManager::AtlasSize& size, Pixel::Format pixelformat );
97 * @copydoc Toolkit::AtlasManager::SetAddPolicy
99 void SetAddPolicy( Toolkit::AtlasManager::AddFailPolicy policy );
102 * @copydoc Toolkit::AtlasManager::Add
104 bool Add( const PixelData& image,
105 Toolkit::AtlasManager::AtlasSlot& slot,
106 Toolkit::AtlasManager::AtlasId atlas );
109 * @copydoc Toolkit::AtlasManager::GenerateMeshData
111 void GenerateMeshData( ImageId id,
112 const Vector2& position,
113 Toolkit::AtlasManager::Mesh2D& mesh,
117 * @copydoc Toolkit::AtlasManager::Remove
119 bool Remove( ImageId id );
122 * @copydoc Toolkit::AtlasManager::GetAtlasContainer
124 Dali::Texture GetAtlasContainer( AtlasId atlas ) const;
127 * @copydoc Toolkit::AtlasManager::GetAtlas
129 AtlasId GetAtlas( ImageId id ) const;
132 * @copydoc Toolkit::AtlasManager::SetNewAtlasSize
134 void SetNewAtlasSize( const Toolkit::AtlasManager::AtlasSize& size );
137 * @copydoc Toolkit::AtlasManager::GetAtlasSize
139 const Toolkit::AtlasManager::AtlasSize& GetAtlasSize( AtlasId atlas );
142 * @copydoc Toolkit::AtlasManager::GetBlockSize
144 Vector2 GetBlockSize( AtlasId atlas );
147 * @copydoc Toolkit::AtlasManager::GetFreeBlocks
149 SizeType GetFreeBlocks( AtlasId atlas ) const;
152 * @copydoc Toolkit::AtlasManager::GetAtlasCount
154 SizeType GetAtlasCount() const;
157 * @copydoc Toolkit::AtlasManager::GetPixelFormat
159 Pixel::Format GetPixelFormat( AtlasId atlas ) const;
162 * @copydoc Toolkit::AtlasManager::GetMetrics
164 void GetMetrics( Toolkit::AtlasManager::Metrics& metrics );
167 * @copydoc Toolkit::AtlasManager::GetTextures
169 TextureSet GetTextures( AtlasId atlas ) const;
172 * @copydoc Toolkit::AtlasManager::SetTextures
174 void SetTextures( AtlasId atlas, TextureSet& textureSet );
178 std::vector< AtlasDescriptor > mAtlasList; // List of atlases created
179 Vector< AtlasSlotDescriptor > mImageList; // List of bitmaps stored in atlases
180 Toolkit::AtlasManager::AtlasSize mNewAtlasSize; // Atlas size to use in next creation
181 Toolkit::AtlasManager::AddFailPolicy mAddFailPolicy; // Policy for failing to add an Image
183 SizeType CheckAtlas( SizeType atlas,
186 Pixel::Format pixelFormat );
188 void UploadImage( const PixelData& image,
189 const AtlasSlotDescriptor& desc );
193 } // namespace Internal
195 inline const Internal::AtlasManager& GetImplementation(const Toolkit::AtlasManager& manager)
197 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
199 const BaseObject& handle = manager.GetBaseObject();
201 return static_cast<const Internal::AtlasManager&>(handle);
204 inline Internal::AtlasManager& GetImplementation(Toolkit::AtlasManager& manager)
206 DALI_ASSERT_ALWAYS( manager && "AtlasManager handle is empty" );
208 BaseObject& handle = manager.GetBaseObject();
210 return static_cast<Internal::AtlasManager&>(handle);
213 } // namespace Toolkit
218 #endif // DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H