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