#include <dali/devel-api/scripting/scripting.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/rendering/decorated-visual-renderer.h>
#include <cstring> // for strlen()
// INTERNAL HEADERS
{
namespace
{
-const int CUSTOM_PROPERTY_COUNT(14); // 5 transform properties + wrap, pixel area, atlas, pixalign, + border/corner
+const int CUSTOM_PROPERTY_COUNT(7); // ltr, wrap, pixel area, atlas, pixalign, crop to mask, mask texture ratio
// fitting modes
DALI_ENUM_TO_STRING_TABLE_BEGIN(FITTING_MODE)
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)
{
Geometry geometry;
else if(mImageUrl.IsBufferResource())
{
TextureManager& textureManager = mFactoryCache.GetTextureManager();
- textureManager.RemoveExternalEncodedImageBuffer(mImageUrl.GetUrl());
+ textureManager.RemoveEncodedImageBuffer(mImageUrl.GetUrl());
}
}
{
DoSetProperty(Toolkit::ImageVisual::Property::CROP_TO_MASK, keyValue.second);
}
+ else if(keyValue.first == MASKING_TYPE_NAME)
+ {
+ DoSetProperty(Toolkit::DevelImageVisual::Property::MASKING_TYPE, keyValue.second);
+ }
else if(keyValue.first == LOAD_POLICY_NAME)
{
DoSetProperty(Toolkit::ImageVisual::Property::LOAD_POLICY, keyValue.second);
{
if(sync)
{
- mImpl->mFlags |= Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
+ mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
}
else
{
- mImpl->mFlags &= ~Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
+ mImpl->mFlags &= ~Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
}
}
else
break;
}
+ case Toolkit::DevelImageVisual::Property::MASKING_TYPE:
+ {
+ int maskingType = 0;
+ if(value.Get(maskingType))
+ {
+ AllocateMaskData();
+ mMaskingData->mPreappliedMasking = Toolkit::DevelImageVisual::MaskingType::Type(maskingType) == Toolkit::DevelImageVisual::MaskingType::MASKING_ON_LOADING ? true : false;
+ }
+ break;
+ }
+
case Toolkit::ImageVisual::Property::RELEASE_POLICY:
{
int releasePolicy = 0;
}
else if(mImpl->mRenderer) // Check if we have a loaded image
{
- if(mImpl->mFlags & Impl::IS_ATLASING_APPLIED)
+ if(mImpl->mFlags & Visual::Base::Impl::IS_ATLASING_APPLIED)
{
naturalSize.x = mAtlasRectSize.GetWidth();
naturalSize.y = mAtlasRectSize.GetHeight();
auto textureSet = mImpl->mRenderer.GetTextures();
if(textureSet && textureSet.GetTextureCount())
{
- auto texture = textureSet.GetTexture(0);
- if(texture)
+ if(mTextureSize != Vector2::ZERO)
{
- naturalSize.x = texture.GetWidth();
- naturalSize.y = texture.GetHeight();
+ naturalSize = mTextureSize;
return;
}
}
Shader shader = GenerateShader();
// Create the renderer
- mImpl->mRenderer = Renderer::New(geometry, shader);
+ mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader);
mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
//Register transform properties
- mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
+ mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
EnablePreMultipliedAlpha(IsPreMultipliedAlphaEnabled());
+
+ if(mMaskingData)
+ {
+ mImpl->mRenderer.RegisterProperty(CROP_TO_MASK_NAME, static_cast<float>(mMaskingData->mCropToMask));
+ }
}
void ImageVisual::LoadTexture(bool& atlasing, Vector4& atlasRect, TextureSet& textures, bool orientationCorrection, TextureManager::ReloadPolicy forceReload)
if(atlasing) // Flag needs to be set before creating renderer
{
- mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
+ mImpl->mFlags |= Visual::Base::Impl::IS_ATLASING_APPLIED;
}
else
{
- mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
+ mImpl->mFlags &= ~Visual::Base::Impl::IS_ATLASING_APPLIED;
}
}
if(mTextures)
{
mImpl->mRenderer.SetTextures(mTextures);
- if(DevelTexture::IsNative(mTextures.GetTexture(0)))
+ ComputeTextureSize();
+ CheckMaskTexture();
+
+ 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();
}
TextureSet textureSet = TextureSet::New();
mImpl->mRenderer.SetTextures(textureSet);
+ ComputeTextureSize();
mLoadState = TextureManager::LoadState::NOT_STARTED;
}
map.Insert(Toolkit::ImageVisual::Property::ALPHA_MASK_URL, mMaskingData->mAlphaMaskUrl.GetUrl());
map.Insert(Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE, mMaskingData->mContentScaleFactor);
map.Insert(Toolkit::ImageVisual::Property::CROP_TO_MASK, mMaskingData->mCropToMask);
+ map.Insert(Toolkit::DevelImageVisual::Property::MASKING_TYPE, mMaskingData->mPreappliedMasking ? DevelImageVisual::MaskingType::MASKING_ON_LOADING : DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
}
map.Insert(Toolkit::ImageVisual::Property::LOAD_POLICY, mLoadPolicy);
{
if(mImpl->mRenderer)
{
- mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
+ mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
}
}
-bool ImageVisual::IsResourceReady() const
-{
- return (mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY ||
- mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::FAILED);
-}
-
void ImageVisual::UpdateShader()
{
if(mImpl->mRenderer)
sampler.SetWrapMode(mWrapModeU, mWrapModeV);
textureInformation.textureSet.SetSampler(0u, sampler);
mImpl->mRenderer.SetTextures(textureInformation.textureSet);
+ ComputeTextureSize();
+ CheckMaskTexture();
+
+ 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)
}
}
+void ImageVisual::ComputeTextureSize()
+{
+ if(mImpl->mRenderer)
+ {
+ auto textureSet = mImpl->mRenderer.GetTextures();
+ if(textureSet && textureSet.GetTextureCount())
+ {
+ auto texture = textureSet.GetTexture(0);
+ if(texture)
+ {
+ mTextureSize.x = texture.GetWidth();
+ mTextureSize.y = texture.GetHeight();
+ if(textureSet.GetTextureCount() > 1u && mMaskingData && !mMaskingData->mPreappliedMasking && mMaskingData->mCropToMask)
+ {
+ Texture maskTexture = textureSet.GetTexture(1);
+ if(maskTexture)
+ {
+ mTextureSize.x = std::min(static_cast<uint32_t>(mTextureSize.x * mMaskingData->mContentScaleFactor), maskTexture.GetWidth());
+ mTextureSize.y = std::min(static_cast<uint32_t>(mTextureSize.y * mMaskingData->mContentScaleFactor), maskTexture.GetHeight());
+ }
+ }
+ }
+ }
+ }
+}
+
+Vector2 ImageVisual::ComputeMaskTextureRatio()
+{
+ Vector2 maskTextureRatio;
+ if(mImpl->mRenderer)
+ {
+ auto textureSet = mImpl->mRenderer.GetTextures();
+ if(textureSet && textureSet.GetTextureCount())
+ {
+ auto texture = textureSet.GetTexture(0);
+ if(texture)
+ {
+ if(textureSet.GetTextureCount() > 1u && mMaskingData && !mMaskingData->mPreappliedMasking && mMaskingData->mCropToMask)
+ {
+ Texture maskTexture = textureSet.GetTexture(1);
+ if(maskTexture)
+ {
+ float textureWidth = std::max(static_cast<float>(texture.GetWidth() * mMaskingData->mContentScaleFactor), Dali::Math::MACHINE_EPSILON_1);
+ float textureHeight = std::max(static_cast<float>(texture.GetHeight() * mMaskingData->mContentScaleFactor), Dali::Math::MACHINE_EPSILON_1);
+ maskTextureRatio = Vector2(std::min(static_cast<float>(maskTexture.GetWidth()), textureWidth) / textureWidth,
+ std::min(static_cast<float>(maskTexture.GetHeight()), textureHeight) / textureHeight);
+ }
+ }
+ }
+ }
+ }
+ return maskTextureRatio;
+}
+
Shader ImageVisual::GenerateShader() const
{
Shader shader;
if(useStandardShader)
{
+ bool requiredAlphaMaskingOnRendering = (mMaskingData && !mMaskingData->mMaskImageLoadingFailed) ? !mMaskingData->mPreappliedMasking : false;
// Create and cache the standard shader
shader = mImageVisualShaderFactory.GetShader(
mFactoryCache,
ImageVisualShaderFeature::FeatureBuilder()
- .EnableTextureAtlas(mImpl->mFlags & Impl::IS_ATLASING_APPLIED && !useNativeImage)
+ .EnableTextureAtlas(mImpl->mFlags & Visual::Base::Impl::IS_ATLASING_APPLIED && !useNativeImage)
.ApplyDefaultTextureWrapMode(mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE)
.EnableRoundedCorner(IsRoundedCornerRequired())
.EnableBorderline(IsBorderlineRequired())
- .SetTextureForFragmentShaderCheck(useNativeImage ? mTextures.GetTexture(0) : Dali::Texture()));
+ .SetTextureForFragmentShaderCheck(useNativeImage ? mTextures.GetTexture(0) : Dali::Texture())
+ .EnableAlphaMaskingOnRendering(requiredAlphaMaskingOnRendering)
+ .EnableYuvToRgb(mNeedYuvToRgb));
}
else
{
return shader;
}
+void ImageVisual::CheckMaskTexture()
+{
+ if(mMaskingData && !mMaskingData->mPreappliedMasking)
+ {
+ bool maskLoadFailed = true;
+ TextureSet textures = mImpl->mRenderer.GetTextures();
+ if(textures && textures.GetTextureCount() >= TEXTURE_COUNT_FOR_GPU_ALPHA_MASK)
+ {
+ if(mMaskingData->mCropToMask)
+ {
+ mImpl->mRenderer.RegisterProperty(MASK_TEXTURE_RATIO_NAME, ComputeMaskTextureRatio());
+ }
+ maskLoadFailed = false;
+ }
+
+ if(mMaskingData->mMaskImageLoadingFailed != maskLoadFailed)
+ {
+ mMaskingData->mMaskImageLoadingFailed = maskLoadFailed;
+ UpdateShader();
+ }
+ }
+}
+
} // namespace Internal
} // namespace Toolkit