From cc3e05c92b5b85abed449a979f72e7ec52317312 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Tue, 12 Mar 2024 14:12:22 +0900 Subject: [PATCH] (Vector) Change shader at visual side Let we change animated vector visual shader at visual side, instead of dali-extension. Now we can use cached shader. Change-Id: Ie530f295227ce55b9d374bc4ddfd1a09361905a4 Signed-off-by: Eunki, Hong --- .../toolkit-vector-animation-renderer.cpp | 31 +++++++++--- .../toolkit-vector-animation-renderer.h | 3 +- .../utc-Dali-AnimatedVectorImageVisual.cpp | 47 ++++++++++++++++++- .../animated-vector-image-visual.cpp | 32 +++++++++++-- .../animated-vector-image-visual.h | 14 +++--- 5 files changed, 109 insertions(+), 18 deletions(-) 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 4c5fe551d5..aec90add5f 100644 --- 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 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. @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ public: mFrameRate(60.0f), mTestFrameDrop(false), mNeedDroppedFrames(false), + mUseNativeImage(false), mEventThreadCallback(new EventThreadCallback(MakeCallback(this, &VectorAnimationRenderer::OnTriggered))) { mCount++; @@ -229,12 +231,22 @@ public: mResourceReady = true; Dali::TextureSet textureSet = mRenderer.GetTextures(); - Dali::Texture texture = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight); - textureSet.SetTexture(0, texture); - Devel::PixelBuffer pixelBuffer = Devel::PixelBuffer::New(mWidth, mHeight, Pixel::RGBA8888); - Dali::PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); - texture.Upload(pixelData); + if(mUseNativeImage) + { + Dali::NativeImageSourcePtr nativeImageSource = Dali::NativeImageSource::New(mWidth, mHeight, Dali::NativeImageSource::COLOR_DEPTH_32); + Dali::Texture texture = Dali::Texture::New(*nativeImageSource); + textureSet.SetTexture(0, texture); + } + else + { + Dali::Texture texture = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, mWidth, mHeight); + textureSet.SetTexture(0, texture); + + Devel::PixelBuffer pixelBuffer = Devel::PixelBuffer::New(mWidth, mHeight, Pixel::RGBA8888); + Dali::PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); + texture.Upload(pixelData); + } mUploadCompletedSignal.Emit(); } @@ -263,6 +275,7 @@ public: bool mResourceReady{false}; bool mNeedTrigger{true}; bool mEnableFixedCache{false}; + bool mUseNativeImage{false}; Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal; std::unique_ptr mEventThreadCallback; @@ -403,7 +416,6 @@ void VectorAnimationRenderer::KeepRasterizedBuffer() Internal::Adaptor::GetImplementation(*this).KeepRasterizedBuffer(); } - VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal() { return Internal::Adaptor::GetImplementation(*this).UploadCompletedSignal(); @@ -426,5 +438,10 @@ uint32_t GetDroppedFrames() return Dali::Internal::Adaptor::gVectorAnimationRenderer->mDroppedFrames; } +void UseNativeImageTexture(bool useNativeImage) +{ + Dali::Internal::Adaptor::gVectorAnimationRenderer->mUseNativeImage = useNativeImage; +} + } // namespace VectorAnimationRenderer } // namespace Test diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.h index bc241f120a..9177afd5df 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-vector-animation-renderer.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_TEST_VECTOR_ANIMATION_RENDERER_H /* - * 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. @@ -32,6 +32,7 @@ namespace VectorAnimationRenderer void DelayRendering(uint32_t delay); uint32_t GetDroppedFrames(); +void UseNativeImageTexture(bool useNativeImage); } // namespace VectorAnimationRenderer } // namespace Test diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp index 8136955836..72a4966379 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 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. @@ -24,6 +24,7 @@ #include #include #include "dummy-control.h" +#include "test-native-image-source.h" #include @@ -2500,5 +2501,49 @@ int UtcDaliAnimatedVectorImageVisualFlushAction(void) dummyControl.Unparent(); + END_TEST; +} + +int UtcDaliAnimatedVectorImageNativeTextureChangeShader(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliAnimatedVectorImageNativeTextureChangeShader"); + + VisualFactory factory = VisualFactory::Get(); + Visual::Base visual = factory.CreateVisual(TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions()); + DALI_TEST_CHECK(visual); + + DummyControl actor = DummyControl::New(true); + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual); + + // Make we use native texture now. + Test::VectorAnimationRenderer::UseNativeImageTexture(true); + + application.GetScene().Add(actor); + + application.SendNotification(); + application.Render(); + + // Trigger count is 1 - resource ready + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + Renderer renderer = actor.GetRendererAt(0); + Shader shader = renderer.GetShader(); + Property::Value value = shader.GetProperty(Shader::Property::PROGRAM); + Property::Map* map = value.GetMap(); + DALI_TEST_CHECK(map); + + std::string resultFragmentShader, resultVertexShader; + Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp + fragment->Get(resultFragmentShader); + DALI_TEST_CHECK(resultFragmentShader.find(NativeImageSourceTest::GetCustomFragmentPrefix()) != std::string::npos); + + // Reset to make we use normal texture again. + Test::VectorAnimationRenderer::UseNativeImageTexture(false); + END_TEST; } \ No newline at end of file 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 5d8a355102..f078dc8741 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 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. @@ -101,7 +101,8 @@ AnimatedVectorImageVisual::AnimatedVectorImageVisual(VisualFactoryCache& factory mRendererAdded(false), mCoreShutdown(false), mRedrawInScalingDown(true), - mEnableFrameCache(false) + mEnableFrameCache(false), + mUseNativeImage(false) { // the rasterized image is with pre-multiplied alpha format mImpl->mFlags |= Visual::Base::Impl::IS_PREMULTIPLIED_ALPHA; @@ -457,6 +458,7 @@ void AnimatedVectorImageVisual::DoSetOnScene(Actor& actor) Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get(); mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false); actor.AddRenderer(mImpl->mRenderer); + mRendererAdded = true; ResourceReady(Toolkit::Visual::ResourceStatus::FAILED); } else @@ -645,6 +647,29 @@ void AnimatedVectorImageVisual::OnResourceReady(VectorAnimationTask::ResourceSta else { mLoadFailed = status == VectorAnimationTask::ResourceStatus::FAILED ? true : false; + if(status == VectorAnimationTask::ResourceStatus::READY) + { + // Texture was ready. Change the shader if we need. + bool useNativeImage = false; + if(mImpl->mRenderer) + { + auto textureSet = mImpl->mRenderer.GetTextures(); + if(textureSet && textureSet.GetTextureCount() > 0) + { + auto texture = textureSet.GetTexture(0u); + if(texture) + { + useNativeImage = DevelTexture::IsNative(texture); + + if(mUseNativeImage != useNativeImage) + { + mUseNativeImage = useNativeImage; + UpdateShader(); + } + } + } + } + } // If weak handle is holding a placement actor, it is the time to add the renderer to actor. Actor actor = mPlacementActor.GetHandle(); @@ -850,7 +875,8 @@ Shader AnimatedVectorImageVisual::GenerateShader() const mFactoryCache, ImageVisualShaderFeatureBuilder() .EnableRoundedCorner(IsRoundedCornerRequired()) - .EnableBorderline(IsBorderlineRequired())); + .EnableBorderline(IsBorderlineRequired()) + .SetTextureForFragmentShaderCheck(mUseNativeImage ? mImpl->mRenderer.GetTextures().GetTexture(0) : Dali::Texture())); } return shader; } diff --git a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h index 5ebd051e35..493e62143d 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h +++ b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H /* - * Copyright (c) 2023 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. @@ -249,11 +249,13 @@ private: WeakHandle mPlacementActor; DevelImageVisual::PlayState::Type mPlayState; CallbackBase* mEventCallback; // Not owned - bool mLoadFailed; - bool mRendererAdded; - bool mCoreShutdown; - bool mRedrawInScalingDown; - bool mEnableFrameCache; + + bool mLoadFailed : 1; + bool mRendererAdded : 1; + bool mCoreShutdown : 1; + bool mRedrawInScalingDown : 1; + bool mEnableFrameCache : 1; + bool mUseNativeImage : 1; }; } // namespace Internal -- 2.34.1