Changes following "Remove Sampler scene object"
[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     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 BufferImage& 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 Stitch Two Meshes together
103    *
104    * @param[in] first first mesh
105    * @param[in] second second mesh
106    */
107   void StitchMesh( Toolkit::AtlasManager::Mesh2D& first,
108                    const Toolkit::AtlasManager::Mesh2D& second );
109
110   /**
111    * @brief Check to see if a glyph is being cached
112    *
113    * @param[in] fontId The font that this glyph comes from
114    * @param[in] index The GlyphIndex of this glyph
115    * @param[out] slot container holding information about the glyph( mImage = 0 indicates not being cached )
116    *
117    * @return Whether glyph is cached or not ?
118    */
119   bool Cached( Text::FontId fontId,
120                Text::GlyphIndex index,
121                AtlasManager::AtlasSlot& slot );
122
123   /**
124    * @brief Retrieve the size of an atlas
125    *
126    * @param[in] atlasId Id of the atlas to interrogate
127    *
128    * @return The pixel size of the atlas
129    */
130   Vector2 GetAtlasSize( uint32_t atlasId );
131
132    /**
133     * @brief Set the atlas size and block size for subsequent Atlas generation
134     *
135     * @param[in] width width of atlas in pixels
136     * @param[in] height height of atlas in pixels
137     * @param[in] blockWidth width of a block in pixels
138     * @param[in] blockHeight height of a block in pixels
139     */
140   void SetNewAtlasSize( uint32_t width, uint32_t height, uint32_t blockWidth, uint32_t blockHeight );
141
142   /**
143    * @brief Get the Pixel Format used by an atlas
144    *
145    * @param[in] atlasId Id of atlas to check
146    *
147    * @return The pixel format of the atlas
148    */
149   Pixel::Format GetPixelFormat( uint32_t atlasId );
150
151   /**
152    * @brief Get the material used by an atlas
153    *
154    * @param[in] atlasId Id of an atlas
155    *
156    * @return The material used by the atlas
157    */
158   Material GetMaterial( uint32_t atlasId ) const;
159
160   /**
161    * @brief Get the sampler used by an atlas
162    *
163    * @param[in] atlasId Id of an atlas
164    *
165    * @return The sampler used by the atlas
166    */
167   Image GetImage( uint32_t atlasId ) const;
168
169   /**
170    * @brief Get Glyph Manager metrics
171    *
172    * @return const reference to glyph manager metrics
173    */
174   const Metrics& GetMetrics();
175
176   /**
177    * @brief Adjust the reference count for glyph
178    *
179    * @param[in] fontId The font this image came from
180    * @param[in] index The index of the glyph
181    * @param[in] delta The adjustment to make to the reference count
182    */
183   void AdjustReferenceCount( Text::FontId fontId, Text::GlyphIndex index, int32_t delta );
184
185   /**
186    * @brief Get Shader used for rendering glyph effect buffers
187    *
188    * @return Handle of shader needed
189    */
190   Shader GetEffectBufferShader() const;
191
192   /**
193    * @brief Get Shader used rendering Glyph Shadows
194    *
195    * @return Handle of shader needed
196    */
197   Shader GetGlyphShadowShader() const;
198
199 private:
200
201   explicit DALI_INTERNAL AtlasGlyphManager(Internal::AtlasGlyphManager *impl);
202
203 };
204
205 } // namespace Toolkit
206
207 } // namespace Dali
208
209 #endif // __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_H__