X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-AnimatedImageVisual.cpp;h=3c23a0649eb2ed9c7c1177e6d8dd9c78949d91e5;hb=HEAD;hp=55745fbf3a9f71794e6aece20d90bbe658fb9ba2;hpb=30ab0b53e3db70b863106e105a9bcce27a0369b1;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp index 55745fb..161b479 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 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. @@ -28,6 +28,7 @@ #include #include #include +#include #include "dummy-control.h" @@ -49,6 +50,12 @@ namespace const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/application-icon-%02d.png"; const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif"; const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png"; +const char* TEST_WEBP_FILE_NAME = TEST_RESOURCE_DIR "/dali-logo.webp"; + +const char* TEST_N_PATCH_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/heartsframe.9.png"; +const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg"; +const char* TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json"; + } // namespace void CopyUrlsIntoArray(Property::Array& urls, int startIndex = 0) @@ -79,9 +86,14 @@ int UtcDaliAnimatedImageVisualGetPropertyMap01(void) .Add(ImageVisual::Property::PIXEL_AREA, Vector4()) .Add(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT) .Add(ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT) + .Add(ImageVisual::Property::FITTING_MODE, FittingMode::FIT_WIDTH) + .Add(ImageVisual::Property::SAMPLING_MODE, SamplingMode::NEAREST) + .Add(ImageVisual::Property::DESIRED_WIDTH, 154) + .Add(ImageVisual::Property::DESIRED_HEIGHT, 79) .Add(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME) .Add(ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f) .Add(ImageVisual::Property::CROP_TO_MASK, true) + .Add(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING) .Add(DevelVisual::Property::CORNER_RADIUS, 22.2f) .Add(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE) .Add(DevelVisual::Property::BORDERLINE_WIDTH, 33.3f) @@ -99,6 +111,30 @@ int UtcDaliAnimatedImageVisualGetPropertyMap01(void) DALI_TEST_CHECK(value); DALI_TEST_CHECK(value->Get() == TEST_GIF_FILE_NAME); + value = resultMap.Find(Toolkit::ImageVisual::Property::WRAP_MODE_U, Property::INTEGER); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == WrapMode::REPEAT); + + value = resultMap.Find(Toolkit::ImageVisual::Property::WRAP_MODE_V, Property::INTEGER); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == WrapMode::DEFAULT); + + value = resultMap.Find(Toolkit::ImageVisual::Property::FITTING_MODE, Property::INTEGER); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == FittingMode::FIT_WIDTH); + + value = resultMap.Find(Toolkit::ImageVisual::Property::SAMPLING_MODE, Property::INTEGER); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == SamplingMode::NEAREST); + + value = resultMap.Find(Toolkit::ImageVisual::Property::DESIRED_WIDTH, Property::INTEGER); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == 154); + + value = resultMap.Find(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, Property::INTEGER); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == 79); + value = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4); DALI_TEST_CHECK(value); DALI_TEST_EQUALS(value->Get(), Vector4(22.2f, 22.2f, 22.2f, 22.2f), TEST_LOCATION); @@ -132,9 +168,14 @@ int UtcDaliAnimatedImageVisualGetPropertyMap01(void) DALI_TEST_CHECK(value); DALI_TEST_EQUALS(value->Get(), true, TEST_LOCATION); + value = resultMap.Find(DevelImageVisual::Property::MASKING_TYPE, Property::INTEGER); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == DevelImageVisual::MaskingType::MASKING_ON_RENDERING); + + // Natural size getted as desired size Vector2 naturalSize; animatedImageVisual.GetNaturalSize(naturalSize); - DALI_TEST_EQUALS(naturalSize, Vector2(100, 100), TEST_LOCATION); + DALI_TEST_EQUALS(naturalSize, Vector2(154, 79), TEST_LOCATION); // request AnimatedImageVisual with an URL Visual::Base animatedImageVisual2 = factory.CreateVisual(TEST_GIF_FILE_NAME, ImageDimensions()); @@ -149,6 +190,10 @@ int UtcDaliAnimatedImageVisualGetPropertyMap01(void) DALI_TEST_CHECK(value); DALI_TEST_CHECK(value->Get() == TEST_GIF_FILE_NAME); + // Natural size getted as image size + animatedImageVisual2.GetNaturalSize(naturalSize); + DALI_TEST_EQUALS(naturalSize, Vector2(50, 50), TEST_LOCATION); + END_TEST; } @@ -173,9 +218,14 @@ int UtcDaliAnimatedImageVisualGetPropertyMap02(void) .Add("pixelArea", Vector4()) .Add("wrapModeU", WrapMode::REPEAT) .Add("wrapModeV", WrapMode::DEFAULT) + .Add("fittingMode", FittingMode::FIT_WIDTH) + .Add("samplingMode", SamplingMode::NEAREST) + .Add("desiredWidth", 154) + .Add("desiredHeight", 79) .Add("alphaMaskUrl", TEST_MASK_IMAGE_FILE_NAME) .Add("maskContentScale", 1.6f) .Add("cropToMask", true) + .Add(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING) .Add("cornerRadius", Vector4(50.0f, 25.0f, 12.5f, 33.0f)) .Add("cornerRadiusPolicy", Visual::Transform::Policy::RELATIVE) .Add("borderlineWidth", 20.0f) @@ -215,6 +265,30 @@ int UtcDaliAnimatedImageVisualGetPropertyMap02(void) DALI_TEST_CHECK(value); DALI_TEST_EQUALS(value->Get(), 11, TEST_LOCATION); + value = resultMap.Find(Toolkit::ImageVisual::Property::WRAP_MODE_U, "wrapModeU"); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == WrapMode::REPEAT); + + value = resultMap.Find(Toolkit::ImageVisual::Property::WRAP_MODE_V, "wrapModeV"); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == WrapMode::DEFAULT); + + value = resultMap.Find(Toolkit::ImageVisual::Property::FITTING_MODE, "fittingMode"); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == FittingMode::FIT_WIDTH); + + value = resultMap.Find(Toolkit::ImageVisual::Property::SAMPLING_MODE, "samplingMode"); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == SamplingMode::NEAREST); + + value = resultMap.Find(Toolkit::ImageVisual::Property::DESIRED_WIDTH, "desiredWidth"); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == 154); + + value = resultMap.Find(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, "desiredHeight"); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == 79); + value = resultMap.Find(Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius"); DALI_TEST_CHECK(value); DALI_TEST_EQUALS(value->Get(), Vector4(50.0f, 25.0f, 12.5f, 33.0f), TEST_LOCATION); @@ -248,6 +322,10 @@ int UtcDaliAnimatedImageVisualGetPropertyMap02(void) DALI_TEST_CHECK(value); DALI_TEST_EQUALS(value->Get(), true, TEST_LOCATION); + value = resultMap.Find(DevelImageVisual::Property::MASKING_TYPE, Property::INTEGER); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == DevelImageVisual::MaskingType::MASKING_ON_RENDERING); + END_TEST; } @@ -275,6 +353,7 @@ int UtcDaliAnimatedImageVisualGetPropertyMap03(void) .Add("alphaMaskUrl", TEST_MASK_IMAGE_FILE_NAME) .Add("maskContentScale", 1.6f) .Add("cropToMask", true) + .Add(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING) .Add("cornerRadius", 50.5f)); Property::Map resultMap; @@ -343,6 +422,15 @@ int UtcDaliAnimatedImageVisualGetPropertyMap03(void) DALI_TEST_CHECK(value); DALI_TEST_EQUALS(value->Get(), true, TEST_LOCATION); + value = resultMap.Find(DevelImageVisual::Property::MASKING_TYPE, Property::INTEGER); + DALI_TEST_CHECK(value); + DALI_TEST_CHECK(value->Get() == DevelImageVisual::MaskingType::MASKING_ON_RENDERING); + + // Natural size getted as masked image size + Vector2 naturalSize; + animatedImageVisual.GetNaturalSize(naturalSize); + DALI_TEST_EQUALS(naturalSize, Vector2(100, 100), TEST_LOCATION); + END_TEST; } @@ -398,7 +486,7 @@ int UtcDaliAnimatedImageVisualGetPropertyMap04(void) value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber"); DALI_TEST_CHECK(value); - DALI_TEST_EQUALS(value->Get(), 4, TEST_LOCATION); + DALI_TEST_EQUALS(value->Get(), -1, TEST_LOCATION); value = resultMap.Find(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, "borderlineWidth"); DALI_TEST_CHECK(value); @@ -462,6 +550,112 @@ int UtcDaliAnimatedImageVisualImageLoadingFail01(void) END_TEST; } +int UtcDaliAnimatedImageVisualImageLoadingFail02(void) +{ + ToolkitTestApplication application; + + tet_infoline("Test with non-animated single image. We should show broken image than."); + + for(int isSynchronousLoading = 0; isSynchronousLoading < 2; ++isSynchronousLoading) + { + tet_printf("Test to load non-animatable image %s\n", (isSynchronousLoading == 1) ? "Synchronously" : "Asynchronously"); + + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, "dummy"); + propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, (isSynchronousLoading == 1)); + + VisualFactory factory = VisualFactory::Get(); + Visual::Base visual = factory.CreateVisual(propertyMap); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual); + + dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + + DALI_TEST_EQUALS(dummyControl.GetRendererCount(), 0u, TEST_LOCATION); + + application.GetScene().Add(dummyControl); + + application.SendNotification(); + application.Render(20); + + if(!(isSynchronousLoading == 1)) + { + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + } + + application.SendNotification(); + application.Render(20); + + // Check broken image uploaded. + DALI_TEST_EQUALS(dummyControl.GetRendererCount(), 1u, TEST_LOCATION); + + dummyControl.Unparent(); + + // Remove cached image at TextureManager. + application.SendNotification(); + application.Render(20); + } + + END_TEST; +} + +int UtcDaliAnimatedImageVisualImageLoadingFail03(void) +{ + ToolkitTestApplication application; + + tet_infoline("Test with invalid image that suffix is .gif, and AnimatedImageLoading not supported. We should show broken image than."); + + for(int isSynchronousLoading = 0; isSynchronousLoading < 2; ++isSynchronousLoading) + { + tet_printf("Test to load non-animatable image %s\n", (isSynchronousLoading == 1) ? "Synchronously" : "Asynchronously"); + + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, "dummy.Gif"); ///< Suffix is gif so visual become AnimatedImageVisual. But AnimatedImageLoading become null. + propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, (isSynchronousLoading == 1)); + + VisualFactory factory = VisualFactory::Get(); + Visual::Base visual = factory.CreateVisual(propertyMap); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual); + + dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + + DALI_TEST_EQUALS(dummyControl.GetRendererCount(), 0u, TEST_LOCATION); + + application.GetScene().Add(dummyControl); + + application.SendNotification(); + application.Render(20); + + // TODO : Since fixed-image-cache didn't support synchronous loading now, we need to wait for a while. + // We have to remove it in future! + //if(!(isSynchronousLoading == 1)) + { + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + } + + application.SendNotification(); + application.Render(20); + + // Check broken image uploaded. + DALI_TEST_EQUALS(dummyControl.GetRendererCount(), 1u, TEST_LOCATION); + + dummyControl.Unparent(); + + // Remove cached image at TextureManager. + application.SendNotification(); + application.Render(20); + } + + END_TEST; +} + int UtcDaliAnimatedImageVisualSynchronousLoading(void) { ToolkitTestApplication application; @@ -525,11 +719,11 @@ int UtcDaliAnimatedImageVisualSynchronousLoading(void) END_TEST; } - -int UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask(void) +int UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask01(void) { ToolkitTestApplication application; - TestGlAbstraction& gl = application.GetGlAbstraction(); + tet_infoline("UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask01 for CPU Alpha Masking"); + TestGlAbstraction& gl = application.GetGlAbstraction(); { Property::Map propertyMap; @@ -582,6 +776,64 @@ int UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask(void) END_TEST; } +int UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask02(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliAnimatedImageVisualSynchronousLoadingWithAlphaMask02 for GPU Alpha Masking"); + TestGlAbstraction& gl = application.GetGlAbstraction(); + + { + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME); + propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2); + propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 2); + propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20); + propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true); + propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME); + propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING); + propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS, 0.23f); + propertyMap.Insert(DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE); + + VisualFactory factory = VisualFactory::Get(); + Visual::Base visual = factory.CreateVisual(propertyMap); + + 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 dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual); + + dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + application.GetScene().Add(dummyControl); + + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + application.SendNotification(); + application.Render(20); + + // The first frame is loaded synchronously and load next batch with masking + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::GetTimerCount(), 1, TEST_LOCATION); + DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION); + + dummyControl.Unparent(); + } + tet_infoline("Test that removing the visual from stage deletes all textures"); + application.SendNotification(); + application.Render(16); + DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION); + + END_TEST; +} + int UtcDaliAnimatedImageVisualJumpToAction(void) { ToolkitTestApplication application; @@ -634,7 +886,7 @@ int UtcDaliAnimatedImageVisualJumpToAction(void) DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::JUMP_TO, 6); - DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(6), true, TEST_LOCATION); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION); DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 4, TEST_LOCATION); dummyControl.Unparent(); @@ -789,6 +1041,7 @@ int UtcDaliAnimatedImageVisualAnimatedImage01(void) ToolkitTestApplication application; TestGlAbstraction& gl = application.GetGlAbstraction(); + tet_infoline("Set cache size same as GIF frame, and try to load same image at another ImageView"); { Property::Map propertyMap; propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE); @@ -815,6 +1068,7 @@ int UtcDaliAnimatedImageVisualAnimatedImage01(void) DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + // Batch 2 frames. Now frame 0, 1 cached. application.SendNotification(); application.Render(20); @@ -832,12 +1086,54 @@ int UtcDaliAnimatedImageVisualAnimatedImage01(void) DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + // 0 frame removed. and after, batch 2 frames. Now frame 1, 2, 3 cached. application.SendNotification(); application.Render(20); DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 4, TEST_LOCATION); + Visual::Base visual2 = factory.CreateVisual(propertyMap); + DummyControl dummyControl2 = DummyControl::New(true); + Impl::DummyControl& dummyImpl2 = static_cast(dummyControl2.GetImplementation()); + dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2); + application.GetScene().Add(dummyControl2); + + tet_infoline("Add new view with same url"); + + application.SendNotification(); + application.Render(); + + // Note that we only re-load 0 frame. + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + tet_infoline("Test that we don't try to re-load new image cause it cached"); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 1), false, TEST_LOCATION); + + // Batch 2 frames. Now visual frame 1, 2, 3 cached and visual2 frame 0, 1 cached. + application.SendNotification(); + application.Render(20); + + DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 5, TEST_LOCATION); + + textureTrace.Reset(); + + tet_infoline("Load some many frames"); + + const int repeatCount = 10; + for(int repeat = 0; repeat < repeatCount; ++repeat) + { + Test::EmitGlobalTimerSignal(); + application.SendNotification(); + application.Render(2000); + } + + DALI_TEST_EQUALS(textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION); // A new texture should NOT be generated. + DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 5, TEST_LOCATION); + + textureTrace.Reset(); + dummyControl.Unparent(); + dummyControl2.Unparent(); } tet_infoline("Test that removing the visual from stage deletes all textures"); application.SendNotification(); @@ -850,7 +1146,8 @@ int UtcDaliAnimatedImageVisualAnimatedImage01(void) int UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask01(void) { ToolkitTestApplication application; - TestGlAbstraction& gl = application.GetGlAbstraction(); + tet_infoline("UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask01 for CPU Alpha Masking"); + TestGlAbstraction& gl = application.GetGlAbstraction(); { Property::Map propertyMap; @@ -861,7 +1158,6 @@ int UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask01(void) propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20); propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME); - VisualFactory factory = VisualFactory::Get(); Visual::Base visual = factory.CreateVisual(propertyMap); @@ -893,6 +1189,103 @@ int UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask01(void) END_TEST; } +int UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask02(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask02 for GPU Alpha Masking"); + TestGlAbstraction& gl = application.GetGlAbstraction(); + + { + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME); + propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2); + propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4); + propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20); + propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME); + propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING); + + VisualFactory factory = VisualFactory::Get(); + Visual::Base visual = factory.CreateVisual(propertyMap); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual); + + dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + application.GetScene().Add(dummyControl); + + Property::Map attributes; + DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::STOP, attributes); + + application.SendNotification(); + application.Render(); + + // load two frame(batch size), load mask image, and request two masking + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(20); + + DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION); + + dummyControl.Unparent(); + } + tet_infoline("Test that removing the visual from stage deletes all textures"); + application.SendNotification(); + application.Render(20); + DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask03(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliAnimatedImageVisualAnimatedImageWithAlphaMask03 for GPU Alpha Masking with broken mask texture"); + TestGlAbstraction& gl = application.GetGlAbstraction(); + + { + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME); + propertyMap.Insert(ImageVisual::Property::BATCH_SIZE, 2); + propertyMap.Insert(ImageVisual::Property::CACHE_SIZE, 4); + propertyMap.Insert(ImageVisual::Property::FRAME_DELAY, 20); + propertyMap.Insert(ImageVisual::Property::ALPHA_MASK_URL, ""); + propertyMap.Insert(DevelImageVisual::Property::MASKING_TYPE, DevelImageVisual::MaskingType::MASKING_ON_RENDERING); + + VisualFactory factory = VisualFactory::Get(); + Visual::Base visual = factory.CreateVisual(propertyMap); + + DummyControl dummyControl = DummyControl::New(true); + Impl::DummyControl& dummyImpl = static_cast(dummyControl.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual); + + dummyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + application.GetScene().Add(dummyControl); + + application.SendNotification(); + application.Render(); + + // load two frame(batch size), load mask image, and request two masking + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(20); + + DALI_TEST_EQUALS(gl.GetLastGenTextureId(), 3, TEST_LOCATION); + + dummyControl.Unparent(); + } + tet_infoline("Test that removing the visual from stage deletes all textures"); + application.SendNotification(); + application.Render(20); + DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 0, TEST_LOCATION); + + END_TEST; +} + int UtcDaliAnimatedImageVisualMultiImage01(void) { ToolkitTestApplication application; @@ -1063,6 +1456,12 @@ int UtcDaliAnimatedImageVisualMultiImage02(void) dummyImpl1.UnregisterVisual(DummyControl::Property::TEST_VISUAL); dummyControl.Unparent(); + // Ensure to remove cached texture. (Since we support lazy cache removal) + application.SendNotification(); + application.Render(16); + application.SendNotification(); + application.Render(16); + // Batch size is 9 and cache size is 4 propertyMap.Clear(); propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE); @@ -1355,6 +1754,8 @@ int UtcDaliAnimatedImageVisualMultiImage05(void) END_TEST; } +namespace +{ void TestLoopCount(ToolkitTestApplication& application, DummyControl& dummyControl, uint16_t frameCount, uint16_t loopCount, const char* location) { TestGlAbstraction& gl = application.GetGlAbstraction(); @@ -1405,6 +1806,7 @@ void TestLoopCount(ToolkitTestApplication& application, DummyControl& dummyContr dummyControl.Unparent(); } +} // namespace int UtcDaliAnimatedImageVisualLoopCount(void) { @@ -1568,3 +1970,384 @@ int UtcDaliAnimatedImageVisualPlayback(void) END_TEST; } + +int UtcDaliAnimatedImageVisualWrapMode(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliAnimatedImageVisualWrapMode"); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK(factory); + + // Test wrap mode in animated image visual. + const int width = 950; + const int height = 1080; + const Vector4 pixelArea(0.0f, 0.0f, 950 / 40, 1.0f); + + Property::Map propertyMap; + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, TEST_WEBP_FILE_NAME); + propertyMap.Insert(ImageVisual::Property::PIXEL_AREA, pixelArea); + propertyMap.Insert(ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT); + + Visual::Base visual = factory.CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + textureTrace.EnableLogging(true); + TraceCallStack& texParameterTrace = gl.GetTexParameterTrace(); + texParameterTrace.Enable(true); + texParameterTrace.EnableLogging(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(width, height)); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + + DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION); + application.GetScene().Add(actor); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(actor.GetRendererCount() == 1u); + + DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION); + + // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters + std::stringstream out; + out << std::hex << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_REPEAT; + DALI_TEST_CHECK(texParameterTrace.FindMethodAndParams("TexParameteri", out.str())); + + // test the uniforms which used to handle the wrap mode + Renderer renderer = actor.GetRendererAt(0u); + DALI_TEST_CHECK(renderer); + + Property::Value pixelAreaValue = renderer.GetProperty(renderer.GetPropertyIndex("pixelArea")); + DALI_TEST_EQUALS(pixelAreaValue.Get(), pixelArea, TEST_LOCATION); + + actor.Unparent(); + DALI_TEST_CHECK(actor.GetRendererCount() == 0u); + + END_TEST; +} + +int UtcDaliAnimatedImageVisualDesiredSize(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliAnimatedImageVisualDesiredSize"); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + + // Set desiredWidth < 37 and desiredHeight < 50, which is smaller than original image's size. + int desiredWidth = 15; + int desiredHeight = 20; + + // texture size have to keep it's ratio. So, the size of texture should be 20x20. + const int resultWidth = 20; + const int resultHeight = 20; + + Visual::Base visual = VisualFactory::Get().CreateVisual(TEST_GIF_FILE_NAME, ImageDimensions(desiredWidth, desiredHeight)); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(true); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual); + + application.GetScene().Add(actor); + + application.SendNotification(); + application.Render(); + + // Trigger count is 2 - first frame and second frame. + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + + textureTrace.Enable(true); + textureTrace.EnableLogging(true); + + application.SendNotification(); + application.Render(); + + { + std::stringstream out; + out << GL_TEXTURE_2D << ", " << 0u << ", " << resultWidth << ", " << resultHeight; + DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str())); + } + + // Unparent to make next trigger + actor.Unparent(); + + application.SendNotification(); + application.Render(); + + // Set visual size + actor.SetProperty(Actor::Property::SIZE, Vector2(300.0f, 300.0f)); + application.GetScene().Add(actor); + + application.SendNotification(); + application.Render(); + + // Trigger count is 2 - first frame and second frame. + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + + textureTrace.Reset(); + + application.SendNotification(); + application.Render(); + + { + std::stringstream out; + out << GL_TEXTURE_2D << ", " << 0u << ", " << resultWidth << ", " << resultHeight; + DALI_TEST_CHECK(textureTrace.FindMethodAndParams("TexImage2D", out.str().c_str())); // The size should be changed for keeping the aspect ratio. + } + + END_TEST; +} + +int UtcDaliAnimatedImageVisualControlVisibilityChanged(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliAnimatedImageVisualControlVisibilityChanged"); + + Property::Map propertyMap; + propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_IMAGE) + .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME) + .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME) + .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false); + + Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(true); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual); + + Vector2 controlSize(20.f, 30.f); + actor.SetProperty(Actor::Property::SIZE, controlSize); + + application.GetScene().Add(actor); + + application.SendNotification(); + application.Render(); + + // Trigger count is 2 - load & render a frame + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + + Property::Map attributes; + DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes); + + application.SendNotification(); + application.Render(); + + // Check frame number + DALI_TEST_CHECK(actor.GetRendererCount() == 1u); + Renderer renderer = actor.GetRendererAt(0u); + DALI_TEST_CHECK(renderer); + + Test::EmitGlobalTimerSignal(); + application.SendNotification(); + application.Render(16); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + Property::Map resultMap; + visual.CreatePropertyMap(resultMap); + + // check the property values from the returned map from a visual + Property::Value* value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER); + DALI_TEST_CHECK(value); + DALI_TEST_NOT_EQUALS(value->Get(), 0, Math::MACHINE_EPSILON_100, TEST_LOCATION); + + actor.SetProperty(Actor::Property::VISIBLE, false); + + Test::EmitGlobalTimerSignal(); + application.SendNotification(); + application.Render(16); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + visual.CreatePropertyMap(resultMap); + + // check the property values from the returned map from a visual + value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER); + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), 0, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliAnimatedImageVisualWindowVisibilityChanged(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliAnimatedImageVisualWindowVisibilityChanged"); + + Property::Map propertyMap; + propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_IMAGE) + .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME) + .Add(DevelImageVisual::Property::STOP_BEHAVIOR, DevelImageVisual::StopBehavior::FIRST_FRAME) + .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false); + + Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(true); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual); + + Vector2 controlSize(20.f, 30.f); + actor.SetProperty(Actor::Property::SIZE, controlSize); + + application.GetScene().Add(actor); + + application.SendNotification(); + application.Render(); + + // Trigger count is 2 - load & render a frame + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + + Property::Map attributes; + DevelControl::DoAction(actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedImageVisual::Action::PLAY, attributes); + + application.SendNotification(); + application.Render(); + + // Check frame number + DALI_TEST_CHECK(actor.GetRendererCount() == 1u); + Renderer renderer = actor.GetRendererAt(0u); + DALI_TEST_CHECK(renderer); + + Test::EmitGlobalTimerSignal(); + application.SendNotification(); + application.Render(16); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + Property::Map resultMap; + visual.CreatePropertyMap(resultMap); + + // check the property values from the returned map from a visual + Property::Value* value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER); + DALI_TEST_CHECK(value); + DALI_TEST_NOT_EQUALS(value->Get(), 0, Math::MACHINE_EPSILON_100, TEST_LOCATION); + + Window window = DevelWindow::Get(actor); + window.Hide(); + + Test::EmitGlobalTimerSignal(); + application.SendNotification(); + application.Render(16); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + visual.CreatePropertyMap(resultMap); + + // check the property values from the returned map from a visual + value = resultMap.Find(DevelImageVisual::Property::CURRENT_FRAME_NUMBER); + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), 0, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliAnimatedImageVisualFrameCountBeforeLoadingFinished(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliAnimatedImageVisualFrameCountBeforeLoadingFinished"); + + Property::Map propertyMap; + propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_IMAGE) + .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME) + .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false); + + Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + Property::Map resultMap1; + visual.CreatePropertyMap(resultMap1); + Property::Value* value1 = resultMap1.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER); + DALI_TEST_CHECK(value1); + DALI_TEST_EQUALS(value1->Get(), -1, Math::MACHINE_EPSILON_100, TEST_LOCATION); + + DummyControl actor = DummyControl::New(true); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual); + + Property::Map resultMap2; + visual.CreatePropertyMap(resultMap2); + Property::Value* value2 = resultMap2.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER); + DALI_TEST_CHECK(value2); + DALI_TEST_EQUALS(value2->Get(), -1, Math::MACHINE_EPSILON_100, TEST_LOCATION); + + Vector2 controlSize(20.f, 30.f); + actor.SetProperty(Actor::Property::SIZE, controlSize); + + application.GetScene().Add(actor); + + application.SendNotification(); + application.Render(); + + // Trigger count is 2 - load & render a frame + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + + Property::Map resultMap3; + visual.CreatePropertyMap(resultMap3); + Property::Value* value3 = resultMap3.Find(DevelImageVisual::Property::TOTAL_FRAME_NUMBER); + DALI_TEST_CHECK(value3); + DALI_TEST_EQUALS(value3->Get(), 4, Math::MACHINE_EPSILON_100, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliAnimatedImageVisualLoadNonRegularImage(void) +{ + ToolkitTestApplication application; + + std::vector> urlAndExpectVisualTypes = { + {TEST_MASK_IMAGE_FILE_NAME, DevelVisual::IMAGE}, + {TEST_N_PATCH_IMAGE_FILE_NAME, DevelVisual::N_PATCH}, + {TEST_SVG_FILE_NAME, DevelVisual::SVG}, + {TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, DevelVisual::ANIMATED_VECTOR_IMAGE}, + }; + + for(const auto& urlAndExpectVisualTypePair : urlAndExpectVisualTypes) + { + tet_printf("Test AnimatedImageVisual with url: %s\n", urlAndExpectVisualTypePair.first.c_str()); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, urlAndExpectVisualTypePair.first); + propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true); + + Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + Property::Map resultMap; + visual.CreatePropertyMap(resultMap); + + Property::Value* typeValue = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER); + DALI_TEST_CHECK(typeValue); + int type = typeValue->Get(); + DALI_TEST_EQUALS(type, static_cast(urlAndExpectVisualTypePair.second), TEST_LOCATION); + } + + END_TEST; +}