76e963c1ff8183723d0bc4318903330afd60590c
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / visual-factory / visual-factory.h
1 #ifndef __DALI_TOOLKIT_RENDERER_FACTORY_H__
2 #define __DALI_TOOLKIT_RENDERER_FACTORY_H__
3 /*
4  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/object/base-handle.h>
22 #include <dali/public-api/images/image-operations.h>
23 #include <dali/public-api/object/property-map.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/devel-api/visual-factory/visual.h>
27
28 namespace Dali
29 {
30 class Image;
31 class Vector4;
32
33 namespace Toolkit
34 {
35
36 namespace Internal DALI_INTERNAL
37 {
38 class VisualFactory;
39 }
40
41 /**
42  * @brief VisualFactory is a singleton object that provides and shares visuals between controls
43  *
44  * By setting environment variable 'DALI_DEBUG_RENDERING', all concrete renderer is replaced with the debug renderer which renders a quad wireframe.
45  *
46  * The renderer type is required in the property map for requesting a control renderer.
47  *
48  * | %Property Name           | Type             |
49  * |--------------------------|------------------|
50  * | rendererType             | STRING           |
51  */
52 class DALI_IMPORT_API VisualFactory : public BaseHandle
53 {
54 public:
55
56   /**
57    * @brief Create or retrieve VisualFactory singleton.
58    *
59    * @return A handle to the VisualFactory control.
60    */
61   static VisualFactory Get();
62
63   /**
64    * @brief Create a VisualFactory handle.
65    *
66    * Calling member functions with an uninitialised handle is not allowed.
67    */
68   VisualFactory();
69
70   /**
71    * @brief Destructor
72    *
73    * This is non-virtual since derived Handle types must not contain data or virtual methods.
74    */
75   ~VisualFactory();
76
77   /**
78    * @brief This copy constructor is required for (smart) pointer semantics.
79    *
80    * @param[in] handle A reference to the copied handle.
81    */
82   VisualFactory( const VisualFactory& handle );
83
84   /**
85    * @brief This assignment operator is required for (smart) pointer semantics.
86    *
87    * @param [in] handle  A reference to the copied handle.
88    * @return A reference to this.
89    */
90   VisualFactory& operator=( const VisualFactory& handle );
91
92   /**
93    * @brief Request the control renderer
94    *
95    * @param[in] propertyMap The map contains the properties required by the control renderer
96    *            Depends on the content of the map, different kind of renderer would be returned.
97    * @return The pointer pointing to control renderer
98    */
99   Visual CreateVisual( const Property::Map& propertyMap  );
100
101   /**
102    * @brief Request the control renderer to render the image.
103    *
104    * @param[in] image The image to be rendered.
105    * @return The pointer pointing to the control renderer
106    */
107   Visual CreateVisual( const Image& image );
108
109   /**
110    * @brief Request the control renderer to render the given resource at the url.
111    *
112    * @param[in] url The URL to the resource to be rendered.
113    * @param[in] size The width and height to fit the loaded image to.
114    * @return The pointer pointing to the control renderer
115    */
116   Visual CreateVisual( const std::string& url, ImageDimensions size );
117
118 private:
119
120   explicit DALI_INTERNAL VisualFactory(Internal::VisualFactory *impl);
121
122 };
123
124
125 /**
126  * @brief Template to allow discard old renderer, get new one and set it on stage if possible
127  *
128  * @tparam ParameterType0 The type of first argument passed to the CreateVisual()
129  * @tparam ParameterType1 The type of second argument passed to the CreateVisual()
130  * @SINCE_1_0.39
131  * @param[in] actor Actor for which the renderer will be replaced
132  * @param[in,out] renderer The renderer object to be replaced
133  * @param[in] param0 First template based argument passed to the renderer factory
134  * @param[in] param1 Second template based argument passed to the renderer factory
135  */
136 template< class ParameterType0, class ParameterType1 >
137 void InitializeVisual( Actor& actor, Visual& renderer, ParameterType0& param0, ParameterType1& param1 )
138 {
139   renderer.RemoveAndReset( actor );
140   renderer = Toolkit::VisualFactory::Get().CreateVisual( param0, param1 );
141   if( renderer && actor && actor.OnStage() )
142   {
143     renderer.SetOnStage( actor );
144   }
145 }
146
147 /**
148  * @brief Template to allow discard old renderer, get new one and set it on stage if possible
149  *
150  * @tparam ParameterType The type of argument passed to the CreateVisual()
151  * @SINCE_1_0.39
152  * @param[in] actor Actor for which the renderer will be replaced
153  * @param[in,out] renderer The renderer object to be replaced
154  * @param[in] param Template based argument passed to the renderer factory
155  */
156 template< class ParameterType >
157 void InitializeVisual( Actor& actor, Visual& renderer, ParameterType& param )
158 {
159   renderer.RemoveAndReset( actor );
160   renderer =  Toolkit::VisualFactory::Get().CreateVisual( param );
161   if( renderer && actor && actor.OnStage() )
162   {
163     renderer.SetOnStage( actor );
164   }
165 }
166
167 } // namespace Toolkit
168
169 } // namespace Dali
170
171
172 #endif /* __DALI_TOOLKIT_RENDERER_FACTORY_H__ */