1 #ifndef DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H
2 #define DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/common/vector-wrapper.h>
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/integration-api/adaptor-framework/shader-precompiler.h>
26 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
27 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
28 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
29 #include <dali-toolkit/public-api/styling/style-manager.h>
37 class VisualFactoryCache;
38 class ImageVisualShaderFactory;
39 class TextVisualShaderFactory;
42 * @copydoc Toolkit::VisualFactory
44 class VisualFactory : public BaseObject
50 * @param[in] debugEnabled If true, use debug renderer to replace all the concrete renderer.
52 VisualFactory(bool debugEnabled);
55 * @brief StyleChanged callback
57 * @param[in] styleManager Handle for style manager.
58 * @param[in] type Style change type.
60 void OnStyleChangedSignal(Toolkit::StyleManager styleManager, StyleChange::Type type);
63 * @brief BrokenImageChanged callback
65 * @param[in] styleManager Handle for style manager.
67 void OnBrokenImageChangedSignal(Toolkit::StyleManager styleManager);
70 * @copydoc Toolkit::VisualFactory::CreateVisual( const Property::Map& )
72 Toolkit::Visual::Base CreateVisual(const Property::Map& propertyMap);
75 * @copydoc Toolkit::VisualFactory::CreateVisual( const std::string&, ImageDimensions )
77 Toolkit::Visual::Base CreateVisual(const std::string& image, ImageDimensions size);
80 * @copydoc Toolkit::VisualFactory::SetPreMultiplyOnLoad()
82 void SetPreMultiplyOnLoad(bool preMultiply);
85 * @copydoc Toolkit::VisualFactory::GetPreMultiplyOnLoad()
87 bool GetPreMultiplyOnLoad() const;
90 * @copydoc Toolkit::VisualFactory::DiscardVisual()
92 void DiscardVisual(Toolkit::Visual::Base visual);
95 * @copydoc Toolkit::VisualFactory::UsePreCompiledShader()
97 void UsePreCompiledShader();
100 * @return the reference to texture manager
102 Internal::TextureManager& GetTextureManager();
106 * A reference counted object may only be deleted by calling Unreference()
108 ~VisualFactory() override;
112 * @brief Set the Broken Image url
113 * @param[in] styleManager The instance of StyleManager
115 void SetBrokenImageUrl(Toolkit::StyleManager& styleManager);
118 * @brief Get the default shader source.
119 * @param[in] shaders shaderList for precompile
121 void GetPreCompiledShader(RawShaderData& shaders);
124 * Get the factory cache, creating it if necessary.
126 Internal::VisualFactoryCache& GetFactoryCache();
129 * Get the image visual shader factory, creating it if necessary.
131 ImageVisualShaderFactory& GetImageVisualShaderFactory();
134 * Get the text visual shader factory, creating it if necessary.
136 TextVisualShaderFactory& GetTextVisualShaderFactory();
139 * @brief Callbacks called for clear discarded visuals.
141 void OnDiscardCallback();
144 * @brief Register idle callback for discard visuals if need.
146 void RegisterDiscardCallback();
148 VisualFactory(const VisualFactory&) = delete;
150 VisualFactory& operator=(const VisualFactory& rhs) = delete;
153 std::unique_ptr<VisualFactoryCache> mFactoryCache;
154 std::unique_ptr<ImageVisualShaderFactory> mImageVisualShaderFactory;
155 std::unique_ptr<TextVisualShaderFactory> mTextVisualShaderFactory;
156 SlotDelegate<VisualFactory> mSlotDelegate;
157 CallbackBase* mIdleCallback;
158 using DiscardedVisualContainer = std::vector<Toolkit::Visual::Base>;
159 DiscardedVisualContainer mDiscardedVisuals{};
160 bool mDebugEnabled : 1;
161 bool mPreMultiplyOnLoad : 1; ///< Local store for this flag
162 bool mPrecompiledShaderRequested : 1;
166 * @brief Template to allow discard old visual, get new one and set it on stage if possible
168 * @tparam ParameterType0 The type of first argument passed to the CreateVisual()
169 * @tparam ParameterType1 The type of second argument passed to the CreateVisual()
171 * @param[in] actor Actor for which the visual will be replaced
172 * @param[in,out] visual The visual to be replaced
173 * @param[in] param0 First template based argument passed to the visual factory
174 * @param[in] param1 Second template based argument passed to the visual factory
176 template<class ParameterType0, class ParameterType1>
177 void InitializeVisual(Actor& actor, Toolkit::Visual::Base& visual, ParameterType0& param0, ParameterType1& param1)
181 Toolkit::GetImplementation(visual).SetOffScene(actor);
183 visual = Toolkit::VisualFactory::Get().CreateVisual(param0, param1);
184 if(visual && actor && actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
186 Toolkit::GetImplementation(visual).SetOnScene(actor);
191 * @brief Template to allow discard old visual, get new one and set it on stage if possible
193 * @tparam ParameterType The type of argument passed to the CreateVisual()
195 * @param[in] actor Actor for which the visual will be replaced
196 * @param[in,out] visual The visual to be replaced
197 * @param[in] param Template based argument passed to the visual factory
199 template<class ParameterType>
200 void InitializeVisual(Actor& actor, Toolkit::Visual::Base& visual, ParameterType& param)
204 Toolkit::GetImplementation(visual).SetOffScene(actor);
206 visual = Toolkit::VisualFactory::Get().CreateVisual(param);
207 if(visual && actor && actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
209 Toolkit::GetImplementation(visual).SetOnScene(actor);
213 } // namespace Internal
215 inline const Internal::VisualFactory& GetImplementation(const Toolkit::VisualFactory& factory)
217 DALI_ASSERT_ALWAYS(factory && "VisualFactory handle is empty");
219 const BaseObject& handle = factory.GetBaseObject();
221 return static_cast<const Internal::VisualFactory&>(handle);
224 inline Internal::VisualFactory& GetImplementation(Toolkit::VisualFactory& factory)
226 DALI_ASSERT_ALWAYS(factory && "VisualFactory handle is empty");
228 BaseObject& handle = factory.GetBaseObject();
230 return static_cast<Internal::VisualFactory&>(handle);
233 } // namespace Toolkit
237 #endif /* DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H */