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