X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fcolor%2Fcolor-visual.cpp;h=8dfc168f0a7e391d82ddc553c1f9ebd716f919a2;hp=77b0be066d7487b36478e14b59b3fd5deb04353b;hb=38f0ea9fcdf1dc5037144fa19c8a52316c8af763;hpb=ab447436de92a2e8bc8cd1393f4807f19ef6b316 diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 77b0be0..8dfc168 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -19,33 +19,53 @@ #include "color-visual.h" // EXTERNAL INCLUDES -#include #include +#include //INTERNAL INCLUDES -#include -#include #include -#include -#include +#include +#include +#include #include +#include #include -#include -#include +#include +#include namespace Dali { - namespace Toolkit { - namespace Internal { +namespace +{ +const int CUSTOM_PROPERTY_COUNT(6); // Blur Radius + border/corner -ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties ) +VisualFactoryCache::ShaderType SHADER_TYPE_TABLE[6] = + { + VisualFactoryCache::COLOR_SHADER, + VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER, + VisualFactoryCache::COLOR_SHADER_BORDERLINE, + VisualFactoryCache::COLOR_SHADER_ROUNDED_BORDERLINE, + VisualFactoryCache::COLOR_SHADER_BLUR_EDGE, + VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER_BLUR_EDGE, +}; + +// enum of required list when we select shader +enum ColorVisualRequireFlag { - ColorVisualPtr colorVisualPtr( new ColorVisual( factoryCache ) ); - colorVisualPtr->SetProperties( properties ); + DEFAULT = 0, + ROUNDED_CORNER = 1 << 0, + BORDERLINE = 1 << 1, + BLUR = 1 << 2, +}; +} // unnamed namespace +ColorVisualPtr ColorVisual::New(VisualFactoryCache& factoryCache, const Property::Map& properties) +{ + ColorVisualPtr colorVisualPtr(new ColorVisual(factoryCache)); + colorVisualPtr->SetProperties(properties); colorVisualPtr->Initialize(); return colorVisualPtr; } @@ -54,8 +74,7 @@ ColorVisual::ColorVisual(VisualFactoryCache& factoryCache) : Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::COLOR), mBlurRadius(0.0f), mBlurRadiusIndex(Property::INVALID_INDEX), - mRenderIfTransparent(false), - mNeedBlurRadius(false) + mAlwaysUsingBlurRadius(false) { } @@ -63,25 +82,25 @@ ColorVisual::~ColorVisual() { } -void ColorVisual::DoSetProperties( const Property::Map& propertyMap ) +void ColorVisual::DoSetProperties(const Property::Map& propertyMap) { // By virtue of DoSetProperties being called last, this will override // anything set by Toolkit::Visual::Property::MIX_COLOR - Property::Value* colorValue = propertyMap.Find( Toolkit::ColorVisual::Property::MIX_COLOR, MIX_COLOR ); - if( colorValue ) + Property::Value* colorValue = propertyMap.Find(Toolkit::ColorVisual::Property::MIX_COLOR, MIX_COLOR); + if(colorValue) { Vector4 color; - if( colorValue->Get( color ) ) + if(colorValue->Get(color)) { Property::Type type = colorValue->GetType(); - if( type == Property::VECTOR4 ) + if(type == Property::VECTOR4) { - SetMixColor( color ); + SetMixColor(color); } - else if( type == Property::VECTOR3 ) + else if(type == Property::VECTOR3) { Vector3 color3(color); - SetMixColor( color3 ); + SetMixColor(color3); } } else @@ -90,36 +109,43 @@ void ColorVisual::DoSetProperties( const Property::Map& propertyMap ) } } - Property::Value* renderIfTransparentValue = propertyMap.Find( Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT, RENDER_IF_TRANSPARENT_NAME ); - if( renderIfTransparentValue ) + Property::Value* blurRadiusValue = propertyMap.Find(Toolkit::DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_NAME); + if(blurRadiusValue) { - if( ! renderIfTransparentValue->Get( mRenderIfTransparent ) ) + if(!blurRadiusValue->Get(mBlurRadius)) { - DALI_LOG_ERROR( "ColorVisual: renderIfTransparent property has incorrect type: %d\n", renderIfTransparentValue->GetType() ); + DALI_LOG_ERROR("ColorVisual:DoSetProperties:: BLUR_RADIUS property has incorrect type: %d\n", blurRadiusValue->GetType()); } - } - Property::Value* blurRadiusValue = propertyMap.Find( Toolkit::DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_NAME ); - if( blurRadiusValue ) - { - if( !blurRadiusValue->Get( mBlurRadius ) ) + if(mBlurRadiusIndex != Property::INVALID_INDEX) { - DALI_LOG_ERROR( "ColorVisual:DoSetProperties:: BLUR_RADIUS property has incorrect type: %d\n", blurRadiusValue->GetType() ); + mImpl->mRenderer.SetProperty(mBlurRadiusIndex, mBlurRadius); + } + else if(DALI_UNLIKELY(mImpl->mRenderer && (!EqualsZero(mBlurRadius) || mAlwaysUsingBlurRadius))) + { + // Unusual case. SetProperty called after OnInitialize(). + // Assume that DoAction call UPDATE_PROPERTY. + // We must regist properies into renderer, and update shader. + + // BlurRadius added by this action. Regist property to renderer. + mBlurRadiusIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_NAME, mBlurRadius); + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + + // Change the shader must not be occured many times. we always have to use blur feature. + mAlwaysUsingBlurRadius = true; + + // Change shader + UpdateShader(); } } } -void ColorVisual::DoSetOnScene( Actor& actor ) +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 ); + ResourceReady(Toolkit::Visual::ResourceStatus::READY); } void ColorVisual::DoSetOffScene(Actor& actor) @@ -127,12 +153,11 @@ void ColorVisual::DoSetOffScene(Actor& actor) actor.RemoveRenderer(mImpl->mRenderer); } -void ColorVisual::DoCreatePropertyMap( Property::Map& map ) const +void ColorVisual::DoCreatePropertyMap(Property::Map& map) const { 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 ); + map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR); + map.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, mImpl->mMixColor); if(mImpl->mRenderer && mBlurRadiusIndex != Property::INVALID_INDEX) { @@ -146,33 +171,25 @@ void ColorVisual::DoCreatePropertyMap( Property::Map& map ) const } } -void ColorVisual::DoCreateInstancePropertyMap( Property::Map& map ) const +void ColorVisual::DoCreateInstancePropertyMap(Property::Map& map) const { // Do nothing } -void ColorVisual::OnSetTransform() +void ColorVisual::EnablePreMultipliedAlpha(bool preMultiplied) { - if( mImpl->mRenderer ) + // Make always disable pre multiplied alpha whether preMultiplied value is true. + if(preMultiplied) { - mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT ); + DALI_LOG_WARNING("Note : ColorVisual cannot enable PreMultipliedAlpha\n"); } } -void ColorVisual::OnDoAction( const Property::Index actionId, const Property::Value& attributes ) +void ColorVisual::OnSetTransform() { - // Check if action is valid for this visual type and perform action if possible - switch( actionId ) + if(mImpl->mRenderer) { - case DevelColorVisual::Action::UPDATE_PROPERTY: - { - const Property::Map* map = attributes.GetMap(); - if( map ) - { - DoSetProperties( *map ); - } - break; - } + mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT); } } @@ -180,63 +197,81 @@ void ColorVisual::UpdateShader() { if(mImpl->mRenderer) { - Shader shader = GetShader(); + Shader shader = GenerateShader(); mImpl->mRenderer.SetShader(shader); } } void ColorVisual::OnInitialize() { - Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY ); + Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY); - Shader shader = GetShader(); + Shader shader = GenerateShader(); - mImpl->mRenderer = Renderer::New(geometry, shader); + mImpl->mRenderer = VisualRenderer::New(geometry, shader); + mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT); - // ColorVisual has it's own index key for mix color - use this instead - // of using the new base index to avoid changing existing applications - // String keys will get to this property. - mImpl->mMixColorIndex = mImpl->mRenderer.RegisterProperty(Toolkit::ColorVisual::Property::MIX_COLOR, MIX_COLOR, Vector3(mImpl->mMixColor)); + mImpl->mRenderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, Vector3(mImpl->mMixColor)); if(!EqualsZero(mBlurRadius)) { - mBlurRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_NAME, mBlurRadius); + mBlurRadiusIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_NAME, mBlurRadius); mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); } // Register transform properties - mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT); + mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT); } -Shader ColorVisual::GetShader() +Shader ColorVisual::GenerateShader() const { - Shader shader; - if(!EqualsZero(mBlurRadius) || mNeedBlurRadius) + Shader shader; + VisualFactoryCache::ShaderType shaderType; + + bool roundedCorner = IsRoundedCornerRequired(); + bool borderline = IsBorderlineRequired(); + bool blur = !EqualsZero(mBlurRadius) || mAlwaysUsingBlurRadius; + int shaderTypeFlag = ColorVisualRequireFlag::DEFAULT; + + if(roundedCorner) { - shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER_BLUR_EDGE ); - if( !shader ) - { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_VISUAL_BLUR_EDGE_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_VISUAL_BLUR_EDGE_SHADER_FRAG.data() ); - mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER_BLUR_EDGE, shader ); - } + shaderTypeFlag |= ColorVisualRequireFlag::ROUNDED_CORNER; } - else if( !IsRoundedCornerRequired() ) + if(blur) { - shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER ); - if( !shader ) - { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_VISUAL_SHADER_FRAG.data() ); - mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER, shader ); - } + // If we use blur, just ignore borderline + borderline = false; + shaderTypeFlag |= ColorVisualRequireFlag::BLUR; } - else + if(borderline) + { + shaderTypeFlag |= ColorVisualRequireFlag::BORDERLINE; + } + + shaderType = SHADER_TYPE_TABLE[shaderTypeFlag]; + shader = mFactoryCache.GetShader(shaderType); + if(!shader) { - shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER ); - if( !shader ) + std::string vertexShaderPrefixList; + std::string fragmentShaderPrefixList; + if(roundedCorner) { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_VISUAL_ROUNDED_CORNER_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_VISUAL_ROUNDED_CORNER_SHADER_FRAG.data() ); - mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER, shader ); + vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER 1\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER 1\n"; } + if(blur) + { + vertexShaderPrefixList += "#define IS_REQUIRED_BLUR 1\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_BLUR 1\n"; + } + if(borderline) + { + vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n"; + } + shader = Shader::New(Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_VERT.data(), + Dali::Shader::GetFragmentShaderPrefix() + fragmentShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_FRAG.data()); + mFactoryCache.SaveShader(shaderType, shader); } return shader; @@ -254,9 +289,10 @@ Dali::Property ColorVisual::OnGetPropertyObject(Dali::Property::Key key) { mBlurRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_NAME, mBlurRadius); - mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + // Blur is animated now. we always have to use blur feature. + mAlwaysUsingBlurRadius = true; - mNeedBlurRadius = true; + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); // Change shader UpdateShader();