[dali_2.3.20] Merge branch 'devel/master'
[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) 2021 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 // EXTERNAL INCLUDES
21 #include <dali/public-api/common/vector-wrapper.h>
22 #include <dali/public-api/object/base-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 class AtlasGlyphManager;
32
33 } // namespace Toolkit
34
35 namespace Toolkit
36 {
37 namespace Internal
38 {
39 class AtlasGlyphManager;
40 typedef IntrusivePtr<AtlasGlyphManager> AtlasGlyphManagerPtr;
41
42 class AtlasGlyphManager : public Dali::BaseObject
43 {
44 public:
45   struct GlyphRecordEntry
46   {
47     Text::GlyphIndex mIndex;
48     uint32_t         mImageId;
49     int32_t          mCount;
50     uint16_t         mOutlineWidth;
51     bool             isItalic : 1;
52     bool             isBold : 1;
53   };
54
55   struct FontGlyphRecord
56   {
57     Text::FontId             mFontId;
58     Vector<GlyphRecordEntry> mGlyphRecords;
59   };
60
61   /**
62    * @brief Constructor
63    */
64   AtlasGlyphManager();
65
66   /**
67    * @copydoc Toolkit::AtlasGlyphManager::Add
68    */
69   void Add(const Text::GlyphInfo&                        glyph,
70            const Toolkit::AtlasGlyphManager::GlyphStyle& style,
71            const PixelData&                              bitmap,
72            Dali::Toolkit::AtlasManager::AtlasSlot&       slot);
73
74   /**
75    * @copydoc Toolkit::AtlasGlyphManager::GenerateMeshData
76    */
77   void GenerateMeshData(uint32_t                       imageId,
78                         const Vector2&                 position,
79                         Toolkit::AtlasManager::Mesh2D& mesh);
80
81   /**
82    * @copydoc Toolkit::AtlasGlyphManager::IsCached
83    */
84   bool IsCached(Text::FontId                                  fontId,
85                 Text::GlyphIndex                              index,
86                 const Toolkit::AtlasGlyphManager::GlyphStyle& style,
87                 Dali::Toolkit::AtlasManager::AtlasSlot&       slot);
88
89   /**
90    * @copydoc Toolkit::AtlasGlyphManager::GetAtlasSize
91    */
92   Vector2 GetAtlasSize(uint32_t atlasId);
93
94   /**
95    * @copydoc Toolkit::AtlasGlyphManager::SetNewAtlasSize
96    */
97   void SetNewAtlasSize(uint32_t width, uint32_t height, uint32_t blockWidth, uint32_t blockHeight);
98
99   /**
100    * @copydoc Toolkit::AtlasGlyphManager::GetPixelFormat
101    */
102   Pixel::Format GetPixelFormat(uint32_t atlasId);
103
104   /**
105    * @copydoc toolkit::AtlasGlyphManager::AdjustReferenceCount
106    */
107   void AdjustReferenceCount(Text::FontId fontId, Text::GlyphIndex index, const Toolkit::AtlasGlyphManager::GlyphStyle& style, int32_t delta);
108
109   /**
110    * @copydoc Toolkit::AtlasGlyphManager::GetTextures
111    */
112   TextureSet GetTextures(uint32_t atlasId) const;
113
114   /**
115    * @copydoc Toolkit::AtlasGlyphManager::GetMetrics
116    */
117   const Toolkit::AtlasGlyphManager::Metrics& GetMetrics();
118
119 protected:
120   /**
121    * A reference counted object may only be deleted by calling Unreference()
122    */
123   virtual ~AtlasGlyphManager();
124
125 private:
126   Dali::Toolkit::AtlasManager         mAtlasManager; ///> Atlas Manager created by GlyphManager
127   std::vector<FontGlyphRecord>        mFontGlyphRecords;
128   Toolkit::AtlasGlyphManager::Metrics mMetrics; ///> Metrics to pass back on GlyphManager status
129   Sampler                             mSampler;
130 };
131
132 } // namespace Internal
133
134 inline const Internal::AtlasGlyphManager& GetImplementation(const Toolkit::AtlasGlyphManager& manager)
135 {
136   DALI_ASSERT_ALWAYS(manager && "AtlasGlyphManager handle is empty");
137
138   const BaseObject& handle = manager.GetBaseObject();
139
140   return static_cast<const Internal::AtlasGlyphManager&>(handle);
141 }
142
143 inline Internal::AtlasGlyphManager& GetImplementation(Toolkit::AtlasGlyphManager& manager)
144 {
145   DALI_ASSERT_ALWAYS(manager && "AtlasGlyphManager handle is empty");
146
147   BaseObject& handle = manager.GetBaseObject();
148
149   return static_cast<Internal::AtlasGlyphManager&>(handle);
150 }
151
152 } // namespace Toolkit
153
154 } // namespace Dali
155
156 #endif // DALI_TOOLKIT_ATLAS_GLYPH_MANAGER_IMPL_H