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