From 9f54772edf30c4bc7a8ce3bcc175fd2017f2c3d3 Mon Sep 17 00:00:00 2001 From: "Seungho, Baek" Date: Mon, 28 Oct 2019 10:41:52 +0900 Subject: [PATCH 1/1] Add AlphaMask to synchronousLoading Change-Id: I23d5021f31aeb928a899f0c2caaa680ea3a165d9 Signed-off-by: Seungho, Baek --- .../src/dali-toolkit/utc-Dali-ImageVisual.cpp | 60 ++++++++++++++++++++-- .../internal/visuals/image/image-visual.cpp | 4 +- .../internal/visuals/texture-manager-impl.cpp | 14 ++++- 3 files changed, 70 insertions(+), 8 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp index 8cbab66..327d0f0 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -1362,6 +1362,59 @@ int UtcDaliImageVisualAlphaMask(void) END_TEST; } +int UtcDaliImageVisualSynchronousLoadAlphaMask(void) +{ + ToolkitTestApplication application; + tet_infoline( "Request image visual with a Property::Map containing an Alpha mask with synchronous loading" ); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK( factory ); + + Property::Map propertyMap; + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE ); + propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME ); + propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME ); + propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true ); + + Visual::Base visual = factory.CreateVisual( propertyMap ); + DALI_TEST_CHECK( visual ); + + Property::Map testMap; + visual.CreatePropertyMap(testMap); + DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION ); + + // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied. + // Image with a size smaller than 512*512 will be uploaded as a part of the atlas. + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + DummyControl actor = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual ); + + actor.SetSize( 200.f, 200.f ); + DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION ); + + Stage::GetCurrent().Add( actor ); + + // Do not wait for any EventThreadTrigger in synchronous alpha mask. + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION ); + + dummyImpl.UnregisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1 ); + DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliImageVisualRemoteAlphaMask(void) { ToolkitTestApplication application; @@ -1375,13 +1428,14 @@ int UtcDaliImageVisualRemoteAlphaMask(void) Property::Map propertyMap; propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE ); propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); - propertyMap.Insert( "alphaMaskUrl", MASK_IMAGE ); + propertyMap.Insert( ImageVisual::Property::ALPHA_MASK_URL, MASK_IMAGE ); Visual::Base visual = factory.CreateVisual( propertyMap ); DALI_TEST_CHECK( visual ); Property::Map testMap; visual.CreatePropertyMap(testMap); + DALI_TEST_EQUALS(*testMap.Find(ImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION ); // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied. @@ -1394,6 +1448,7 @@ int UtcDaliImageVisualRemoteAlphaMask(void) DummyControl actor = DummyControl::New(); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual ); + DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION ); actor.SetSize( 200.f, 200.f ); @@ -1415,7 +1470,6 @@ int UtcDaliImageVisualRemoteAlphaMask(void) END_TEST; } - int UtcDaliImageVisualAlphaMaskCrop(void) { ToolkitTestApplication application; diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index 8607fa8..7ecfb81 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -427,8 +427,6 @@ void ImageVisual::DoSetProperty( Property::Index index, const Property::Value& v AllocateMaskData(); // Immediately trigger the alpha mask loading (it may just get a cached value) mMaskingData->mAlphaMaskUrl = alphaUrl; - TextureManager& textureManager = mFactoryCache.GetTextureManager(); - mMaskingData->mAlphaMaskId = textureManager.RequestMaskLoad( alphaUrl ); } break; } diff --git a/dali-toolkit/internal/visuals/texture-manager-impl.cpp b/dali-toolkit/internal/visuals/texture-manager-impl.cpp index 6dcc2fc..fbb8114 100644 --- a/dali-toolkit/internal/visuals/texture-manager-impl.cpp +++ b/dali-toolkit/internal/visuals/texture-manager-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -182,6 +182,15 @@ TextureSet TextureManager::LoadTexture( { Devel::PixelBuffer pixelBuffer = LoadImageFromFile( url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection ); + if( maskInfo ) + { + Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile( maskInfo->mAlphaMaskUrl.GetUrl(), ImageDimensions(), + FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true ); + if( maskPixelBuffer ) + { + pixelBuffer.ApplyMask( maskPixelBuffer, maskInfo->mContentScaleFactor, maskInfo->mCropToMask ); + } + } if( pixelBuffer ) { PreMultiply( pixelBuffer, preMultiplyOnLoad ); @@ -243,8 +252,9 @@ TextureSet TextureManager::LoadTexture( } else { + TextureId alphaMaskId = RequestMaskLoad( maskInfo->mAlphaMaskUrl ); textureId = RequestLoad( url, - maskInfo->mAlphaMaskId, + alphaMaskId, maskInfo->mContentScaleFactor, desiredSize, fittingMode, samplingMode, -- 2.7.4