/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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/scripting/scripting.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/adaptor-framework/async-task-manager.h>
#include <dali/public-api/rendering/decorated-visual-renderer.h>
#include <cstring> // for strlen()
const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
-const float PIXEL_ALIGN_ON = 1.0f;
-const float PIXEL_ALIGN_OFF = 0.0f;
-
constexpr uint32_t TEXTURE_COUNT_FOR_GPU_ALPHA_MASK = 2u;
Geometry CreateGeometry(VisualFactoryCache& factoryCache, ImageDimensions gridSize)
mAtlasRectSize(0, 0),
mLoadState(TextureManager::LoadState::NOT_STARTED),
mAttemptAtlasing(false),
- mOrientationCorrection(true)
+ mOrientationCorrection(true),
+ mEnableBrokenImage(true)
{
EnablePreMultipliedAlpha(mFactoryCache.GetPreMultiplyOnLoad());
}
{
RemoveTexture();
}
+
+ ResetFastTrackLoadingTask();
}
}
{
DoSetProperty(Toolkit::DevelImageVisual::Property::MASKING_TYPE, keyValue.second);
}
+ else if(keyValue.first == ENABLE_BROKEN_IMAGE)
+ {
+ DoSetProperty(Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE, keyValue.second);
+ }
else if(keyValue.first == LOAD_POLICY_NAME)
{
DoSetProperty(Toolkit::ImageVisual::Property::LOAD_POLICY, keyValue.second);
{
DoSetProperty(Toolkit::ImageVisual::Property::ORIENTATION_CORRECTION, keyValue.second);
}
+ else if(keyValue.first == FAST_TRACK_UPLOADING_NAME)
+ {
+ DoSetProperty(Toolkit::DevelImageVisual::Property::FAST_TRACK_UPLOADING, keyValue.second);
+ }
}
}
// Load image immediately if LOAD_POLICY requires it
if(value.Get(maskingType))
{
AllocateMaskData();
- mMaskingData->mPreappliedMasking = Toolkit::DevelImageVisual::MaskingType::Type(maskingType) == Toolkit::DevelImageVisual::MaskingType::MASKING_ON_LOADING ? true : false;
+ if(mImageUrl.IsValid() && mImageUrl.GetProtocolType() == VisualUrl::TEXTURE)
+ {
+ // For external textures, only gpu masking is available.
+ // Therefore, MASKING_TYPE is set to MASKING_ON_RENDERING forcelly.
+ mMaskingData->mPreappliedMasking = false;
+ }
+ else
+ {
+ mMaskingData->mPreappliedMasking = Toolkit::DevelImageVisual::MaskingType::Type(maskingType) == Toolkit::DevelImageVisual::MaskingType::MASKING_ON_LOADING ? true : false;
+ }
+ }
+ break;
+ }
+
+ case Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE:
+ {
+ bool enableBrokenImage(mEnableBrokenImage);
+ if(value.Get(enableBrokenImage))
+ {
+ mEnableBrokenImage = enableBrokenImage;
}
break;
}
}
break;
}
+
+ case Toolkit::DevelImageVisual::Property::FAST_TRACK_UPLOADING:
+ {
+ bool fastTrackUploading = false;
+ if(value.Get(fastTrackUploading))
+ {
+ mUseFastTrackUploading = fastTrackUploading;
+ }
+ break;
+ }
}
}
if(!mMaskingData)
{
mMaskingData.reset(new TextureManager::MaskingData());
+ if(mImageUrl.IsValid() && mImageUrl.GetProtocolType() == VisualUrl::TEXTURE)
+ {
+ mMaskingData->mPreappliedMasking = false;
+ }
}
}
: TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
bool synchronousLoading = IsSynchronousLoadingRequired();
- bool loadingStatus;
+ bool loadingStatus = false;
+
+ // Remove previous loading task.
+ ResetFastTrackLoadingTask();
+
+ // Rare case. If someone call LoadTexture during fast track loading task running, (Ex : Action::RELOAD)
+ // we should remove previously added renderer now.
+ if(mRendererAdded)
+ {
+ Actor actor = mPlacementActor.GetHandle();
+ if(actor)
+ {
+ actor.RemoveRenderer(mImpl->mRenderer);
+ mRendererAdded = false;
+ }
+ }
+
+ /**
+ * @brief Check whether FastTrackUploading is avaliable or not.
+ * @return True if we can use fast track uploading feature. False otherwise.
+ */
+ auto IsFastTrackUploadingAvailable = [&]() {
+ if(mUseFastTrackUploading &&
+ mLoadPolicy == Toolkit::ImageVisual::LoadPolicy::ATTACHED &&
+ mReleasePolicy == Toolkit::ImageVisual::ReleasePolicy::DETACHED &&
+ forceReload == TextureManager::ReloadPolicy::CACHED &&
+ (mImageUrl.GetProtocolType() == VisualUrl::LOCAL || mImageUrl.GetProtocolType() == VisualUrl::REMOTE) &&
+ !synchronousLoading &&
+ !atlasing &&
+ !mImpl->mCustomShader &&
+ !(mMaskingData && mMaskingData->mAlphaMaskUrl.IsValid()))
+ {
+ return true;
+ }
+ else if(mUseFastTrackUploading)
+ {
+ DALI_LOG_DEBUG_INFO("FastTrack : Fail to load fast track. mUrl : [%s]%s%s%s%s%s%s%s%s\n",
+ mImageUrl.GetUrl().c_str(),
+ (mLoadPolicy != Toolkit::ImageVisual::LoadPolicy::ATTACHED) ? "/ mLoadPolicy != ATTACHED" : "",
+ (mReleasePolicy != Toolkit::ImageVisual::ReleasePolicy::DETACHED) ? "/ mReleasePolicy != DETACHED" : "",
+ (forceReload != TextureManager::ReloadPolicy::CACHED) ? "/ forceReload != CACHED" : "",
+ (!(mImageUrl.GetProtocolType() == VisualUrl::LOCAL || mImageUrl.GetProtocolType() == VisualUrl::REMOTE)) ? "/ url is not image" : "",
+ (synchronousLoading) ? "/ synchronousLoading" : "",
+ (atlasing) ? "/ atlasing" : "",
+ (mImpl->mCustomShader) ? "/ use customs shader" : "",
+ (mMaskingData && mMaskingData->mAlphaMaskUrl.IsValid()) ? "/ use masking url" : "");
+ }
+ return false;
+ };
- textures = textureManager.LoadTexture(mImageUrl, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, mTextureId, atlasRect, mAtlasRectSize, atlasing, loadingStatus, textureObserver, atlasUploadObserver, atlasManager, mOrientationCorrection, forceReload, preMultiplyOnLoad);
+ if(IsFastTrackUploadingAvailable())
+ {
+ // Enable PremultipliedAlpha first.
+ EnablePreMultipliedAlpha(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
+
+ // Set new TextureSet with fast track loading task
+ mFastTrackLoadingTask = new FastTrackLoadingTask(mImageUrl, mDesiredSize, mFittingMode, mSamplingMode, mOrientationCorrection, preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF, MakeCallback(this, &ImageVisual::FastLoadComplete));
+
+ TextureSet textureSet = TextureSet::New();
+ textureSet.SetTexture(0u, mFastTrackLoadingTask->mTexture);
+ mImpl->mRenderer.SetTextures(textureSet);
+
+ Dali::AsyncTaskManager::Get().AddTask(mFastTrackLoadingTask);
+
+ mLoadState = TextureManager::LoadState::LOADING;
+ }
+ else
+ {
+ textures = textureManager.LoadTexture(mImageUrl, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, mTextureId, atlasRect, mAtlasRectSize, atlasing, loadingStatus, textureObserver, atlasUploadObserver, atlasManager, mOrientationCorrection, forceReload, preMultiplyOnLoad);
+ }
if(textures)
{
}
mPlacementActor = actor;
- // Search the Actor tree to find if Layer UI behaviour set.
- Layer layer = actor.GetLayer();
- if(layer && layer.GetProperty<Layer::Behavior>(Layer::Property::BEHAVIOR) == Layer::LAYER_3D)
- {
- // Layer 3D set, do not align pixels
- mImpl->mRenderer.RegisterProperty(PIXEL_ALIGNED_UNIFORM_NAME, PIXEL_ALIGN_OFF);
- }
if(mPixelArea != FULL_TEXTURE_RECT)
{
if(mLoadState == TextureManager::LoadState::LOAD_FINISHED)
{
actor.AddRenderer(mImpl->mRenderer);
+ mRendererAdded = true;
mPlacementActor.Reset();
// Image loaded and ready to display
}
else if(mLoadState == TextureManager::LoadState::LOAD_FAILED)
{
- Vector2 imageSize = Vector2::ZERO;
- if(actor)
+ ShowBrokenImage();
+ ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
+ }
+ else
+ {
+ if(mFastTrackLoadingTask)
{
- imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
- mPlacementActorSize = imageSize;
+ actor.AddRenderer(mImpl->mRenderer);
+ mRendererAdded = true;
}
-
- mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
- actor.AddRenderer(mImpl->mRenderer);
- mPlacementActor.Reset();
-
- ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
}
}
// Image release is dependent on the ReleasePolicy, renderer is removed.
actor.RemoveRenderer(mImpl->mRenderer);
+ mRendererAdded = false;
+
if(mReleasePolicy == Toolkit::ImageVisual::ReleasePolicy::DETACHED)
{
- RemoveTexture(); // If INVALID_TEXTURE_ID then removal will be attempted on atlas
- mImpl->mResourceStatus = Toolkit::Visual::ResourceStatus::PREPARING;
-
- TextureSet textureSet = TextureSet::New();
- mImpl->mRenderer.SetTextures(textureSet);
- ComputeTextureSize();
-
- mLoadState = TextureManager::LoadState::NOT_STARTED;
+ ResetRenderer();
}
mPlacementActor.Reset();
map.Insert(Toolkit::ImageVisual::Property::LOAD_POLICY, mLoadPolicy);
map.Insert(Toolkit::ImageVisual::Property::RELEASE_POLICY, mReleasePolicy);
map.Insert(Toolkit::ImageVisual::Property::ORIENTATION_CORRECTION, mOrientationCorrection);
+
+ map.Insert(Toolkit::DevelImageVisual::Property::FAST_TRACK_UPLOADING, mUseFastTrackUploading);
}
void ImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
{
mImpl->mRenderer.RegisterProperty(ATLAS_RECT_UNIFORM_NAME, mAtlasRect);
actor.AddRenderer(mImpl->mRenderer);
+ mRendererAdded = true;
// reset the weak handle so that the renderer only get added to actor once
mPlacementActor.Reset();
}
mLoadState = TextureManager::LoadState::LOAD_FINISHED;
}
+// From FastTrackLoadingTask
+void ImageVisual::FastLoadComplete(FastTrackLoadingTaskPtr task)
+{
+ Toolkit::Visual::ResourceStatus resourceStatus;
+
+ DALI_ASSERT_ALWAYS(mFastTrackLoadingTask == task && "Task was not canceled successfully!");
+ DALI_ASSERT_ALWAYS(mRendererAdded && "Some FastTrack logic missed!");
+
+ Actor actor = mPlacementActor.GetHandle();
+
+ if(mFastTrackLoadingTask && mFastTrackLoadingTask->mLoadSuccess)
+ {
+ resourceStatus = Toolkit::Visual::ResourceStatus::READY;
+ mLoadState = TextureManager::LoadState::LOAD_FINISHED;
+
+ // Change premultiplied alpha flag after change renderer.
+ EnablePreMultipliedAlpha(mFastTrackLoadingTask->mPremultiplied);
+ }
+ else
+ {
+ resourceStatus = Toolkit::Visual::ResourceStatus::FAILED;
+ mLoadState = TextureManager::LoadState::LOAD_FAILED;
+
+ // Change renderer as broken.
+ ShowBrokenImage();
+ }
+
+ mFastTrackLoadingTask.Reset();
+
+ // Signal to observers ( control ) that resources are ready. Must be all resources.
+ ResourceReady(resourceStatus);
+}
+
// From Texture Manager
void ImageVisual::LoadComplete(bool loadingSuccess, TextureInformation textureInformation)
{
Actor actor = mPlacementActor.GetHandle();
if(!loadingSuccess)
{
- Vector2 imageSize = Vector2::ZERO;
- if(actor)
- {
- imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
- mPlacementActorSize = imageSize;
- }
- else
- {
- imageSize = mPlacementActorSize;
- }
-
- mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
+ ShowBrokenImage();
textureInformation.textureSet = mImpl->mRenderer.GetTextures();
}
else
UpdateShader();
}
}
- }
- if(actor)
- {
- actor.AddRenderer(mImpl->mRenderer);
- // reset the weak handle so that the renderer only get added to actor once
- mPlacementActor.Reset();
+ if(actor)
+ {
+ actor.AddRenderer(mImpl->mRenderer);
+ mRendererAdded = true;
+ // reset the weak handle so that the renderer only get added to actor once
+ mPlacementActor.Reset();
+ }
}
}
{
if(mTextureId != TextureManager::INVALID_TEXTURE_ID)
{
- mFactoryCache.GetTextureManager().Remove(mTextureId, this);
+ mFactoryCache.GetTextureManager().RequestRemove(mTextureId, this);
mTextureId = TextureManager::INVALID_TEXTURE_ID;
}
else
{
+ ResetFastTrackLoadingTask();
+
Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
Property::Index index = mImpl->mRenderer.GetPropertyIndex(ATLAS_RECT_UNIFORM_NAME);
if(index != Property::INVALID_INDEX)
{
Shader shader;
- bool usesWholeTexture = true;
const bool useStandardShader = !mImpl->mCustomShader;
const bool useNativeImage = (mTextures && DevelTexture::IsNative(mTextures.GetTexture(0)));
}
else
{
+ bool usesWholeTexture = true;
std::string_view vertexShaderView;
std::string_view fragmentShaderView;
{
shader = Shader::New(vertexShaderView, fragmentShaderView, mImpl->mCustomShader->mHints);
}
- }
- if(usesWholeTexture)
- {
- shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
+ if(usesWholeTexture)
+ {
+ shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
+ }
}
- // Set pixel align off as default.
- // ToDo: Pixel align causes issues such as rattling image animation.
- // We should trun it off until issues are resolved
- shader.RegisterProperty(PIXEL_ALIGNED_UNIFORM_NAME, PIXEL_ALIGN_OFF);
-
return shader;
}
}
}
+void ImageVisual::ResetRenderer()
+{
+ RemoveTexture(); // If INVALID_TEXTURE_ID then removal will be attempted on atlas
+ mImpl->mResourceStatus = Toolkit::Visual::ResourceStatus::PREPARING;
+
+ TextureSet textureSet = TextureSet::New();
+ mImpl->mRenderer.SetTextures(textureSet);
+ ComputeTextureSize();
+
+ mLoadState = TextureManager::LoadState::NOT_STARTED;
+}
+
+void ImageVisual::ShowBrokenImage()
+{
+ if(mEnableBrokenImage)
+ {
+ Actor actor = mPlacementActor.GetHandle();
+
+ Vector2 imageSize = Vector2::ZERO;
+ if(actor)
+ {
+ imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
+ mPlacementActorSize = imageSize;
+
+ if(mRendererAdded)
+ {
+ actor.RemoveRenderer(mImpl->mRenderer);
+ mRendererAdded = false;
+ }
+ }
+
+ mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
+ if(actor)
+ {
+ actor.AddRenderer(mImpl->mRenderer);
+ mRendererAdded = true;
+ mPlacementActor.Reset();
+ }
+ }
+ else
+ {
+ if(mRendererAdded)
+ {
+ Actor actor = mPlacementActor.GetHandle();
+ if(actor)
+ {
+ actor.RemoveRenderer(mImpl->mRenderer);
+ mRendererAdded = false;
+ }
+ }
+ ResetRenderer();
+ }
+}
+
+void ImageVisual::ResetFastTrackLoadingTask()
+{
+ if(mFastTrackLoadingTask)
+ {
+ Dali::AsyncTaskManager::Get().RemoveTask(mFastTrackLoadingTask);
+ mFastTrackLoadingTask.Reset();
+ }
+}
+
} // namespace Internal
} // namespace Toolkit