Merge "Add codes to prevent underflow" into 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) 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] outlineWidth the outline width of the glyph
84    * @param[in] bitmap bitmap to use for glyph addition
85    * @param[out] slot information returned by atlas manager for addition
86    */
87   void Add( const Text::GlyphInfo& glyph,
88             const uint32_t outlineWidth,
89             const PixelData& bitmap,
90             AtlasManager::AtlasSlot& slot );
91
92   /**
93    * @brief Generate mesh data for an image contained in an atlas
94    *
95    * @param[in] imageId ID of image to generate geometry for
96    * @param[in] position top left of image
97    * @param[out] meshData generated MeshData
98    */
99   void GenerateMeshData( uint32_t imageId,
100                          const Vector2& position,
101                          Toolkit::AtlasManager::Mesh2D& mesh );
102
103   /**
104    * @brief Check to see if a glyph is being cached
105    *
106    * @param[in] fontId The font that this glyph comes from
107    * @param[in] index The GlyphIndex of this glyph
108    * @param[in] outlineWidth The outline width of this glyph
109    * @param[out] slot container holding information about the glyph( mImage = 0 indicates not being cached )
110    *
111    * @return Whether glyph is cached or not ?
112    */
113   bool IsCached( Text::FontId fontId,
114                  Text::GlyphIndex index,
115                  uint32_t outlineWidth,
116                  AtlasManager::AtlasSlot& slot );
117
118   /**
119    * @brief Retrieve the size of an atlas
120    *
121    * @param[in] atlasId Id of the atlas to interrogate
122    *
123    * @return The pixel size of the atlas
124    */
125   Vector2 GetAtlasSize( uint32_t atlasId );
126
127    /**
128     * @brief Set the atlas size and block size for subsequent Atlas generation
129     *
130     * @param[in] width width of atlas in pixels
131     * @param[in] height height of atlas in pixels
132     * @param[in] blockWidth width of a block in pixels
133     * @param[in] blockHeight height of a block in pixels
134     */
135   void SetNewAtlasSize( uint32_t width, uint32_t height, uint32_t blockWidth, uint32_t blockHeight );
136
137   /**
138    * @brief Get the Pixel Format used by an atlas
139    *
140    * @param[in] atlasId Id of atlas to check
141    *
142    * @return The pixel format of the atlas
143    */
144   Pixel::Format GetPixelFormat( uint32_t atlasId );
145
146   /**
147    * @brief Get the texture set used by an atlas
148    *
149    * @param[in] atlasId Id of an atlas
150    *
151    * @return The texture set used by the atlas
152    */
153   TextureSet GetTextures( uint32_t atlasId ) const;
154
155   /**
156    * @brief Get Glyph Manager metrics
157    *
158    * @return const reference to glyph manager metrics
159    */
160   const Metrics& GetMetrics();
161
162   /**
163    * @brief Adjust the reference count for glyph
164    *
165    * @param[in] fontId The font this image came from
166    * @param[in] index The index of the glyph
167    * @param[in] outlineWidth The outline width of the glyph
168    * @param[in] delta The adjustment to make to the reference count
169    */
170   void AdjustReferenceCount( Text::FontId fontId, Text::GlyphIndex index, uint32_t outlineWidth, int32_t delta );
171
172 private:
173
174   explicit DALI_INTERNAL AtlasGlyphManager(Internal::AtlasGlyphManager *impl);
175
176 };
177
178 } // namespace Toolkit
179
180 } // namespace Dali
181
182 #endif // __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_H__