1 #ifndef DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H
5 * Copyright (c) 2019 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>
40 class ImageVisualShaderFactory;
42 typedef IntrusivePtr< SvgVisual > SvgVisualPtr;
45 * The visual which renders a svg image
47 * The following property is essential
49 * | %Property Name | Type |
50 * |--------------------------|------------------|
54 class SvgVisual: public Visual::Base
59 * @brief Create the SVG Visual using the image URL.
61 * The visual will parse the SVG image once it is set.
62 * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
64 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
65 * @param[in] shaderFactory The ImageVisualShaderFactory object
66 * @param[in] imageUrl The URL to svg resource to use
67 * @param[in] properties A Property::Map containing settings for this visual
68 * @return A smart-pointer to the newly allocated visual.
70 static SvgVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties );
73 * @brief Create the SVG Visual using the image URL.
75 * The visual will parse the SVG image once it is set.
76 * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
78 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
79 * @param[in] shaderFactory The ImageVisualShaderFactory object
80 * @param[in] imageUrl The URL to svg resource to use
81 * @return A smart-pointer to the newly allocated visual.
83 static SvgVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
85 public: // from Visual
88 * @copydoc Visual::Base::GetNaturalSize
90 void GetNaturalSize( Vector2& naturalSize ) override;
93 * @copydoc Visual::Base::CreatePropertyMap
95 void DoCreatePropertyMap( Property::Map& map ) const override;
98 * @copydoc Visual::Base::CreateInstancePropertyMap
100 void DoCreateInstancePropertyMap( Property::Map& map ) const override;
105 * @brief Constructor.
107 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
108 * @param[in] shaderFactory The ImageVisualShaderFactory object
110 SvgVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory );
113 * @brief A reference counted object may only be deleted by calling Unreference().
115 virtual ~SvgVisual();
118 * @copydoc Visual::Base::DoSetProperties
120 void DoSetProperties( const Property::Map& propertyMap ) override;
123 * @copydoc Visual::Base::DoSetOnStage
125 void DoSetOnStage( Actor& actor ) override;
128 * @copydoc Visual::Base::DoSetOffStage
130 void DoSetOffStage( Actor& actor ) override;
133 * @copydoc Visual::Base::OnSetTransform
135 void OnSetTransform() override;
140 * @bried Apply the rasterized image to the visual.
142 * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
144 void ApplyRasterizedImage( PixelData rasterizedPixelData );
149 * @brief Parses the SVG Image from the set URL.
151 * @param[in] imageUrl The URL of the image to parse the SVG from.
153 void ParseFromUrl( const VisualUrl& imageUrl );
156 * @bried Rasterize the svg with the given size, and add it to the visual.
158 * @param[in] size The target size of the SVG rasterization.
160 void AddRasterizationTask( const Vector2& size );
163 * Helper method to set individual values by index key.
164 * @param[in] index The index key of the value
165 * @param[in] value The value
167 void DoSetProperty( Property::Index index, const Property::Value& value );
171 SvgVisual( const SvgVisual& svgRenderer );
174 SvgVisual& operator=( const SvgVisual& svgRenderer );
177 ImageVisualShaderFactory& mImageVisualShaderFactory;
180 NSVGimage* mParsedImage;
181 WeakHandle<Actor> mPlacementActor;
183 bool mAttemptAtlasing; ///< If true will attempt atlasing, otherwise create unique texture
186 } // namespace Internal
188 } // namespace Toolkit
192 #endif /* DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H */