From 583b651c27deafd1afb8a9d55afc50cedce94577 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Tue, 19 Jan 2021 20:23:55 +0900 Subject: [PATCH] Rounded corner for SVG / Animated Vector Image visual Change-Id: I798b46c3cd5cbaedfc717395e4255111f95aef25 Signed-off-by: Eunki, Hong --- .../utc-Dali-AnimatedImageVisual.cpp | 52 +++++++-- .../utc-Dali-AnimatedVectorImageVisual.cpp | 28 ++++- .../src/dali-toolkit/utc-Dali-Visual.cpp | 108 ++++++++++++++++++ .../animated-vector-image-visual.cpp | 2 +- .../internal/visuals/svg/svg-visual.cpp | 2 +- 5 files changed, 177 insertions(+), 15 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp index 3d538cd251..243a73b572 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include "dummy-control.h" @@ -74,7 +75,9 @@ int UtcDaliAnimatedImageVisualGetPropertyMap01(void) .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME ) .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::WRAP_MODE_V, WrapMode::DEFAULT ) + .Add( DevelVisual::Property::CORNER_RADIUS, 22.2f ) + .Add( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE )); Property::Map resultMap; animatedImageVisual.CreatePropertyMap( resultMap ); @@ -87,6 +90,14 @@ int UtcDaliAnimatedImageVisualGetPropertyMap01(void) DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() == TEST_GIF_FILE_NAME ); + value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS, Property::FLOAT ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), 22.2f, TEST_LOCATION ); + + value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == Visual::Transform::Policy::ABSOLUTE ); + // request AnimatedImageVisual with an URL Visual::Base animatedImageVisual2 = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() ); resultMap.Clear(); @@ -124,7 +135,9 @@ int UtcDaliAnimatedImageVisualGetPropertyMap02(void) .Add( "frameDelay", 200 ) .Add( "pixelArea", Vector4() ) .Add( "wrapModeU", WrapMode::REPEAT ) - .Add( "wrapModeV", WrapMode::DEFAULT )); + .Add( "wrapModeV", WrapMode::DEFAULT ) + .Add( "cornerRadius", 50.0f ) + .Add( "cornerRadiusPolicy", Visual::Transform::Policy::RELATIVE )); Property::Map resultMap; animatedImageVisual.CreatePropertyMap( resultMap ); @@ -159,6 +172,14 @@ int UtcDaliAnimatedImageVisualGetPropertyMap02(void) DALI_TEST_CHECK( value ); DALI_TEST_EQUALS( value->Get(), 11, TEST_LOCATION ); + value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius" ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), 50.0f, TEST_LOCATION ); + + value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == Visual::Transform::Policy::RELATIVE ); + END_TEST; } @@ -183,7 +204,8 @@ int UtcDaliAnimatedImageVisualGetPropertyMap03(void) .Add( "frameDelay", 200 ) .Add( "pixelArea", Vector4() ) .Add( "wrapModeU", WrapMode::REPEAT ) - .Add( "wrapModeV", WrapMode::DEFAULT )); + .Add( "wrapModeV", WrapMode::DEFAULT ) + .Add( "cornerRadius", 50.5f )); Property::Map resultMap; animatedImageVisual.CreatePropertyMap( resultMap ); @@ -218,6 +240,14 @@ int UtcDaliAnimatedImageVisualGetPropertyMap03(void) DALI_TEST_CHECK( value ); DALI_TEST_EQUALS( value->Get(), 11, TEST_LOCATION ); + value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius" ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), 50.5f, TEST_LOCATION ); + + value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == Visual::Transform::Policy::ABSOLUTE ); + END_TEST; } @@ -271,12 +301,14 @@ int UtcDaliAnimatedImageVisualSynchronousLoading(void) { 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( 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( 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 ); @@ -1273,4 +1305,4 @@ int UtcDaliAnimatedImageVisualPlayback(void) } END_TEST; -} \ No newline at end of file +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp index 534aeb6dc1..42a9e91671 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp @@ -139,7 +139,8 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual03(void) propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) .Add( DevelImageVisual::Property::LOOP_COUNT, 3 ) - .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ); + .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ) + .Add( DevelVisual::Property::CORNER_RADIUS, 50.0f ); Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); DALI_TEST_CHECK( visual ); @@ -170,6 +171,7 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void) tet_infoline( "UtcDaliVisualFactoryGetAnimatedVectorImageVisual04: Request animated vector image visual with a Property::Map" ); int startFrame = 1, endFrame = 3; + float cornerRadius = 50.0f; Property::Array playRange; playRange.PushBack( startFrame ); playRange.PushBack( endFrame ); @@ -181,7 +183,8 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void) .Add( "playRange", playRange ) .Add( "stopBehavior", DevelImageVisual::StopBehavior::FIRST_FRAME ) .Add( "loopingMode", DevelImageVisual::LoopingMode::AUTO_REVERSE ) - .Add( "redrawInScalingDown", false ); + .Add( "redrawInScalingDown", false ) + .Add( "cornerRadius", cornerRadius ); Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); DALI_TEST_CHECK( visual ); @@ -237,6 +240,14 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void) DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get< bool >() == false ); + value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS, Property::FLOAT ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get< float >(), cornerRadius, TEST_LOCATION ); + + value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< int >() == Visual::Transform::Policy::ABSOLUTE ); + actor.Unparent( ); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); @@ -249,6 +260,7 @@ int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void) tet_infoline( "UtcDaliAnimatedVectorImageVisualGetPropertyMap01" ); int startFrame = 1, endFrame = 3; + float cornerRadius = 50.0f; Property::Array playRange; playRange.PushBack( startFrame ); playRange.PushBack( endFrame ); @@ -257,7 +269,9 @@ int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void) propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) .Add( DevelImageVisual::Property::LOOP_COUNT, 3 ) - .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ); + .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ) + .Add( DevelVisual::Property::CORNER_RADIUS, cornerRadius ) + .Add( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::RELATIVE); // request AnimatedVectorImageVisual with a property map VisualFactory factory = VisualFactory::Get(); @@ -317,6 +331,14 @@ int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void) DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get< bool >() == true ); // Check default value + value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS, Property::FLOAT ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get< float >(), cornerRadius, TEST_LOCATION ); + + value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< int >() == Visual::Transform::Policy::RELATIVE ); + // request AnimatedVectorImageVisual with an URL Visual::Base visual2 = factory.CreateVisual( TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions() ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index 6f3fa6a38d..761e88e266 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp @@ -3617,6 +3617,8 @@ int UtcDaliVisualRoundedCorner(void) application.Render(); DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadius", cornerRadius ), true, TEST_LOCATION ); + // Default corner radius policy is absolute. + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadiusPolicy", Toolkit::Visual::Transform::Policy::ABSOLUTE ), true, TEST_LOCATION ); } // color visual 1 @@ -3759,8 +3761,114 @@ int UtcDaliVisualRoundedCorner(void) application.Render(); DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadius", cornerRadius ), true, TEST_LOCATION ); + // Default corner radius policy is absolute. + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadiusPolicy", Toolkit::Visual::Transform::Policy::ABSOLUTE ), true, TEST_LOCATION ); } + // animated image visual + { + VisualFactory factory = VisualFactory::Get(); + Property::Map properties; + float cornerRadius = 24.0f; + + properties[Visual::Property::TYPE] = Visual::ANIMATED_IMAGE; + properties[ImageVisual::Property::URL] = TEST_GIF_FILE_NAME; + properties[DevelVisual::Property::CORNER_RADIUS] = cornerRadius + 10.0f; // Dummy Input + properties[DevelVisual::Property::CORNER_RADIUS] = cornerRadius; + properties["cornerRadiusPolicy"] = Toolkit::Visual::Transform::Policy::ABSOLUTE; + + Visual::Base visual = factory.CreateVisual( properties ); + + // trigger creation through setting on stage + DummyControl dummy = DummyControl::New( true ); + Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + application.GetScene().Add( dummy ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadius", cornerRadius ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadiusPolicy", Toolkit::Visual::Transform::Policy::ABSOLUTE ), true, TEST_LOCATION ); + } + + // vector image visual + { + VisualFactory factory = VisualFactory::Get(); + Property::Map properties; + float cornerRadius = 27.0f; + + properties[Visual::Property::TYPE] = Visual::SVG; + properties[ImageVisual::Property::URL] = TEST_SVG_FILE_NAME; + properties[DevelVisual::Property::CORNER_RADIUS] = cornerRadius; + + Visual::Base visual = factory.CreateVisual( properties ); + + // trigger creation through setting on stage + DummyControl dummy = DummyControl::New( true ); + Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + application.GetScene().Add( dummy ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadius", cornerRadius ), true, TEST_LOCATION ); + // Default corner radius policy is absolute. + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadiusPolicy", Toolkit::Visual::Transform::Policy::ABSOLUTE ), true, TEST_LOCATION ); + } + + // animated vector image visual + { + VisualFactory factory = VisualFactory::Get(); + Property::Map properties; + float cornerRadius = 1.3f; + + properties[Visual::Property::TYPE] = DevelVisual::ANIMATED_VECTOR_IMAGE; + properties[ImageVisual::Property::URL] = TEST_VECTOR_IMAGE_FILE_NAME; + properties["cornerRadius"] = cornerRadius; + properties[DevelVisual::Property::CORNER_RADIUS_POLICY] = Toolkit::Visual::Transform::Policy::RELATIVE; + + Visual::Base visual = factory.CreateVisual( properties ); + + // trigger creation through setting on stage + DummyControl dummy = DummyControl::New( true ); + Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + application.GetScene().Add( dummy ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadius", cornerRadius ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadiusPolicy", Toolkit::Visual::Transform::Policy::RELATIVE ), true, TEST_LOCATION ); + } + + END_TEST; } diff --git a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp index a2d102a10a..db97880ad0 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp @@ -293,7 +293,7 @@ void AnimatedVectorImageVisual::DoSetOnScene( Actor& actor ) } else { - shader = mImageVisualShaderFactory.GetShader( mFactoryCache, false, true, false ); + shader = mImageVisualShaderFactory.GetShader( mFactoryCache, false, true, IsRoundedCornerRequired() ); } Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY ); diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.cpp b/dali-toolkit/internal/visuals/svg/svg-visual.cpp index 09d8de2b91..bce5c27318 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.cpp +++ b/dali-toolkit/internal/visuals/svg/svg-visual.cpp @@ -141,7 +141,7 @@ void SvgVisual::DoSetOnScene( Actor& actor ) Shader shader; if( !mImpl->mCustomShader ) { - shader = mImageVisualShaderFactory.GetShader( mFactoryCache, mAttemptAtlasing, true, false ); + shader = mImageVisualShaderFactory.GetShader( mFactoryCache, mAttemptAtlasing, true, IsRoundedCornerRequired() ); } else { -- 2.34.1