#include <dali-toolkit/devel-api/image-loader/texture-manager.h>
#include <dali-toolkit/devel-api/visual-factory/visual-base.h>
#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
+#include <dali-toolkit/devel-api/visuals/image-visual-actions-devel.h>
#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <test-native-image.h>
Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
bool enable;
DALI_TEST_CHECK( value.Get( enable ) );
- DALI_TEST_CHECK( !enable );
+ DALI_TEST_CHECK( enable );
// pre-multiplied alpha blending
imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
END_TEST;
}
+int UtcDaliImageViewPreMultipliedAlphaPng(void)
+{
+ ToolkitTestApplication application;
+
+ // Set up trace debug
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable( true );
+
+ Property::Map imageMap;
+ imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
+ imageMap[ ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
+
+ ImageView imageView1 = ImageView::New();
+ imageView1.SetProperty( ImageView::Property::IMAGE, imageMap );
+
+ Stage::GetCurrent().Add( imageView1 );
+
+ Property::Value value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
+ bool enable;
+ DALI_TEST_CHECK( value.Get( enable ) );
+ DALI_TEST_CHECK( enable ); // Default value is true
+
+ // loading started, this waits for the loader thread for max 30 seconds
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+
+ value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
+ DALI_TEST_CHECK( value.Get( enable ) );
+ DALI_TEST_CHECK( enable ); // Keep true
+
+ // conventional alpha blending
+ Renderer renderer1 = imageView1.GetRendererAt( 0 );
+ value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
+ DALI_TEST_CHECK( value.Get( enable ) );
+ DALI_TEST_CHECK( enable );
+
+ int srcFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
+ int destFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
+ int srcFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
+ int destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
+ DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
+ DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
+ DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
+ DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
+
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); // A new texture should be generated.
+ textureTrace.Reset();
+
+ // Disable pre-multiplied alpha blending
+ imageView1.SetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA, false );
+
+ // Reload the image
+ Property::Map attributes;
+ DevelControl::DoAction( imageView1, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes );
+
+ // loading started, this waits for the loader thread for max 30 seconds
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+
+ value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
+ DALI_TEST_CHECK( value.Get( enable ) );
+ DALI_TEST_CHECK( !enable );
+
+ // conventional alpha blending
+ value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
+ DALI_TEST_CHECK( value.Get( enable ) );
+ DALI_TEST_CHECK( !enable );
+
+ srcFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
+ destFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
+ srcFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
+ destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
+ DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
+ DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
+ DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
+ DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
+
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); // A new texture should be generated.
+ textureTrace.Reset();
+
+ // Make a new ImageView using the same image
+ ImageView imageView2 = ImageView::New();
+ imageView2.SetProperty( ImageView::Property::IMAGE, imageMap );
+
+ Stage::GetCurrent().Add( imageView2 );
+
+ application.SendNotification();
+ application.Render();
+
+ Renderer renderer2 = imageView2.GetRendererAt( 0 );
+ value = renderer2.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
+ DALI_TEST_CHECK( value.Get( enable ) );
+ DALI_TEST_CHECK( enable );
+
+ srcFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
+ destFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
+ srcFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
+ destFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
+ DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
+ DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
+ DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
+ DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
+
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); // The cached texture should be used.
+
+ END_TEST;
+}
+
+int UtcDaliImageViewPreMultipliedAlphaJpg(void)
+{
+ ToolkitTestApplication application;
+
+ // Set up trace debug
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable( true );
+
+ Property::Map imageMap;
+ imageMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
+ imageMap[ ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
+
+ ImageView imageView1 = ImageView::New();
+ imageView1.SetProperty( ImageView::Property::IMAGE, imageMap );
+
+ Stage::GetCurrent().Add( imageView1 );
+
+ Property::Value value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
+ bool enable;
+ DALI_TEST_CHECK( value.Get( enable ) );
+ DALI_TEST_CHECK( enable ); // Default value is true
+
+ // loading started, this waits for the loader thread for max 30 seconds
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+
+ value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
+ DALI_TEST_CHECK( value.Get( enable ) );
+ DALI_TEST_CHECK( !enable ); // Should be false after loading
+
+ // conventional alpha blending
+ Renderer renderer1 = imageView1.GetRendererAt( 0 );
+ value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
+ DALI_TEST_CHECK( value.Get( enable ) );
+ DALI_TEST_CHECK( !enable );
+
+ int srcFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
+ int destFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
+ int srcFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
+ int destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
+ DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
+ DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
+ DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
+ DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
+
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); // A new texture should be generated.
+ textureTrace.Reset();
+
+ ImageView imageView2 = ImageView::New();
+ imageView2.SetProperty( ImageView::Property::IMAGE, imageMap );
+
+ // Disable pre-multiplied alpha blending
+ imageView2.SetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA, false );
+
+ Stage::GetCurrent().Add( imageView2 );
+
+ application.SendNotification();
+ application.Render();
+
+ value = imageView2.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
+ DALI_TEST_CHECK( value.Get( enable ) );
+ DALI_TEST_CHECK( !enable );
+
+ // conventional alpha blending
+ Renderer renderer2 = imageView2.GetRendererAt( 0 );
+ value = renderer2.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
+ DALI_TEST_CHECK( value.Get( enable ) );
+ DALI_TEST_CHECK( !enable );
+
+ srcFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
+ destFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
+ srcFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
+ destFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
+ DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
+ DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
+ DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
+ DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
+
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); // The cached texture should be used.
+
+ END_TEST;
+}
+
int UtcDaliImageViewPixelArea(void)
{
// Test pixel area property
{
// First check if the requested Texture is cached.
const TextureHash textureHash = GenerateHash( url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas,
- maskTextureId, preMultiplyOnLoad );
+ maskTextureId );
TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
const FittingMode::Type fittingMode,
const Dali::SamplingMode::Type samplingMode,
const UseAtlas useAtlas,
- TextureId maskTextureId,
- TextureManager::MultiplyOnLoad preMultiplyOnLoad)
+ TextureId maskTextureId )
{
std::string hashTarget( url );
const size_t urlLength = hashTarget.length();
}
}
- auto premultipliedIndex = hashTarget.length();
- hashTarget.resize( premultipliedIndex + 1 );
- switch( preMultiplyOnLoad )
- {
- case TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD:
- {
- hashTarget[ premultipliedIndex ] = 't';
- break;
- }
- case TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY:
- {
- hashTarget[ premultipliedIndex ] = 'f';
- break;
- }
- }
-
return Dali::CalculateHash( hashTarget );
}
{
// We have a match, now we check all the original parameters in case of a hash collision.
TextureInfo& textureInfo( mTextureInfoContainer[i] );
- auto multiplyOnLoad = textureInfo.preMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD :
- TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
if( ( url == textureInfo.url.GetUrl() ) &&
( useAtlas == textureInfo.useAtlas ) &&
( maskTextureId == textureInfo.maskTextureId ) &&
( size == textureInfo.desiredSize ) &&
- ( preMultiplyOnLoad == multiplyOnLoad ) &&
( ( size.GetWidth() == 0 && size.GetHeight() == 0 ) ||
( fittingMode == textureInfo.fittingMode &&
samplingMode == textureInfo.samplingMode ) ) )
{
- // The found Texture is a match.
- cacheIndex = i;
- break;
+ // 1. If preMultiplyOnLoad is MULTIPLY_ON_LOAD, then textureInfo.preMultiplyOnLoad should be true. The premultiplication result can be different.
+ // 2. If preMultiplyOnLoad is LOAD_WITHOUT_MULTIPLY, then textureInfo.preMultiplied should be false.
+ if( ( preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD && textureInfo.preMultiplyOnLoad )
+ || ( preMultiplyOnLoad == TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY && !textureInfo.preMultiplied ) )
+ {
+ // The found Texture is a match.
+ cacheIndex = i;
+ break;
+ }
}
}
}