8cf01dd1372390a323bcfc8c035b19def7d687c6
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / renderer-factory-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 // CLASS HEADER
18 #include "renderer-factory-impl.h"
19
20 // EXTERNAL INCLUDES
21 #include <dali/integration-api/debug.h>
22 #include <dali/public-api/object/property-array.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/devel-api/object/type-registry-helper.h>
25
26 // Internal HEADER
27 #include <dali-toolkit/internal/controls/renderers/color/color-renderer.h>
28 #include <dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.h>
29 #include <dali-toolkit/internal/controls/renderers/renderer-factory-cache.h>
30
31 namespace
32 {
33 const char * const RENDERER_TYPE_NAME( "renderer-type" );
34 const char * const COLOR_RENDERER("color-renderer");
35 const char * const GRADIENT_RENDERER("gradient-renderer");
36 }
37
38 namespace Dali
39 {
40
41 namespace Toolkit
42 {
43
44 namespace Internal
45 {
46
47 namespace
48 {
49
50 BaseHandle Create()
51 {
52   BaseHandle handle = Toolkit::RendererFactory::Get();
53
54   return handle;
55 }
56
57 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::RendererFactory, Dali::BaseHandle, Create, true )
58 DALI_TYPE_REGISTRATION_END()
59
60 } // namespace
61
62 RendererFactory::RendererFactory()
63 {
64 }
65
66 RendererFactory::~RendererFactory()
67 {
68 }
69
70 Toolkit::ControlRenderer RendererFactory::GetControlRenderer( const Property::Map& propertyMap )
71 {
72   ControlRenderer* rendererPtr = NULL;
73
74   Property::Value* type = propertyMap.Find( RENDERER_TYPE_NAME );
75   std::string typeValue ;
76   if( type && type->Get( typeValue ))
77   {
78     if( typeValue ==  COLOR_RENDERER )
79     {
80       rendererPtr = new ColorRenderer();
81     }
82     else if( typeValue ==  GRADIENT_RENDERER )
83     {
84       rendererPtr = new GradientRenderer();
85     }
86   }
87
88   if( rendererPtr )
89   {
90     if( !mFactoryCache )
91     {
92       mFactoryCache = new RendererFactoryCache();
93     }
94     rendererPtr->Initialize( *( mFactoryCache.Get() ), propertyMap );
95   }
96   else
97   {
98     DALI_LOG_ERROR( "Renderer type unknown" );
99   }
100
101   return Toolkit::ControlRenderer(rendererPtr);
102 }
103
104 } // namespace Internal
105
106 } // namespace Toolkit
107
108 } // namespace Dali
109