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