257b03cdf633bfcad18fce2469c394772745c021
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-factory-impl.h
1 #ifndef DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H
2 #define DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/object/base-object.h>
22
23 // INTERNAL INCLUDES
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
26 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal
35 {
36
37 class VisualFactoryCache;
38 typedef IntrusivePtr<VisualFactoryCache> VisualFactoryCachePtr;
39
40 /**
41  * @copydoc Toolkit::VisualFactory
42  */
43 class VisualFactory : public BaseObject
44 {
45 public:
46
47   /**
48    * @brief Constructor
49    *
50    * @param[in] debugEnabled If true, use debug renderer to replace all the concrete renderer.
51    */
52   VisualFactory( bool debugEnabled );
53
54   /**
55    * @copydoc Toolkit::RenderFactory::CreateVisual( const Property::Map& )
56    */
57   Toolkit::Visual::Base CreateVisual( const Property::Map& propertyMap );
58
59   /**
60    * @copydoc Toolkit::RenderFactory::CreateVisual( const Image& )
61    */
62   Toolkit::Visual::Base CreateVisual( const Image& image );
63
64   /**
65    * @copydoc Toolkit::RenderFactory::CreateVisual( const std::string&, ImageDimensions )
66    */
67   Toolkit::Visual::Base CreateVisual( const std::string& image, ImageDimensions size );
68
69   /**
70    * @return the reference to texture manager
71    */
72   Internal::TextureManager& GetTextureManager();
73
74 protected:
75
76   /**
77    * A reference counted object may only be deleted by calling Unreference()
78    */
79   virtual ~VisualFactory();
80
81 private:
82
83   /**
84    * Undefined copy constructor.
85    */
86   VisualFactory(const VisualFactory&);
87
88   /**
89    * Undefined assignment operator.
90    */
91   VisualFactory& operator=(const VisualFactory& rhs);
92
93 private:
94
95   VisualFactoryCachePtr   mFactoryCache;
96   bool                    mDebugEnabled;
97 };
98
99 /**
100  * @brief Template to allow discard old visual, get new one and set it on stage if possible
101  *
102  * @tparam ParameterType0 The type of first argument passed to the CreateVisual()
103  * @tparam ParameterType1 The type of second argument passed to the CreateVisual()
104  * @SINCE_1_0.39
105  * @param[in] actor Actor for which the visual will be replaced
106  * @param[in,out] visual The visual to be replaced
107  * @param[in] param0 First template based argument passed to the visual factory
108  * @param[in] param1 Second template based argument passed to the visual factory
109  */
110 template< class ParameterType0, class ParameterType1 >
111 void InitializeVisual( Actor& actor, Toolkit::Visual::Base& visual, ParameterType0& param0, ParameterType1& param1 )
112 {
113   if( actor )
114   {
115     Toolkit::GetImplementation(visual).SetOffStage( actor );
116   }
117   visual = Toolkit::VisualFactory::Get().CreateVisual( param0, param1 );
118   if( visual && actor && actor.OnStage() )
119   {
120     Toolkit::GetImplementation(visual).SetOnStage(actor);
121   }
122 }
123
124 /**
125  * @brief Template to allow discard old visual, get new one and set it on stage if possible
126  *
127  * @tparam ParameterType The type of argument passed to the CreateVisual()
128  * @SINCE_1_0.39
129  * @param[in] actor Actor for which the visual will be replaced
130  * @param[in,out] visual The visual to be replaced
131  * @param[in] param Template based argument passed to the visual factory
132  */
133 template< class ParameterType >
134 void InitializeVisual( Actor& actor, Toolkit::Visual::Base& visual, ParameterType& param )
135 {
136   if( actor && visual )
137   {
138     Toolkit::GetImplementation(visual).SetOffStage( actor );
139   }
140   visual =  Toolkit::VisualFactory::Get().CreateVisual( param );
141   if( visual && actor && actor.OnStage() )
142   {
143     Toolkit::GetImplementation(visual).SetOnStage(actor);
144   }
145 }
146
147 } // namespace Internal
148
149 inline const Internal::VisualFactory& GetImplementation(const Toolkit::VisualFactory& factory)
150 {
151   DALI_ASSERT_ALWAYS( factory && "VisualFactory handle is empty" );
152
153   const BaseObject& handle = factory.GetBaseObject();
154
155   return static_cast<const Internal::VisualFactory&>(handle);
156 }
157
158 inline Internal::VisualFactory& GetImplementation(Toolkit::VisualFactory& factory)
159 {
160   DALI_ASSERT_ALWAYS( factory && "VisualFactory handle is empty" );
161
162   BaseObject& handle = factory.GetBaseObject();
163
164   return static_cast<Internal::VisualFactory&>(handle);
165 }
166
167 } // namespace Toolkit
168
169 } // namespace Dali
170
171 #endif /* DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H */