1 #ifndef DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H
5 * Copyright (c) 2022 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.
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/object/weak-handle.h>
26 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
27 #include <dali-toolkit/internal/visuals/visual-url.h>
28 #include <dali-toolkit/internal/visuals/svg/svg-task.h>
36 class ImageVisualShaderFactory;
38 typedef IntrusivePtr<SvgVisual> SvgVisualPtr;
41 * The visual which renders a svg image
43 * The following property is essential
45 * | %Property Name | Type |
46 * |--------------------------|------------------|
50 class SvgVisual : public Visual::Base
54 * @brief Create the SVG Visual using the image URL.
56 * The visual will parse the SVG image once it is set.
57 * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
59 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
60 * @param[in] shaderFactory The ImageVisualShaderFactory object
61 * @param[in] imageUrl The URL to svg resource to use
62 * @param[in] properties A Property::Map containing settings for this visual
63 * @return A smart-pointer to the newly allocated visual.
65 static SvgVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties);
68 * @brief Create the SVG Visual using the image URL.
70 * The visual will parse the SVG image once it is set.
71 * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
73 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
74 * @param[in] shaderFactory The ImageVisualShaderFactory object
75 * @param[in] imageUrl The URL to svg resource to use
76 * @param[in] size The width and height of the rasterized buffer. The visual size will be used if these are 0.
77 * @return A smart-pointer to the newly allocated visual.
79 static SvgVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size = ImageDimensions());
81 public: // from Visual
83 * @copydoc Visual::Base::GetNaturalSize
85 void GetNaturalSize(Vector2& naturalSize) override;
88 * @copydoc Visual::Base::CreatePropertyMap
90 void DoCreatePropertyMap(Property::Map& map) const override;
93 * @copydoc Visual::Base::CreateInstancePropertyMap
95 void DoCreateInstancePropertyMap(Property::Map& map) const override;
98 * @copydoc Visual::Base::EnablePreMultipliedAlpha
100 void EnablePreMultipliedAlpha(bool preMultiplied) override;
104 * @brief Constructor.
106 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
107 * @param[in] shaderFactory The ImageVisualShaderFactory object
108 * @param[in] imageUrl The URL to svg resource to use
109 * @param[in] size The width and height of the rasterized buffer. The visual size will be used if these are 0.
111 SvgVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size);
114 * @brief A reference counted object may only be deleted by calling Unreference().
116 virtual ~SvgVisual();
119 * @copydoc Visual::Base::OnInitialize
121 void OnInitialize() override;
124 * @copydoc Visual::Base::DoSetProperties
126 void DoSetProperties(const Property::Map& propertyMap) override;
129 * @copydoc Visual::Base::DoSetOnScene
131 void DoSetOnScene(Actor& actor) override;
134 * @copydoc Visual::Base::DoSetOffScene
136 void DoSetOffScene(Actor& actor) override;
139 * @copydoc Visual::Base::OnSetTransform
141 void OnSetTransform() override;
144 * @copydoc Visual::Base::UpdateShader
146 void UpdateShader() override;
149 * @copydoc Visual::Base::GenerateShader
151 Shader GenerateShader() const override;
155 * @bried Apply the rasterized image to the visual.
157 * @param[in] task SvgTaskPtr
159 void ApplyRasterizedImage(SvgTaskPtr task);
163 * @bried Rasterize the svg with the given size, and add it to the visual.
165 * @param[in] size The target size of the SVG rasterization.
167 void AddRasterizationTask(const Vector2& size);
170 * Helper method to set individual values by index key.
171 * @param[in] index The index key of the value
172 * @param[in] value The value
174 void DoSetProperty(Property::Index index, const Property::Value& value);
177 SvgVisual(const SvgVisual& svgRenderer);
180 SvgVisual& operator=(const SvgVisual& svgRenderer);
183 ImageVisualShaderFactory& mImageVisualShaderFactory;
186 VectorImageRenderer mVectorRenderer;
187 uint32_t mDefaultWidth;
188 uint32_t mDefaultHeight;
189 WeakHandle<Actor> mPlacementActor;
190 Vector2 mRasterizedSize;
191 Dali::ImageDimensions mDesiredSize{};
192 SvgTaskPtr mLoadingTask;
193 SvgTaskPtr mRasterizingTask;
195 bool mAttemptAtlasing; ///< If true will attempt atlasing, otherwise create unique texture
198 } // namespace Internal
200 } // namespace Toolkit
204 #endif /* DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H */