Fix SVACE issue
[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 #include <dali-toolkit/public-api/styling/style-manager.h>
28 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 class VisualFactoryCache;
40 class ImageVisualShaderFactory;
41
42 /**
43  * @copydoc Toolkit::VisualFactory
44  */
45 class VisualFactory : public BaseObject
46 {
47 public:
48
49   /**
50    * @brief Constructor
51    *
52    * @param[in] debugEnabled If true, use debug renderer to replace all the concrete renderer.
53    */
54   VisualFactory( bool debugEnabled );
55
56   /**
57    * @brief StyleChanged callback
58    *
59    * @param[in] styleManager Handle for style manager.
60    * @param[in] type Style change type.
61    */
62   void OnStyleChangedSignal( Toolkit::StyleManager styleManager, StyleChange::Type type );
63
64   /**
65    * @copydoc Toolkit::VisualFactory::CreateVisual( const Property::Map& )
66    */
67   Toolkit::Visual::Base CreateVisual( const Property::Map& propertyMap );
68
69   /**
70    * @copydoc Toolkit::VisualFactory::CreateVisual( const Image& )
71    */
72   Toolkit::Visual::Base CreateVisual( const Image& image );
73
74   /**
75    * @copydoc Toolkit::VisualFactory::CreateVisual( const std::string&, ImageDimensions )
76    */
77   Toolkit::Visual::Base CreateVisual( const std::string& image, ImageDimensions size );
78
79   /**
80    * @copydoc Toolkit::VisualFactory::SetPreMultiplyOnLoad()
81    */
82   void SetPreMultiplyOnLoad( bool preMultiply );
83
84   /**
85    * @copydoc Toolkit::VisualFactory::GetPreMultiplyOnLoad()
86    */
87   bool GetPreMultiplyOnLoad() const;
88
89   /**
90    * @return the reference to texture manager
91    */
92   Internal::TextureManager& GetTextureManager();
93
94 protected:
95
96   /**
97    * A reference counted object may only be deleted by calling Unreference()
98    */
99   virtual ~VisualFactory();
100
101 private:
102   /**
103    * Get the factory cache, creating it if necessary.
104    */
105   Internal::VisualFactoryCache& GetFactoryCache();
106
107   /**
108    * Get the image visual shader factory, creating it if necessary.
109    */
110   ImageVisualShaderFactory& GetImageVisualShaderFactory();
111
112   VisualFactory(const VisualFactory&) = delete;
113
114   VisualFactory& operator=(const VisualFactory& rhs) = delete;
115
116 private:
117   std::unique_ptr< VisualFactoryCache >       mFactoryCache;
118   std::unique_ptr< ImageVisualShaderFactory > mImageVisualShaderFactory;
119   SlotDelegate< VisualFactory >               mSlotDelegate;
120   bool                                        mDebugEnabled:1;
121   bool                                        mPreMultiplyOnLoad:1; ///< Local store for this flag
122 };
123
124 /**
125  * @brief Template to allow discard old visual, get new one and set it on stage if possible
126  *
127  * @tparam ParameterType0 The type of first argument passed to the CreateVisual()
128  * @tparam ParameterType1 The type of second argument passed to the CreateVisual()
129  * @SINCE_1_0.39
130  * @param[in] actor Actor for which the visual will be replaced
131  * @param[in,out] visual The visual to be replaced
132  * @param[in] param0 First template based argument passed to the visual factory
133  * @param[in] param1 Second template based argument passed to the visual factory
134  */
135 template< class ParameterType0, class ParameterType1 >
136 void InitializeVisual( Actor& actor, Toolkit::Visual::Base& visual, ParameterType0& param0, ParameterType1& param1 )
137 {
138   if( actor )
139   {
140     Toolkit::GetImplementation(visual).SetOffStage( actor );
141   }
142   visual = Toolkit::VisualFactory::Get().CreateVisual( param0, param1 );
143   if( visual && actor && actor.OnStage() )
144   {
145     Toolkit::GetImplementation(visual).SetOnStage(actor);
146   }
147 }
148
149 /**
150  * @brief Template to allow discard old visual, get new one and set it on stage if possible
151  *
152  * @tparam ParameterType The type of argument passed to the CreateVisual()
153  * @SINCE_1_0.39
154  * @param[in] actor Actor for which the visual will be replaced
155  * @param[in,out] visual The visual to be replaced
156  * @param[in] param Template based argument passed to the visual factory
157  */
158 template< class ParameterType >
159 void InitializeVisual( Actor& actor, Toolkit::Visual::Base& visual, ParameterType& param )
160 {
161   if( actor && visual )
162   {
163     Toolkit::GetImplementation(visual).SetOffStage( actor );
164   }
165   visual =  Toolkit::VisualFactory::Get().CreateVisual( param );
166   if( visual && actor && actor.OnStage() )
167   {
168     Toolkit::GetImplementation(visual).SetOnStage(actor);
169   }
170 }
171
172 } // namespace Internal
173
174 inline const Internal::VisualFactory& GetImplementation(const Toolkit::VisualFactory& factory)
175 {
176   DALI_ASSERT_ALWAYS( factory && "VisualFactory handle is empty" );
177
178   const BaseObject& handle = factory.GetBaseObject();
179
180   return static_cast<const Internal::VisualFactory&>(handle);
181 }
182
183 inline Internal::VisualFactory& GetImplementation(Toolkit::VisualFactory& factory)
184 {
185   DALI_ASSERT_ALWAYS( factory && "VisualFactory handle is empty" );
186
187   BaseObject& handle = factory.GetBaseObject();
188
189   return static_cast<Internal::VisualFactory&>(handle);
190 }
191
192 } // namespace Toolkit
193
194 } // namespace Dali
195
196 #endif /* DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H */