Updated all header files to new format
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / atlas / atlas-manager-impl.h
1 #ifndef DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H
2 #define DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/common/vector-wrapper.h>
22 #include <dali/public-api/object/base-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/rendering/atlas/atlas-manager.h>
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 class AtlasManager;
32
33 } // namespace Toolkit
34
35 namespace Toolkit
36 {
37 namespace Internal
38 {
39 typedef Dali::Vector<Toolkit::AtlasManager::AtlasSlot> slotContainer;
40
41 class AtlasManager;
42 typedef IntrusivePtr<AtlasManager> AtlasManagerPtr;
43
44 class AtlasManager : public Dali::BaseObject
45 {
46 public:
47   typedef uint32_t SizeType;
48   typedef SizeType AtlasId;
49   typedef SizeType ImageId;
50
51   /**
52    * @brief Internal storage of atlas attributes and image upload results
53    */
54   struct AtlasDescriptor
55   {
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
65   };
66
67   struct AtlasSlotDescriptor
68   {
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
74   };
75
76   AtlasManager();
77
78   /**
79    * Create a new AtlasManager
80    */
81   static AtlasManagerPtr New();
82
83   virtual ~AtlasManager();
84
85   /**
86    * @copydoc: Toolkit::AtlasManager::CreateAtlas
87    */
88   AtlasId CreateAtlas(const Toolkit::AtlasManager::AtlasSize& size, Pixel::Format pixelformat);
89
90   /**
91    * @copydoc Toolkit::AtlasManager::SetAddPolicy
92    */
93   void SetAddPolicy(Toolkit::AtlasManager::AddFailPolicy policy);
94
95   /**
96    * @copydoc Toolkit::AtlasManager::Add
97    */
98   bool Add(const PixelData&                  image,
99            Toolkit::AtlasManager::AtlasSlot& slot,
100            Toolkit::AtlasManager::AtlasId    atlas);
101
102   /**
103    * @copydoc Toolkit::AtlasManager::GenerateMeshData
104    */
105   void GenerateMeshData(ImageId                        id,
106                         const Vector2&                 position,
107                         Toolkit::AtlasManager::Mesh2D& mesh,
108                         bool                           addReference);
109
110   /**
111    * @copydoc Toolkit::AtlasManager::Remove
112    */
113   bool Remove(ImageId id);
114
115   /**
116    * @copydoc Toolkit::AtlasManager::GetAtlasContainer
117    */
118   Dali::Texture GetAtlasContainer(AtlasId atlas) const;
119
120   /**
121    * @copydoc Toolkit::AtlasManager::GetAtlas
122    */
123   AtlasId GetAtlas(ImageId id) const;
124
125   /**
126    * @copydoc Toolkit::AtlasManager::SetNewAtlasSize
127    */
128   void SetNewAtlasSize(const Toolkit::AtlasManager::AtlasSize& size);
129
130   /**
131    * @copydoc Toolkit::AtlasManager::GetAtlasSize
132    */
133   const Toolkit::AtlasManager::AtlasSize& GetAtlasSize(AtlasId atlas);
134
135   /**
136    * @copydoc Toolkit::AtlasManager::GetBlockSize
137    */
138   Vector2 GetBlockSize(AtlasId atlas);
139
140   /**
141    * @copydoc Toolkit::AtlasManager::GetFreeBlocks
142    */
143   SizeType GetFreeBlocks(AtlasId atlas) const;
144
145   /*
146    * @copydoc Toolkit::AtlasManager::GetAtlasCount
147    */
148   SizeType GetAtlasCount() const;
149
150   /**
151    * @copydoc Toolkit::AtlasManager::GetPixelFormat
152    */
153   Pixel::Format GetPixelFormat(AtlasId atlas) const;
154
155   /**
156    * @copydoc Toolkit::AtlasManager::GetMetrics
157    */
158   void GetMetrics(Toolkit::AtlasManager::Metrics& metrics);
159
160   /**
161    * @copydoc Toolkit::AtlasManager::GetTextures
162    */
163   TextureSet GetTextures(AtlasId atlas) const;
164
165   /**
166    * @copydoc Toolkit::AtlasManager::SetTextures
167    */
168   void SetTextures(AtlasId atlas, TextureSet& textureSet);
169
170 private:
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
175
176   SizeType CheckAtlas(SizeType      atlas,
177                       SizeType      width,
178                       SizeType      height,
179                       Pixel::Format pixelFormat);
180
181   void UploadImage(const PixelData&           image,
182                    const AtlasSlotDescriptor& desc);
183 };
184
185 } // namespace Internal
186
187 inline const Internal::AtlasManager& GetImplementation(const Toolkit::AtlasManager& manager)
188 {
189   DALI_ASSERT_ALWAYS(manager && "AtlasManager handle is empty");
190
191   const BaseObject& handle = manager.GetBaseObject();
192
193   return static_cast<const Internal::AtlasManager&>(handle);
194 }
195
196 inline Internal::AtlasManager& GetImplementation(Toolkit::AtlasManager& manager)
197 {
198   DALI_ASSERT_ALWAYS(manager && "AtlasManager handle is empty");
199
200   BaseObject& handle = manager.GetBaseObject();
201
202   return static_cast<Internal::AtlasManager&>(handle);
203 }
204
205 } // namespace Toolkit
206
207 } // namespace Dali
208
209 #endif // DALI_TOOLKIT_ATLAS_MANAGER_IMPL_H