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 <eunkiki.hong@samsung.com>
/*
- * 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.
#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
#include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
#include <dali/devel-api/threading/mutex.h>
+#include <dali/public-api/adaptor-framework/native-image-source.h>
#include <dali/public-api/object/base-object.h>
#include <dali/public-api/object/property-array.h>
#include <toolkit-application.h>
mFrameRate(60.0f),
mTestFrameDrop(false),
mNeedDroppedFrames(false),
+ mUseNativeImage(false),
mEventThreadCallback(new EventThreadCallback(MakeCallback(this, &VectorAnimationRenderer::OnTriggered)))
{
mCount++;
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();
}
bool mResourceReady{false};
bool mNeedTrigger{true};
bool mEnableFixedCache{false};
+ bool mUseNativeImage{false};
Dali::VectorAnimationRenderer::UploadCompletedSignalType mUploadCompletedSignal;
std::unique_ptr<EventThreadCallback> mEventThreadCallback;
Internal::Adaptor::GetImplementation(*this).KeepRasterizedBuffer();
}
-
VectorAnimationRenderer::UploadCompletedSignalType& VectorAnimationRenderer::UploadCompletedSignal()
{
return Internal::Adaptor::GetImplementation(*this).UploadCompletedSignal();
return Dali::Internal::Adaptor::gVectorAnimationRenderer->mDroppedFrames;
}
+void UseNativeImageTexture(bool useNativeImage)
+{
+ Dali::Internal::Adaptor::gVectorAnimationRenderer->mUseNativeImage = useNativeImage;
+}
+
} // namespace VectorAnimationRenderer
} // namespace Test
#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.
void DelayRendering(uint32_t delay);
uint32_t GetDroppedFrames();
+void UseNativeImageTexture(bool useNativeImage);
} // namespace VectorAnimationRenderer
} // namespace Test
/*
- * 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.
#include <toolkit-timer.h>
#include <toolkit-vector-animation-renderer.h>
#include "dummy-control.h"
+#include "test-native-image-source.h"
#include <dali-toolkit/dali-toolkit.h>
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<DummyControlImpl&>(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
/*
- * 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.
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;
Vector2 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize, false);
actor.AddRenderer(mImpl->mRenderer);
+ mRendererAdded = true;
ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
}
else
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();
mFactoryCache,
ImageVisualShaderFeatureBuilder()
.EnableRoundedCorner(IsRoundedCornerRequired())
- .EnableBorderline(IsBorderlineRequired()));
+ .EnableBorderline(IsBorderlineRequired())
+ .SetTextureForFragmentShaderCheck(mUseNativeImage ? mImpl->mRenderer.GetTextures().GetTexture(0) : Dali::Texture()));
}
return shader;
}
#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.
WeakHandle<Actor> 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