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>
35 class ImageVisualShaderFactory;
37 typedef IntrusivePtr<SvgVisual> SvgVisualPtr;
40 * The visual which renders a svg image
42 * The following property is essential
44 * | %Property Name | Type |
45 * |--------------------------|------------------|
49 class SvgVisual : public Visual::Base
53 * @brief Create the SVG Visual using the image URL.
55 * The visual will parse the SVG image once it is set.
56 * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
58 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
59 * @param[in] shaderFactory The ImageVisualShaderFactory object
60 * @param[in] imageUrl The URL to svg resource to use
61 * @param[in] properties A Property::Map containing settings for this visual
62 * @return A smart-pointer to the newly allocated visual.
64 static SvgVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties);
67 * @brief Create the SVG Visual using the image URL.
69 * The visual will parse the SVG image once it is set.
70 * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
72 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
73 * @param[in] shaderFactory The ImageVisualShaderFactory object
74 * @param[in] imageUrl The URL to svg resource to use
75 * @return A smart-pointer to the newly allocated visual.
77 static SvgVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl);
79 public: // from Visual
81 * @copydoc Visual::Base::GetNaturalSize
83 void GetNaturalSize(Vector2& naturalSize) override;
86 * @copydoc Visual::Base::CreatePropertyMap
88 void DoCreatePropertyMap(Property::Map& map) const override;
91 * @copydoc Visual::Base::CreateInstancePropertyMap
93 void DoCreateInstancePropertyMap(Property::Map& map) const override;
96 * @copydoc Visual::Base::EnablePreMultipliedAlpha
98 void EnablePreMultipliedAlpha(bool preMultiplied) override;
102 * @brief Constructor.
104 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
105 * @param[in] shaderFactory The ImageVisualShaderFactory object
106 * @param[in] imageUrl The URL to svg resource to use
108 SvgVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl);
111 * @brief A reference counted object may only be deleted by calling Unreference().
113 virtual ~SvgVisual();
116 * @copydoc Visual::Base::OnInitialize
118 void OnInitialize() override;
121 * @copydoc Visual::Base::DoSetProperties
123 void DoSetProperties(const Property::Map& propertyMap) override;
126 * @copydoc Visual::Base::DoSetOnScene
128 void DoSetOnScene(Actor& actor) override;
131 * @copydoc Visual::Base::DoSetOffScene
133 void DoSetOffScene(Actor& actor) override;
136 * @copydoc Visual::Base::OnSetTransform
138 void OnSetTransform() override;
141 * @copydoc Visual::Base::UpdateShader
143 void UpdateShader() override;
146 * @copydoc Visual::Base::GenerateShader
148 Shader GenerateShader() const override;
152 * @bried Apply the rasterized image to the visual.
154 * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
155 * @param[in] success Whether the task succeeds.
157 void ApplyRasterizedImage(PixelData rasterizedPixelData, bool success);
161 * @bried Rasterize the svg with the given size, and add it to the visual.
163 * @param[in] size The target size of the SVG rasterization.
165 void AddRasterizationTask(const Vector2& size);
168 * Helper method to set individual values by index key.
169 * @param[in] index The index key of the value
170 * @param[in] value The value
172 void DoSetProperty(Property::Index index, const Property::Value& value);
175 SvgVisual(const SvgVisual& svgRenderer);
178 SvgVisual& operator=(const SvgVisual& svgRenderer);
181 ImageVisualShaderFactory& mImageVisualShaderFactory;
184 VectorImageRenderer mVectorRenderer;
185 uint32_t mDefaultWidth;
186 uint32_t mDefaultHeight;
187 WeakHandle<Actor> mPlacementActor;
188 Vector2 mRasterizedSize;
190 bool mAttemptAtlasing; ///< If true will attempt atlasing, otherwise create unique texture
193 } // namespace Internal
195 } // namespace Toolkit
199 #endif /* DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H */