From 129430611d13fed94f333b0429af19cc61001eb1 Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Fri, 17 Jul 2020 19:06:52 +0900 Subject: [PATCH] Do not request relayout when a control background color is changed Change-Id: I9047335cf832d956615feed53826e5e5557acac3 --- .../src/dali-toolkit/utc-Dali-Control.cpp | 12 +++++ dali-toolkit/devel-api/file.list | 1 + .../devel-api/visuals/color-visual-actions-devel.h | 54 ++++++++++++++++++++++ .../internal/visuals/color/color-visual.cpp | 18 ++++++++ dali-toolkit/internal/visuals/color/color-visual.h | 5 ++ dali-toolkit/public-api/controls/control-impl.cpp | 37 +++++++++++---- 6 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 dali-toolkit/devel-api/visuals/color-visual-actions-devel.h diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp index c08e360..1f1b2bc 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp @@ -512,6 +512,18 @@ int UtcDaliControlBackgroundColorRendererCount(void) DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION ); DALI_TEST_EQUALS( GetControlBackgroundColor( control ), semiTransparent, TEST_LOCATION ); + Renderer renderer = control.GetRendererAt( 0 ); + DALI_TEST_CHECK( renderer ); + + tet_infoline( "Set semi transparent alpha with positive RGB values, renderer should not be changed" ); + const Vector4 newColor( 1.0f, 1.0f, 0.5f, 0.5f ); + control.SetBackgroundColor( newColor ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( GetControlBackgroundColor( control ), newColor, TEST_LOCATION ); + DALI_TEST_EQUALS( renderer, control.GetRendererAt( 0 ), TEST_LOCATION ); + tet_infoline( "Set transparent, ensure no renderers are created" ); control.SetBackgroundColor( Color::TRANSPARENT ); application.SendNotification(); diff --git a/dali-toolkit/devel-api/file.list b/dali-toolkit/devel-api/file.list index 4df34bb..7315172 100755 --- a/dali-toolkit/devel-api/file.list +++ b/dali-toolkit/devel-api/file.list @@ -154,6 +154,7 @@ SET( devel_api_visuals_header_files ${devel_api_src_dir}/visuals/animated-vector-image-visual-signals-devel.h ${devel_api_src_dir}/visuals/arc-visual-actions-devel.h ${devel_api_src_dir}/visuals/arc-visual-properties-devel.h + ${devel_api_src_dir}/visuals/color-visual-actions-devel.h ${devel_api_src_dir}/visuals/color-visual-properties-devel.h ${devel_api_src_dir}/visuals/image-visual-properties-devel.h ${devel_api_src_dir}/visuals/image-visual-actions-devel.h diff --git a/dali-toolkit/devel-api/visuals/color-visual-actions-devel.h b/dali-toolkit/devel-api/visuals/color-visual-actions-devel.h new file mode 100644 index 0000000..daffa3b --- /dev/null +++ b/dali-toolkit/devel-api/visuals/color-visual-actions-devel.h @@ -0,0 +1,54 @@ +#ifndef DALI_TOOLKIT_DEVEL_API_VISUALS_COLOR_VISUAL_ACTIONS_DEVEL_H +#define DALI_TOOLKIT_DEVEL_API_VISUALS_COLOR_VISUAL_ACTIONS_DEVEL_H + +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +namespace Dali +{ + +namespace Toolkit +{ + +namespace DevelColorVisual +{ + +/** + * @brief Actions that the color visual can perform. These actions are called through the Visual::Base::DoAction API. + */ +namespace Action +{ +/** + * @brief The available actions for this visual + */ +enum Type +{ + /** + * @brief Update the properties of the visual. + */ + UPDATE_PROPERTY = 0 +}; + +} // namespace Actions + +} // namespace DevelVisual + +} // namespace Toolkit + +} // namespace Dali + +#endif // DALI_TOOLKIT_DEVEL_API_VISUALS_COLOR_VISUAL_ACTIONS_DEVEL_H diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 74ad4d2..86fa121 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -282,6 +283,23 @@ void ColorVisual::OnSetTransform() } } +void ColorVisual::OnDoAction( const Property::Index actionId, const Property::Value& attributes ) +{ + // Check if action is valid for this visual type and perform action if possible + switch( actionId ) + { + case DevelColorVisual::Action::UPDATE_PROPERTY: + { + Property::Map* map = attributes.GetMap(); + if( map ) + { + DoSetProperties( *map ); + } + break; + } + } +} + void ColorVisual::InitializeRenderer() { Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY ); diff --git a/dali-toolkit/internal/visuals/color/color-visual.h b/dali-toolkit/internal/visuals/color/color-visual.h index 05c8ba9..16c65a7 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.h +++ b/dali-toolkit/internal/visuals/color/color-visual.h @@ -99,6 +99,11 @@ protected: */ void OnSetTransform() override; + /** + * @copydoc Visual::Base::OnDoAction + */ + void OnDoAction( const Property::Index actionId, const Property::Value& attributes ) override; + private: /** * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing. diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index f17092f..3afa397 100755 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -71,17 +72,14 @@ void ChangeBackgroundColorVisual( Control& controlImpl, bool renderIfTransparent Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl ); Toolkit::Visual::Base backgroundVisual = controlDataImpl.GetVisual( Toolkit::Control::Property::BACKGROUND ); - if( backgroundVisual ) + if( backgroundVisual && backgroundVisual.GetType() == Toolkit::Visual::COLOR ) { Property::Map map; backgroundVisual.CreatePropertyMap( map ); - Property::Value* typeValue = map.Find( Toolkit::Visual::Property::TYPE ); - if( typeValue && typeValue->Get< int >() == Toolkit::Visual::COLOR ) - { - // Only change it if it's a color visual - map[ Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT ] = renderIfTransparent; - controlImpl.SetBackground( map ); - } + + // Only change it if it's a color visual + map[ Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT ] = renderIfTransparent; + controlImpl.SetBackground( map ); } } @@ -170,16 +168,39 @@ const std::string& Control::GetStyleName() const void Control::SetBackgroundColor( const Vector4& color ) { mImpl->mBackgroundColor = color; + Property::Map map; map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR; map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color; + bool renderIfTransparent = false; int clippingMode = ClippingMode::DISABLED; if( ( Self().GetProperty( Actor::Property::CLIPPING_MODE ).Get( clippingMode ) ) && ( clippingMode == ClippingMode::CLIP_CHILDREN ) ) { // If clipping-mode is set to CLIP_CHILDREN, then force visual to add the render even if transparent map[ Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT ] = true; + renderIfTransparent = true; + } + + Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND ); + if( visual && visual.GetType() == Toolkit::Visual::COLOR ) + { + Property::Map visualMap; + visual.CreatePropertyMap( visualMap ); + + Property::Value* renderValue = visualMap.Find( Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT ); + Property::Value* colorValue = visualMap.Find( Toolkit::ColorVisual::Property::MIX_COLOR ); + if( renderValue && colorValue ) + { + if( ( renderValue->Get< bool >() == true || colorValue->Get< Vector4 >().a > 0.0f ) + && ( renderIfTransparent || color.a > 0.0f ) ) + { + // Update background color only + mImpl->DoAction( Toolkit::Control::Property::BACKGROUND, DevelColorVisual::Action::UPDATE_PROPERTY, map ); + return; + } + } } SetBackground( map ); -- 2.7.4