From 9c1520c7e421a8866e8d7481a2a2965e5b26c89e Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Thu, 6 Apr 2017 15:55:03 +0900 Subject: [PATCH] Fix npatch visual issue When the same image with different borders is used, the cached data should not be used. Change-Id: Ib986594bd74f82cf18afad3b14b28dca5dcd9254 --- .../src/dali-toolkit/utc-Dali-VisualFactory.cpp | 19 ++++++++++ dali-toolkit/internal/visuals/npatch-loader.cpp | 41 +++++++++++++++++++++- dali-toolkit/internal/visuals/npatch-loader.h | 1 + 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp b/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp index acf3192..b8e40b8 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp @@ -695,6 +695,25 @@ int UtcDaliVisualFactoryGetNPatchVisual2(void) DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); } + propertyMap.Clear(); + propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH ); + propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA ); + propertyMap.Insert( DevelImageVisual::Property::BORDER, Rect< int >( 1, 1, 1, 1 ) ); + { + tet_infoline( "whole grid" ); + Visual::Base visual = factory.CreateVisual( propertyMap ); + DALI_TEST_CHECK( visual ); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + DummyControl actor = DummyControl::New(); + TestVisualRender( application, actor, visual, 1u ); + + DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + } + END_TEST; } diff --git a/dali-toolkit/internal/visuals/npatch-loader.cpp b/dali-toolkit/internal/visuals/npatch-loader.cpp index 5da7bd1..f23f1ca 100644 --- a/dali-toolkit/internal/visuals/npatch-loader.cpp +++ b/dali-toolkit/internal/visuals/npatch-loader.cpp @@ -45,6 +45,8 @@ std::size_t NPatchLoader::Load( const std::string& url, const Rect< int >& borde std::size_t hash = CalculateHash( url ); OwnerContainer< Data* >::SizeType index = UNINITIALIZED_ID; const OwnerContainer< Data* >::SizeType count = mCache.Count(); + int cachedIndex = -1; + for( ; index < count; ++index ) { if( mCache[ index ]->hash == hash ) @@ -52,10 +54,45 @@ std::size_t NPatchLoader::Load( const std::string& url, const Rect< int >& borde // hash match, check url as well in case of hash collision if( mCache[ index ]->url == url ) { - return index+1u; // valid indices are from 1 onwards + // Use cached data + if( mCache[ index ]->border == border ) + { + return index+1u; // valid indices are from 1 onwards + } + else + { + cachedIndex = index; + } } } } + + if( cachedIndex != -1 ) + { + // Same url but border is different - use the existing texture + Data* data = new Data(); + data->hash = hash; + data->url = url; + data->croppedWidth = mCache[ cachedIndex ]->croppedWidth; + data->croppedHeight = mCache[ cachedIndex ]->croppedHeight; + + data->textureSet = mCache[ cachedIndex ]->textureSet; + + NinePatchImage::StretchRanges stretchRangesX; + stretchRangesX.PushBack( Uint16Pair( border.left, data->croppedWidth - border.right ) ); + + NinePatchImage::StretchRanges stretchRangesY; + stretchRangesY.PushBack( Uint16Pair( border.top, data->croppedHeight - border.bottom ) ); + + data->stretchPixelsX = stretchRangesX; + data->stretchPixelsY = stretchRangesY; + data->border = border; + + mCache.PushBack( data ); + + return mCache.Count(); // valid ids start from 1u + } + // got to the end so no match, decode N patch and append new item to cache if( border == Rect< int >( 0, 0, 0, 0 ) ) { @@ -74,6 +111,7 @@ std::size_t NPatchLoader::Load( const std::string& url, const Rect< int >& borde data->croppedHeight = croppedImage.GetHeight(); data->stretchPixelsX = ninePatch.GetStretchPixelsX(); data->stretchPixelsY = ninePatch.GetStretchPixelsY(); + data->border = Rect< int >( 0, 0, 0, 0 ); mCache.PushBack( data ); return mCache.Count(); // valid ids start from 1u @@ -106,6 +144,7 @@ std::size_t NPatchLoader::Load( const std::string& url, const Rect< int >& borde data->stretchPixelsX = stretchRangesX; data->stretchPixelsY = stretchRangesY; + data->border = border; mCache.PushBack( data ); diff --git a/dali-toolkit/internal/visuals/npatch-loader.h b/dali-toolkit/internal/visuals/npatch-loader.h index 61ec60d..d1df302 100644 --- a/dali-toolkit/internal/visuals/npatch-loader.h +++ b/dali-toolkit/internal/visuals/npatch-loader.h @@ -62,6 +62,7 @@ public: std::size_t hash; ///< Hash code for the Url uint32_t croppedWidth; ///< Width of the cropped middle part of N-patch uint32_t croppedHeight; ///< Height of the cropped middle part of N-patch + Rect< int > border; ///< The size of the border }; public: -- 2.7.4