Merge "Simplified the glyph reference counting" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / atlas / atlas-glyph-manager-impl.h
1
2 #ifndef __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_IMPL_H__
3 #define __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_IMPL_H__
4
5 /*
6  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21
22 // EXTERNAL INCLUDES
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/object/base-object.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 class AtlasGlyphManager;
36
37 } // namespace Toolkit
38
39 namespace Toolkit
40 {
41
42 namespace Internal
43 {
44
45 class AtlasGlyphManager;
46 typedef IntrusivePtr<AtlasGlyphManager> AtlasGlyphManagerPtr;
47
48 class AtlasGlyphManager : public Dali::BaseObject
49 {
50 public:
51
52   struct GlyphRecordEntry
53   {
54     Text::GlyphIndex mIndex;
55     uint32_t mImageId;
56     int32_t mCount;
57   };
58
59   struct FontGlyphRecord
60   {
61     Text::FontId mFontId;
62     Vector< GlyphRecordEntry > mGlyphRecords;
63   };
64
65   /**
66    * @brief Constructor
67    */
68   AtlasGlyphManager();
69
70   /**
71    * @copydoc Toolkit::AtlasGlyphManager::Add
72    */
73   void Add( const Text::GlyphInfo& glyph,
74             const BufferImage& bitmap,
75             Dali::Toolkit::AtlasManager::AtlasSlot& slot );
76
77   /**
78    * @copydoc Toolkit::AtlasGlyphManager::GenerateMeshData
79    */
80   void GenerateMeshData( uint32_t imageId,
81                          const Vector2& position,
82                          Toolkit::AtlasManager::Mesh2D& mesh );
83
84   /**
85    * @copydoc Toolkit::AtlasGlyphManager::StitchMesh
86    */
87   void StitchMesh( Toolkit::AtlasManager::Mesh2D& first,
88                    const Toolkit::AtlasManager::Mesh2D& second );
89
90   /**
91    * @copydoc Toolkit::AtlasGlyphManager::Cached
92    */
93   bool Cached( Text::FontId fontId,
94                Text::GlyphIndex index,
95                Dali::Toolkit::AtlasManager::AtlasSlot& slot );
96
97   /**
98    * @copydoc Toolkit::AtlasGlyphManager::GetAtlasSize
99    */
100   Vector2 GetAtlasSize( uint32_t atlasId );
101
102   /**
103    * @copydoc Toolkit::AtlasGlyphManager::SetNewAtlasSize
104    */
105   void SetNewAtlasSize( uint32_t width, uint32_t height, uint32_t blockWidth, uint32_t blockHeight );
106
107   /**
108    * @copydoc Toolkit::AtlasGlyphManager::GetPixelFormat
109    */
110   Pixel::Format GetPixelFormat( uint32_t atlasId );
111
112   /**
113    * @copydoc toolkit::AtlasGlyphManager::AdjustReferenceCount
114    */
115   void AdjustReferenceCount( Text::FontId fontId, Text::GlyphIndex index, int32_t delta );
116
117   /**
118    * @copydoc Toolkit::AtlasGlyphManager::GetMaterial
119    */
120   Material GetMaterial( uint32_t atlasId ) const;
121
122   /**
123    * @copydoc Toolkit::AtlasGlyphManager::GetMaterial
124    */
125   Sampler GetSampler( uint32_t atlasId ) const;
126
127   /**
128    * @copydoc Toolkit::AtlasGlyphManager::GetMetrics
129    */
130   const Toolkit::AtlasGlyphManager::Metrics& GetMetrics();
131
132   /**
133    * @copydoc Toolkit::AtlasGlyphManager::GetEffectBufferShader
134    */
135   Shader GetEffectBufferShader() const
136   {
137     return mEffectBufferShader;
138   }
139
140   /**
141    * @copydoc Toolkit::AtlasGlyphManager::GetGlyphShadowShader
142    */
143   Shader GetGlyphShadowShader() const
144   {
145     return mShadowShader;
146   }
147
148 protected:
149
150   /**
151    * A reference counted object may only be deleted by calling Unreference()
152    */
153   virtual ~AtlasGlyphManager();
154
155 private:
156
157   Dali::Toolkit::AtlasManager mAtlasManager;          ///> Atlas Manager created by GlyphManager
158   std::vector< FontGlyphRecord > mFontGlyphRecords;
159   Toolkit::AtlasGlyphManager::Metrics mMetrics;       ///> Metrics to pass back on GlyphManager status
160   Shader mEffectBufferShader;                         ///> Shader used to render drop shadow buffer textures
161   Shader mShadowShader;                               ///> Shader used to render drop shadow into buffer
162 };
163
164 } // namespace Internal
165
166 inline const Internal::AtlasGlyphManager& GetImplementation(const Toolkit::AtlasGlyphManager& manager)
167 {
168   DALI_ASSERT_ALWAYS( manager && "AtlasGlyphManager handle is empty" );
169
170   const BaseObject& handle = manager.GetBaseObject();
171
172   return static_cast<const Internal::AtlasGlyphManager&>(handle);
173 }
174
175 inline Internal::AtlasGlyphManager& GetImplementation(Toolkit::AtlasGlyphManager& manager)
176 {
177   DALI_ASSERT_ALWAYS( manager && "AtlasGlyphManager handle is empty" );
178
179   BaseObject& handle = manager.GetBaseObject();
180
181   return static_cast<Internal::AtlasGlyphManager&>(handle);
182 }
183
184 } // namespace Toolkit
185
186 } // namespace Dali
187
188
189  #endif // __DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_IMPL_H__