2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/text/rendering/vector-based/vector-blob-atlas-share.h>
22 #include <dali/devel-api/common/singleton-service.h>
23 #include <dali/public-api/object/base-object.h>
27 const int INITIAL_VECTOR_BLOB_ATLAS_WIDTH = 512;
28 const int INITIAL_VECTOR_BLOB_ATLAS_HEIGHT = 512;
30 const int NEW_VECTOR_BLOB_ATLAS_WIDTH = 1024;
31 const int NEW_VECTOR_BLOB_ATLAS_HEIGHT = 1024;
33 const int VECTOR_BLOB_ATLAS_ITEM_WIDTH = 64;
34 const int VECTOR_BLOB_ATLAS_HEIGHT_QUANTUM = 8;
36 } // unnamed namespace
44 class VectorBlobAtlasShare::Impl : public Dali::BaseObject
54 VectorBlobAtlas* GetCurrentAtlas()
58 mCurrentAtlas = new VectorBlobAtlas(INITIAL_VECTOR_BLOB_ATLAS_WIDTH, INITIAL_VECTOR_BLOB_ATLAS_HEIGHT, VECTOR_BLOB_ATLAS_ITEM_WIDTH, VECTOR_BLOB_ATLAS_HEIGHT_QUANTUM);
61 return mCurrentAtlas.Get();
64 VectorBlobAtlas* GetNewAtlas()
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");
69 mCurrentAtlas = new VectorBlobAtlas(NEW_VECTOR_BLOB_ATLAS_WIDTH, NEW_VECTOR_BLOB_ATLAS_HEIGHT, VECTOR_BLOB_ATLAS_ITEM_WIDTH, VECTOR_BLOB_ATLAS_HEIGHT_QUANTUM);
71 return mCurrentAtlas.Get();
76 * A reference counted object may only be deleted by calling Unreference()
83 IntrusivePtr<VectorBlobAtlas> mCurrentAtlas;
86 VectorBlobAtlasShare::VectorBlobAtlasShare()
90 VectorBlobAtlasShare::~VectorBlobAtlasShare()
94 VectorBlobAtlasShare VectorBlobAtlasShare::Get()
96 VectorBlobAtlasShare manager;
98 // Check whether the VectorBlobAtlasShare is already created
99 SingletonService singletonService(SingletonService::Get());
102 Dali::BaseHandle handle = singletonService.GetSingleton(typeid(VectorBlobAtlasShare));
105 // If so, downcast the handle of singleton to VectorBlobAtlasShare
106 manager = VectorBlobAtlasShare(dynamic_cast<VectorBlobAtlasShare::Impl*>(handle.GetObjectPtr()));
111 // If not, create the VectorBlobAtlasShare and register it as a singleton
112 manager = VectorBlobAtlasShare(new VectorBlobAtlasShare::Impl());
113 singletonService.Register(typeid(manager), manager);
120 VectorBlobAtlasShare::VectorBlobAtlasShare(VectorBlobAtlasShare::Impl* impl)
125 VectorBlobAtlas* VectorBlobAtlasShare::GetCurrentAtlas()
127 VectorBlobAtlasShare::Impl& impl = static_cast<VectorBlobAtlasShare::Impl&>(GetBaseObject());
129 return impl.GetCurrentAtlas();
132 VectorBlobAtlas* VectorBlobAtlasShare::GetNewAtlas()
134 VectorBlobAtlasShare::Impl& impl = static_cast<VectorBlobAtlasShare::Impl&>(GetBaseObject());
136 return impl.GetNewAtlas();
141 } // namespace Toolkit