From: Taehyub Kim Date: Fri, 2 Apr 2021 12:36:42 +0000 (+0900) Subject: [Tizen] visual: Implements rive animation X-Git-Tag: accepted/tizen/unified/20210509.123850~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5a9b06018c30b3d3696f4a4d8cb2d91a224ee0e9;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git [Tizen] visual: Implements rive animation Change-Id: I6c6db8ff53493ad164142805d2655cb34b9ce10e --- diff --git a/automated-tests/resources/juice.riv b/automated-tests/resources/juice.riv new file mode 100644 index 0000000..80003ec Binary files /dev/null and b/automated-tests/resources/juice.riv differ diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.cpp index 18ce2ef..b2e2ef6 100755 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.cpp @@ -60,7 +60,7 @@ public: bool Load(const std::string& url) { mUrl = url; - if(mUrl == "invalid.json") + if(mUrl == "invalid.json" || mUrl == "invalid.riv") { return false; } diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp index d6efd03..6bdf227 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp @@ -52,6 +52,9 @@ namespace const char* TEST_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json"; const char* TEST_VECTOR_IMAGE_INVALID_FILE_NAME = "invalid.json"; +const char* TEST_VECTOR_IMAGE_RIVE_FILE_NAME = TEST_RESOURCE_DIR "/juice.riv"; +const char* TEST_VECTOR_IMAGE_INVALID_RIVE_FILE_NAME = "invalid.riv"; + bool gAnimationFinishedSignalFired = false; void VisualEventSignal( Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId ) @@ -1530,3 +1533,199 @@ int UtcDaliAnimatedVectorImageVisualInvalidFile(void) END_TEST; } + +int UtcDaliAnimatedVectorImageVisualLoadRiveFileP(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliAnimatedVectorImageVisualLoadRiveFile: Request animated vector image visual with a rive url" ); + + VisualFactory factory = VisualFactory::Get(); + Visual::Base visual = factory.CreateVisual( TEST_VECTOR_IMAGE_RIVE_FILE_NAME, ImageDimensions() ); + DALI_TEST_CHECK( visual ); + + DummyControl actor = DummyControl::New( true ); + DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) ); + application.GetScene().Add( actor ); + + application.SendNotification(); + application.Render(); + + // renderer is added to actor + DALI_TEST_CHECK( actor.GetRendererCount() == 1u ); + Renderer renderer = actor.GetRendererAt( 0u ); + DALI_TEST_CHECK( renderer ); + + // Test SetOffScene(). + actor.Unparent(); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + + END_TEST; +} + +int UtcDaliAnimatedVectorImageVisualLoadRiveFileN(void) +{ + ToolkitTestApplication application; + tet_infoline("Request loading with invalid rive file - should draw broken image"); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + Property::Map propertyMap; + propertyMap.Add(Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE) + .Add(ImageVisual::Property::URL, TEST_VECTOR_IMAGE_INVALID_RIVE_FILE_NAME); + + Visual::Base visual = VisualFactory::Get().CreateVisual(propertyMap); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(true); + DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >(actor.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual); + + actor.SetProperty(Actor::Property::SIZE, Vector2(20.0f, 20.0f)); + + application.GetScene().Add(actor); + + application.SendNotification(); + application.Render(); + + // Check resource status + Visual::ResourceStatus status = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL); + 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); + + END_TEST; +} + +int UtcDaliAnimatedVectorImageVisualPlaybackRiveFile(void) +{ + ToolkitTestApplication application; + + tet_infoline( "UtcDaliAnimatedVectorImageVisualPlaybackRiveFile" ); + + { + // request AnimatedVectorImageVisual for Rive with a property map + VisualFactory factory = VisualFactory::Get(); + Visual::Base visual = factory.CreateVisual( + Property::Map() + .Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) + .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_RIVE_FILE_NAME ) ); + + DummyControl dummyControl = DummyControl::New( true ); + Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummyControl.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + dummyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + + Property::Map attributes; + tet_infoline( "Test Play action" ); + DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.GetScene().Add( dummyControl ); + application.SendNotification(); + application.Render( 16 ); + + Property::Map map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING ); + + tet_infoline( "Test Pause action" ); + DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PAUSE, attributes ); + + application.SendNotification(); + application.Render(16); + + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PAUSED ); + + tet_infoline( "Test Play action" ); + DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.SendNotification(); + application.Render(16); + + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING ); + + tet_infoline( "Test Stop action" ); + DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes ); + + application.SendNotification(); + application.Render(16); + + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED ); + + tet_infoline( "Test Stop action again" ); + DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::STOP, attributes ); + + application.SendNotification(); + application.Render(16); + + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED ); + + tet_infoline( "Test Play action" ); + DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.SendNotification(); + application.Render(16); + + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING ); + + tet_infoline( "Off stage" ); + dummyControl.Unparent(); + + application.SendNotification(); + application.Render(16); + + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED ); + + tet_infoline( "On stage again" ); + application.GetScene().Add( dummyControl ); + + application.SendNotification(); + application.Render(16); + + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::STOPPED ); + + tet_infoline( "Test Play action" ); + DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelAnimatedVectorImageVisual::Action::PLAY, attributes ); + + application.SendNotification(); + application.Render(16); + + map = dummyControl.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + DALI_TEST_CHECK( value->Get< int >() == DevelImageVisual::PlayState::PLAYING ); + + // Change Size + Vector3 newSize( 100.0f, 100.0f, 0.0f ); + dummyControl.SetProperty( Actor::Property::SIZE, newSize ); + + application.SendNotification(); + application.Render(16); + + // Size should be changed + Vector3 naturalSize = dummyControl.GetNaturalSize(); + DALI_TEST_CHECK( naturalSize == newSize ); + + dummyControl.Unparent(); + } + + END_TEST; +} diff --git a/dali-toolkit/internal/visuals/visual-factory-impl.cpp b/dali-toolkit/internal/visuals/visual-factory-impl.cpp index 8c4b2f8..6bbc2df 100644 --- a/dali-toolkit/internal/visuals/visual-factory-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-impl.cpp @@ -166,6 +166,7 @@ Toolkit::Visual::Base VisualFactory::CreateVisual(const Property::Map& propertyM break; } case VisualUrl::JSON: + case VisualUrl::RIVE: { visualPtr = AnimatedVectorImageVisual::New(GetFactoryCache(), GetImageVisualShaderFactory(), imageUrl, propertyMap); break; @@ -330,6 +331,7 @@ Toolkit::Visual::Base VisualFactory::CreateVisual(const std::string& url, ImageD break; } case VisualUrl::JSON: + case VisualUrl::RIVE: { visualPtr = AnimatedVectorImageVisual::New(GetFactoryCache(), GetImageVisualShaderFactory(), visualUrl); break; diff --git a/dali-toolkit/internal/visuals/visual-url.cpp b/dali-toolkit/internal/visuals/visual-url.cpp index e498313..97bc9b9 100644 --- a/dali-toolkit/internal/visuals/visual-url.cpp +++ b/dali-toolkit/internal/visuals/visual-url.cpp @@ -103,10 +103,12 @@ VisualUrl::Type ResolveType(const std::string& url) char GIF[4] = {'f', 'i', 'g', '.'}; char WEBP[5] = {'p', 'b', 'e', 'w', '.'}; char JSON[5] = {'n', 'o', 's', 'j', '.'}; + char RIVE[4] = {'v', 'i', 'r', '.'}; unsigned int svgScore = 0; unsigned int gifScore = 0; unsigned int webpScore = 0; unsigned int jsonScore = 0; + unsigned int riveScore = 0; int index = count; while(--index >= 0) { @@ -144,6 +146,14 @@ VisualUrl::Type ResolveType(const std::string& url) return VisualUrl::JSON; } } + if((offsetFromEnd < sizeof(RIVE)) && (currentChar == RIVE[offsetFromEnd])) + { + // early out if RIVE as can't be used in N patch for now + if(++riveScore == sizeof(RIVE)) + { + return VisualUrl::RIVE; + } + } switch(state) { case SUFFIX: diff --git a/dali-toolkit/internal/visuals/visual-url.h b/dali-toolkit/internal/visuals/visual-url.h index 8857184..827dfce 100644 --- a/dali-toolkit/internal/visuals/visual-url.h +++ b/dali-toolkit/internal/visuals/visual-url.h @@ -38,7 +38,8 @@ public: SVG, GIF, WEBP, - JSON + JSON, + RIVE }; enum ProtocolType