From: Adeel Kazmi Date: Tue, 8 Nov 2016 11:56:57 +0000 (+0000) Subject: (GradientVisual) Turn BlendMode on renderer to OFF if using fully opaque colors X-Git-Tag: dali_1.2.14~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d2265be3cc2e43a7464b27a6d611a5548313fb8e;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git (GradientVisual) Turn BlendMode on renderer to OFF if using fully opaque colors Change-Id: Ib5c0da3df30b42940254561315854f8f8ab12d87 --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index 7cda6e5a95..ff64e24b55 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp @@ -1615,4 +1615,41 @@ int UtcDaliNPatchVisualCustomShader(void) 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( 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)BlendMode::OFF, TEST_LOCATION ); + DALI_TEST_EQUALS( control.GetRendererAt( 1 ).GetProperty( Renderer::Property::BLEND_MODE ).Get(), (int)BlendMode::AUTO, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp index e0ae085ca8..6f50a9a77d 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp @@ -222,7 +222,8 @@ GradientVisualPtr GradientVisual::New( VisualFactoryCache& factoryCache ) GradientVisual::GradientVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), - mGradientType( LINEAR ) + mGradientType( LINEAR ), + mIsOpaque( true ) { mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; } @@ -362,6 +363,12 @@ void GradientVisual::InitializeRenderer() 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 @@ -423,6 +430,10 @@ bool GradientVisual::NewGradient(Type gradientType, const Property::Map& propert { 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; + } } } } diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.h b/dali-toolkit/internal/visuals/gradient/gradient-visual.h index e4920d18eb..bc131aeb11 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.h +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.h @@ -177,6 +177,7 @@ private: Matrix3 mGradientTransform; IntrusivePtr mGradient; Type mGradientType; + bool mIsOpaque; ///< Set to false if any of the stop colors are not opaque }; } // namespace Internal