X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-ImageVisual.cpp;h=c6a87119321e94fe65f5709def3806fe9adfdd49;hb=d3a278fc71c792d900071194e50d7235caff0811;hp=4622431154ebca691ed945c91f00b994823454dd;hpb=6ebbbf8ac1bc813b1f34950e4f76d6f55b304495;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp index 4622431..c6a8711 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) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -20,6 +20,7 @@ #include +#include #include #include @@ -32,8 +33,8 @@ #include #include -#include #include "dummy-control.h" +#include "test-encoded-image-buffer.h" #include "test-native-image-source.h" using namespace Dali; @@ -60,6 +61,11 @@ const char* TEST_INVALID_FILE_NAME = TEST_RESOURCE_DIR "/invalid.jpg"; const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png"; const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png"; const char* TEST_ROTATED_IMAGE = TEST_RESOURCE_DIR "/keyboard-Landscape.jpg"; +const char* TEST_YUV420_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1-yuv420.jpg"; +const char* TEST_N_PATCH_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/heartsframe.9.png"; + +constexpr auto LOAD_IMAGE_YUV_PLANES_ENV = "DALI_LOAD_IMAGE_YUV_PLANES"; +constexpr auto ENABLE_DECODE_JPEG_TO_YUV_420_ENV = "DALI_ENABLE_DECODE_JPEG_TO_YUV_420"; bool gResourceReadySignalFired = false; std::vector gReadyIds = {}; @@ -418,6 +424,304 @@ int UtcDaliImageVisualRemoteImageLoad(void) END_TEST; } +int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha01(void) +{ + ToolkitTestApplication application; + tet_infoline("Use FrameBuffer as url"); + + uint32_t width(64); + uint32_t height(64); + FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE); + + DALI_TEST_CHECK(frameBuffer); + ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, Pixel::Format::RGBA8888, width, height); + std::string url = imageUrl.GetUrl(); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK(factory); + + Property::Map propertyMap; + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, url); + + Visual::Base visual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + + application.GetScene().Add(actor); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + + application.SendNotification(); + application.Render(16); + + Renderer renderer = actor.GetRendererAt(0); + + // Check whether preMultipliedAlpha is true. + auto preMultipliedAlpha = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA); + DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliImageVisualWithFrameBufferPreMultipliedAlpha02(void) +{ + ToolkitTestApplication application; + tet_infoline("Use FrameBuffer as url"); + + uint32_t width(64); + uint32_t height(64); + FrameBuffer frameBuffer = Dali::FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE); + + DALI_TEST_CHECK(frameBuffer); + + Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height); + frameBuffer.AttachColorTexture(texture); + + ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(frameBuffer, 0u); + std::string url = imageUrl.GetUrl(); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK(factory); + + Property::Map propertyMap; + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, url); + + Visual::Base visual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + + application.GetScene().Add(actor); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + + application.SendNotification(); + application.Render(16); + + Renderer renderer = actor.GetRendererAt(0); + + // Check whether preMultipliedAlpha is true. + auto preMultipliedAlpha = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA); + DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliImageVisualWithPixelData(void) +{ + ToolkitTestApplication application; + tet_infoline("Use PixelData as url"); + + uint32_t width(64); + uint32_t height(64); + uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888); + + uint8_t* buffer = reinterpret_cast(malloc(bufferSize)); + PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE); + + DALI_TEST_CHECK(pixelData); + + ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData); + std::string url = imageUrl.GetUrl(); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK(factory); + + Property::Map propertyMap; + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, url); + + Visual::Base visual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + + application.GetScene().Add(actor); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + + application.SendNotification(); + application.Render(16); + + Renderer renderer = actor.GetRendererAt(0); + + // Check whether preMultipliedAlpha is false. + auto preMultipliedAlpha = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA); + DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliImageVisualWithPixelDataPreMultipliedAlpha(void) +{ + ToolkitTestApplication application; + tet_infoline("Use PixelData as url"); + + uint32_t width(64); + uint32_t height(64); + uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888); + + uint8_t* buffer = reinterpret_cast(malloc(bufferSize)); + PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE); + + DALI_TEST_CHECK(pixelData); + + ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true); + std::string url = imageUrl.GetUrl(); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK(factory); + + Property::Map propertyMap; + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, url); + + Visual::Base visual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + + application.GetScene().Add(actor); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + + application.SendNotification(); + application.Render(16); + + Renderer renderer = actor.GetRendererAt(0); + + // Check whether preMultipliedAlpha is true. + auto preMultipliedAlpha = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA); + DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliImageVisualWithPixelDataMasking(void) +{ + ToolkitTestApplication application; + tet_infoline("Load external texture with mask"); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + uint32_t width(64); + uint32_t height(64); + uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888); + + uint8_t* buffer = reinterpret_cast(malloc(bufferSize)); + PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE); + + DALI_TEST_CHECK(pixelData); + + ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true); + std::string url = imageUrl.GetUrl(); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK(factory); + + Property::Map propertyMap; + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, url); + propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME); + + 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); + + DummyControl actor = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + + application.GetScene().Add(actor); + application.SendNotification(); + application.Render(16); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + 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 UtcDaliImageVisualWithPixelDataMaskingSynchronously(void) +{ + ToolkitTestApplication application; + tet_infoline("Load synchronously external texture with mask"); + + uint32_t width(64); + uint32_t height(64); + uint32_t bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888); + + uint8_t* buffer = reinterpret_cast(malloc(bufferSize)); + PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE); + + DALI_TEST_CHECK(pixelData); + + ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(pixelData, true); + std::string url = imageUrl.GetUrl(); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK(factory); + + Property::Map propertyMap; + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, url); + 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); + + DummyControl actor = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + + application.GetScene().Add(actor); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + + application.SendNotification(); + application.Render(16); + + END_TEST; +} + int UtcDaliImageVisualWithNativeImage(void) { ToolkitTestApplication application; @@ -447,6 +751,9 @@ int UtcDaliImageVisualWithNativeImage(void) DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + application.SendNotification(); + application.Render(16); + Renderer renderer = actor.GetRendererAt(0); Shader shader = renderer.GetShader(); @@ -460,6 +767,62 @@ int UtcDaliImageVisualWithNativeImage(void) DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION); + // Check whether preMultipliedAlpha is false. + auto preMultipliedAlpha = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA); + DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliImageVisualWithNativeImagePreMultipliedAlpha(void) +{ + ToolkitTestApplication application; + tet_infoline("Use Native Image as url"); + + NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT); + ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true); + std::string url = imageUrl.GetUrl(); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK(factory); + + Property::Map propertyMap; + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, url); + + Visual::Base visual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + + application.GetScene().Add(actor); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + + application.SendNotification(); + application.Render(16); + + Renderer renderer = actor.GetRendererAt(0); + Shader shader = renderer.GetShader(); + + Property::Value value = shader.GetProperty(Shader::Property::PROGRAM); + DALI_TEST_CHECK(value.GetType() == Property::MAP); + const Property::Map* outMap = value.GetMap(); + std::string fragmentShader = (*outMap)["fragment"].Get(); + + const char* fragmentPrefix = Dali::NativeImageSourceTest::GetCustomFragmentPrefix(); + size_t pos = fragmentShader.find(fragmentPrefix); + + DALI_TEST_EQUALS(pos != std::string::npos, true, TEST_LOCATION); + + // Check whether preMultipliedAlpha is true. + auto preMultipliedAlpha = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA); + DALI_TEST_EQUALS(preMultipliedAlpha, true, TEST_LOCATION); + END_TEST; } @@ -469,7 +832,7 @@ int UtcDaliImageVisualWithNativeImageCustomShader(void) tet_infoline("Use Native Image as url and Use custom shader"); NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT); - ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource); + ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true); std::string url = imageUrl.GetUrl(); VisualFactory factory = VisualFactory::Get(); @@ -525,6 +888,11 @@ int UtcDaliImageVisualWithNativeImageCustomShader(void) DALI_TEST_EQUALS(std::string(fragmentPrefix) + customFragmentShaderSource, fragmentShaderSource, TEST_LOCATION); + // Check whether preMultipliedAlpha is false. + // Note : We dont use preMultiplied alpha when app developer using custom shader. + auto preMultipliedAlpha = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA); + DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION); + END_TEST; } @@ -726,14 +1094,10 @@ int UtcDaliImageVisualTextureReuse1(void) DALI_TEST_EQUALS(actor2.GetRendererCount(), 1u, TEST_LOCATION); - tet_infoline( - "Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n" - "draw calls use the same texture as the previous draw call\n"); - + // Testing for texture re-use in gl side is not relevant - we are not using actual graphics + // backend here, but test graphics backend. DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION); - // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back. - // DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION ); tet_infoline("Test that removing 1 actor doesn't delete the texture\n"); @@ -1101,10 +1465,7 @@ int UtcDaliImageVisualAnimateMixColor(void) DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue("uColor", Vector4(1.0f, 1.0f, 1.0f, 0.5f)), true, TEST_LOCATION); DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION); - // GL_BLEND should not be changed: Keep enabled - // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back. - // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); - DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str())); + // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend) TestMixColor(visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR); @@ -1180,8 +1541,7 @@ int UtcDaliImageVisualAnimateOpacity(void) DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue("uColor", color)); DALI_TEST_EQUALS(color.a, 1.0f, TEST_LOCATION); - // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back. - // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); + // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend) DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", blendStr.str())); } @@ -1221,10 +1581,7 @@ int UtcDaliImageVisualAnimateOpacity(void) DALI_TEST_CHECK(application.GetGlAbstraction().GetUniformValue("uColor", color)); DALI_TEST_EQUALS(color.a, 0.1f, TEST_LOCATION); - // GL_BLEND should not be changed: Keep enabled - // @todo - // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back. - // DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) ); + // (Don't test for caching of capabilities, toolkit uses Test graphics backend, not actual backend) DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Disable", blendStr.str())); } @@ -1451,11 +1808,143 @@ int UtcDaliImageVisualTextureCancelAsyncLoad(void) application.GetScene().Add(actor); - // Create another visual with the same image - visual = factory.CreateVisual(propertyMap); - DALI_TEST_CHECK(visual); + // Create another visual with the same image + visual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual); + + application.SendNotification(); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); + DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION); + DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliImageVisualSetInvalidAsyncImage(void) +{ + ToolkitTestApplication application; + tet_infoline("Request image visual with invalid images - should draw broken.png"); + + 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_INVALID_FILE_NAME); + + 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(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + + actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + + application.GetScene().Add(actor); + + application.SendNotification(); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION); + + application.GetScene().Remove(actor); + DALI_TEST_CHECK(actor.GetRendererCount() == 0u); + + END_TEST; +} + +int UtcDaliImageVisualSetInvalidSyncImage(void) +{ + ToolkitTestApplication application; + tet_infoline("Request image visual with invalid images - should draw broken.png"); + + 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_INVALID_FILE_NAME); + propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true); + + 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(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + + actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + + application.GetScene().Add(actor); + + application.SendNotification(); + application.Render(); + + // Check resource status + Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1); + DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION); + + // The broken image should be shown. + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION); + + application.GetScene().Remove(actor); + DALI_TEST_CHECK(actor.GetRendererCount() == 0u); + + END_TEST; +} + +int UtcDaliImageVisualSetInvalidRemoteImage(void) +{ + ToolkitTestApplication application; + tet_infoline("Request image visual with invalid images - should draw broken.png"); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK(factory); + + // Local invalid file, asynchronous loading + Property::Map propertyMap; + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME); + + 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(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + + actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); - dummyImpl.RegisterVisual(Control::Property::BACKGROUND, visual); + application.GetScene().Add(actor); application.SendNotification(); DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); @@ -1464,28 +1953,37 @@ int UtcDaliImageVisualTextureCancelAsyncLoad(void) application.Render(); DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); - DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION); - DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION); + + application.GetScene().Remove(actor); + DALI_TEST_CHECK(actor.GetRendererCount() == 0u); END_TEST; } -int UtcDaliImageVisualSetInvalidAsyncImage(void) +int UtcDaliImageVisualAlphaMask01(void) { ToolkitTestApplication application; - tet_infoline("Request image visual with invalid images - should draw broken.png"); + tet_infoline("Request image visual with a Property::Map containing an Alpha mask"); 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_INVALID_FILE_NAME); + propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME); + propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME); 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); @@ -1496,40 +1994,52 @@ int UtcDaliImageVisualSetInvalidAsyncImage(void) actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION); application.GetScene().Add(actor); - application.SendNotification(); - DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION); 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); - application.GetScene().Remove(actor); - DALI_TEST_CHECK(actor.GetRendererCount() == 0u); + dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1); + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); END_TEST; } -int UtcDaliImageVisualSetInvalidSyncImage(void) +int UtcDaliImageVisualAlphaMask02(void) { ToolkitTestApplication application; - tet_infoline("Request image visual with invalid images - should draw broken.png"); + tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU"); 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_INVALID_FILE_NAME); - propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true); + propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME); + propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME); + propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING); 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); + DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::MASKING_TYPE), Property::Value(DevelImageVisual::MaskingType::MASKING_ON_RENDERING), 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); @@ -1540,42 +2050,55 @@ int UtcDaliImageVisualSetInvalidSyncImage(void) actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION); application.GetScene().Add(actor); - application.SendNotification(); application.Render(); - // Check resource status - Visual::ResourceStatus status = actor.GetVisualResourceStatus(Control::CONTROL_PROPERTY_END_INDEX + 1); - DALI_TEST_EQUALS(status, Visual::ResourceStatus::FAILED, TEST_LOCATION); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); - // The broken image should be shown. DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + Renderer renderer = actor.GetRendererAt(0u); + TextureSet textures = renderer.GetTextures(); + DALI_TEST_CHECK(textures); + DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION); + DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION); + DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION); - application.GetScene().Remove(actor); - DALI_TEST_CHECK(actor.GetRendererCount() == 0u); + dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1); + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); END_TEST; } -int UtcDaliImageVisualSetInvalidRemoteImage(void) +int UtcDaliImageVisualAlphaMask03(void) { ToolkitTestApplication application; - tet_infoline("Request image visual with invalid images - should draw broken.png"); + tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with fail case"); VisualFactory factory = VisualFactory::Get(); DALI_TEST_CHECK(factory); - // Local invalid file, asynchronous loading Property::Map propertyMap; propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); - propertyMap.Insert(ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME); + propertyMap.Insert(ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME); + propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, "dummy_path"); + propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING); Visual::Base visual = factory.CreateVisual(propertyMap); DALI_TEST_CHECK(visual); + Property::Map testMap; + visual.CreatePropertyMap(testMap); + + // 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); @@ -1586,28 +2109,36 @@ int UtcDaliImageVisualSetInvalidRemoteImage(void) actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION); application.GetScene().Add(actor); - application.SendNotification(); - DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); application.SendNotification(); application.Render(); DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + Renderer renderer = actor.GetRendererAt(0u); + TextureSet textures = renderer.GetTextures(); + DALI_TEST_CHECK(textures); + DALI_TEST_EQUALS(textures.GetTextureCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION); + DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION); - application.GetScene().Remove(actor); - DALI_TEST_CHECK(actor.GetRendererCount() == 0u); + dummyImpl.UnregisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1); + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); END_TEST; } -int UtcDaliImageVisualAlphaMask(void) +int UtcDaliImageVisualSynchronousLoadAlphaMask01(void) { ToolkitTestApplication application; - tet_infoline("Request image visual with a Property::Map containing an Alpha mask"); + tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading"); VisualFactory factory = VisualFactory::Get(); DALI_TEST_CHECK(factory); @@ -1616,6 +2147,7 @@ int UtcDaliImageVisualAlphaMask(void) 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); @@ -1640,10 +2172,8 @@ int UtcDaliImageVisualAlphaMask(void) DALI_TEST_EQUALS(actor.IsResourceReady(), false, TEST_LOCATION); application.GetScene().Add(actor); - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION); + // Do not wait for any EventThreadTrigger in synchronous alpha mask. application.SendNotification(); application.Render(); @@ -1658,10 +2188,10 @@ int UtcDaliImageVisualAlphaMask(void) END_TEST; } -int UtcDaliImageVisualSynchronousLoadAlphaMask(void) +int UtcDaliImageVisualSynchronousLoadAlphaMask02(void) { ToolkitTestApplication application; - tet_infoline("Request image visual with a Property::Map containing an Alpha mask with synchronous loading"); + tet_infoline("Request image visual with a Property::Map containing an Alpha mask for GPU with synchronous loading"); VisualFactory factory = VisualFactory::Get(); DALI_TEST_CHECK(factory); @@ -1671,6 +2201,7 @@ int UtcDaliImageVisualSynchronousLoadAlphaMask(void) 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); + propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING); Visual::Base visual = factory.CreateVisual(propertyMap); DALI_TEST_CHECK(visual); @@ -1702,6 +2233,11 @@ int UtcDaliImageVisualSynchronousLoadAlphaMask(void) application.Render(); DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + Renderer renderer = actor.GetRendererAt(0u); + TextureSet textures = renderer.GetTextures(); + DALI_TEST_CHECK(textures); + DALI_TEST_EQUALS(textures.GetTextureCount(), 2u, TEST_LOCATION); + DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION); DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION); @@ -2228,9 +2764,9 @@ int UtcDaliImageVisualReleasePolicy08(void) 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(); + // Ensure Texture is same after detach/attach on stage when texture used the DESTROYED release policy + // 1. Get Texture + Texture textureBefore = actor.GetRendererAt(0u).GetTextures().GetTexture(0u); // 2.Remove actor from stage. In this case, renderer also is deleted. tet_infoline("Remove actor from stage"); @@ -2253,12 +2789,12 @@ int UtcDaliImageVisualReleasePolicy08(void) 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(); + // 4.Compare Texture with before and after. texture need to be same because release policy is the DESTROYED. + tet_infoline("Ensure a texture is not deleted because it is used the DESTROYED release policy"); + Texture textureAfter = actor.GetRendererAt(0u).GetTextures().GetTexture(0u); + DALI_TEST_CHECK(textureBefore == textureAfter); + textureBefore.Reset(); + textureAfter.Reset(); dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL); DALI_TEST_CHECK(actor.GetRendererCount() == 0u); @@ -2269,6 +2805,65 @@ int UtcDaliImageVisualReleasePolicy08(void) END_TEST; } +int UtcDaliImageVisualReleasePolicy09(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliImageVisualReleasePolicy09 Destroyed Policy with N-Patch, Texture should be deleted when visual destroyed"); + + Property::Map propertyMapNPatchReleasePolicy; + propertyMapNPatchReleasePolicy.Insert(Visual::Property::TYPE, Visual::N_PATCH); + propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::URL, TEST_N_PATCH_IMAGE_FILE_NAME); + propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_MASK_IMAGE_FILE_NAME); + propertyMapNPatchReleasePolicy.Insert(DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA, 0.9f); + propertyMapNPatchReleasePolicy.Insert(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DESTROYED); + + VisualFactory factory = VisualFactory::Get(); + Visual::Base imageVisual = factory.CreateVisual(propertyMapNPatchReleasePolicy); + DALI_TEST_CHECK(imageVisual); + + // Setup debug trace + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + tet_infoline("Register visual with control and ensure it has the only handle"); + DummyControl actor = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual); + imageVisual.Reset(); // reduce ref count so only the control keeps the visual alive. + + actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK(actor.GetRendererCount() == 0u); + DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); + + application.GetScene().Add(actor); + + // Wait for image to load + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(0); + // Test renderer and texture created + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); + + DALI_TEST_CHECK(actor.GetRendererCount() == 1u); + tet_infoline("Destroy visual by UnRegistering visual with control, check renderer is destroyed"); + dummyImpl.UnregisterVisual(DummyControl::Property::TEST_VISUAL); + DALI_TEST_CHECK(actor.GetRendererCount() == 0u); + application.SendNotification(); + application.Render(); + + // Test texture removed after visual destroyed. + tet_infoline("Ensure texture is deleted after visual destroyed"); + DALI_TEST_EQUALS(textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION); + + END_TEST; +} + int UtcDaliImageVisualLoadPolicy01(void) { ToolkitTestApplication application; @@ -2422,7 +3017,7 @@ int UtcDaliImageVisualLoadPolicy03(void) // Ensure texture has been uploaded DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); - DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION); + DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION); END_TEST; } @@ -2460,7 +3055,7 @@ int UtcDaliImageVisualLoadPolicy04(void) tet_infoline("Testing texture is loaded and resource ready signal fired"); DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION); - DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION); + DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION); tet_infoline("Original control correctly signalled, now testing for signal with new Control reusing the image"); @@ -2753,3 +3348,131 @@ int UtcDaliImageVisualLoadReady01(void) END_TEST; } + +int UtcDaliImageVisualLoadImagePlanes01(void) +{ + EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1"); + EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1"); + + ToolkitTestApplication application; + + 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_YUV420_IMAGE_FILE_NAME); + + Visual::Base visual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); + application.GetScene().Add(actor); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION); + DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION); + + Renderer renderer = actor.GetRendererAt(0); + auto preMultipliedAlpha = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA); + DALI_TEST_EQUALS(preMultipliedAlpha, false, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliImageVisualLoadImagePlanes02(void) +{ + EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1"); + EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1"); + + ToolkitTestApplication application; + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK(factory); + + // Alpha masking case - not support yuv planes + Property::Map propertyMap; + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME); + propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME); + + Visual::Base visual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); + application.GetScene().Add(actor); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION); + DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 1, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliImageVisualLoadImagePlanes03(void) +{ + EnvironmentVariable::SetTestEnvironmentVariable(LOAD_IMAGE_YUV_PLANES_ENV, "1"); + EnvironmentVariable::SetTestEnvironmentVariable(ENABLE_DECODE_JPEG_TO_YUV_420_ENV, "1"); + + ToolkitTestApplication application; + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK(factory); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + Property::Map propertyMap; + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, TEST_YUV420_IMAGE_FILE_NAME); + propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true); + + Visual::Base visual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, visual); + actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); + application.GetScene().Add(actor); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(actor.IsResourceReady(), true, TEST_LOCATION); + DALI_TEST_EQUALS(textureTrace.CountMethod("GenTextures"), 3, TEST_LOCATION); + + END_TEST; +}