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/integration-api/shader-precompiler.h>
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/base-object.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 * Get the factory cache, creating it if necessary.
120 Internal::VisualFactoryCache& GetFactoryCache();
123 * Get the image visual shader factory, creating it if necessary.
125 ImageVisualShaderFactory& GetImageVisualShaderFactory();
128 * Get the text visual shader factory, creating it if necessary.
130 TextVisualShaderFactory& GetTextVisualShaderFactory();
133 * @brief Callbacks called for clear discarded visuals.
135 void OnDiscardCallback();
138 * @brief Register idle callback for discard visuals if need.
140 void RegisterDiscardCallback();
142 VisualFactory(const VisualFactory&) = delete;
144 VisualFactory& operator=(const VisualFactory& rhs) = delete;
147 std::unique_ptr<VisualFactoryCache> mFactoryCache;
148 std::unique_ptr<ImageVisualShaderFactory> mImageVisualShaderFactory;
149 std::unique_ptr<TextVisualShaderFactory> mTextVisualShaderFactory;
150 SlotDelegate<VisualFactory> mSlotDelegate;
151 CallbackBase* mIdleCallback;
153 using DiscardedVisualContainer = std::vector<Toolkit::Visual::Base>;
154 DiscardedVisualContainer mDiscardedVisuals{};
156 bool mDebugEnabled : 1;
157 bool mPreMultiplyOnLoad : 1; ///< Local store for this flag
158 bool mPrecompiledShaderRequested{false};
162 * @brief Template to allow discard old visual, get new one and set it on stage if possible
164 * @tparam ParameterType0 The type of first argument passed to the CreateVisual()
165 * @tparam ParameterType1 The type of second argument passed to the CreateVisual()
167 * @param[in] actor Actor for which the visual will be replaced
168 * @param[in,out] visual The visual to be replaced
169 * @param[in] param0 First template based argument passed to the visual factory
170 * @param[in] param1 Second template based argument passed to the visual factory
172 template<class ParameterType0, class ParameterType1>
173 void InitializeVisual(Actor& actor, Toolkit::Visual::Base& visual, ParameterType0& param0, ParameterType1& param1)
177 Toolkit::GetImplementation(visual).SetOffScene(actor);
179 visual = Toolkit::VisualFactory::Get().CreateVisual(param0, param1);
180 if(visual && actor && actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
182 Toolkit::GetImplementation(visual).SetOnScene(actor);
187 * @brief Template to allow discard old visual, get new one and set it on stage if possible
189 * @tparam ParameterType The type of argument passed to the CreateVisual()
191 * @param[in] actor Actor for which the visual will be replaced
192 * @param[in,out] visual The visual to be replaced
193 * @param[in] param Template based argument passed to the visual factory
195 template<class ParameterType>
196 void InitializeVisual(Actor& actor, Toolkit::Visual::Base& visual, ParameterType& param)
200 Toolkit::GetImplementation(visual).SetOffScene(actor);
202 visual = Toolkit::VisualFactory::Get().CreateVisual(param);
203 if(visual && actor && actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
205 Toolkit::GetImplementation(visual).SetOnScene(actor);
209 } // namespace Internal
211 inline const Internal::VisualFactory& GetImplementation(const Toolkit::VisualFactory& factory)
213 DALI_ASSERT_ALWAYS(factory && "VisualFactory handle is empty");
215 const BaseObject& handle = factory.GetBaseObject();
217 return static_cast<const Internal::VisualFactory&>(handle);
220 inline Internal::VisualFactory& GetImplementation(Toolkit::VisualFactory& factory)
222 DALI_ASSERT_ALWAYS(factory && "VisualFactory handle is empty");
224 BaseObject& handle = factory.GetBaseObject();
226 return static_cast<Internal::VisualFactory&>(handle);
229 } // namespace Toolkit
233 #endif /* DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H */