/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
namespace
{
-// property names
-const char * const IMAGE_FITTING_MODE( "fittingMode" );
-const char * const IMAGE_SAMPLING_MODE( "samplingMode" );
-const char * const IMAGE_DESIRED_WIDTH( "desiredWidth" );
-const char * const IMAGE_DESIRED_HEIGHT( "desiredHeight" );
-const char * const SYNCHRONOUS_LOADING( "synchronousLoading" );
-const char * const IMAGE_ATLASING("atlasing");
-const char * const ALPHA_MASK_URL("alphaMaskUrl");
-
// fitting modes
DALI_ENUM_TO_STRING_TABLE_BEGIN( FITTING_MODE )
DALI_ENUM_TO_STRING_WITH_SCOPE( Dali::FittingMode, SHRINK_TO_FIT )
mLoading( false ),
mOrientationCorrection( true )
{
+ EnablePreMultipliedAlpha( mFactoryCache.GetPreMultiplyOnLoad() );
}
ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const Image& image )
mLoading( false ),
mOrientationCorrection( true )
{
+ // PreMultiplied alpha should be disabled when the Image is used.
+ EnablePreMultipliedAlpha( false );
}
ImageVisual::~ImageVisual()
if( mMaskingData->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID )
{
TextureManager& textureManager = mFactoryCache.GetTextureManager();
- textureManager.Remove( mMaskingData->mAlphaMaskId );
+ textureManager.Remove( mMaskingData->mAlphaMaskId, this );
}
}
if( value.Get( alphaUrl ) )
{
AllocateMaskData();
- // Immediately trigger the alpha mask loading (it may just get a cached value)
mMaskingData->mAlphaMaskUrl = alphaUrl;
- TextureManager& textureManager = mFactoryCache.GetTextureManager();
- mMaskingData->mAlphaMaskId = textureManager.RequestMaskLoad( alphaUrl );
}
break;
}
shader = mImageVisualShaderFactory.GetShader( mFactoryCache,
mImpl->mFlags & Impl::IS_ATLASING_APPLIED,
- mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE );
+ mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE,
+ IsRoundedCornerRequired() );
}
else
{
mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
}
-bool ImageVisual::IsSynchronousResourceLoading() const
-{
- return mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
-}
-
void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& textures, bool orientationCorrection,
TextureManager::ReloadPolicy forceReload )
{
atlasUploadObserver = this;
}
- auto preMultiplyOnLoad = mFactoryCache.GetPreMultiplyOnLoad() && !mImpl->mCustomShader
+ auto preMultiplyOnLoad = IsPreMultipliedAlphaEnabled() && !mImpl->mCustomShader
? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
: TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
textures = textureManager.LoadTexture( mImageUrl, mDesiredSize, mFittingMode, mSamplingMode,
- mMaskingData, IsSynchronousResourceLoading(), mTextureId,
+ mMaskingData, IsSynchronousLoadingRequired(), mTextureId,
atlasRect, mAtlasRectSize, atlasing, mLoading, mWrapModeU,
mWrapModeV, textureObserver, atlasUploadObserver, atlasManager,
mOrientationCorrection, forceReload, preMultiplyOnLoad);
map.Clear();
map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
- bool sync = IsSynchronousResourceLoading();
+ bool sync = IsSynchronousLoadingRequired();
map.Insert( SYNCHRONOUS_LOADING, sync );
if( mImageUrl.IsValid() )
{
const Vector4& atlasRectangle, bool preMultiplied )
{
Toolkit::Visual::ResourceStatus resourceStatus;
- Actor actor = mPlacementActor.GetHandle();
- if( actor )
+ if( mImpl->mRenderer )
{
- if( mImpl->mRenderer )
+ if( usingAtlas )
{
- if( usingAtlas )
- {
- mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, mAtlasRect );
- }
+ mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, mAtlasRect );
+ }
- EnablePreMultipliedAlpha( preMultiplied );
+ EnablePreMultipliedAlpha( preMultiplied );
+ Actor actor = mPlacementActor.GetHandle();
+ if( actor )
+ {
actor.AddRenderer( mImpl->mRenderer );
// reset the weak handle so that the renderer only get added to actor once
mPlacementActor.Reset();
- if( loadingSuccess )
- {
- Sampler sampler = Sampler::New();
- sampler.SetWrapMode( mWrapModeU, mWrapModeV );
- textureSet.SetSampler( 0u, sampler );
- mImpl->mRenderer.SetTextures(textureSet);
- }
- else
- {
- Image brokenImage = mFactoryCache.GetBrokenVisualImage();
+ }
+
+ if( loadingSuccess )
+ {
+ Sampler sampler = Sampler::New();
+ sampler.SetWrapMode( mWrapModeU, mWrapModeV );
+ textureSet.SetSampler( 0u, sampler );
+ mImpl->mRenderer.SetTextures(textureSet);
+ }
+ else
+ {
+ Image brokenImage = mFactoryCache.GetBrokenVisualImage();
- textureSet = TextureSet::New();
- mImpl->mRenderer.SetTextures( textureSet );
+ textureSet = TextureSet::New();
+ mImpl->mRenderer.SetTextures( textureSet );
- ApplyImageToSampler( brokenImage );
- }
+ ApplyImageToSampler( brokenImage );
}
}
+
// Storing TextureSet needed when renderer staged.
if( ! mImpl->mRenderer )
{
{
if( mTextureId != TextureManager::INVALID_TEXTURE_ID )
{
- mFactoryCache.GetTextureManager().Remove( mTextureId );
+ mFactoryCache.GetTextureManager().Remove( mTextureId, this );
mTextureId = TextureManager::INVALID_TEXTURE_ID;
}
else