X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fimage%2Fimage-visual.cpp;h=07ead876afb845c10f0f1dc48f6939f13f5f067e;hp=bbef5e4225dea74555425820f84ff145fd9a3e2a;hb=5aaba5adcf1a717e1ece3ef9c55c8912420993b5;hpb=5f181f3628644b3192a216e228a9ff40093e90a3 diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index bbef5e4..07ead87 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) 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. @@ -56,15 +56,6 @@ namespace Internal 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 ) @@ -131,6 +122,7 @@ Geometry CreateGeometry( VisualFactoryCache& factoryCache, ImageDimensions gridS } // unnamed namespace + ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, @@ -187,10 +179,11 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, mLoading( false ), mOrientationCorrection( true ) { + EnablePreMultipliedAlpha( mFactoryCache.GetPreMultiplyOnLoad() ); } ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const Image& image ) -: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ), +: Visual::Base( factoryCache, Visual::FittingMode::FILL ), mImage( image ), mPixelArea( FULL_TEXTURE_RECT ), mPlacementActor(), @@ -211,6 +204,8 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFac mLoading( false ), mOrientationCorrection( true ) { + // PreMultiplied alpha should be disabled when the Image is used. + EnablePreMultipliedAlpha( false ); } ImageVisual::~ImageVisual() @@ -225,7 +220,7 @@ ImageVisual::~ImageVisual() if( mMaskingData->mAlphaMaskId != TextureManager::INVALID_TEXTURE_ID ) { TextureManager& textureManager = mFactoryCache.GetTextureManager(); - textureManager.Remove( mMaskingData->mAlphaMaskId ); + textureManager.Remove( mMaskingData->mAlphaMaskId, this ); } } @@ -423,10 +418,7 @@ void ImageVisual::DoSetProperty( Property::Index index, const Property::Value& v 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; } @@ -515,9 +507,12 @@ void ImageVisual::GetNaturalSize( Vector2& naturalSize ) if( textureSet ) { auto texture = textureSet.GetTexture(0); - naturalSize.x = texture.GetWidth(); - naturalSize.y = texture.GetHeight(); - return; + if( texture ) + { + naturalSize.x = texture.GetWidth(); + naturalSize.y = texture.GetHeight(); + return; + } } } @@ -553,7 +548,6 @@ void ImageVisual::GetNaturalSize( Vector2& naturalSize ) return; } } - naturalSize = Vector2::ZERO; } @@ -568,7 +562,8 @@ void ImageVisual::CreateRenderer( TextureSet& textureSet ) 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 { @@ -663,11 +658,6 @@ void ImageVisual::CreateNativeImageRenderer( NativeImage& nativeImage ) 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 ) { @@ -683,12 +673,12 @@ void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& t 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); @@ -781,7 +771,7 @@ void ImageVisual::DoSetOnStage( Actor& actor ) mPlacementActor = actor; // Search the Actor tree to find if Layer UI behaviour set. Layer layer = actor.GetLayer(); - if( layer && layer.GetBehavior() == Layer::LAYER_3D ) + 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 ); @@ -829,7 +819,7 @@ void ImageVisual::DoCreatePropertyMap( Property::Map& map ) const 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() ) { @@ -953,39 +943,41 @@ void ImageVisual::UploadComplete( bool loadingSuccess, int32_t textureId, Textur 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(); + } - textureSet = TextureSet::New(); - mImpl->mRenderer.SetTextures( textureSet ); + if( loadingSuccess ) + { + Sampler sampler = Sampler::New(); + sampler.SetWrapMode( mWrapModeU, mWrapModeV ); + textureSet.SetSampler( 0u, sampler ); + mImpl->mRenderer.SetTextures(textureSet); + } + else + { + Image brokenImage = mFactoryCache.GetBrokenVisualImage(); - ApplyImageToSampler( brokenImage ); - } + textureSet = TextureSet::New(); + mImpl->mRenderer.SetTextures( textureSet ); + + ApplyImageToSampler( brokenImage ); } } + // Storing TextureSet needed when renderer staged. if( ! mImpl->mRenderer ) { @@ -1010,7 +1002,7 @@ void ImageVisual::RemoveTexture() { if( mTextureId != TextureManager::INVALID_TEXTURE_ID ) { - mFactoryCache.GetTextureManager().Remove( mTextureId ); + mFactoryCache.GetTextureManager().Remove( mTextureId, this ); mTextureId = TextureManager::INVALID_TEXTURE_ID; } else