[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / vector-based / vector-blob-atlas-share.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/vector-based/vector-blob-atlas-share.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/common/singleton-service.h>
23 #include <dali/public-api/object/base-object.h>
24
25 namespace
26 {
27 const int INITIAL_VECTOR_BLOB_ATLAS_WIDTH  = 512;
28 const int INITIAL_VECTOR_BLOB_ATLAS_HEIGHT = 512;
29
30 const int NEW_VECTOR_BLOB_ATLAS_WIDTH  = 1024;
31 const int NEW_VECTOR_BLOB_ATLAS_HEIGHT = 1024;
32
33 const int VECTOR_BLOB_ATLAS_ITEM_WIDTH     = 64;
34 const int VECTOR_BLOB_ATLAS_HEIGHT_QUANTUM = 8;
35
36 } // unnamed namespace
37
38 namespace Dali
39 {
40 namespace Toolkit
41 {
42 namespace Text
43 {
44 class VectorBlobAtlasShare::Impl : public Dali::BaseObject
45 {
46 public:
47   /**
48    * @brief Constructor
49    */
50   Impl()
51   {
52   }
53
54   VectorBlobAtlas* GetCurrentAtlas()
55   {
56     if(!mCurrentAtlas)
57     {
58       mCurrentAtlas = new VectorBlobAtlas(INITIAL_VECTOR_BLOB_ATLAS_WIDTH, INITIAL_VECTOR_BLOB_ATLAS_HEIGHT, VECTOR_BLOB_ATLAS_ITEM_WIDTH, VECTOR_BLOB_ATLAS_HEIGHT_QUANTUM);
59     }
60
61     return mCurrentAtlas.Get();
62   }
63
64   VectorBlobAtlas* GetNewAtlas()
65   {
66     // The current atlas should have been filled, before asking for a new one
67     DALI_ASSERT_DEBUG(mCurrentAtlas->IsFull() && "Current atlas is not full yet");
68
69     mCurrentAtlas = new VectorBlobAtlas(NEW_VECTOR_BLOB_ATLAS_WIDTH, NEW_VECTOR_BLOB_ATLAS_HEIGHT, VECTOR_BLOB_ATLAS_ITEM_WIDTH, VECTOR_BLOB_ATLAS_HEIGHT_QUANTUM);
70
71     return mCurrentAtlas.Get();
72   }
73
74 protected:
75   /**
76    * A reference counted object may only be deleted by calling Unreference()
77    */
78   virtual ~Impl()
79   {
80   }
81
82 private:
83   IntrusivePtr<VectorBlobAtlas> mCurrentAtlas;
84 };
85
86 VectorBlobAtlasShare::VectorBlobAtlasShare()
87 {
88 }
89
90 VectorBlobAtlasShare::~VectorBlobAtlasShare()
91 {
92 }
93
94 VectorBlobAtlasShare VectorBlobAtlasShare::Get()
95 {
96   VectorBlobAtlasShare manager;
97
98   // Check whether the VectorBlobAtlasShare is already created
99   SingletonService singletonService(SingletonService::Get());
100   if(singletonService)
101   {
102     Dali::BaseHandle handle = singletonService.GetSingleton(typeid(VectorBlobAtlasShare));
103     if(handle)
104     {
105       // If so, downcast the handle of singleton to VectorBlobAtlasShare
106       manager = VectorBlobAtlasShare(dynamic_cast<VectorBlobAtlasShare::Impl*>(handle.GetObjectPtr()));
107     }
108
109     if(!manager)
110     {
111       // If not, create the VectorBlobAtlasShare and register it as a singleton
112       manager = VectorBlobAtlasShare(new VectorBlobAtlasShare::Impl());
113       singletonService.Register(typeid(manager), manager);
114     }
115   }
116
117   return manager;
118 }
119
120 VectorBlobAtlasShare::VectorBlobAtlasShare(VectorBlobAtlasShare::Impl* impl)
121 : BaseHandle(impl)
122 {
123 }
124
125 VectorBlobAtlas* VectorBlobAtlasShare::GetCurrentAtlas()
126 {
127   VectorBlobAtlasShare::Impl& impl = static_cast<VectorBlobAtlasShare::Impl&>(GetBaseObject());
128
129   return impl.GetCurrentAtlas();
130 }
131
132 VectorBlobAtlas* VectorBlobAtlasShare::GetNewAtlas()
133 {
134   VectorBlobAtlasShare::Impl& impl = static_cast<VectorBlobAtlasShare::Impl&>(GetBaseObject());
135
136   return impl.GetNewAtlas();
137 }
138
139 } // namespace Text
140
141 } // namespace Toolkit
142
143 } // namespace Dali