1bc058bcf7c46cf07e606e2ed2e43c9dd06da098
[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) 2015 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   /**
59    * @brief Create a AtlasGlyphManager handle.
60    *
61    * Calling member functions with an uninitialised handle is not allowed.
62    */
63   AtlasGlyphManager();
64
65   /**
66    * @brief Destructor
67    *
68    * This is non-virtual since derived Handle types must not contain data or virtual methods.
69    */
70   ~AtlasGlyphManager();
71
72   /**
73    * @brief Create or retrieve AtlasGlyphManager singleton.
74    *
75    * @return A handle to the AtlasGlyphManager control.
76    */
77   static AtlasGlyphManager Get();
78
79   /**
80    * @brief Ask Atlas Manager to add a glyph
81    *
82    * @param[in] glyph glyph to add to an atlas
83    * @param[in] bitmap bitmap to use for glyph addition
84    * @param[out] slot information returned by atlas manager for addition
85    */
86   void Add( const Text::GlyphInfo& glyph,
87             const PixelData& bitmap,
88             AtlasManager::AtlasSlot& slot );
89
90   /**
91    * @brief Generate mesh data for an image contained in an atlas
92    *
93    * @param[in] imageId ID of image to generate geometry for
94    * @param[in] position top left of image
95    * @param[out] meshData generated MeshData
96    */
97   void GenerateMeshData( uint32_t imageId,
98                          const Vector2& position,
99                          Toolkit::AtlasManager::Mesh2D& mesh );
100
101   /**
102    * @brief Check to see if a glyph is being cached
103    *
104    * @param[in] fontId The font that this glyph comes from
105    * @param[in] index The GlyphIndex of this glyph
106    * @param[out] slot container holding information about the glyph( mImage = 0 indicates not being cached )
107    *
108    * @return Whether glyph is cached or not ?
109    */
110   bool IsCached( Text::FontId fontId,
111                  Text::GlyphIndex index,
112                  AtlasManager::AtlasSlot& slot );
113
114   /**
115    * @brief Retrieve the size of an atlas
116    *
117    * @param[in] atlasId Id of the atlas to interrogate
118    *
119    * @return The pixel size of the atlas
120    */
121   Vector2 GetAtlasSize( uint32_t atlasId );
122
123    /**
124     * @brief Set the atlas size and block size for subsequent Atlas generation
125     *
126     * @param[in] width width of atlas in pixels
127     * @param[in] height height of atlas in pixels
128     * @param[in] blockWidth width of a block in pixels
129     * @param[in] blockHeight height of a block in pixels
130     */
131   void SetNewAtlasSize( uint32_t width, uint32_t height, uint32_t blockWidth, uint32_t blockHeight );
132
133   /**
134    * @brief Get the Pixel Format used by an atlas
135    *
136    * @param[in] atlasId Id of atlas to check
137    *
138    * @return The pixel format of the atlas
139    */
140   Pixel::Format GetPixelFormat( uint32_t atlasId );
141
142   /**
143    * @brief Get the texture set used by an atlas
144    *
145    * @param[in] atlasId Id of an atlas
146    *
147    * @return The texture set used by the atlas
148    */
149   TextureSet GetTextures( uint32_t atlasId ) const;
150
151   /**
152    * @brief Get Glyph Manager metrics
153    *
154    * @return const reference to glyph manager metrics
155    */
156   const Metrics& GetMetrics();
157
158   /**
159    * @brief Adjust the reference count for glyph
160    *
161    * @param[in] fontId The font this image came from
162    * @param[in] index The index of the glyph
163    * @param[in] delta The adjustment to make to the reference count
164    */
165   void AdjustReferenceCount( Text::FontId fontId, Text::GlyphIndex index, int32_t delta );
166
167 private:
168
169   explicit DALI_INTERNAL AtlasGlyphManager(Internal::AtlasGlyphManager *impl);
170
171 };
172
173 } // namespace Toolkit
174
175 } // namespace Dali
176
177 #endif // __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_H__