X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fsvg%2Fsvg-visual.h;h=0f1dc95674834680d9af55c1627f1237e9848581;hp=c040f4753c145167a05d48e21e0ddccc141be04f;hb=8bb92d7d1170f2ddf59da60bd3588be601ef8cd2;hpb=d6fead18ff8cc7fca3feb1aa1789e47583796814 diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.h b/dali-toolkit/internal/visuals/svg/svg-visual.h index c040f47..0f1dc95 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.h +++ b/dali-toolkit/internal/visuals/svg/svg-visual.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,13 +18,17 @@ * */ -//EXTERNAL INCLUDES -#include +// EXTERNAL INCLUDES +#include +#include // INTERNAL INCLUDES #include +#include +#ifdef NO_THORVG struct NSVGimage; +#endif /* NO_THORVG */ namespace Dali { @@ -35,6 +39,10 @@ namespace Toolkit namespace Internal { +class ImageVisualShaderFactory; +class SvgVisual; +typedef IntrusivePtr< SvgVisual > SvgVisualPtr; + /** * The visual which renders a svg image * @@ -50,80 +58,126 @@ class SvgVisual: public Visual::Base public: /** - * @brief Constructor. + * @brief Create the SVG Visual using the image URL. + * + * The visual will parse the SVG image once it is set. + * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @param[in] shaderFactory The ImageVisualShaderFactory object + * @param[in] imageUrl The URL to svg resource to use + * @param[in] properties A Property::Map containing settings for this visual + * @return A smart-pointer to the newly allocated visual. */ - SvgVisual( VisualFactoryCache& factoryCache ); + static SvgVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties ); /** - * @brief A reference counted object may only be deleted by calling Unreference(). + * @brief Create the SVG Visual using the image URL. + * + * The visual will parse the SVG image once it is set. + * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @param[in] shaderFactory The ImageVisualShaderFactory object + * @param[in] imageUrl The URL to svg resource to use + * @return A smart-pointer to the newly allocated visual. */ - ~SvgVisual(); + static SvgVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl ); public: // from Visual /** * @copydoc Visual::Base::GetNaturalSize */ - virtual void GetNaturalSize( Vector2& naturalSize ) const; + void GetNaturalSize( Vector2& naturalSize ) override; /** - * @copydoc Visual::Base::SetSize + * @copydoc Visual::Base::CreatePropertyMap */ - virtual void SetSize( const Vector2& size ); + void DoCreatePropertyMap( Property::Map& map ) const override; /** - * @copydoc Visual::Base::CreatePropertyMap + * @copydoc Visual::Base::CreateInstancePropertyMap */ - virtual void DoCreatePropertyMap( Property::Map& map ) const; + void DoCreateInstancePropertyMap( Property::Map& map ) const override; + +protected: /** - * @copydoc Visual::Base::DoSetProperty + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @param[in] shaderFactory The ImageVisualShaderFactory object + * @param[in] imageUrl The URL to svg resource to use */ - virtual void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue ); + SvgVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl ); /** - * @copydoc Visual::Base::DoGetProperty + * @brief A reference counted object may only be deleted by calling Unreference(). */ - virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index ); + virtual ~SvgVisual(); -protected: + /** + * @copydoc Visual::Base::DoSetProperties + */ + void DoSetProperties( const Property::Map& propertyMap ) override; /** - * @copydoc Visual::Base::DoInitialize + * @copydoc Visual::Base::DoSetOnScene */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); + void DoSetOnScene( Actor& actor ) override; /** - * @copydoc Visual::Base::DoSetOnStage + * @copydoc Visual::Base::DoSetOffScene */ - virtual void DoSetOnStage( Actor& actor ); + void DoSetOffScene( Actor& actor ) override; /** - * @copydoc Visual::Base::DoSetOffStage + * @copydoc Visual::Base::OnSetTransform */ - virtual void DoSetOffStage( Actor& actor ); + void OnSetTransform() override; + + /** + * @copydoc Visual::Base::IsResourceReady + */ + bool IsResourceReady() const override; public: +#ifdef NO_THORVG /** - * @brief Sets the svg image of this visual to the resource at imageUrl - * The visual will parse the svg image once it is set. - * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage + * @bried Apply the rasterized image to the visual. * - * @param[in] imageUrl The URL to svg resource to use + * @param[in] parsedSvg The data of parsed image. + * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels */ - void SetImage( const std::string& imageUrl, ImageDimensions size = ImageDimensions() ); - + void ApplyRasterizedImage( NSVGimage* parsedSvg, PixelData rasterizedPixelData ); +#else /* NO_THORVG */ /** * @bried Apply the rasterized image to the visual. * + * @param[in] vectorImage The data of vector image. * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels + * @param[in] bool Whether the resource is loaded */ - void ApplyRasterizedImage( PixelData rasterizedPixelData ); + void ApplyRasterizedImage( VectorImageRenderer vectorImage, PixelData rasterizedPixelData, bool isLoaded ); +#endif /* NO_THORVG */ private: +#ifdef NO_THORVG + /** + * @brief Parses the SVG Image from the set URL. + * + * @param[in] imageUrl The URL of the image to parse the SVG from. + */ + void ParseFromUrl( const VisualUrl& imageUrl ); +#else /* NO_THORVG */ + /** + * @brief Load the SVG Image from the set URL. + */ + void Load(); +#endif /* NO_THORVG */ + /** * @bried Rasterize the svg with the given size, and add it to the visual. * @@ -131,6 +185,12 @@ private: */ void AddRasterizationTask( const Vector2& size ); + /** + * Helper method to set individual values by index key. + * @param[in] index The index key of the value + * @param[in] value The value + */ + void DoSetProperty( Property::Index index, const Property::Value& value ); // Undefined SvgVisual( const SvgVisual& svgRenderer ); @@ -139,11 +199,21 @@ private: SvgVisual& operator=( const SvgVisual& svgRenderer ); private: - Vector4 mAtlasRect; - std::string mImageUrl; - NSVGimage* mParsedImage; - WeakHandle mPlacementActor; - + ImageVisualShaderFactory& mImageVisualShaderFactory; + Vector4 mAtlasRect; + VisualUrl mImageUrl; +#ifdef NO_THORVG + NSVGimage* mParsedImage; +#else /* NO_THORVG */ + VectorImageRenderer mVectorRenderer; + uint32_t mDefaultWidth; + uint32_t mDefaultHeight; + bool mLoaded; + bool mLocalResource; +#endif /* NO_THORVG */ + WeakHandle mPlacementActor; + Vector2 mVisualSize; + bool mAttemptAtlasing; ///< If true will attempt atlasing, otherwise create unique texture }; } // namespace Internal