da659bc2f289e9efd6f0b90e848a1da1cefd1fc8
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / atlas / atlas-glyph-manager-impl.h
1 #ifndef __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_IMPL_H__
2 #define __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_IMPL_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/base-object.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 class AtlasGlyphManager;
35
36 } // namespace Toolkit
37
38 namespace Toolkit
39 {
40
41 namespace Internal
42 {
43
44 class AtlasGlyphManager;
45 typedef IntrusivePtr<AtlasGlyphManager> AtlasGlyphManagerPtr;
46
47 class AtlasGlyphManager : public Dali::BaseObject
48 {
49 public:
50
51   struct GlyphRecordEntry
52   {
53     Text::GlyphIndex mIndex;
54     uint32_t mImageId;
55     int32_t mCount;
56   };
57
58   struct FontGlyphRecord
59   {
60     Text::FontId mFontId;
61     Vector< GlyphRecordEntry > mGlyphRecords;
62   };
63
64   /**
65    * @brief Constructor
66    */
67   AtlasGlyphManager();
68
69   /**
70    * @copydoc Toolkit::AtlasGlyphManager::Add
71    */
72   void Add( const Text::GlyphInfo& glyph,
73             const BufferImage& bitmap,
74             Dali::Toolkit::AtlasManager::AtlasSlot& slot );
75
76   /**
77    * @copydoc Toolkit::AtlasGlyphManager::GenerateMeshData
78    */
79   void GenerateMeshData( uint32_t imageId,
80                          const Vector2& position,
81                          Toolkit::AtlasManager::Mesh2D& mesh );
82
83   /**
84    * @copydoc Toolkit::AtlasGlyphManager::StitchMesh
85    */
86   void StitchMesh( Toolkit::AtlasManager::Mesh2D& first,
87                    const Toolkit::AtlasManager::Mesh2D& second );
88
89   /**
90    * @copydoc Toolkit::AtlasGlyphManager::Cached
91    */
92   bool Cached( Text::FontId fontId,
93                Text::GlyphIndex index,
94                Dali::Toolkit::AtlasManager::AtlasSlot& slot );
95
96   /**
97    * @copydoc Toolkit::AtlasGlyphManager::GetAtlasSize
98    */
99   Vector2 GetAtlasSize( uint32_t atlasId );
100
101   /**
102    * @copydoc Toolkit::AtlasGlyphManager::SetNewAtlasSize
103    */
104   void SetNewAtlasSize( uint32_t width, uint32_t height, uint32_t blockWidth, uint32_t blockHeight );
105
106   /**
107    * @copydoc Toolkit::AtlasGlyphManager::GetPixelFormat
108    */
109   Pixel::Format GetPixelFormat( uint32_t atlasId );
110
111   /**
112    * @copydoc toolkit::AtlasGlyphManager::AdjustReferenceCount
113    */
114   void AdjustReferenceCount( Text::FontId fontId, Text::GlyphIndex index, int32_t delta );
115
116   /**
117    * @copydoc Toolkit::AtlasGlyphManager::GetMaterial
118    */
119   Material GetMaterial( uint32_t atlasId ) const;
120
121   /**
122    * @copydoc Toolkit::AtlasGlyphManager::GetMaterial
123    */
124   Image GetImage( uint32_t atlasId ) const;
125
126   /**
127    * @copydoc Toolkit::AtlasGlyphManager::GetMetrics
128    */
129   const Toolkit::AtlasGlyphManager::Metrics& GetMetrics();
130
131   /**
132    * @copydoc Toolkit::AtlasGlyphManager::GetEffectBufferShader
133    */
134   Shader GetEffectBufferShader() const
135   {
136     return mEffectBufferShader;
137   }
138
139   /**
140    * @copydoc Toolkit::AtlasGlyphManager::GetGlyphShadowShader
141    */
142   Shader GetGlyphShadowShader() const
143   {
144     return mShadowShader;
145   }
146
147 protected:
148
149   /**
150    * A reference counted object may only be deleted by calling Unreference()
151    */
152   virtual ~AtlasGlyphManager();
153
154 private:
155
156   Dali::Toolkit::AtlasManager mAtlasManager;          ///> Atlas Manager created by GlyphManager
157   std::vector< FontGlyphRecord > mFontGlyphRecords;
158   Toolkit::AtlasGlyphManager::Metrics mMetrics;       ///> Metrics to pass back on GlyphManager status
159   Shader mEffectBufferShader;                         ///> Shader used to render drop shadow buffer textures
160   Shader mShadowShader;                               ///> Shader used to render drop shadow into buffer
161 };
162
163 } // namespace Internal
164
165 inline const Internal::AtlasGlyphManager& GetImplementation(const Toolkit::AtlasGlyphManager& manager)
166 {
167   DALI_ASSERT_ALWAYS( manager && "AtlasGlyphManager handle is empty" );
168
169   const BaseObject& handle = manager.GetBaseObject();
170
171   return static_cast<const Internal::AtlasGlyphManager&>(handle);
172 }
173
174 inline Internal::AtlasGlyphManager& GetImplementation(Toolkit::AtlasGlyphManager& manager)
175 {
176   DALI_ASSERT_ALWAYS( manager && "AtlasGlyphManager handle is empty" );
177
178   BaseObject& handle = manager.GetBaseObject();
179
180   return static_cast<Internal::AtlasGlyphManager&>(handle);
181 }
182
183 } // namespace Toolkit
184
185 } // namespace Dali
186
187 #endif // __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_IMPL_H__