X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fimage%2Fimage-visual.cpp;h=18cf2b49ff8f66c60526e245fcc5053ca17e6541;hb=ac080a64ce7058a380a3a3d0492a05e788f3e6cd;hp=b798e57db7c98dab46d915148bd97b714d583c5b;hpb=908a404d710bddfa2337e82a4f7515c97fa09232;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index b798e57..18cf2b4 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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. @@ -27,13 +27,14 @@ #include #include #include +#include #include // for strlen() // INTERNAL HEADERS #include +#include #include #include -#include #include #include #include @@ -51,6 +52,8 @@ namespace Internal { namespace { +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) DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::FittingMode, SHRINK_TO_FIT) @@ -94,8 +97,7 @@ DALI_ENUM_TO_STRING_TABLE_END(RELEASE_POLICY) 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) { @@ -166,7 +168,8 @@ ImageVisual::ImageVisual(VisualFactoryCache& factoryCache, mAtlasRectSize(0, 0), mLoadState(TextureManager::LoadState::NOT_STARTED), mAttemptAtlasing(false), - mOrientationCorrection(true) + mOrientationCorrection(true), + mEnableBrokenImage(true) { EnablePreMultipliedAlpha(mFactoryCache.GetPreMultiplyOnLoad()); } @@ -175,18 +178,6 @@ ImageVisual::~ImageVisual() { 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 : @@ -200,7 +191,7 @@ ImageVisual::~ImageVisual() else if(mImageUrl.IsBufferResource()) { TextureManager& textureManager = mFactoryCache.GetTextureManager(); - textureManager.RemoveExternalEncodedImageBuffer(mImageUrl.GetUrl()); + textureManager.RemoveEncodedImageBuffer(mImageUrl.GetUrl()); } } @@ -272,6 +263,14 @@ void ImageVisual::DoSetProperties(const Property::Map& propertyMap) { 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 == 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); @@ -305,11 +304,11 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va { 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 @@ -321,7 +320,7 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va case Toolkit::ImageVisual::Property::DESIRED_WIDTH: { - float desiredWidth = 0.0f; + int32_t desiredWidth = 0; if(value.Get(desiredWidth)) { mDesiredSize.SetWidth(desiredWidth); @@ -335,7 +334,7 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va case Toolkit::ImageVisual::Property::DESIRED_HEIGHT: { - float desiredHeight = 0.0f; + int32_t desiredHeight = 0; if(value.Get(desiredHeight)) { mDesiredSize.SetHeight(desiredHeight); @@ -424,6 +423,36 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va break; } + case Toolkit::DevelImageVisual::Property::MASKING_TYPE: + { + int maskingType = 0; + if(value.Get(maskingType)) + { + AllocateMaskData(); + 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; + } + case Toolkit::ImageVisual::Property::RELEASE_POLICY: { int releasePolicy = 0; @@ -456,6 +485,10 @@ void ImageVisual::AllocateMaskData() if(!mMaskingData) { mMaskingData.reset(new TextureManager::MaskingData()); + if(mImageUrl.IsValid() && mImageUrl.GetProtocolType() == VisualUrl::TEXTURE) + { + mMaskingData->mPreappliedMasking = false; + } } } @@ -469,7 +502,7 @@ void ImageVisual::GetNaturalSize(Vector2& naturalSize) } 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(); @@ -479,11 +512,9 @@ void ImageVisual::GetNaturalSize(Vector2& naturalSize) 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; } } @@ -513,16 +544,21 @@ void ImageVisual::GetNaturalSize(Vector2& naturalSize) } else { - Actor actor = mPlacementActor.GetHandle(); + Actor actor = mPlacementActor.GetHandle(); Vector2 imageSize = Vector2::ZERO; if(actor) { imageSize = actor.GetProperty(Actor::Property::SIZE).Get(); } + else + { + imageSize = mPlacementActorSize; + } + mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize); Texture brokenImage = mImpl->mRenderer.GetTextures().GetTexture(0); - naturalSize.x = brokenImage.GetWidth(); - naturalSize.y = brokenImage.GetWidth(); + naturalSize.x = brokenImage.GetWidth(); + naturalSize.y = brokenImage.GetWidth(); } return; } @@ -565,12 +601,18 @@ void ImageVisual::OnInitialize() 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(mMaskingData->mCropToMask)); + } } void ImageVisual::LoadTexture(bool& atlasing, Vector4& atlasRect, TextureSet& textures, bool orientationCorrection, TextureManager::ReloadPolicy forceReload) @@ -594,7 +636,7 @@ void ImageVisual::LoadTexture(bool& atlasing, Vector4& atlasRect, TextureSet& te 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) { @@ -608,6 +650,12 @@ void ImageVisual::LoadTexture(bool& atlasing, Vector4& atlasRect, TextureSet& te } EnablePreMultipliedAlpha(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD); + if(!atlasing) + { + Sampler sampler = Sampler::New(); + sampler.SetWrapMode(mWrapModeU, mWrapModeV); + textures.SetSampler(0u, sampler); + } } else if(synchronousLoading) { @@ -617,11 +665,11 @@ void ImageVisual::LoadTexture(bool& atlasing, Vector4& atlasRect, TextureSet& te 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; } } @@ -652,13 +700,33 @@ void ImageVisual::InitializeRenderer() 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); + } } } 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(); } @@ -693,13 +761,6 @@ void ImageVisual::DoSetOnScene(Actor& actor) } mPlacementActor = actor; - // Search the Actor tree to find if Layer UI behaviour set. - Layer layer = actor.GetLayer(); - if(layer && layer.GetProperty(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) { @@ -716,15 +777,7 @@ void ImageVisual::DoSetOnScene(Actor& actor) } else if(mLoadState == TextureManager::LoadState::LOAD_FAILED) { - Vector2 imageSize = Vector2::ZERO; - if(actor) - { - imageSize = actor.GetProperty(Actor::Property::SIZE).Get(); - } - mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize); - actor.AddRenderer(mImpl->mRenderer); - mPlacementActor.Reset(); - + ShowBrokenImage(); ResourceReady(Toolkit::Visual::ResourceStatus::FAILED); } } @@ -737,13 +790,7 @@ void ImageVisual::DoSetOffScene(Actor& actor) 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); - - mLoadState = TextureManager::LoadState::NOT_STARTED; + ResetRenderer(); } mPlacementActor.Reset(); @@ -755,7 +802,7 @@ void ImageVisual::DoCreatePropertyMap(Property::Map& map) const map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE); bool sync = IsSynchronousLoadingRequired(); - map.Insert(SYNCHRONOUS_LOADING, sync); + map.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, sync); if(mImageUrl.IsValid()) { map.Insert(Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl()); @@ -777,6 +824,7 @@ void ImageVisual::DoCreatePropertyMap(Property::Map& map) const 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); @@ -795,11 +843,11 @@ void ImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const } } -void ImageVisual::OnDoAction(const Dali::Property::Index actionName, const Dali::Property::Value& attributes) +void ImageVisual::OnDoAction(const Dali::Property::Index actionId, const Dali::Property::Value& attributes) { // Check if action is valid for this visual type and perform action if possible - switch(actionName) + switch(actionId) { case DevelImageVisual::Action::RELOAD: { @@ -814,16 +862,10 @@ void ImageVisual::OnSetTransform() { 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) @@ -853,49 +895,59 @@ void ImageVisual::UploadCompleted() } // From Texture Manager -void ImageVisual::UploadComplete(bool loadingSuccess, int32_t textureId, TextureSet textureSet, bool usingAtlas, const Vector4& atlasRectangle, bool preMultiplied) +void ImageVisual::LoadComplete(bool loadingSuccess, TextureInformation textureInformation) { Toolkit::Visual::ResourceStatus resourceStatus; if(mImpl->mRenderer) { - if(usingAtlas) + if(textureInformation.useAtlasing) { mImpl->mRenderer.RegisterProperty(ATLAS_RECT_UNIFORM_NAME, mAtlasRect); } - EnablePreMultipliedAlpha(preMultiplied); + EnablePreMultipliedAlpha(textureInformation.preMultiplied); Actor actor = mPlacementActor.GetHandle(); if(!loadingSuccess) { - Vector2 imageSize = Vector2::ZERO; - if(actor) - { - imageSize = actor.GetProperty(Actor::Property::SIZE).Get(); - } - mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize); - textureSet = mImpl->mRenderer.GetTextures(); + ShowBrokenImage(); + textureInformation.textureSet = mImpl->mRenderer.GetTextures(); } else { - Sampler sampler = Sampler::New(); - sampler.SetWrapMode(mWrapModeU, mWrapModeV); - textureSet.SetSampler(0u, sampler); - mImpl->mRenderer.SetTextures(textureSet); - } + if(!textureInformation.useAtlasing) + { + Sampler sampler = Sampler::New(); + sampler.SetWrapMode(mWrapModeU, mWrapModeV); + textureInformation.textureSet.SetSampler(0u, sampler); + } - if(actor) - { - actor.AddRenderer(mImpl->mRenderer); - // reset the weak handle so that the renderer only get added to actor once - mPlacementActor.Reset(); + 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) + { + actor.AddRenderer(mImpl->mRenderer); + // reset the weak handle so that the renderer only get added to actor once + mPlacementActor.Reset(); + } } } // Storing TextureSet needed when renderer staged. if(!mImpl->mRenderer) { - mTextures = textureSet; + mTextures = textureInformation.textureSet; } // Image loaded, set status regardless of staged status. @@ -948,7 +1000,7 @@ void ImageVisual::RemoveTexture() { if(mTextureId != TextureManager::INVALID_TEXTURE_ID) { - mFactoryCache.GetTextureManager().Remove(mTextureId, this); + mFactoryCache.GetTextureManager().RequestRemove(mTextureId, this); mTextureId = TextureManager::INVALID_TEXTURE_ID; } else @@ -970,26 +1022,82 @@ void ImageVisual::RemoveTexture() } } +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(mTextureSize.x * mMaskingData->mContentScaleFactor), maskTexture.GetWidth()); + mTextureSize.y = std::min(static_cast(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(texture.GetWidth() * mMaskingData->mContentScaleFactor), Dali::Math::MACHINE_EPSILON_1); + float textureHeight = std::max(static_cast(texture.GetHeight() * mMaskingData->mContentScaleFactor), Dali::Math::MACHINE_EPSILON_1); + maskTextureRatio = Vector2(std::min(static_cast(maskTexture.GetWidth()), textureWidth) / textureWidth, + std::min(static_cast(maskTexture.GetHeight()), textureHeight) / textureHeight); + } + } + } + } + } + return maskTextureRatio; +} + Shader ImageVisual::GenerateShader() const { Shader shader; - bool usesWholeTexture = true; - const bool useStandardShader = !mImpl->mCustomShader; - const bool useNativeImage = (mTextures && DevelTexture::IsNative(mTextures.GetTexture(0))); + bool usesWholeTexture = true; + const bool useStandardShader = !mImpl->mCustomShader; + const bool useNativeImage = (mTextures && DevelTexture::IsNative(mTextures.GetTexture(0))); 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) - .ApplyDefaultTextureWrapMode(mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE) - .EnableRoundedCorner(IsRoundedCornerRequired()) - .EnableBorderline(IsBorderlineRequired()) - .SetTextureForFragmentShaderCheck(useNativeImage ? mTextures.GetTexture(0) : Dali::Texture()) - ); + .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()) + .EnableAlphaMaskingOnRendering(requiredAlphaMaskingOnRendering) + .EnableYuvToRgb(mNeedYuvToRgb)); } else { @@ -1043,14 +1151,70 @@ Shader ImageVisual::GenerateShader() const 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::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(); + } + } +} + +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(); + mPlacementActorSize = imageSize; + } + + mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize); + if(actor) + { + actor.AddRenderer(mImpl->mRenderer); + mPlacementActor.Reset(); + } + } + else + { + ResetRenderer(); + } +} + } // namespace Internal } // namespace Toolkit