[Tizen] Apply precompile shader
[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    * Get the factory cache, creating it if necessary.
113    */
114   Internal::VisualFactoryCache& GetFactoryCache();
115
116   /**
117    * Get the image visual shader factory, creating it if necessary.
118    */
119   ImageVisualShaderFactory& GetImageVisualShaderFactory();
120
121   /**
122    * Get the text visual shader factory, creating it if necessary.
123    */
124   TextVisualShaderFactory& GetTextVisualShaderFactory();
125
126   VisualFactory(const VisualFactory&) = delete;
127
128   VisualFactory& operator=(const VisualFactory& rhs) = delete;
129
130 private:
131   std::unique_ptr<VisualFactoryCache>       mFactoryCache;
132   std::unique_ptr<ImageVisualShaderFactory> mImageVisualShaderFactory;
133   std::unique_ptr<TextVisualShaderFactory>  mTextVisualShaderFactory;
134   SlotDelegate<VisualFactory>               mSlotDelegate;
135   bool                                      mDebugEnabled : 1;
136   bool                                      mPreMultiplyOnLoad : 1; ///< Local store for this flag
137   bool                                      mPrecompiledShaderRequested{false};
138 };
139
140 /**
141  * @brief Template to allow discard old visual, get new one and set it on stage if possible
142  *
143  * @tparam ParameterType0 The type of first argument passed to the CreateVisual()
144  * @tparam ParameterType1 The type of second argument passed to the CreateVisual()
145  * @SINCE_1_0.39
146  * @param[in] actor Actor for which the visual will be replaced
147  * @param[in,out] visual The visual to be replaced
148  * @param[in] param0 First template based argument passed to the visual factory
149  * @param[in] param1 Second template based argument passed to the visual factory
150  */
151 template<class ParameterType0, class ParameterType1>
152 void InitializeVisual(Actor& actor, Toolkit::Visual::Base& visual, ParameterType0& param0, ParameterType1& param1)
153 {
154   if(actor)
155   {
156     Toolkit::GetImplementation(visual).SetOffScene(actor);
157   }
158   visual = Toolkit::VisualFactory::Get().CreateVisual(param0, param1);
159   if(visual && actor && actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
160   {
161     Toolkit::GetImplementation(visual).SetOnScene(actor);
162   }
163 }
164
165 /**
166  * @brief Template to allow discard old visual, get new one and set it on stage if possible
167  *
168  * @tparam ParameterType The type of argument passed to the CreateVisual()
169  * @SINCE_1_0.39
170  * @param[in] actor Actor for which the visual will be replaced
171  * @param[in,out] visual The visual to be replaced
172  * @param[in] param Template based argument passed to the visual factory
173  */
174 template<class ParameterType>
175 void InitializeVisual(Actor& actor, Toolkit::Visual::Base& visual, ParameterType& param)
176 {
177   if(actor && visual)
178   {
179     Toolkit::GetImplementation(visual).SetOffScene(actor);
180   }
181   visual = Toolkit::VisualFactory::Get().CreateVisual(param);
182   if(visual && actor && actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
183   {
184     Toolkit::GetImplementation(visual).SetOnScene(actor);
185   }
186 }
187
188 } // namespace Internal
189
190 inline const Internal::VisualFactory& GetImplementation(const Toolkit::VisualFactory& factory)
191 {
192   DALI_ASSERT_ALWAYS(factory && "VisualFactory handle is empty");
193
194   const BaseObject& handle = factory.GetBaseObject();
195
196   return static_cast<const Internal::VisualFactory&>(handle);
197 }
198
199 inline Internal::VisualFactory& GetImplementation(Toolkit::VisualFactory& factory)
200 {
201   DALI_ASSERT_ALWAYS(factory && "VisualFactory handle is empty");
202
203   BaseObject& handle = factory.GetBaseObject();
204
205   return static_cast<Internal::VisualFactory&>(handle);
206 }
207
208 } // namespace Toolkit
209
210 } // namespace Dali
211
212 #endif /* DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H */