From 5af3c7c9147d2697cf2324738d357c52ce9598b9 Mon Sep 17 00:00:00 2001 From: Sunghyun Kim Date: Thu, 2 Jul 2020 13:57:58 +0900 Subject: [PATCH 1/1] Call LoadTexture() for ReleasePolicy When ReleasePolicy is not DETACHED, There are cases where the wrong texture is seen. To avoid this case, i added a patch. Detailed description is added below. Load Texture if mTextures is empty. mTextures is already set, the mTexture can be used to create Renderer. There are two cases mTextures is empty. 1. mTextureId == TextureManager::INVALID_TEXTURE_ID and mTextures is empty - Visual is on stage with LoadPolicy::ATTACHED - mTextureId != TextureManager::INVALID_TEXTURE_ID and mTextures is empty - If ReleasePolicy is DESTROYED, InitializeRenderer called every on stage called. - Then every resources those contained in Visual are Reset but mTextureId is remained when the Off stage time, - So, mTextures needed to be get from texture manager to created resources like mImpl->mRenderer. Change-Id: Ice111ee467eaeba222eaa9063bde3b23ada484d4 --- .../src/dali-toolkit/utc-Dali-ImageVisual.cpp | 81 ++++++++++++++++++++++ .../internal/visuals/image/image-visual.cpp | 24 +++++-- 2 files changed, 100 insertions(+), 5 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp index 78792d9..ddcbd55 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp @@ -1861,6 +1861,87 @@ int UtcDaliImageVisualReleasePolicy07(void) END_TEST; } +int UtcDaliImageVisualReleasePolicy08(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliImageVisualReleasePolicy08 Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy" ); + + tet_infoline( "Create first visual with DESTROYED release policy" ); + Visual::Base imageVisualDestroyed = CreateVisualWithPolicy( TEST_IMAGE_FILE_NAME, ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED ); + + // Set up trace debug + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + tet_infoline( "Register visuals with control and ensure it has the only handles" ); + DummyControl actor = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisualDestroyed ); + imageVisualDestroyed.Reset(); // reduce ref count so only the control keeps the visual alive. + + actor.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) ); + + // Test initially zero renderers + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); + textureTrace.Reset(); + + Stage::GetCurrent().Add( actor ); + + // Wait for image to load + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(0); + tet_infoline( "Ensure a texture is created" ); + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); + textureTrace.Reset(); + + // Ensure TextureSet is same after detach/attach on stage when texture used the DESTROYED release policy + // 1. Get TextureSet + TextureSet textureSetBefore = actor.GetRendererAt( 0u ).GetTextures(); + + // 2.Remove actor from stage. In this case, renderer also is deleted. + tet_infoline( "Remove actor from stage" ); + Stage::GetCurrent().Remove( actor ); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + application.SendNotification(); + application.Render(); + + tet_infoline( "Ensure a texture is not deleted as visual used the DESTROYED release policy" ); + DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION ); + textureTrace.Reset(); + + // 3.Add actor in stage. In this case, renderer is created. + tet_infoline( "Add actor in stage" ); + Stage::GetCurrent().Add( actor ); + DALI_TEST_CHECK( actor.GetRendererCount() == 1u ); + application.SendNotification(); + application.Render(); + tet_infoline( "Ensure a texture is not created again" ); + DALI_TEST_EQUALS( textureTrace.CountMethod("GenTextures"), 0, TEST_LOCATION ); + textureTrace.Reset(); + + // 4.Compare Texture with before and after. textureSet need to be same because release policy is the DESTROYED. + tet_infoline( "Ensure a textureSet is not deleted because it is used the DESTROYED release policy" ); + TextureSet textureSetAfter = actor.GetRendererAt( 0u ).GetTextures(); + DALI_TEST_CHECK( textureSetBefore == textureSetAfter ); + textureSetBefore.Reset(); + textureSetAfter.Reset(); + + dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL ); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliImageVisualLoadPolicy01(void) { ToolkitTestApplication application; diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index 9823a92..194b9ba 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -609,13 +609,27 @@ bool ImageVisual::AttemptAtlasing() void ImageVisual::InitializeRenderer() { auto attemptAtlasing = AttemptAtlasing(); - // texture set has to be created first as we need to know if atlasing succeeded or not - // when selecting the shader - if( mTextureId == TextureManager::INVALID_TEXTURE_ID && ! mTextures ) // Only load the texture once + // Load Texture if mTextures is empty. + // mTextures is already set, the mTexture can be used to create Renderer. + // There are two cases mTextures is empty. + // 1. mTextureId == TextureManager::INVALID_TEXTURE_ID + // - Visual is on stage with LoadPolicy::ATTACHED + // 2. mTextureId != TextureManager::INVALID_TEXTURE_ID + // - If ReleasePolicy is DESTROYED, InitializeRenderer called every on stage called. + // - Then every resources those contained in Visual are Reset but mTextureId is remained when the Off stage time, + // - So, mTextures needed to be get from texture manager to created resources like mImpl->mRenderer. + if( ! mTextures ) { - LoadTexture( attemptAtlasing, mAtlasRect, mTextures, mOrientationCorrection, - TextureManager::ReloadPolicy::CACHED ); + if( mTextureId == TextureManager::INVALID_TEXTURE_ID ) + { + LoadTexture( attemptAtlasing, mAtlasRect, mTextures, mOrientationCorrection, + TextureManager::ReloadPolicy::CACHED ); + } + else + { + mTextures = mFactoryCache.GetTextureManager().GetTextureSet( mTextureId ); + } } CreateRenderer( mTextures ); -- 2.7.4