X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-ImageVisual.cpp;h=cd834df31f6c95dfd3b17060701b4bfcba12185b;hp=ce1a0222231e45f2345561d5849ee3ac6becdf0b;hb=42a61237c2ecc17d977fbf9596603da2ff221be7;hpb=bed9d1fafb2def9ec59d67277a4935a9f7fcbdd1 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp index ce1a022..cd834df 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp @@ -24,8 +24,14 @@ #include #include #include +#include +#include +#include #include + +#include #include "dummy-control.h" +#include "test-native-image-source.h" using namespace Dali; using namespace Dali::Toolkit; @@ -416,6 +422,208 @@ int UtcDaliImageVisualRemoteImageLoad(void) END_TEST; } + +int UtcDaliImageVisualWithNativeImage(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); + 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 ); + + 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 ); + + END_TEST; +} + +int UtcDaliImageVisualWithNativeImageRemoved(void) +{ + ToolkitTestApplication application; + tet_infoline( "Use Native Image as url" ); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + NativeImageSourcePtr nativeImageSource = NativeImageSource::New(500, 500, NativeImageSource::COLOR_DEPTH_DEFAULT); + ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSource); + 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( DummyControl::Property::TEST_VISUAL, visual ); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); + + application.GetScene().Add( actor ); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION ); + + tet_infoline( "No delete texture because reference count is not zero" ); + imageUrl.Reset(); + application.GetScene().Remove( actor ); + dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL ); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION ); + + tet_infoline( "Delete texture because reference count is zero" ); + visual.Reset(); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageVisualWithEncodedImageBuffer(void) +{ + ToolkitTestApplication application; + tet_infoline( "Use Encoded Image Buffer as url" ); + + EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME); + ImageUrl url = Dali::Toolkit::Image::GenerateUrl(rawBuffer); + + 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.GetUrl() ); + + 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 UtcDaliImageVisualWithEncodedImageBufferRemoved(void) +{ + ToolkitTestApplication application; + tet_infoline( "Use Encoded Image Buffer as url" ); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + EncodedImageBuffer rawBuffer = ConvertFileToEncodedImageBuffer(TEST_LARGE_IMAGE_FILE_NAME); + ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(rawBuffer); + 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( DummyControl::Property::TEST_VISUAL, visual ); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); + + application.GetScene().Add( actor ); + application.SendNotification(); + + // Wait for decode buffer and make texture. + 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.CountMethod("DeleteTextures"), 0, TEST_LOCATION ); + + tet_infoline( "Delete texture because there is no actor to use decoded texture" ); + imageUrl.Reset(); + application.GetScene().Remove( actor ); + dummyImpl.UnregisterVisual( DummyControl::Property::TEST_VISUAL ); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliImageVisualTextureReuse1(void) { ToolkitTestApplication application; @@ -575,6 +783,15 @@ int UtcDaliImageVisualCustomWrapModePixelArea(void) ToolkitTestApplication application; tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" ); + static std::vector customUniforms = + { + UniformData("pixelArea", Property::Type::VECTOR4), + UniformData("wrapMode", Property::Type::VECTOR2), + }; + + TestGraphicsController& graphics = application.GetGraphicsController(); + graphics.AddCustomUniforms(customUniforms); + VisualFactory factory = VisualFactory::Get(); DALI_TEST_CHECK( factory ); @@ -654,6 +871,14 @@ int UtcDaliImageVisualCustomWrapModeNoAtlas(void) ToolkitTestApplication application; tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" ); + static std::vector customUniforms = + { + UniformData("pixelArea", Property::Type::VECTOR4), + }; + + TestGraphicsController& graphics = application.GetGraphicsController(); + graphics.AddCustomUniforms(customUniforms); + VisualFactory factory = VisualFactory::Get(); DALI_TEST_CHECK( factory ); @@ -731,6 +956,14 @@ int UtcDaliImageVisualAnimateMixColor(void) ToolkitTestApplication application; tet_infoline( "Animate mix color" ); + static std::vector customUniforms = + { + UniformData("mixColor", Property::Type::VECTOR3), + }; + + TestGraphicsController& graphics = application.GetGraphicsController(); + graphics.AddCustomUniforms(customUniforms); + application.GetPlatform().SetClosestImageSize( Vector2(100, 100) ); VisualFactory factory = VisualFactory::Get(); @@ -784,7 +1017,7 @@ int UtcDaliImageVisualAnimateMixColor(void) glAbstraction.EnableEnableDisableCallTrace( true ); TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace(); std::ostringstream blendStr; - blendStr << GL_BLEND; + blendStr << std::hex << GL_BLEND; application.SendNotification(); application.Render(0); // Ensure animation starts @@ -795,7 +1028,7 @@ int UtcDaliImageVisualAnimateMixColor(void) DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue( "uColor", Vector4( 0.5f, 0.5f, 0.5f, 0.75f ) ), true, TEST_LOCATION ); DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue( "mixColor", testColor ), true, TEST_LOCATION ); - DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); + DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) ); glEnableStack.Reset(); @@ -808,7 +1041,7 @@ int UtcDaliImageVisualAnimateMixColor(void) // 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().c_str() ) ); + DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) ); TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR ); @@ -845,12 +1078,12 @@ int UtcDaliImageVisualAnimateOpacity(void) glAbstraction.EnableEnableDisableCallTrace( true ); TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace(); std::ostringstream blendStr; - blendStr << GL_BLEND; + blendStr << std::hex << GL_BLEND; application.SendNotification(); application.Render(); - DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); + DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str()) ); { tet_infoline( "Test that the opacity can be increased to full via animation, and that the blend mode is set appropriately at the start and end of the animation." ); @@ -888,7 +1121,7 @@ int UtcDaliImageVisualAnimateOpacity(void) // 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().c_str() ) ); + DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) ); } @@ -920,7 +1153,7 @@ int UtcDaliImageVisualAnimateOpacity(void) DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) ); DALI_TEST_EQUALS( color.a, 0.55f, TEST_LOCATION ); - DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); + DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) ); glEnableStack.Reset(); @@ -931,9 +1164,10 @@ int UtcDaliImageVisualAnimateOpacity(void) DALI_TEST_EQUALS( color.a, 0.1f, 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().c_str() ) ); +// @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() ) ); + DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) ); } END_TEST; @@ -1006,14 +1240,14 @@ int UtcDaliImageVisualAnimateOpacity02(void) glAbstraction.EnableEnableDisableCallTrace( true ); TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace(); std::ostringstream blendStr; - blendStr << GL_BLEND; + blendStr << std::hex << GL_BLEND; application.SendNotification(); application.Render(0); // Ensure animation starts application.Render(2000u); // Halfway point through animation application.SendNotification(); // Handle any signals - DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); + DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) ); Vector4 color; DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) ); @@ -1027,7 +1261,7 @@ int UtcDaliImageVisualAnimateOpacity02(void) DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) ); DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION ); - DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) ); + DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) ); END_TEST; } @@ -1039,6 +1273,14 @@ int UtcDaliImageVisualAnimatePixelArea(void) ToolkitTestApplication application; tet_infoline( "ImageVisual animate pixel area" ); + static std::vector customUniforms = + { + UniformData("pixelArea", Property::Type::VECTOR4), + }; + + TestGraphicsController& graphics = application.GetGraphicsController(); + graphics.AddCustomUniforms(customUniforms); + application.GetPlatform().SetClosestImageSize( Vector2(100, 100) ); VisualFactory factory = VisualFactory::Get(); @@ -2368,8 +2610,8 @@ int UtcDaliImageVisualCustomShader(void) TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace(); std::ostringstream blendStr; - blendStr << GL_BLEND; - DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); + blendStr << std::hex << GL_BLEND; + DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) ); END_TEST; }