[dali_2.0.26] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / atlas / atlas-glyph-manager.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/common/singleton-service.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.h>
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 AtlasGlyphManager::AtlasGlyphManager()
32 {
33 }
34
35 AtlasGlyphManager::~AtlasGlyphManager()
36 {
37 }
38
39 AtlasGlyphManager AtlasGlyphManager::Get()
40 {
41   AtlasGlyphManager manager;
42
43   // Check whether the AtlasGlyphManager is already created
44   SingletonService singletonService(SingletonService::Get());
45   if(singletonService)
46   {
47     Dali::BaseHandle handle = singletonService.GetSingleton(typeid(AtlasGlyphManager));
48     if(handle)
49     {
50       // If so, downcast the handle of singleton to AtlasGlyphManager
51       manager = AtlasGlyphManager(dynamic_cast<Internal::AtlasGlyphManager*>(handle.GetObjectPtr()));
52     }
53
54     if(!manager)
55     {
56       // If not, create the AtlasGlyphManager and register it as a singleton
57       manager = AtlasGlyphManager(new Internal::AtlasGlyphManager());
58       singletonService.Register(typeid(manager), manager);
59     }
60   }
61   return manager;
62 }
63
64 AtlasGlyphManager::AtlasGlyphManager(Internal::AtlasGlyphManager* impl)
65 : BaseHandle(impl)
66 {
67 }
68
69 void AtlasGlyphManager::Add(const Text::GlyphInfo&   glyph,
70                             const GlyphStyle&        style,
71                             const PixelData&         bitmap,
72                             AtlasManager::AtlasSlot& slot)
73 {
74   GetImplementation(*this).Add(glyph, style, bitmap, slot);
75 }
76
77 void AtlasGlyphManager::GenerateMeshData(uint32_t                       imageId,
78                                          const Vector2&                 position,
79                                          Toolkit::AtlasManager::Mesh2D& mesh)
80 {
81   GetImplementation(*this).GenerateMeshData(imageId,
82                                             position,
83                                             mesh);
84 }
85
86 bool AtlasGlyphManager::IsCached(Text::FontId             fontId,
87                                  Text::GlyphIndex         index,
88                                  const GlyphStyle&        style,
89                                  AtlasManager::AtlasSlot& slot)
90 {
91   return GetImplementation(*this).IsCached(fontId, index, style, slot);
92 }
93
94 void AtlasGlyphManager::SetNewAtlasSize(uint32_t width, uint32_t height, uint32_t blockWidth, uint32_t blockHeight)
95 {
96   GetImplementation(*this).SetNewAtlasSize(width, height, blockWidth, blockHeight);
97 }
98
99 Vector2 AtlasGlyphManager::GetAtlasSize(uint32_t atlasId)
100 {
101   return GetImplementation(*this).GetAtlasSize(atlasId);
102 }
103
104 Pixel::Format AtlasGlyphManager::GetPixelFormat(uint32_t atlasId)
105 {
106   return GetImplementation(*this).GetPixelFormat(atlasId);
107 }
108
109 TextureSet AtlasGlyphManager::GetTextures(uint32_t atlasId) const
110 {
111   return GetImplementation(*this).GetTextures(atlasId);
112 }
113
114 const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics()
115 {
116   return GetImplementation(*this).GetMetrics();
117 }
118
119 void AtlasGlyphManager::AdjustReferenceCount(Text::FontId fontId, Text::GlyphIndex index, const GlyphStyle& style, int32_t delta)
120 {
121   GetImplementation(*this).AdjustReferenceCount(fontId, index, style, delta);
122 }
123
124 } // namespace Toolkit
125
126 } // namespace Dali