/*
- * 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.
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());
}
{
if(Stage::IsInstalled())
{
- if(mMaskingData)
- {
- // TextureManager could have been deleted before the actor that contains this
- // ImageVisual is destroyed (e.g. due to stage shutdown). Ensure the stage
- // is still valid before accessing texture manager.
- if(mMaskingData->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID)
- {
- TextureManager& textureManager = mFactoryCache.GetTextureManager();
- textureManager.Remove(mMaskingData->mAlphaMaskId, this);
- }
- }
-
if(mImageUrl.IsValid())
{
// Decrease reference count of External Resources :
{
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);
case Toolkit::ImageVisual::Property::DESIRED_WIDTH:
{
- float desiredWidth = 0.0f;
+ int32_t desiredWidth = 0;
if(value.Get(desiredWidth))
{
mDesiredSize.SetWidth(desiredWidth);
case Toolkit::ImageVisual::Property::DESIRED_HEIGHT:
{
- float desiredHeight = 0.0f;
+ int32_t desiredHeight = 0;
if(value.Get(desiredHeight))
{
mDesiredSize.SetHeight(desiredHeight);
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;
}
if(!mMaskingData)
{
mMaskingData.reset(new TextureManager::MaskingData());
+ if(mImageUrl.IsValid() && mImageUrl.GetProtocolType() == VisualUrl::TEXTURE)
+ {
+ mMaskingData->mPreappliedMasking = false;
+ }
}
}
{
imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
}
+ else
+ {
+ imageSize = mPlacementActorSize;
+ }
+
mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
Texture brokenImage = mImpl->mRenderer.GetTextures().GetTexture(0);
naturalSize.x = brokenImage.GetWidth();
bool synchronousLoading = IsSynchronousLoadingRequired();
bool loadingStatus;
- textures = textureManager.LoadTexture(mImageUrl, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, mTextureId, atlasRect, mAtlasRectSize, atlasing, loadingStatus, mWrapModeU, mWrapModeV, textureObserver, atlasUploadObserver, atlasManager, mOrientationCorrection, forceReload, preMultiplyOnLoad);
+ textures = textureManager.LoadTexture(mImageUrl, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, mTextureId, atlasRect, mAtlasRectSize, atlasing, loadingStatus, textureObserver, atlasUploadObserver, atlasManager, mOrientationCorrection, forceReload, preMultiplyOnLoad);
if(textures)
{
}
EnablePreMultipliedAlpha(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
+ if(!atlasing)
+ {
+ Sampler sampler = Sampler::New();
+ sampler.SetWrapMode(mWrapModeU, mWrapModeV);
+ textures.SetSampler(0u, sampler);
+ }
}
else if(synchronousLoading)
{
else
{
mTextures = mFactoryCache.GetTextureManager().GetTextureSet(mTextureId);
+ if(!(mImpl->mFlags & Visual::Base::Impl::IS_ATLASING_APPLIED) && mTextures)
+ {
+ Sampler sampler = Sampler::New();
+ sampler.SetWrapMode(mWrapModeU, mWrapModeV);
+ mTextures.SetSampler(0u, sampler);
+ }
}
}
mImpl->mRenderer.SetTextures(mTextures);
ComputeTextureSize();
CheckMaskTexture();
- if(DevelTexture::IsNative(mTextures.GetTexture(0)))
+
+ bool needToUpdateShader = DevelTexture::IsNative(mTextures.GetTexture(0));
+
+ if(mTextures.GetTextureCount() == 3)
+ {
+ if(mTextures.GetTexture(0).GetPixelFormat() == Pixel::L8 && mTextures.GetTexture(1).GetPixelFormat() == Pixel::CHROMINANCE_U && mTextures.GetTexture(2).GetPixelFormat() == Pixel::CHROMINANCE_V)
+ {
+ mNeedYuvToRgb = true;
+ needToUpdateShader = true;
+ }
+ }
+
+ if(needToUpdateShader)
{
UpdateShader();
}
}
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)
{
}
else if(mLoadState == TextureManager::LoadState::LOAD_FAILED)
{
- Vector2 imageSize = Vector2::ZERO;
- if(actor)
- {
- imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
- }
- mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
- actor.AddRenderer(mImpl->mRenderer);
- mPlacementActor.Reset();
-
+ ShowBrokenImage();
ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
}
}
actor.RemoveRenderer(mImpl->mRenderer);
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();
Actor actor = mPlacementActor.GetHandle();
if(!loadingSuccess)
{
- Vector2 imageSize = Vector2::ZERO;
- if(actor)
- {
- imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
- }
- mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
+ ShowBrokenImage();
textureInformation.textureSet = mImpl->mRenderer.GetTextures();
}
else
{
- Sampler sampler = Sampler::New();
- sampler.SetWrapMode(mWrapModeU, mWrapModeV);
- textureInformation.textureSet.SetSampler(0u, sampler);
+ if(!textureInformation.useAtlasing)
+ {
+ Sampler sampler = Sampler::New();
+ sampler.SetWrapMode(mWrapModeU, mWrapModeV);
+ textureInformation.textureSet.SetSampler(0u, sampler);
+ }
+
mImpl->mRenderer.SetTextures(textureInformation.textureSet);
ComputeTextureSize();
CheckMaskTexture();
- }
- if(actor)
- {
- actor.AddRenderer(mImpl->mRenderer);
- // reset the weak handle so that the renderer only get added to actor once
- mPlacementActor.Reset();
+ if(textureInformation.textureSet.GetTextureCount() == 3)
+ {
+ if(textureInformation.textureSet.GetTexture(0).GetPixelFormat() == Pixel::L8 && textureInformation.textureSet.GetTexture(1).GetPixelFormat() == Pixel::CHROMINANCE_U && textureInformation.textureSet.GetTexture(2).GetPixelFormat() == Pixel::CHROMINANCE_V)
+ {
+ mNeedYuvToRgb = true;
+ UpdateShader();
+ }
+ }
+
+ if(actor)
+ {
+ actor.AddRenderer(mImpl->mRenderer);
+ // 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
.EnableRoundedCorner(IsRoundedCornerRequired())
.EnableBorderline(IsBorderlineRequired())
.SetTextureForFragmentShaderCheck(useNativeImage ? mTextures.GetTexture(0) : Dali::Texture())
- .EnableAlphaMaskingOnRendering(requiredAlphaMaskingOnRendering));
+ .EnableAlphaMaskingOnRendering(requiredAlphaMaskingOnRendering)
+ .EnableYuvToRgb(mNeedYuvToRgb));
}
else
{
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;
+ }
+
+ mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
+ if(actor)
+ {
+ actor.AddRenderer(mImpl->mRenderer);
+ mPlacementActor.Reset();
+ }
+ }
+ else
+ {
+ ResetRenderer();
+ }
+}
+
} // namespace Internal
} // namespace Toolkit