From: Kimmo Hoikka Date: Tue, 1 Nov 2016 14:25:38 +0000 (+0000) Subject: Stop trying to find the URL parameter multiple times from property map X-Git-Tag: dali_1.2.13~4^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=25b212f44160ea19465962203f604cdbc6623871;hp=533d8c2ec94a43bbe098b556bb905cbe10f427ab Stop trying to find the URL parameter multiple times from property map - factory already needs to find it so no need for image visuals to do so Change-Id: I2d4f50949b52c43c24d6220f539f25abf9fcad76 --- diff --git a/dali-toolkit/internal/visuals/image/batch-image-visual.cpp b/dali-toolkit/internal/visuals/image/batch-image-visual.cpp index 2aba159..fe803b2 100644 --- a/dali-toolkit/internal/visuals/image/batch-image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/batch-image-visual.cpp @@ -88,13 +88,16 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( } // unnamed namespace -BatchImageVisualPtr BatchImageVisual::New( VisualFactoryCache& factoryCache ) +BatchImageVisualPtr BatchImageVisual::New( VisualFactoryCache& factoryCache, const std::string& url ) { - return new BatchImageVisual( factoryCache ); + BatchImageVisualPtr visual = new BatchImageVisual( factoryCache ); + visual->mImageUrl = url; + return visual; } BatchImageVisual::BatchImageVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), + mImageUrl(""), mDesiredSize() { } @@ -105,29 +108,23 @@ BatchImageVisual::~BatchImageVisual() void BatchImageVisual::DoSetProperties( const Property::Map& propertyMap ) { - std::string oldImageUrl = mImageUrl; - Property::Value* imageURLValue = propertyMap.Find( Dali::Toolkit::ImageVisual::Property::URL, Dali::Toolkit::Internal::IMAGE_URL_NAME ); + // url already passed in constructor - if( imageURLValue ) + int desiredWidth = 0; + Property::Value* desiredWidthValue = propertyMap.Find( Dali::Toolkit::ImageVisual::Property::DESIRED_WIDTH, DESIRED_WIDTH ); + if( desiredWidthValue ) { - imageURLValue->Get( mImageUrl ); - - int desiredWidth = 0; - Property::Value* desiredWidthValue = propertyMap.Find( Dali::Toolkit::ImageVisual::Property::DESIRED_WIDTH, DESIRED_WIDTH ); - if( desiredWidthValue ) - { - desiredWidthValue->Get( desiredWidth ); - } - - int desiredHeight = 0; - Property::Value* desiredHeightValue = propertyMap.Find( Dali::Toolkit::ImageVisual::Property::DESIRED_HEIGHT, DESIRED_HEIGHT ); - if( desiredHeightValue ) - { - desiredHeightValue->Get( desiredHeight ); - } + desiredWidthValue->Get( desiredWidth ); + } - mDesiredSize = ImageDimensions( desiredWidth, desiredHeight ); + int desiredHeight = 0; + Property::Value* desiredHeightValue = propertyMap.Find( Dali::Toolkit::ImageVisual::Property::DESIRED_HEIGHT, DESIRED_HEIGHT ); + if( desiredHeightValue ) + { + desiredHeightValue->Get( desiredHeight ); } + + mDesiredSize = ImageDimensions( desiredWidth, desiredHeight ); } void BatchImageVisual::SetSize( const Vector2& size ) diff --git a/dali-toolkit/internal/visuals/image/batch-image-visual.h b/dali-toolkit/internal/visuals/image/batch-image-visual.h index be84aab..d670c5d 100644 --- a/dali-toolkit/internal/visuals/image/batch-image-visual.h +++ b/dali-toolkit/internal/visuals/image/batch-image-visual.h @@ -45,7 +45,7 @@ public: * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object * @return A smart-pointer to the newly allocated visual. */ - static BatchImageVisualPtr New( VisualFactoryCache& factoryCache ); + static BatchImageVisualPtr New( VisualFactoryCache& factoryCache, const std::string& url ); public: // from Visual diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index 723afb6..dcc3590 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -201,11 +201,6 @@ Geometry CreateGeometry( VisualFactoryCache& factoryCache, ImageDimensions gridS } // unnamed namespace -ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache ) -{ - return new ImageVisual( factoryCache ); -} - ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size, @@ -220,21 +215,6 @@ ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache, const Image& return new ImageVisual( factoryCache, image ); } -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 ) -{ -} - ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size, @@ -275,70 +255,61 @@ ImageVisual::~ImageVisual() void ImageVisual::DoSetProperties( const Property::Map& propertyMap ) { - Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME ); - if( imageURLValue ) + // Url is already received in constructor + Property::Value* fittingValue = propertyMap.Find( Toolkit::ImageVisual::Property::FITTING_MODE, IMAGE_FITTING_MODE ); + if( fittingValue ) { - imageURLValue->Get( mImageUrl ); - if( !mImageUrl.empty() ) - { - mImage.Reset(); - } - - Property::Value* fittingValue = propertyMap.Find( Toolkit::ImageVisual::Property::FITTING_MODE, IMAGE_FITTING_MODE ); - if( fittingValue ) - { - int value; - Scripting::GetEnumerationProperty( *fittingValue, FITTING_MODE_TABLE, FITTING_MODE_TABLE_COUNT, value ); - mFittingMode = Dali::FittingMode::Type( value ); - } - - Property::Value* samplingValue = propertyMap.Find( Toolkit::ImageVisual::Property::SAMPLING_MODE, IMAGE_SAMPLING_MODE ); - if( samplingValue ) - { - int value; - Scripting::GetEnumerationProperty( *samplingValue, SAMPLING_MODE_TABLE, SAMPLING_MODE_TABLE_COUNT, value ); - mSamplingMode = Dali::SamplingMode::Type( value ); - } + int value; + Scripting::GetEnumerationProperty( *fittingValue, FITTING_MODE_TABLE, FITTING_MODE_TABLE_COUNT, value ); + mFittingMode = Dali::FittingMode::Type( value ); + } - int desiredWidth = 0; - Property::Value* desiredWidthValue = propertyMap.Find( Toolkit::ImageVisual::Property::DESIRED_WIDTH, IMAGE_DESIRED_WIDTH ); - if( desiredWidthValue ) - { - desiredWidthValue->Get( desiredWidth ); - } + Property::Value* samplingValue = propertyMap.Find( Toolkit::ImageVisual::Property::SAMPLING_MODE, IMAGE_SAMPLING_MODE ); + if( samplingValue ) + { + int value; + Scripting::GetEnumerationProperty( *samplingValue, SAMPLING_MODE_TABLE, SAMPLING_MODE_TABLE_COUNT, value ); + mSamplingMode = Dali::SamplingMode::Type( value ); + } - int desiredHeight = 0; - Property::Value* desiredHeightValue = propertyMap.Find( Toolkit::ImageVisual::Property::DESIRED_HEIGHT, IMAGE_DESIRED_HEIGHT ); - if( desiredHeightValue ) - { - desiredHeightValue->Get( desiredHeight ); - } + int desiredWidth = 0; + Property::Value* desiredWidthValue = propertyMap.Find( Toolkit::ImageVisual::Property::DESIRED_WIDTH, IMAGE_DESIRED_WIDTH ); + if( desiredWidthValue ) + { + desiredWidthValue->Get( desiredWidth ); + } - Property::Value* pixelAreaValue = propertyMap.Find( Toolkit::ImageVisual::Property::PIXEL_AREA, PIXEL_AREA_UNIFORM_NAME ); - if( pixelAreaValue ) - { - pixelAreaValue->Get( mPixelArea ); - } + int desiredHeight = 0; + Property::Value* desiredHeightValue = propertyMap.Find( Toolkit::ImageVisual::Property::DESIRED_HEIGHT, IMAGE_DESIRED_HEIGHT ); + if( desiredHeightValue ) + { + desiredHeightValue->Get( desiredHeight ); + } - Property::Value* wrapModeValueU = propertyMap.Find( Toolkit::ImageVisual::Property::WRAP_MODE_U, IMAGE_WRAP_MODE_U ); - if( wrapModeValueU ) - { - int value; - Scripting::GetEnumerationProperty( *wrapModeValueU, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, value ); - mWrapModeU = Dali::WrapMode::Type( value ); - } + Property::Value* pixelAreaValue = propertyMap.Find( Toolkit::ImageVisual::Property::PIXEL_AREA, PIXEL_AREA_UNIFORM_NAME ); + if( pixelAreaValue ) + { + pixelAreaValue->Get( mPixelArea ); + } - Property::Value* wrapModeValueV = propertyMap.Find( Toolkit::ImageVisual::Property::WRAP_MODE_V, IMAGE_WRAP_MODE_V ); - if( wrapModeValueV ) - { - int value; - Scripting::GetEnumerationProperty( *wrapModeValueV, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, value ); - mWrapModeV = Dali::WrapMode::Type( value ); - } + Property::Value* wrapModeValueU = propertyMap.Find( Toolkit::ImageVisual::Property::WRAP_MODE_U, IMAGE_WRAP_MODE_U ); + if( wrapModeValueU ) + { + int value; + Scripting::GetEnumerationProperty( *wrapModeValueU, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, value ); + mWrapModeU = Dali::WrapMode::Type( value ); + } - mDesiredSize = ImageDimensions( desiredWidth, desiredHeight ); + Property::Value* wrapModeValueV = propertyMap.Find( Toolkit::ImageVisual::Property::WRAP_MODE_V, IMAGE_WRAP_MODE_V ); + if( wrapModeValueV ) + { + int value; + Scripting::GetEnumerationProperty( *wrapModeValueV, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, value ); + mWrapModeV = Dali::WrapMode::Type( value ); } + mDesiredSize = ImageDimensions( desiredWidth, desiredHeight ); + Property::Value* syncLoading = propertyMap.Find( Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, SYNCHRONOUS_LOADING ); if( syncLoading ) { @@ -349,7 +320,7 @@ void ImageVisual::DoSetProperties( const Property::Map& propertyMap ) mImpl->mFlags |= Impl::IS_SYNCHRONOUS_RESOURCE_LOADING; // 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( imageURLValue ) + if( mImageUrl.size() > 0u ) { LoadResourceSynchronously(); } diff --git a/dali-toolkit/internal/visuals/image/image-visual.h b/dali-toolkit/internal/visuals/image/image-visual.h index bedb56d..7ad511f 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.h +++ b/dali-toolkit/internal/visuals/image/image-visual.h @@ -80,14 +80,6 @@ class ImageVisual: public Visual::Base, public ConnectionTracker, public AtlasUp public: /** - * @brief Create a new image visual. - * - * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object - * @return A smart-pointer to the newly allocated visual. - */ - static ImageVisualPtr New( VisualFactoryCache& factoryCache ); - - /** * @brief Create a new image visual 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 @@ -137,13 +129,6 @@ public: // from Visual protected: /** - * @brief Constructor. - * - * @param[in] factoryCache The VisualFactoryCache object - */ - 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 diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp index 4cf199a..a4cf8c0 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp @@ -225,14 +225,9 @@ void RegisterStretchProperties( Renderer& renderer, const char * uniformName, co /////////////////NPatchVisual//////////////// -NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache ) +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl ) { - return new NPatchVisual( factoryCache ); -} - -NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly ) -{ - NPatchVisual* nPatchVisual = new NPatchVisual( factoryCache, borderOnly ); + NPatchVisual* nPatchVisual = new NPatchVisual( factoryCache ); nPatchVisual->mImageUrl = imageUrl; NinePatchImage image = NinePatchImage::New( imageUrl ); @@ -241,9 +236,9 @@ NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std:: return nPatchVisual; } -NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly ) +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, NinePatchImage image ) { - NPatchVisual* nPatchVisual = new NPatchVisual( factoryCache, borderOnly ); + NPatchVisual* nPatchVisual = new NPatchVisual( factoryCache ); nPatchVisual->mImage = image; nPatchVisual->InitializeFromImage( image ); @@ -251,7 +246,7 @@ NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, NinePatchIm return nPatchVisual; } -NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache, bool borderOnly ) +NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), mImage(), mCroppedImage(), @@ -259,7 +254,7 @@ NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache, bool borderOnly ) mStretchPixelsX(), mStretchPixelsY(), mImageSize(), - mBorderOnly( borderOnly ) + mBorderOnly( false ) { } @@ -269,26 +264,12 @@ NPatchVisual::~NPatchVisual() void NPatchVisual::DoSetProperties( const Property::Map& propertyMap ) { - Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME ); - if( imageURLValue ) + // URL is already passed in via constructor + //Read the borderOnly property first since InitialiseFromImage relies on mBorderOnly to be properly set + Property::Value* borderOnlyValue = propertyMap.Find( Toolkit::ImageVisual::Property::BORDER_ONLY, BORDER_ONLY ); + if( borderOnlyValue ) { - //Read the borderOnly property first since InitialiseFromImage relies on mBorderOnly to be properly set - Property::Value* borderOnlyValue = propertyMap.Find( Toolkit::ImageVisual::Property::BORDER_ONLY, BORDER_ONLY ); - if( borderOnlyValue ) - { - borderOnlyValue->Get( mBorderOnly ); - } - - if( imageURLValue->Get( mImageUrl ) ) - { - NinePatchImage nPatch = NinePatchImage::New( mImageUrl ); - InitializeFromImage( nPatch ); - } - else - { - InitializeFromBrokenImage(); - DALI_LOG_ERROR( "The property '%s' is not a string\n", IMAGE_URL_NAME ); - } + borderOnlyValue->Get( mBorderOnly ); } } diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.h b/dali-toolkit/internal/visuals/npatch/npatch-visual.h index 506087a..b3d2815 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.h +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.h @@ -58,32 +58,22 @@ class NPatchVisual: public Visual::Base public: /** - * @brief Create a new n-patch visual. - * - * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object - * @return A smart-pointer to the newly allocated visual. - */ - static NPatchVisualPtr New( VisualFactoryCache& factoryCache ); - - /** * @brief Create 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 */ - static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly = false ); + static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl ); /** * @brief Create an N-patch visual 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 */ - static NPatchVisualPtr New( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly = false ); + static NPatchVisualPtr New( VisualFactoryCache& factoryCache, NinePatchImage image ); public: // from Visual @@ -112,10 +102,9 @@ protected: /** * @brief Constructor. * - * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object - * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border + * @param[in] factoryCache Reference to the VisualFactoryCache object */ - NPatchVisual( VisualFactoryCache& factoryCache, bool borderOnly = false ); + NPatchVisual( VisualFactoryCache& factoryCache ); /** * @brief A reference counted object may only be deleted by calling Unreference(). diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.cpp b/dali-toolkit/internal/visuals/svg/svg-visual.cpp index 5929eca..652b03d 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.cpp +++ b/dali-toolkit/internal/visuals/svg/svg-visual.cpp @@ -54,11 +54,6 @@ namespace Toolkit namespace Internal { -SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache ) -{ - return new SvgVisual( factoryCache ); -} - SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size ) { SvgVisual* svgVisual = new SvgVisual( factoryCache ); @@ -87,19 +82,7 @@ SvgVisual::~SvgVisual() void SvgVisual::DoSetProperties( const Property::Map& propertyMap ) { - Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME ); - if( imageURLValue ) - { - std::string imageUrl; - if( imageURLValue->Get( imageUrl ) ) - { - ParseFromUrl( imageUrl ); - } - else - { - DALI_LOG_ERROR( "The property '%s' is not a string\n", IMAGE_URL_NAME ); - } - } + // url already passed in from constructor } void SvgVisual::DoSetOnStage( Actor& actor ) diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.h b/dali-toolkit/internal/visuals/svg/svg-visual.h index 0456bb5..7beb6d6 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.h +++ b/dali-toolkit/internal/visuals/svg/svg-visual.h @@ -54,14 +54,6 @@ class SvgVisual: public Visual::Base public: /** - * @brief Create a new SVG visual. - * - * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object - * @return A smart-pointer to the newly allocated visual. - */ - static SvgVisualPtr New( VisualFactoryCache& factoryCache ); - - /** * @brief Create the SVG Visual using the image URL. * * The visual will parse the SVG image once it is set. diff --git a/dali-toolkit/internal/visuals/visual-factory-impl.cpp b/dali-toolkit/internal/visuals/visual-factory-impl.cpp index d7e4b97..9b77e63 100644 --- a/dali-toolkit/internal/visuals/visual-factory-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-impl.cpp @@ -142,11 +142,11 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property UrlType::Type type = ResolveUrlType( imageUrl ); if( UrlType::N_PATCH == type ) { - visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ) ); + visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), imageUrl ); } else if( UrlType::SVG == type ) { - visualPtr = SvgVisual::New( *( mFactoryCache.Get() ) ); + visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), imageUrl ); } else // Regular image { @@ -159,12 +159,12 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property if( batchingEnabled ) { - visualPtr = BatchImageVisual::New( *( mFactoryCache.Get() ) ); + visualPtr = BatchImageVisual::New( *( mFactoryCache.Get() ), imageUrl ); break; } else { - visualPtr = ImageVisual::New( *( mFactoryCache.Get() ) ); + visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), imageUrl ); } } }