Merge "Fix Klocwork issues." 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/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     Metrics()
47     : mGlyphCount( 0u )
48     {}
49
50     ~Metrics()
51     {}
52
53     uint32_t mGlyphCount;                   // number of glyphs being managed
54     AtlasManager::Metrics mAtlasMetrics;    // metrics from the Atlas Manager
55   };
56
57   /**
58    * @brief Create a AtlasGlyphManager handle.
59    *
60    * Calling member functions with an uninitialised handle is not allowed.
61    */
62   AtlasGlyphManager();
63
64   /**
65    * @brief Destructor
66    *
67    * This is non-virtual since derived Handle types must not contain data or virtual methods.
68    */
69   ~AtlasGlyphManager();
70
71   /**
72    * @brief Create or retrieve AtlasGlyphManager singleton.
73    *
74    * @return A handle to the AtlasGlyphManager control.
75    */
76   static AtlasGlyphManager Get();
77
78   /**
79    * @brief Ask Atlas Manager to add a glyph
80    *
81    * @param[in] glyph glyph to add to an atlas
82    * @param[in] bitmap bitmap to use for glyph addition
83    * @param[out] slot information returned by atlas manager for addition
84    */
85   void Add( const Text::GlyphInfo& glyph,
86             const BufferImage& bitmap,
87             AtlasManager::AtlasSlot& slot );
88
89   /**
90    * @brief Generate mesh data for an image contained in an atlas
91    *
92    * @param[in] imageId ID of image to generate geometry for
93    * @param[in] position top left of image
94    * @param[out] meshData generated MeshData
95    */
96   void GenerateMeshData( uint32_t imageId,
97                          const Vector2& position,
98                          Toolkit::AtlasManager::Mesh2D& mesh );
99
100   /**
101    * @brief Stitch Two Meshes together
102    *
103    * @param[in] first first mesh
104    * @param[in] second second mesh
105    */
106   void StitchMesh( Toolkit::AtlasManager::Mesh2D& first,
107                    const Toolkit::AtlasManager::Mesh2D& second );
108
109   /**
110    * @brief Check to see if a glyph is being cached
111    *
112    * @param[in] fontId The font that this glyph comes from
113    * @param[in] index The GlyphIndex of this glyph
114    * @param[out] slot container holding information about the glyph( mImage = 0 indicates not being cached )
115    *
116    * @return Whether glyph is cached or not ?
117    */
118   bool Cached( Text::FontId fontId,
119                Text::GlyphIndex index,
120                AtlasManager::AtlasSlot& slot );
121
122   /**
123    * @brief Retrieve the size of an atlas
124    *
125    * @param[in] atlasId Id of the atlas to interrogate
126    *
127    * @return The pixel size of the atlas
128    */
129   Vector2 GetAtlasSize( uint32_t atlasId );
130
131    /**
132     * @brief Set the atlas size and block size for subsequent Atlas generation
133     *
134     * @param[in] width width of atlas in pixels
135     * @param[in] height height of atlas in pixels
136     * @param[in] blockWidth width of a block in pixels
137     * @param[in] blockHeight height of a block in pixels
138     */
139   void SetNewAtlasSize( uint32_t width, uint32_t height, uint32_t blockWidth, uint32_t blockHeight );
140
141   /**
142    * @brief Get the Pixel Format used by an atlas
143    *
144    * @param[in] atlasId Id of atlas to check
145    *
146    * @return The pixel format of the atlas
147    */
148   Pixel::Format GetPixelFormat( uint32_t atlasId );
149
150   /**
151    * @brief Get the material used by an atlas
152    *
153    * @param[in] atlasId Id of an atlas
154    *
155    * @return The material used by the atlas
156    */
157   Material GetMaterial( uint32_t atlasId ) const;
158
159   /**
160    * @brief Get the sampler used by an atlas
161    *
162    * @param[in] atlasId Id of an atlas
163    *
164    * @return The sampler used by the atlas
165    */
166   Sampler GetSampler( 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 an imageId and remove cache entry if it becomes free
177    *
178    * @param[in] fontId the font this image came from
179    * @param[in] imageId The imageId
180    * @param[in] delta adjustment to make to reference count
181    */
182   void AdjustReferenceCount( Text::FontId fontId, uint32_t imageId, int32_t delta );
183
184   /**
185    * @brief Get Shader used for rendering glyph effect buffers
186    *
187    * @return Handle of shader needed
188    */
189   Shader GetEffectBufferShader() const;
190
191   /**
192    * @brief Get Shader used rendering Glyph Shadows
193    *
194    * @return Handle of shader needed
195    */
196   Shader GetGlyphShadowShader() const;
197
198 private:
199
200   explicit DALI_INTERNAL AtlasGlyphManager(Internal::AtlasGlyphManager *impl);
201
202 };
203
204 } // namespace Toolkit
205
206 } // namespace Dali
207
208 #endif // __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_H__