Merge remote-tracking branch 'origin/tizen' into new_text
[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/public-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 #include <dali-toolkit/internal/text/rendering/basic/text-basic-renderer.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Text
37 {
38
39 namespace Internal
40 {
41
42 struct Backend::Impl
43 {
44   int temp; // placeholder for future backend implemenations
45 };
46
47 Backend::Backend()
48 : mImpl( NULL )
49 {
50   mImpl = new Impl();
51 }
52
53 Backend::~Backend()
54 {
55   delete mImpl;
56 }
57
58 Dali::Toolkit::Text::Backend Backend::Get()
59 {
60   Dali::Toolkit::Text::Backend backendHandle;
61
62   Dali::SingletonService service( SingletonService::Get() );
63   if ( service )
64   {
65     // Check whether the singleton is already created
66     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::Toolkit::Text::Backend ) );
67     if(handle)
68     {
69       // If so, downcast the handle
70       Backend* impl = dynamic_cast< Dali::Toolkit::Text::Internal::Backend* >( handle.GetObjectPtr() );
71       backendHandle = Dali::Toolkit::Text::Backend( impl );
72     }
73     else // create and register the object
74     {
75       backendHandle = Dali::Toolkit::Text::Backend( new Backend );
76       service.Register( typeid( backendHandle ), backendHandle );
77     }
78   }
79
80   return backendHandle;
81 }
82
83 RendererPtr Backend::NewRenderer( unsigned int renderingType )
84 {
85   RendererPtr renderer;
86
87   switch( renderingType )
88   {
89     case Dali::Toolkit::Text::RENDERING_BASIC:
90     {
91       renderer = Dali::Toolkit::Text::BasicRenderer::New();
92     }
93     break;
94
95     case Dali::Toolkit::Text::RENDERING_SHARED_ATLAS:
96     {
97       renderer = Dali::Toolkit::Text::AtlasRenderer::New();
98     }
99     break;
100
101     default:
102     {
103       DALI_LOG_WARNING( "Unknown renderer type: %d", renderingType );
104       break;
105     }
106   }
107
108   return renderer;
109 }
110
111 } // namespace Internal
112
113 } // namespace Text
114
115 } // namespace Toolkit
116
117 } // namespace Dali