1 #ifndef DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H
2 #define DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H
5 * Copyright (c) 2021 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/object/base-object.h>
24 #include <dali-toolkit/devel-api/styling/style-manager-devel.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;
40 * @copydoc Toolkit::VisualFactory
42 class VisualFactory : public BaseObject
48 * @param[in] debugEnabled If true, use debug renderer to replace all the concrete renderer.
50 VisualFactory(bool debugEnabled);
53 * @brief StyleChanged callback
55 * @param[in] styleManager Handle for style manager.
56 * @param[in] type Style change type.
58 void OnStyleChangedSignal(Toolkit::StyleManager styleManager, StyleChange::Type type);
61 * @copydoc Toolkit::VisualFactory::CreateVisual( const Property::Map& )
63 Toolkit::Visual::Base CreateVisual(const Property::Map& propertyMap);
66 * @copydoc Toolkit::VisualFactory::CreateVisual( const std::string&, ImageDimensions )
68 Toolkit::Visual::Base CreateVisual(const std::string& image, ImageDimensions size);
71 * @copydoc Toolkit::VisualFactory::SetPreMultiplyOnLoad()
73 void SetPreMultiplyOnLoad(bool preMultiply);
76 * @copydoc Toolkit::VisualFactory::GetPreMultiplyOnLoad()
78 bool GetPreMultiplyOnLoad() const;
81 * @return the reference to texture manager
83 Internal::TextureManager& GetTextureManager();
87 * A reference counted object may only be deleted by calling Unreference()
89 ~VisualFactory() override;
93 * Get the factory cache, creating it if necessary.
95 Internal::VisualFactoryCache& GetFactoryCache();
98 * Get the image visual shader factory, creating it if necessary.
100 ImageVisualShaderFactory& GetImageVisualShaderFactory();
102 VisualFactory(const VisualFactory&) = delete;
104 VisualFactory& operator=(const VisualFactory& rhs) = delete;
107 std::unique_ptr<VisualFactoryCache> mFactoryCache;
108 std::unique_ptr<ImageVisualShaderFactory> mImageVisualShaderFactory;
109 SlotDelegate<VisualFactory> mSlotDelegate;
110 bool mDebugEnabled : 1;
111 bool mPreMultiplyOnLoad : 1; ///< Local store for this flag
115 * @brief Template to allow discard old visual, get new one and set it on stage if possible
117 * @tparam ParameterType0 The type of first argument passed to the CreateVisual()
118 * @tparam ParameterType1 The type of second argument passed to the CreateVisual()
120 * @param[in] actor Actor for which the visual will be replaced
121 * @param[in,out] visual The visual to be replaced
122 * @param[in] param0 First template based argument passed to the visual factory
123 * @param[in] param1 Second template based argument passed to the visual factory
125 template<class ParameterType0, class ParameterType1>
126 void InitializeVisual(Actor& actor, Toolkit::Visual::Base& visual, ParameterType0& param0, ParameterType1& param1)
130 Toolkit::GetImplementation(visual).SetOffScene(actor);
132 visual = Toolkit::VisualFactory::Get().CreateVisual(param0, param1);
133 if(visual && actor && actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
135 Toolkit::GetImplementation(visual).SetOnScene(actor);
140 * @brief Template to allow discard old visual, get new one and set it on stage if possible
142 * @tparam ParameterType The type of argument passed to the CreateVisual()
144 * @param[in] actor Actor for which the visual will be replaced
145 * @param[in,out] visual The visual to be replaced
146 * @param[in] param Template based argument passed to the visual factory
148 template<class ParameterType>
149 void InitializeVisual(Actor& actor, Toolkit::Visual::Base& visual, ParameterType& param)
153 Toolkit::GetImplementation(visual).SetOffScene(actor);
155 visual = Toolkit::VisualFactory::Get().CreateVisual(param);
156 if(visual && actor && actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
158 Toolkit::GetImplementation(visual).SetOnScene(actor);
162 } // namespace Internal
164 inline const Internal::VisualFactory& GetImplementation(const Toolkit::VisualFactory& factory)
166 DALI_ASSERT_ALWAYS(factory && "VisualFactory handle is empty");
168 const BaseObject& handle = factory.GetBaseObject();
170 return static_cast<const Internal::VisualFactory&>(handle);
173 inline Internal::VisualFactory& GetImplementation(Toolkit::VisualFactory& factory)
175 DALI_ASSERT_ALWAYS(factory && "VisualFactory handle is empty");
177 BaseObject& handle = factory.GetBaseObject();
179 return static_cast<Internal::VisualFactory&>(handle);
182 } // namespace Toolkit
186 #endif /* DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H */