/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
ToolkitTestApplication application;
Control control = Control::New();
+ control[Actor::Property::SIZE] = Vector2(100.0f, 100.0f);
application.GetScene().Add( control );
- tet_infoline( "Set transparent, no renderers should be created" );
- control.SetBackgroundColor( Color::TRANSPARENT );
- application.SendNotification();
- application.Render();
- DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
-
- tet_infoline( "Set transparent alpha with positive RGB values, no renderers should be created, but returned color should reflect what we set" );
- const Vector4 alphaZero( 1.0f, 0.5f, 0.25f, 0.0f );
- control.SetBackgroundColor( alphaZero );
- application.SendNotification();
- application.Render();
- DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
- DALI_TEST_EQUALS( GetControlBackgroundColor( control ), alphaZero, TEST_LOCATION );
-
tet_infoline( "Set semi transparent alpha with positive RGB values, 1 renderer should be created, but returned color should reflect what we set" );
const Vector4 semiTransparent( 1.0f, 0.75f, 0.5f, 0.5f );
control.SetBackgroundColor( semiTransparent );
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" );
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& drawTrace = gl.GetDrawTrace();
+ drawTrace.Enable(true);
+
+ tet_infoline( "Set transparent, 1 renderer should be created, but ensure nothing is drawn" );
control.SetBackgroundColor( Color::TRANSPARENT );
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
+
+ DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
+ DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
+
+ drawTrace.Reset();
tet_infoline( "Set control to clip its children, a renderer should be created which will be transparent" );
control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
application.SendNotification();
application.Render();
+
DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
+ DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION);
tet_infoline( "Set a color, only 1 renderer should exist" );
control.SetBackgroundColor( Color::RED );
DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
- tet_infoline( "Disable clipping, no renderers" );
+ drawTrace.Reset();
+
+ tet_infoline( "Disable clipping, render nothing" );
control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::DISABLED );
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
+
DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
+ DALI_TEST_EQUALS(drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION);
END_TEST;
}
END_TEST;
}
-int UtcDaliColorVisualRenderIfTransparentProperty(void)
-{
- ToolkitTestApplication application;
- tet_infoline( "Test the renderIfTransparent property of ColorVisual" );
-
- VisualFactory factory = VisualFactory::Get();
- Property::Map propertyMap;
- propertyMap.Insert( Visual::Property::TYPE, Visual::COLOR );
- propertyMap.Insert( ColorVisual::Property::MIX_COLOR, Color::BLUE );
-
- tet_infoline( "Check default value" );
- {
- Visual::Base testVisual = factory.CreateVisual( propertyMap );
- Property::Map returnedMap;
- testVisual.CreatePropertyMap( returnedMap );
-
- Property::Value* renderIfTransparentProperty = returnedMap.Find( DevelColorVisual::Property::RENDER_IF_TRANSPARENT );
- DALI_TEST_CHECK( renderIfTransparentProperty );
- DALI_TEST_EQUALS( renderIfTransparentProperty->Get< bool >(), false, TEST_LOCATION );
- }
-
- propertyMap.Insert( DevelColorVisual::Property::RENDER_IF_TRANSPARENT, true );
-
- tet_infoline( "Ensure set to value required" );
- {
- Visual::Base testVisual = factory.CreateVisual( propertyMap );
- Property::Map returnedMap;
- testVisual.CreatePropertyMap( returnedMap );
-
- Property::Value* renderIfTransparentProperty = returnedMap.Find( DevelColorVisual::Property::RENDER_IF_TRANSPARENT );
- DALI_TEST_CHECK( renderIfTransparentProperty );
- DALI_TEST_EQUALS( renderIfTransparentProperty->Get< bool >(), true, TEST_LOCATION );
- }
-
- propertyMap[ DevelColorVisual::Property::RENDER_IF_TRANSPARENT ] = Color::BLUE;
-
- tet_infoline( "Ensure it returns default value if set to wrong type" );
- {
- Visual::Base testVisual = factory.CreateVisual( propertyMap );
- Property::Map returnedMap;
- testVisual.CreatePropertyMap( returnedMap );
-
- Property::Value* renderIfTransparentProperty = returnedMap.Find( DevelColorVisual::Property::RENDER_IF_TRANSPARENT );
- DALI_TEST_CHECK( renderIfTransparentProperty );
- DALI_TEST_EQUALS( renderIfTransparentProperty->Get< bool >(), false, TEST_LOCATION );
- }
-
- END_TEST;
-}
-
int UtcDaliSvgVisualCustomShader(void)
{
ToolkitTestApplication application;
DALI_TEST_CHECK(!property1.object);
DALI_TEST_CHECK(property1.propertyIndex == Property::INVALID_INDEX);
- // Test not-supported property
- Property property2 = DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, DevelColorVisual::Property::RENDER_IF_TRANSPARENT);
- DALI_TEST_CHECK(!property2.object);
- DALI_TEST_CHECK(property2.propertyIndex == Property::INVALID_INDEX);
-
// Test unregistered visual
Property property3 = DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL2, Visual::Property::MIX_COLOR);
DALI_TEST_CHECK(!property3.object);
#define DALI_TOOLKIT_COLOR_VISUAL_PROPERTIES_DEVEL_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
MIX_COLOR = Toolkit::ColorVisual::Property::MIX_COLOR,
/**
- * @brief Whether to render if the MIX_COLOR is transparent.
- * @details Name "renderIfTransparent", type Property::BOOLEAN.
- * @note Optional.
- * @note By default it's false, i.e. ColorVisual will not render if the MIX_COLOR is transparent.
- */
- RENDER_IF_TRANSPARENT = MIX_COLOR + 1,
-
- /**
* @brief The blur radius of the visual.
* @details Name "blurRadius", type Property::FLOAT, animatable.
* If the value is 0, the edge is sharp. Otherwise, the larger the value, the more the edge is blurred.
: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::COLOR),
mBlurRadius(0.0f),
mBlurRadiusIndex(Property::INVALID_INDEX),
- mRenderIfTransparent(false),
mNeedBlurRadius(false)
{
}
}
}
- Property::Value* renderIfTransparentValue = propertyMap.Find(Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT, RENDER_IF_TRANSPARENT_NAME);
- if(renderIfTransparentValue)
- {
- if(!renderIfTransparentValue->Get(mRenderIfTransparent))
- {
- DALI_LOG_ERROR("ColorVisual: renderIfTransparent property has incorrect type: %d\n", renderIfTransparentValue->GetType());
- }
- }
-
Property::Value* blurRadiusValue = propertyMap.Find(Toolkit::DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_NAME);
if(blurRadiusValue)
{
void ColorVisual::DoSetOnScene(Actor& actor)
{
- // Only add the renderer if it's not fully transparent
- // We cannot avoid creating a renderer as it's used in the base class
- if(mRenderIfTransparent || mImpl->mMixColor.a > 0.0f)
- {
- actor.AddRenderer(mImpl->mRenderer);
- }
+ actor.AddRenderer(mImpl->mRenderer);
// Color Visual generated and ready to display
ResourceReady(Toolkit::Visual::ResourceStatus::READY);
map.Clear();
map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR);
map.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, mImpl->mMixColor);
- map.Insert(Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT, mRenderIfTransparent);
if(mImpl->mRenderer && mBlurRadiusIndex != Property::INVALID_INDEX)
{
ColorVisual& operator=(const ColorVisual& colorRenderer);
private:
- float mBlurRadius; ///< The blur radius
- Property::Index mBlurRadiusIndex; ///< The blur radius property index
- bool mRenderIfTransparent; ///< Whether we should render even if the mix-color is transparent.
- bool mNeedBlurRadius; ///< Whether we need the blur radius in shader.
+ float mBlurRadius; ///< The blur radius
+ Property::Index mBlurRadiusIndex; ///< The blur radius property index
+ bool mNeedBlurRadius; ///< Whether we need the blur radius in shader.
};
} // namespace Internal
const char* const CORNER_RADIUS_POLICY("cornerRadiusPolicy");
// Color visual
-const char* const RENDER_IF_TRANSPARENT_NAME("renderIfTransparent");
const char* const BLUR_RADIUS_NAME("blurRadius");
// Image visual
extern const char* const CORNER_RADIUS_POLICY;
// Color visual
-extern const char* const RENDER_IF_TRANSPARENT_NAME;
extern const char* const BLUR_RADIUS_NAME;
// Image visual
#endif
/**
- * @brief Replace the background visual if it's a color visual with the renderIfTransparent property set as required.
- * @param[in] controlImpl The control implementation
- * @param[in] renderIfTransaparent Whether we should render if the color is transparent
- */
-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 && backgroundVisual.GetType() == Toolkit::Visual::COLOR)
- {
- Property::Map map;
- backgroundVisual.CreatePropertyMap(map);
-
- // Only change it if it's a color visual
- map[Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT] = renderIfTransparent;
- controlImpl.SetBackground(map);
- }
-}
-
-/**
* @brief Creates a clipping renderer if required.
* (EG. If no renders exist and clipping is enabled).
* @param[in] controlImpl The control implementation.
int clippingMode = ClippingMode::DISABLED;
if(self.GetProperty(Actor::Property::CLIPPING_MODE).Get(clippingMode))
{
- switch(clippingMode)
- {
- case ClippingMode::CLIP_CHILDREN:
- {
- if(self.GetRendererCount() == 0u)
- {
- Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(controlImpl);
- if(controlDataImpl.mVisuals.Empty())
- {
- controlImpl.SetBackgroundColor(Color::TRANSPARENT);
- }
- else
- {
- // We have visuals, check if we've set the background and re-create it to
- // render even if transparent (only if it's a color visual)
- ChangeBackgroundColorVisual(controlImpl, true);
- }
- }
- break;
- }
+ Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(controlImpl);
- case ClippingMode::DISABLED:
- case ClippingMode::CLIP_TO_BOUNDING_BOX:
- {
- // If we have a background visual, check if it's a color visual and remove the render if transparent flag
- ChangeBackgroundColorVisual(controlImpl, false);
- break;
- }
+ if(clippingMode == ClippingMode::CLIP_CHILDREN && controlDataImpl.mVisuals.Empty() && self.GetRendererCount() == 0u)
+ {
+ controlImpl.SetBackgroundColor(Color::TRANSPARENT);
}
}
}
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;
- }
- }
+ // Update background color only
+ mImpl->DoAction(Toolkit::Control::Property::BACKGROUND, DevelColorVisual::Action::UPDATE_PROPERTY, map);
+ return;
}
SetBackground(map);