From e7229b4d17bab7395474229f3b209e42dc3ca9fa Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Mon, 17 Oct 2016 16:26:26 +0100 Subject: [PATCH] (Visuals) Remove dead code & redundant Get prefix to check if on stage or from the cache - SetImage always called on initialisation now so checking if we have a renderer is not needed Change-Id: I5f767a3a4065af7992eda6329c2a1436583a4114 --- .../src/dali-toolkit/utc-Dali-Visual.cpp | 6 + .../internal/visuals/image/image-visual.cpp | 225 +++++++-------------- dali-toolkit/internal/visuals/image/image-visual.h | 57 +++--- .../internal/visuals/npatch/npatch-visual.cpp | 87 +++----- .../internal/visuals/npatch/npatch-visual.h | 39 ++-- dali-toolkit/internal/visuals/svg/svg-visual.cpp | 53 ++--- dali-toolkit/internal/visuals/svg/svg-visual.h | 29 ++- dali-toolkit/internal/visuals/visual-base-impl.cpp | 6 +- dali-toolkit/internal/visuals/visual-base-impl.h | 5 +- .../internal/visuals/visual-factory-impl.cpp | 21 +- 10 files changed, 218 insertions(+), 310 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index 577213d..c329ccc 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp @@ -188,6 +188,12 @@ int UtcDaliVisualSize(void) // DALI_TEST_EQUALS( naturalSize, Vector2(100.f, 100.f), TEST_LOCATION ); + // svg visual with a size + Visual::Base svgVisual2 = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions(200, 200) ); + DALI_TEST_EQUALS( svgVisual2.GetSize(), Vector2( 200.f, 200.f ), TEST_LOCATION ); + svgVisual2.GetNaturalSize(naturalSize); + DALI_TEST_EQUALS( naturalSize, Vector2(100.f, 100.f), TEST_LOCATION ); // Natural size should still be 100, 100 + // Batch Image visual propertyMap.Clear(); propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index f4652dd..d9cb845 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -190,17 +190,69 @@ Geometry CreateGeometry( VisualFactoryCache& factoryCache, ImageDimensions gridS ImageVisual::ImageVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), + mImage(), + mPixels(), mPixelArea( FULL_TEXTURE_RECT ), + mPlacementActor(), + mImageUrl(), mDesiredSize(), mFittingMode( FittingMode::DEFAULT ), mSamplingMode( SamplingMode::DEFAULT ), mWrapModeU( WrapMode::DEFAULT ), mWrapModeV( WrapMode::DEFAULT ), - mNativeFragmentShaderCode( ), + mNativeFragmentShaderCode(), mNativeImageFlag( false ) { } +ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, + const std::string& imageUrl, + ImageDimensions size, + FittingMode::Type fittingMode, + Dali::SamplingMode::Type samplingMode ) +: Visual::Base( factoryCache ), + mImage(), + mPixels(), + mPixelArea( FULL_TEXTURE_RECT ), + mPlacementActor(), + mImageUrl( imageUrl ), + mDesiredSize( size ), + mFittingMode( fittingMode ), + mSamplingMode( samplingMode ), + mWrapModeU( WrapMode::DEFAULT ), + mWrapModeV( WrapMode::DEFAULT ), + mNativeFragmentShaderCode(), + mNativeImageFlag( false ) +{ +} + +ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, const Image& image ) +: Visual::Base( factoryCache ), + mImage( image ), + mPixels(), + mPixelArea( FULL_TEXTURE_RECT ), + mPlacementActor(), + mImageUrl(), + mDesiredSize(), + mFittingMode( FittingMode::DEFAULT ), + mSamplingMode( SamplingMode::DEFAULT ), + mWrapModeU( WrapMode::DEFAULT ), + mWrapModeV( WrapMode::DEFAULT ), + mNativeFragmentShaderCode(), + mNativeImageFlag( false ) +{ + NativeImage newNativeImage = NativeImage::DownCast( image ); + if( newNativeImage ) + { + SetNativeFragmentShaderCode( newNativeImage ); + mNativeImageFlag = true; + } + else + { + mNativeImageFlag = false; + } +} + ImageVisual::~ImageVisual() { } @@ -282,22 +334,9 @@ void ImageVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) // if sync loading is required, the loading should start immediately when new image url is set or the actor is off stage // ( for on-stage actor with image url unchanged, resource loading is already finished) - if( ( !mImpl->mRenderer || imageURLValue) && IsSynchronousResourceLoading() ) + if( imageURLValue && IsSynchronousResourceLoading() ) { - DoSynchronousResourceLoading(); - } - - // remove old renderer if exit - if( mImpl->mRenderer ) - { - if( actor ) //remove old renderer from actor - { - actor.RemoveRenderer( mImpl->mRenderer ); - } - if( !oldImageUrl.empty() ) //clean old renderer from cache - { - CleanCache( oldImageUrl ); - } + LoadResourceSynchronously(); } NativeImage nativeImage = NativeImage::DownCast( mImage ); @@ -419,7 +458,7 @@ bool ImageVisual::IsSynchronousResourceLoading() const return mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING; } -void ImageVisual::DoSynchronousResourceLoading() +void ImageVisual::LoadResourceSynchronously() { if( !mImageUrl.empty() ) { @@ -709,131 +748,6 @@ Shader ImageVisual::GetImageShader( VisualFactoryCache& factoryCache, bool atlas return shader; } -void ImageVisual::SetImage( Actor& actor, const std::string& imageUrl, ImageDimensions size, Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode ) -{ - if( mImageUrl != imageUrl ) - { - std::string oldImageUrl = mImageUrl; - mImageUrl = imageUrl; - mDesiredSize = size; - mFittingMode = fittingMode; - mSamplingMode = samplingMode; - mImage.Reset(); - - if( IsSynchronousResourceLoading() ) - { - DoSynchronousResourceLoading(); - } - - if( mImpl->mRenderer ) - { - if( GetIsFromCache() ) // if renderer is from cache, remove the old one - { - //remove old renderer - if( actor ) - { - actor.RemoveRenderer( mImpl->mRenderer ); - } - - //clean the cache - if( !oldImageUrl.empty() ) - { - CleanCache(oldImageUrl); - } - - if( actor && actor.OnStage() ) // if actor on stage, create a new renderer and apply to actor - { - SetOnStage(actor); - } - } - else // if renderer is not from cache, reuse the same renderer and only change the texture - { - Image image = LoadImage( imageUrl, IsSynchronousResourceLoading() ); - ApplyImageToSampler( image ); - } - } - } -} - -void ImageVisual::SetImage( Actor& actor, const Image& image ) -{ - if( mImage != image ) - { - NativeImage newNativeImage = NativeImage::DownCast( image ); - bool newRendererFlag = true; - - if( newNativeImage && !mNativeImageFlag ) - { - SetNativeFragmentShaderCode( newNativeImage ); - } - - if( ( newNativeImage && mNativeImageFlag ) || ( !newNativeImage && !mNativeImageFlag ) ) - { - newRendererFlag = false; - } - - if( newNativeImage ) - { - mNativeImageFlag = true; - } - else - { - mNativeFragmentShaderCode.clear(); - mNativeImageFlag = false; - } - - mImage = image; - - if( mImpl->mRenderer ) - { - // if renderer is from cache, remove the old one, and create new renderer - if( GetIsFromCache() ) - { - //remove old renderer - if( actor ) - { - actor.RemoveRenderer( mImpl->mRenderer ); - } - - //clean the cache - if( !mImageUrl.empty() ) - { - CleanCache(mImageUrl); - } - mImageUrl.clear(); - - if( actor && actor.OnStage() ) // if actor on stage, create a new renderer and apply to actor - { - SetOnStage(actor); - } - } - // if input image is nativeImage and mImage is regular image or the reverse, remove the old one, and create new renderer - else if( newRendererFlag ) - { - //remove old renderer - if( actor ) - { - actor.RemoveRenderer( mImpl->mRenderer ); - } - - if( actor && actor.OnStage() ) // if actor on stage, create a new renderer and apply to actor - { - SetOnStage(actor); - } - } - else // if renderer is not from cache, reuse the same renderer and only change the texture - { - ApplyImageToSampler( image ); - } - } - - mImageUrl.clear(); - mDesiredSize = ImageDimensions(); - mFittingMode = FittingMode::DEFAULT; - mSamplingMode = SamplingMode::DEFAULT; - } -} - void ImageVisual::ApplyImageToSampler( const Image& image ) { if( image ) @@ -865,20 +779,23 @@ void ImageVisual::OnImageLoaded( ResourceImage image ) void ImageVisual::CleanCache(const std::string& url) { - TextureSet textureSet = mImpl->mRenderer.GetTextures(); - - Vector4 atlasRect( 0.f, 0.f, 1.f, 1.f ); - Property::Index index = mImpl->mRenderer.GetPropertyIndex( ATLAS_RECT_UNIFORM_NAME ); - if( index != Property::INVALID_INDEX ) + if( IsFromCache() ) { - Property::Value atlasRectValue = mImpl->mRenderer.GetProperty( index ); - atlasRectValue.Get( atlasRect ); - } + TextureSet textureSet = mImpl->mRenderer.GetTextures(); - mImpl->mRenderer.Reset(); - if( mFactoryCache.CleanRendererCache( url ) && index != Property::INVALID_INDEX ) - { - mFactoryCache.GetAtlasManager()->Remove( textureSet, atlasRect ); + Vector4 atlasRect( 0.f, 0.f, 1.f, 1.f ); + Property::Index index = mImpl->mRenderer.GetPropertyIndex( ATLAS_RECT_UNIFORM_NAME ); + if( index != Property::INVALID_INDEX ) + { + Property::Value atlasRectValue = mImpl->mRenderer.GetProperty( index ); + atlasRectValue.Get( atlasRect ); + } + + mImpl->mRenderer.Reset(); + if( mFactoryCache.CleanRendererCache( url ) && index != Property::INVALID_INDEX ) + { + mFactoryCache.GetAtlasManager()->Remove( textureSet, atlasRect ); + } } } diff --git a/dali-toolkit/internal/visuals/image/image-visual.h b/dali-toolkit/internal/visuals/image/image-visual.h index 3079c93..56b1ae1 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.h +++ b/dali-toolkit/internal/visuals/image/image-visual.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_IMAGE_VISUAL_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -86,6 +86,31 @@ public: ImageVisual( VisualFactoryCache& factoryCache ); /** + * @brief Constructor with a URL. + * + * The visual will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage + * + * @param[in] factoryCache The VisualFactoryCache object + * @param[in] imageUrl The URL of the image resource to use + * @param[in] size The width and height to fit the loaded image to. + * @param[in] fittingMode The FittingMode of the resource to load + * @param[in] samplingMode The SamplingMode of the resource to load + */ + ImageVisual( VisualFactoryCache& factoryCache, + const std::string& imageUrl, + ImageDimensions size=ImageDimensions(), + FittingMode::Type fittingMode = FittingMode::DEFAULT, + Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR ); + + /** + * @brief Constructor with an Image type. + * + * @param[in] factoryCache The VisualFactoryCache object + * @param[in] image The image to use + */ + ImageVisual( VisualFactoryCache& factoryCache, const Image& image ); + + /** * @brief A reference counted object may only be deleted by calling Unreference(). */ ~ImageVisual(); @@ -139,30 +164,6 @@ public: static Shader GetImageShader( VisualFactoryCache& factoryCache, bool atlasing, bool defaultTextureWrapping ); /** - * @brief Sets the image of this visual to the resource at imageUrl - * The visual will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage - * - * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor - * @param[in] imageUrl The URL of the image resource to use - * @param[in] size The width and height to fit the loaded image to. - * @param[in] fittingMode The FittingMode of the resource to load - * @param[in] samplingMode The SamplingMode of the resource to load - */ - void SetImage( Actor& actor, - const std::string& imageUrl, - ImageDimensions size=ImageDimensions(), - FittingMode::Type fittingMode = FittingMode::DEFAULT, - Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR ); - - /** - * @brief Sets the image to be rendered by this visual - * - * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor - * @param[in] image The image to use - */ - void SetImage( Actor& actor, const Image& image ); - - /** * @copydoc AtlasUploadObserver::UploadCompleted * * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready. @@ -209,14 +210,14 @@ private: /** * @brief Query whether resources requires to be loaded synchronously. - * @return Returns true if synchronoud resource loading is required, false otherwise. + * @return Returns true if synchronous resource loading is required, false otherwise. */ bool IsSynchronousResourceLoading() const; /** - * @brief Do the synchronous resource loading + * @brief Load the resource synchronously */ - void DoSynchronousResourceLoading(); + void LoadResourceSynchronously(); /** * Load the image. diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp index 77d522e..1a3f640 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp @@ -202,10 +202,43 @@ void RegisterStretchProperties( Renderer& renderer, const char * uniformName, co NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), + mImage(), + mCroppedImage(), + mImageUrl(), + mStretchPixelsX(), + mStretchPixelsY(), + mImageSize(), mBorderOnly( false ) { } +NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly ) +: Visual::Base( factoryCache ), + mImage(), + mCroppedImage(), + mImageUrl( imageUrl ), + mStretchPixelsX(), + mStretchPixelsY(), + mImageSize(), + mBorderOnly( borderOnly ) +{ + NinePatchImage nPatch = NinePatchImage::New( mImageUrl ); + InitializeFromImage( nPatch ); +} + +NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly ) +: Visual::Base( factoryCache ), + mImage( image ), + mCroppedImage(), + mImageUrl(), + mStretchPixelsX(), + mStretchPixelsY(), + mImageSize(), + mBorderOnly( borderOnly ) +{ + InitializeFromImage( image ); +} + NPatchVisual::~NPatchVisual() { } @@ -452,60 +485,6 @@ void NPatchVisual::ChangeRenderer( bool oldBorderOnly, size_t oldGridX, size_t o } } -void NPatchVisual::SetImage( const std::string& imageUrl, bool borderOnly ) -{ - bool oldBorderOnly = mBorderOnly; - size_t oldGridX = mStretchPixelsX.Size(); - size_t oldGridY = mStretchPixelsY.Size(); - - mBorderOnly = borderOnly; - mImage.Reset(); - if( mImageUrl == imageUrl ) - { - return; - } - - mImageUrl = imageUrl; - if( mImpl->mRenderer ) - { - NinePatchImage nPatch = NinePatchImage::New( mImageUrl ); - InitializeFromImage( nPatch ); - - ChangeRenderer( oldBorderOnly, oldGridX, oldGridY ); - - if( mCroppedImage ) - { - ApplyImageToSampler(); - } - } -} - -void NPatchVisual::SetImage( NinePatchImage image, bool borderOnly ) -{ - bool oldBorderOnly = mBorderOnly; - size_t oldGridX = mStretchPixelsX.Size(); - size_t oldGridY = mStretchPixelsY.Size(); - - mBorderOnly = borderOnly; - mImageUrl.empty(); - if( mImage == image ) - { - return; - } - - mImage = image; - if( mImpl->mRenderer ) - { - InitializeFromImage( mImage ); - ChangeRenderer( oldBorderOnly, oldGridX, oldGridY ); - - if( mCroppedImage ) - { - ApplyImageToSampler(); - } - } -} - void NPatchVisual::InitializeFromImage( NinePatchImage nPatch ) { mCroppedImage = nPatch.CreateCroppedBufferImage(); diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.h b/dali-toolkit/internal/visuals/npatch/npatch-visual.h index 366d2b5..e178eb8 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.h +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.h @@ -61,6 +61,26 @@ public: NPatchVisual( VisualFactoryCache& factoryCache ); /** + * @brief Constructor which creates an N-patch visual using an image URL. + * + * The visual will load the image synchronously when the associated actor is put on stage, and destroy the image when it is off stage + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @param[in] imageUrl The URL to 9 patch image resource to use + * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border + */ + NPatchVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly = false ); + + /** + * @brief Constructor which creates an N-patch viusal with a NinePatchImage resource. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @param[in] image The NinePatchImage to use + * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border + */ + NPatchVisual( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly = false ); + + /** * @brief A reference counted object may only be deleted by calling Unreference(). */ ~NPatchVisual(); @@ -104,25 +124,6 @@ protected: */ virtual void DoSetOffStage( Actor& actor ); -public: - - /** - * @brief Sets the 9 patch image of this visual to the resource at imageUrl - * The visual will load the image synchronously when the associated actor is put on stage, and destroy the image when it is off stage - * - * @param[in] imageUrl The URL to 9 patch image resource to use - * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border - */ - void SetImage( const std::string& imageUrl, bool borderOnly = false ); - - /** - * @brief Sets the 9 patch image of this viusal to the 9 patch image - * - * @param[in] image The NinePatchImage to use - * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border - */ - void SetImage( NinePatchImage image, bool borderOnly = false ); - private: /** diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.cpp b/dali-toolkit/internal/visuals/svg/svg-visual.cpp index 6c0bcfb..fec7797 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.cpp +++ b/dali-toolkit/internal/visuals/svg/svg-visual.cpp @@ -56,12 +56,27 @@ namespace Internal SvgVisual::SvgVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), mAtlasRect( FULL_TEXTURE_RECT ), - mParsedImage( NULL ) + mImageUrl(), + mParsedImage( NULL ), + mPlacementActor() { // the rasterized image is with pre-multiplied alpha format mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; } +SvgVisual::SvgVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size ) +: Visual::Base( factoryCache ), + mAtlasRect( FULL_TEXTURE_RECT ), + mImageUrl(), + mParsedImage( NULL ), + mPlacementActor() +{ + // the rasterized image is with pre-multiplied alpha format + mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; + + ParseFromUrl( imageUrl, size ); +} + SvgVisual::~SvgVisual() { if( mParsedImage ) @@ -78,7 +93,7 @@ void SvgVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) std::string imageUrl; if( imageURLValue->Get( imageUrl ) ) { - SetImage( imageUrl ); + ParseFromUrl( imageUrl ); } else { @@ -133,7 +148,7 @@ void SvgVisual::GetNaturalSize( Vector2& naturalSize ) const void SvgVisual::SetSize( const Vector2& size ) { - if(mImpl->mSize != size && mParsedImage && GetIsOnStage() ) + if(mImpl->mSize != size && mParsedImage && IsOnStage() ) { AddRasterizationTask( size ); } @@ -161,30 +176,18 @@ Dali::Property::Value SvgVisual::DoGetProperty( Dali::Property::Index index ) return Dali::Property::Value(); } -void SvgVisual::SetImage( const std::string& imageUrl, ImageDimensions size ) +void SvgVisual::ParseFromUrl( const std::string& imageUrl, ImageDimensions size ) { - if( mImageUrl != imageUrl ) - { - mImageUrl = imageUrl; + mImageUrl = imageUrl; - NSVGimage* parsedImageOld = mParsedImage; + Vector2 dpi = Stage::GetCurrent().GetDpi(); + float meanDpi = (dpi.height + dpi.width) * 0.5f; + mParsedImage = nsvgParseFromFile( imageUrl.c_str(), UNITS, meanDpi ); - Vector2 dpi = Stage::GetCurrent().GetDpi(); - float meanDpi = (dpi.height + dpi.width) * 0.5f; - mParsedImage = nsvgParseFromFile(mImageUrl.c_str(), UNITS, meanDpi); - - if( size.GetWidth() != 0u && size.GetHeight() != 0u) - { - mImpl->mSize.x = size.GetWidth(); - mImpl->mSize.y = size.GetHeight(); - } - - if( mImpl->mSize != Vector2::ZERO && GetIsOnStage() ) - { - AddRasterizationTask( mImpl->mSize ); - } - - mFactoryCache.GetSVGRasterizationThread()->DeleteImage( parsedImageOld ); + if( size.GetWidth() != 0u && size.GetHeight() != 0u) + { + mImpl->mSize.x = size.GetWidth(); + mImpl->mSize.y = size.GetHeight(); } } @@ -203,7 +206,7 @@ void SvgVisual::AddRasterizationTask( const Vector2& size ) void SvgVisual::ApplyRasterizedImage( PixelData rasterizedPixelData ) { - if( GetIsOnStage() ) + if( IsOnStage() ) { TextureSet currentTextureSet = mImpl->mRenderer.GetTextures(); if( mAtlasRect != FULL_TEXTURE_RECT ) diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.h b/dali-toolkit/internal/visuals/svg/svg-visual.h index c040f47..8fd9165 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.h +++ b/dali-toolkit/internal/visuals/svg/svg-visual.h @@ -57,6 +57,17 @@ public: SvgVisual( VisualFactoryCache& factoryCache ); /** + * @brief Constructor which creates 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] imageUrl The URL to svg resource to use + */ + SvgVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size = ImageDimensions() ); + + /** * @brief A reference counted object may only be deleted by calling Unreference(). */ ~SvgVisual(); @@ -108,15 +119,6 @@ protected: public: /** - * @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 - * - * @param[in] imageUrl The URL to svg resource to use - */ - void SetImage( const std::string& imageUrl, ImageDimensions size = ImageDimensions() ); - - /** * @bried Apply the rasterized image to the visual. * * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels @@ -124,6 +126,15 @@ public: void ApplyRasterizedImage( PixelData rasterizedPixelData ); private: + + /** + * @brief Parses the SVG Image from the set URL. + * + * @param[in] imageUrl The URL of the image to parse the SVG from. + * @param[in] size The required size of the SVG + */ + void ParseFromUrl( const std::string& imageUrl, ImageDimensions size = ImageDimensions() ); + /** * @bried Rasterize the svg with the given size, and add it to the visual. * diff --git a/dali-toolkit/internal/visuals/visual-base-impl.cpp b/dali-toolkit/internal/visuals/visual-base-impl.cpp index 32f8b8d..4156d1a 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-impl.cpp @@ -116,7 +116,7 @@ void Visual::Base::SetOnStage( Actor& actor ) void Visual::Base::SetOffStage( Actor& actor ) { - if( GetIsOnStage() ) + if( IsOnStage() ) { DoSetOffStage( actor ); @@ -162,12 +162,12 @@ void Visual::Base::CreatePropertyMap( Property::Map& map ) const } } -bool Visual::Base::GetIsOnStage() const +bool Visual::Base::IsOnStage() const { return mImpl->mFlags & Impl::IS_ON_STAGE; } -bool Visual::Base::GetIsFromCache() const +bool Visual::Base::IsFromCache() const { return mImpl->mFlags & Impl::IS_FROM_CACHE; } diff --git a/dali-toolkit/internal/visuals/visual-base-impl.h b/dali-toolkit/internal/visuals/visual-base-impl.h index 8334841..c073518 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.h +++ b/dali-toolkit/internal/visuals/visual-base-impl.h @@ -194,19 +194,20 @@ protected: virtual void DoSetOffStage( Actor& actor ); protected: + /** * @brief Gets the on stage state for this Visual * * @return Returns true if this Visual is on stage, false if it is off the stage */ - bool GetIsOnStage() const; + bool IsOnStage() const; /** * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer) * * @return Returns true if the renderer is from shared cache, false otherwise */ - bool GetIsFromCache() const; + bool IsFromCache() const; protected: /** diff --git a/dali-toolkit/internal/visuals/visual-factory-impl.cpp b/dali-toolkit/internal/visuals/visual-factory-impl.cpp index 6baaec2..f76aeed 100644 --- a/dali-toolkit/internal/visuals/visual-factory-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-impl.cpp @@ -219,17 +219,12 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Image& image ) NinePatchImage npatchImage = NinePatchImage::DownCast( image ); if( npatchImage ) { - NPatchVisual* visualPtr = new NPatchVisual( *( mFactoryCache.Get() ) ); - visualPtr->SetImage( npatchImage ); - + NPatchVisual* visualPtr = new NPatchVisual( *( mFactoryCache.Get() ), npatchImage ); return Toolkit::Visual::Base( visualPtr ); } else { - ImageVisual* visualPtr = new ImageVisual( *( mFactoryCache.Get() ) ); - Actor actor; - visualPtr->SetImage( actor, image ); - + ImageVisual* visualPtr = new ImageVisual( *( mFactoryCache.Get() ), image ); return Toolkit::Visual::Base( visualPtr ); } } @@ -250,23 +245,17 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, Image UrlType::Type type = ResolveUrlType( url ); if( UrlType::N_PATCH == type ) { - NPatchVisual* visualPtr = new NPatchVisual( *( mFactoryCache.Get() ) ); - visualPtr->SetImage( url ); - + NPatchVisual* visualPtr = new NPatchVisual( *( mFactoryCache.Get() ), url ); return Toolkit::Visual::Base( visualPtr ); } else if( UrlType::SVG == type ) { - SvgVisual* visualPtr = new SvgVisual( *( mFactoryCache.Get() ) ); - visualPtr->SetImage( url, size ); + SvgVisual* visualPtr = new SvgVisual( *( mFactoryCache.Get() ), url, size ); return Toolkit::Visual::Base( visualPtr ); } else // Regular image { - ImageVisual* visualPtr = new ImageVisual( *( mFactoryCache.Get() )); - Actor actor; - visualPtr->SetImage( actor, url, size ); - + ImageVisual* visualPtr = new ImageVisual( *( mFactoryCache.Get() ), url, size ); return Toolkit::Visual::Base( visualPtr ); } } -- 2.7.4