END_TEST;
}
+int UtcDaliGradientVisualBlendMode(void)
+{
+ ToolkitTestApplication application;
+
+ VisualFactory factory = VisualFactory::Get();
+
+ Visual::Base opaqueGradientVisual = factory.CreateVisual(
+ Property::Map().Add( Visual::Property::TYPE, Visual::GRADIENT )
+ .Add( GradientVisual::Property::START_POSITION, Vector2( -0.5f, -0.5f ) )
+ .Add( GradientVisual::Property::END_POSITION, Vector2( 0.5f, 0.5f ) )
+ .Add( GradientVisual::Property::STOP_COLOR, Property::Array().Add( Color::RED )
+ .Add( Color::GREEN ) ) );
+
+ Visual::Base alphaGradientVisual = factory.CreateVisual(
+ Property::Map().Add( Visual::Property::TYPE, Visual::GRADIENT )
+ .Add( GradientVisual::Property::START_POSITION, Vector2( -0.5f, -0.5f ) )
+ .Add( GradientVisual::Property::END_POSITION, Vector2( 0.5f, 0.5f ) )
+ .Add( GradientVisual::Property::STOP_COLOR, Property::Array().Add( Color::RED )
+ .Add( Vector4( 1.0f, 1.0f, 1.0f, 0.5f ) ) ) );
+
+ DummyControl control = DummyControl::New();
+ control.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
+ Stage::GetCurrent().Add( control );
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>( control.GetImplementation() );
+ dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, opaqueGradientVisual );
+ dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 2, alphaGradientVisual );
+
+ application.SendNotification();
+ application.Render();
+
+ // Control should have two renderers, the first one is opaque so our blending mode should be off, the second one has some alpha so should be set to automatic
+ DALI_TEST_EQUALS( 2u, control.GetRendererCount(), TEST_LOCATION );
+ DALI_TEST_EQUALS( control.GetRendererAt( 0 ).GetProperty( Renderer::Property::BLEND_MODE ).Get<int>(), (int)BlendMode::OFF, TEST_LOCATION );
+ DALI_TEST_EQUALS( control.GetRendererAt( 1 ).GetProperty( Renderer::Property::BLEND_MODE ).Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
+
+ END_TEST;
+}
GradientVisual::GradientVisual( VisualFactoryCache& factoryCache )
: Visual::Base( factoryCache ),
- mGradientType( LINEAR )
+ mGradientType( LINEAR ),
+ mIsOpaque( true )
{
mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
}
mImpl->mRenderer = Renderer::New( geometry, shader );
mImpl->mRenderer.SetTextures( textureSet );
+ // If opaque then no need to have blending
+ if( mIsOpaque )
+ {
+ mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
+ }
+
mImpl->mRenderer.RegisterProperty( UNIFORM_ALIGNMENT_MATRIX_NAME, mGradientTransform );
//Register transform properties
{
mGradient->AddStop( offsetArray[i], Vector4(color.r*color.a, color.g*color.a, color.b*color.a, color.a));
numValidStop++;
+ if( ! Equals( color.a, 1.0f, Math::MACHINE_EPSILON_1 ) )
+ {
+ mIsOpaque = false;
+ }
}
}
}