f9f15df09b497ee80dd404480ab57fc913eb7f27
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / text-backend-impl.cpp
1 /*
2  * Copyright (c) 2015 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/text-backend-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/singleton-service.h>
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/text/rendering-backend.h>
27 #include <dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Text
36 {
37
38 namespace Internal
39 {
40
41 struct Backend::Impl
42 {
43   int temp; // placeholder for future backend implemenations
44 };
45
46 Backend::Backend()
47 : mImpl( NULL )
48 {
49   mImpl = new Impl();
50 }
51
52 Backend::~Backend()
53 {
54   delete mImpl;
55 }
56
57 Dali::Toolkit::Text::Backend Backend::Get()
58 {
59   Dali::Toolkit::Text::Backend backendHandle;
60
61   Dali::SingletonService service( SingletonService::Get() );
62   if ( service )
63   {
64     // Check whether the singleton is already created
65     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::Toolkit::Text::Backend ) );
66     if(handle)
67     {
68       // If so, downcast the handle
69       Backend* impl = dynamic_cast< Dali::Toolkit::Text::Internal::Backend* >( handle.GetObjectPtr() );
70       backendHandle = Dali::Toolkit::Text::Backend( impl );
71     }
72     else // create and register the object
73     {
74       backendHandle = Dali::Toolkit::Text::Backend( new Backend );
75       service.Register( typeid( backendHandle ), backendHandle );
76     }
77   }
78
79   return backendHandle;
80 }
81
82 RendererPtr Backend::NewRenderer( unsigned int renderingType )
83 {
84   RendererPtr renderer;
85
86   switch( renderingType )
87   {
88     case Dali::Toolkit::Text::RENDERING_SHARED_ATLAS:
89     {
90       renderer = Dali::Toolkit::Text::AtlasRenderer::New();
91     }
92     break;
93
94     default:
95     {
96       DALI_LOG_WARNING( "Unknown renderer type: %d", renderingType );
97       break;
98     }
99   }
100
101   return renderer;
102 }
103
104 } // namespace Internal
105
106 } // namespace Text
107
108 } // namespace Toolkit
109
110 } // namespace Dali