084ddcbb6245ff4eac46f47dcea7498e4e1b7537
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / renderer-factory / renderer-factory.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 "renderer-factory.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/singleton-service.h>
23 #include <dali/devel-api/adaptor-framework/environment-variable.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/controls/renderers/renderer-factory-impl.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace
35 {
36   const char * const DALI_DEBUG_RENDERING("DALI_DEBUG_RENDERING");
37 }
38
39 RendererFactory RendererFactory::Get()
40 {
41   RendererFactory factory;
42
43   // Check whether the RendererFactory is already created
44   SingletonService singletonService( SingletonService::Get() );
45   if( singletonService )
46   {
47     BaseHandle handle = singletonService.GetSingleton( typeid(RendererFactory) );
48     if( handle )
49     {
50       //If so, downcast the handle of singleton to RendererFactory
51       factory = RendererFactory( dynamic_cast<Internal::RendererFactory*>(handle.GetObjectPtr()) );
52     }
53
54     if( !factory )// If not, create the RendererFactory and register it as a singleton
55     {
56       // Check whether debug rendering is required
57       if( EnvironmentVariable::GetEnvironmentVariable( DALI_DEBUG_RENDERING ) )
58       {
59         factory = RendererFactory( new Internal::RendererFactory(true) );
60       }
61       else
62       {
63         factory = RendererFactory( new Internal::RendererFactory(false) );
64       }
65       singletonService.Register( typeid(RendererFactory), factory );
66
67     }
68   }
69
70   return factory;
71 }
72
73 RendererFactory::RendererFactory()
74 {
75 }
76
77 RendererFactory::~RendererFactory()
78 {
79 }
80
81 RendererFactory::RendererFactory( const RendererFactory& handle )
82 : BaseHandle( handle )
83 {
84 }
85
86 RendererFactory& RendererFactory::operator=( const RendererFactory& handle )
87 {
88   BaseHandle::operator=( handle );
89   return *this;
90 }
91
92 RendererFactory::RendererFactory(Internal::RendererFactory *impl)
93 : BaseHandle(impl)
94 {
95 }
96
97 ControlRenderer RendererFactory::GetControlRenderer( const Property::Map& propertyMap )
98 {
99   return GetImplementation( *this ).GetControlRenderer( propertyMap );
100 }
101
102 ControlRenderer RendererFactory::GetControlRenderer( const Vector4& color )
103 {
104   return GetImplementation( *this ).GetControlRenderer( color );
105 }
106
107 void RendererFactory::ResetRenderer( ControlRenderer& renderer, Actor& actor, const Vector4& color )
108 {
109   GetImplementation( *this ).ResetRenderer( renderer, actor, color );
110 }
111
112 ControlRenderer RendererFactory::GetControlRenderer( float borderSize, const Vector4& borderColor )
113 {
114   return GetImplementation( *this ).GetControlRenderer( borderSize, borderColor );
115 }
116
117 ControlRenderer RendererFactory::GetControlRenderer( const Image& image )
118 {
119   return GetImplementation( *this ).GetControlRenderer( image );
120 }
121
122 void RendererFactory::ResetRenderer( ControlRenderer& renderer, Actor& actor, const Image& image )
123 {
124   GetImplementation( *this ).ResetRenderer( renderer, actor, image );
125 }
126
127 ControlRenderer RendererFactory::GetControlRenderer( const std::string& url, ImageDimensions size )
128 {
129   return GetImplementation( *this ).GetControlRenderer( url, size );
130 }
131
132 void RendererFactory::ResetRenderer( ControlRenderer& renderer, Actor& actor, const std::string& url, ImageDimensions size )
133 {
134   GetImplementation( *this ).ResetRenderer( renderer, actor, url, size );
135 }
136
137 void RendererFactory::ResetRenderer( ControlRenderer& renderer, Actor& actor, const Property::Map& propertyMap )
138 {
139   GetImplementation( *this ).ResetRenderer( renderer, actor, propertyMap );
140 }
141
142 } // namespace Toolkit
143
144 } // namespace Dali