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>
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>
36 class VisualFactoryCache;
37 class ImageVisualShaderFactory;
38 class TextVisualShaderFactory;
41 * @copydoc Toolkit::VisualFactory
43 class VisualFactory : public BaseObject
49 * @param[in] debugEnabled If true, use debug renderer to replace all the concrete renderer.
51 VisualFactory(bool debugEnabled);
54 * @brief StyleChanged callback
56 * @param[in] styleManager Handle for style manager.
57 * @param[in] type Style change type.
59 void OnStyleChangedSignal(Toolkit::StyleManager styleManager, StyleChange::Type type);
62 * @brief BrokenImageChanged callback
64 * @param[in] styleManager Handle for style manager.
66 void OnBrokenImageChangedSignal(Toolkit::StyleManager styleManager);
69 * @copydoc Toolkit::VisualFactory::CreateVisual( const Property::Map& )
71 Toolkit::Visual::Base CreateVisual(const Property::Map& propertyMap);
74 * @copydoc Toolkit::VisualFactory::CreateVisual( const std::string&, ImageDimensions )
76 Toolkit::Visual::Base CreateVisual(const std::string& image, ImageDimensions size);
79 * @copydoc Toolkit::VisualFactory::SetPreMultiplyOnLoad()
81 void SetPreMultiplyOnLoad(bool preMultiply);
84 * @copydoc Toolkit::VisualFactory::GetPreMultiplyOnLoad()
86 bool GetPreMultiplyOnLoad() const;
89 * @copydoc Toolkit::VisualFactory::DiscardVisual()
91 void DiscardVisual(Toolkit::Visual::Base visual);
94 * @return the reference to texture manager
96 Internal::TextureManager& GetTextureManager();
100 * A reference counted object may only be deleted by calling Unreference()
102 ~VisualFactory() override;
106 * @brief Set the Broken Image url
107 * @param[in] styleManager The instance of StyleManager
109 void SetBrokenImageUrl(Toolkit::StyleManager& styleManager);
112 * Get the factory cache, creating it if necessary.
114 Internal::VisualFactoryCache& GetFactoryCache();
117 * Get the image visual shader factory, creating it if necessary.
119 ImageVisualShaderFactory& GetImageVisualShaderFactory();
122 * Get the text visual shader factory, creating it if necessary.
124 TextVisualShaderFactory& GetTextVisualShaderFactory();
127 * @brief Callbacks called for clear discarded visuals.
129 void OnDiscardCallback();
132 * @brief Register idle callback for discard visuals if need.
134 void RegisterDiscardCallback();
136 VisualFactory(const VisualFactory&) = delete;
138 VisualFactory& operator=(const VisualFactory& rhs) = delete;
141 std::unique_ptr<VisualFactoryCache> mFactoryCache;
142 std::unique_ptr<ImageVisualShaderFactory> mImageVisualShaderFactory;
143 std::unique_ptr<TextVisualShaderFactory> mTextVisualShaderFactory;
144 SlotDelegate<VisualFactory> mSlotDelegate;
145 CallbackBase* mIdleCallback;
147 using DiscardedVisualContainer = std::vector<Toolkit::Visual::Base>;
148 DiscardedVisualContainer mDiscardedVisuals{};
150 bool mDebugEnabled : 1;
151 bool mPreMultiplyOnLoad : 1; ///< Local store for this flag
155 * @brief Template to allow discard old visual, get new one and set it on stage if possible
157 * @tparam ParameterType0 The type of first argument passed to the CreateVisual()
158 * @tparam ParameterType1 The type of second argument passed to the CreateVisual()
160 * @param[in] actor Actor for which the visual will be replaced
161 * @param[in,out] visual The visual to be replaced
162 * @param[in] param0 First template based argument passed to the visual factory
163 * @param[in] param1 Second template based argument passed to the visual factory
165 template<class ParameterType0, class ParameterType1>
166 void InitializeVisual(Actor& actor, Toolkit::Visual::Base& visual, ParameterType0& param0, ParameterType1& param1)
170 Toolkit::GetImplementation(visual).SetOffScene(actor);
172 visual = Toolkit::VisualFactory::Get().CreateVisual(param0, param1);
173 if(visual && actor && actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
175 Toolkit::GetImplementation(visual).SetOnScene(actor);
180 * @brief Template to allow discard old visual, get new one and set it on stage if possible
182 * @tparam ParameterType The type of argument passed to the CreateVisual()
184 * @param[in] actor Actor for which the visual will be replaced
185 * @param[in,out] visual The visual to be replaced
186 * @param[in] param Template based argument passed to the visual factory
188 template<class ParameterType>
189 void InitializeVisual(Actor& actor, Toolkit::Visual::Base& visual, ParameterType& param)
193 Toolkit::GetImplementation(visual).SetOffScene(actor);
195 visual = Toolkit::VisualFactory::Get().CreateVisual(param);
196 if(visual && actor && actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
198 Toolkit::GetImplementation(visual).SetOnScene(actor);
202 } // namespace Internal
204 inline const Internal::VisualFactory& GetImplementation(const Toolkit::VisualFactory& factory)
206 DALI_ASSERT_ALWAYS(factory && "VisualFactory handle is empty");
208 const BaseObject& handle = factory.GetBaseObject();
210 return static_cast<const Internal::VisualFactory&>(handle);
213 inline Internal::VisualFactory& GetImplementation(Toolkit::VisualFactory& factory)
215 DALI_ASSERT_ALWAYS(factory && "VisualFactory handle is empty");
217 BaseObject& handle = factory.GetBaseObject();
219 return static_cast<Internal::VisualFactory&>(handle);
222 } // namespace Toolkit
226 #endif /* DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H */