1 #ifndef DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H
2 #define DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H
5 * Copyright (c) 2021 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.
21 #include <dali/public-api/common/vector-wrapper.h>
22 #include <dali/public-api/object/base-object.h>
25 #include <dali-toolkit/internal/text/rendering/atlas/atlas-manager.h>
33 } // namespace Toolkit
39 typedef Dali::Vector<Toolkit::AtlasManager::AtlasSlot> slotContainer;
42 typedef IntrusivePtr<AtlasManager> AtlasManagerPtr;
44 class AtlasManager : public Dali::BaseObject
47 typedef uint32_t SizeType;
48 typedef SizeType AtlasId;
49 typedef SizeType ImageId;
52 * @brief Internal storage of atlas attributes and image upload results
54 struct AtlasDescriptor
56 Dali::Texture mAtlas; // atlas image
57 Toolkit::AtlasManager::AtlasSize mSize; // size of atlas
58 Pixel::Format mPixelFormat; // pixel format used by atlas
59 PixelData mHorizontalStrip; // Image used to pad upload
60 PixelData mVerticalStrip; // Image used to pad upload
61 TextureSet mTextureSet; // Texture set used for atlas texture
62 SizeType mTotalBlocks; // total number of blocks in atlas
63 SizeType mAvailableBlocks; // number of blocks available in atlas
64 Dali::Vector<SizeType> mFreeBlocksList; // unless there are any previously freed blocks
67 struct AtlasSlotDescriptor
69 SizeType mCount; // Reference count for this slot
70 SizeType mImageWidth; // Width of image stored
71 SizeType mImageHeight; // Height of image stored
72 AtlasId mAtlasId; // Image is stored in this Atlas
73 SizeType mBlock; // Block within atlas used for image
79 * Create a new AtlasManager
81 static AtlasManagerPtr New();
83 virtual ~AtlasManager();
86 * @copydoc: Toolkit::AtlasManager::CreateAtlas
88 AtlasId CreateAtlas(const Toolkit::AtlasManager::AtlasSize& size, Pixel::Format pixelformat);
91 * @copydoc Toolkit::AtlasManager::SetAddPolicy
93 void SetAddPolicy(Toolkit::AtlasManager::AddFailPolicy policy);
96 * @copydoc Toolkit::AtlasManager::Add
98 bool Add(const PixelData& image,
99 Toolkit::AtlasManager::AtlasSlot& slot,
100 Toolkit::AtlasManager::AtlasId atlas);
103 * @copydoc Toolkit::AtlasManager::GenerateMeshData
105 void GenerateMeshData(ImageId id,
106 const Vector2& position,
107 Toolkit::AtlasManager::Mesh2D& mesh,
111 * @copydoc Toolkit::AtlasManager::Remove
113 bool Remove(ImageId id);
116 * @copydoc Toolkit::AtlasManager::GetAtlasContainer
118 Dali::Texture GetAtlasContainer(AtlasId atlas) const;
121 * @copydoc Toolkit::AtlasManager::GetAtlas
123 AtlasId GetAtlas(ImageId id) const;
126 * @copydoc Toolkit::AtlasManager::SetNewAtlasSize
128 void SetNewAtlasSize(const Toolkit::AtlasManager::AtlasSize& size);
131 * @copydoc Toolkit::AtlasManager::GetAtlasSize
133 const Toolkit::AtlasManager::AtlasSize& GetAtlasSize(AtlasId atlas);
136 * @copydoc Toolkit::AtlasManager::GetBlockSize
138 Vector2 GetBlockSize(AtlasId atlas);
141 * @copydoc Toolkit::AtlasManager::GetFreeBlocks
143 SizeType GetFreeBlocks(AtlasId atlas) const;
146 * @copydoc Toolkit::AtlasManager::GetAtlasCount
148 SizeType GetAtlasCount() const;
151 * @copydoc Toolkit::AtlasManager::GetPixelFormat
153 Pixel::Format GetPixelFormat(AtlasId atlas) const;
156 * @copydoc Toolkit::AtlasManager::GetMetrics
158 void GetMetrics(Toolkit::AtlasManager::Metrics& metrics);
161 * @copydoc Toolkit::AtlasManager::GetTextures
163 TextureSet GetTextures(AtlasId atlas) const;
166 * @copydoc Toolkit::AtlasManager::SetTextures
168 void SetTextures(AtlasId atlas, TextureSet& textureSet);
171 std::vector<AtlasDescriptor> mAtlasList; // List of atlases created
172 Vector<AtlasSlotDescriptor> mImageList; // List of bitmaps stored in atlases
173 Toolkit::AtlasManager::AtlasSize mNewAtlasSize; // Atlas size to use in next creation
174 Toolkit::AtlasManager::AddFailPolicy mAddFailPolicy; // Policy for failing to add an Image
176 SizeType CheckAtlas(SizeType atlas,
179 Pixel::Format pixelFormat);
181 void UploadImage(const PixelData& image,
182 const AtlasSlotDescriptor& desc);
185 } // namespace Internal
187 inline const Internal::AtlasManager& GetImplementation(const Toolkit::AtlasManager& manager)
189 DALI_ASSERT_ALWAYS(manager && "AtlasManager handle is empty");
191 const BaseObject& handle = manager.GetBaseObject();
193 return static_cast<const Internal::AtlasManager&>(handle);
196 inline Internal::AtlasManager& GetImplementation(Toolkit::AtlasManager& manager)
198 DALI_ASSERT_ALWAYS(manager && "AtlasManager handle is empty");
200 BaseObject& handle = manager.GetBaseObject();
202 return static_cast<Internal::AtlasManager&>(handle);
205 } // namespace Toolkit
209 #endif // DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H