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