[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / atlas / atlas-glyph-manager.h
1 #ifndef DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_H
2 #define DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_H
3
4 /*
5  * Copyright (c) 2022 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
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/internal/text/rendering/atlas/atlas-manager.h>
23 #include <dali-toolkit/internal/text/text-definitions.h>
24
25 namespace Dali
26 {
27 namespace Toolkit
28 {
29 namespace Internal DALI_INTERNAL
30 {
31 class AtlasGlyphManager;
32 }
33
34 class AtlasGlyphManager : public BaseHandle
35 {
36 public:
37   /**
38    * Description of GlyphManager state
39    */
40   struct Metrics
41   {
42     Metrics()
43     : mGlyphCount(0u)
44     {
45     }
46
47     ~Metrics()
48     {
49     }
50
51     uint32_t              mGlyphCount;         ///< number of glyphs being managed
52     std::string           mVerboseGlyphCounts; ///< a verbose list of the glyphs + ref counts
53     AtlasManager::Metrics mAtlasMetrics;       ///< metrics from the Atlas Manager
54   };
55
56   struct GlyphStyle
57   {
58     GlyphStyle()
59     : outline{0u},
60       isItalic{false},
61       isBold{false}
62     {
63     }
64
65     uint16_t outline;      ///< The outline width of this glyph
66     bool     isItalic : 1; ///< Whether the glyph is italic.
67     bool     isBold : 1;   ///< Whether the glyph is bold.
68   };
69
70   /**
71    * @brief Create a AtlasGlyphManager handle.
72    *
73    * Calling member functions with an uninitialised handle is not allowed.
74    */
75   AtlasGlyphManager();
76
77   /**
78    * @brief Destructor
79    *
80    * This is non-virtual since derived Handle types must not contain data or virtual methods.
81    */
82   ~AtlasGlyphManager();
83
84   /**
85    * @brief Create or retrieve AtlasGlyphManager singleton.
86    *
87    * @return A handle to the AtlasGlyphManager control.
88    */
89   static AtlasGlyphManager Get();
90
91   /**
92    * @brief Ask Atlas Manager to add a glyph
93    *
94    * @param[in] glyph glyph to add to an atlas
95    * @param[in] style The style of this glyph
96    * @param[in] bitmap bitmap to use for glyph addition
97    * @param[out] slot information returned by atlas manager for addition
98    */
99   void Add(const Text::GlyphInfo&   glyph,
100            const GlyphStyle&        style,
101            const PixelData&         bitmap,
102            AtlasManager::AtlasSlot& slot);
103
104   /**
105    * @brief Generate mesh data for an image contained in an atlas
106    *
107    * @param[in] imageId ID of image to generate geometry for
108    * @param[in] position top left of image
109    * @param[out] meshData generated MeshData
110    */
111   void GenerateMeshData(uint32_t                       imageId,
112                         const Vector2&                 position,
113                         Toolkit::AtlasManager::Mesh2D& mesh);
114
115   /**
116    * @brief Check to see if a glyph is being cached
117    *
118    * @param[in] fontId The font that this glyph comes from
119    * @param[in] index The GlyphIndex of this glyph
120    * @param[in] style The style of this glyph
121    * @param[out] slot container holding information about the glyph( mImage = 0 indicates not being cached )
122    *
123    * @return Whether glyph is cached or not ?
124    */
125   bool IsCached(Text::FontId             fontId,
126                 Text::GlyphIndex         index,
127                 const GlyphStyle&        style,
128                 AtlasManager::AtlasSlot& slot);
129
130   /**
131    * @brief Retrieve the size of an atlas
132    *
133    * @param[in] atlasId Id of the atlas to interrogate
134    *
135    * @return The pixel size of the atlas
136    */
137   Vector2 GetAtlasSize(uint32_t atlasId);
138
139   /**
140     * @brief Set the atlas size and block size for subsequent Atlas generation
141     *
142     * @param[in] width width of atlas in pixels
143     * @param[in] height height of atlas in pixels
144     * @param[in] blockWidth width of a block in pixels
145     * @param[in] blockHeight height of a block in pixels
146     */
147   void SetNewAtlasSize(uint32_t width, uint32_t height, uint32_t blockWidth, uint32_t blockHeight);
148
149   /**
150    * @brief Get the Pixel Format used by an atlas
151    *
152    * @param[in] atlasId Id of atlas to check
153    *
154    * @return The pixel format of the atlas
155    */
156   Pixel::Format GetPixelFormat(uint32_t atlasId);
157
158   /**
159    * @brief Get the texture set used by an atlas
160    *
161    * @param[in] atlasId Id of an atlas
162    *
163    * @return The texture set used by the atlas
164    */
165   TextureSet GetTextures(uint32_t atlasId) const;
166
167   /**
168    * @brief Get Glyph Manager metrics
169    *
170    * @return const reference to glyph manager metrics
171    */
172   const Metrics& GetMetrics();
173
174   /**
175    * @brief Adjust the reference count for glyph
176    *
177    * @param[in] fontId The font this image came from
178    * @param[in] index The index of the glyph
179    * @param[in] style The style of this glyph
180    * @param[in] delta The adjustment to make to the reference count
181    */
182   void AdjustReferenceCount(Text::FontId fontId, Text::GlyphIndex index, const GlyphStyle& style, int32_t delta);
183
184 public:
185   // Default copy and move operator
186   AtlasGlyphManager(const AtlasGlyphManager& rhs) = default;
187   AtlasGlyphManager(AtlasGlyphManager&& rhs)      = default;
188   AtlasGlyphManager& operator=(const AtlasGlyphManager& rhs) = default;
189   AtlasGlyphManager& operator=(AtlasGlyphManager&& rhs) = default;
190
191 private:
192   explicit DALI_INTERNAL AtlasGlyphManager(Internal::AtlasGlyphManager* impl);
193 };
194
195 } // namespace Toolkit
196
197 } // namespace Dali
198
199 #endif // DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_H