X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fcolor%2Fcolor-visual.cpp;h=09fd60ef05e07efe65fc4e926ab55ad05dc31e2f;hb=refs%2Fchanges%2F63%2F274263%2F16;hp=9863364499f51325be4ea2b672fa34399f1e61e9;hpb=f15cbe6c00c4bcb9baffe8d6f95747e3c2e051d1;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 9863364..09fd60e 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. @@ -21,10 +21,11 @@ // EXTERNAL INCLUDES #include #include +#include //INTERNAL INCLUDES -#include #include +#include #include #include #include @@ -41,14 +42,16 @@ namespace Internal { namespace { +const int CUSTOM_PROPERTY_COUNT(0); + 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, + { + 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 @@ -71,8 +74,7 @@ ColorVisualPtr ColorVisual::New(VisualFactoryCache& factoryCache, const Property ColorVisual::ColorVisual(VisualFactoryCache& factoryCache) : Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::COLOR), mBlurRadius(0.0f), - mBlurRadiusIndex(Property::INVALID_INDEX), - mNeedBlurRadius(false) + mAlwaysUsingBlurRadius(false) { } @@ -114,6 +116,28 @@ void ColorVisual::DoSetProperties(const Property::Map& propertyMap) { DALI_LOG_ERROR("ColorVisual:DoSetProperties:: BLUR_RADIUS property has incorrect type: %d\n", blurRadiusValue->GetType()); } + + if(DALI_UNLIKELY(mImpl->mRenderer)) + { + // Unusual case. SetProperty called after OnInitialize(). + // Assume that DoAction call UPDATE_PROPERTY. + DownCast(mImpl->mRenderer).RegisterBlurRadiusUniform(); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BLUR_RADIUS, mBlurRadius); + + // Check whether we must update shader. + if(!mAlwaysUsingBlurRadius && IsBlurRequired()) + { + // Change the shader must not be occured many times. we always have to use blur feature. + mAlwaysUsingBlurRadius = true; + + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + // Change shader + if(!mImpl->mCustomShader) + { + UpdateShader(); + } + } + } } } @@ -136,10 +160,10 @@ void ColorVisual::DoCreatePropertyMap(Property::Map& map) const 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) + if(mImpl->mRenderer) { // Update values from Renderer - float blurRadius = mImpl->mRenderer.GetProperty(mBlurRadiusIndex); + float blurRadius = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::BLUR_RADIUS); map.Insert(Toolkit::DevelColorVisual::Property::BLUR_RADIUS, blurRadius); } else @@ -153,28 +177,20 @@ 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); } } @@ -193,32 +209,31 @@ void ColorVisual::OnInitialize() Shader shader = GenerateShader(); - mImpl->mRenderer = Renderer::New(geometry, shader); + mImpl->mRenderer = DecoratedVisualRenderer::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)) + if(mAlwaysUsingBlurRadius || !EqualsZero(mBlurRadius)) { - mBlurRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_NAME, mBlurRadius); + DownCast(mImpl->mRenderer).RegisterBlurRadiusUniform(); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BLUR_RADIUS, 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::GenerateShader() const { - Shader shader; + Shader shader; VisualFactoryCache::ShaderType shaderType; - bool roundedCorner = IsRoundedCornerRequired(); - bool borderline = IsBorderlineRequired(); - bool blur = !EqualsZero(mBlurRadius) || mNeedBlurRadius; - int shaderTypeFlag = ColorVisualRequireFlag::DEFAULT; + bool roundedCorner = IsRoundedCornerRequired(); + bool borderline = IsBorderlineRequired(); + bool blur = IsBlurRequired(); + int shaderTypeFlag = ColorVisualRequireFlag::DEFAULT; if(roundedCorner) { @@ -236,27 +251,27 @@ Shader ColorVisual::GenerateShader() const } shaderType = SHADER_TYPE_TABLE[shaderTypeFlag]; - shader = mFactoryCache.GetShader(shaderType); + shader = mFactoryCache.GetShader(shaderType); if(!shader) { std::string vertexShaderPrefixList; std::string fragmentShaderPrefixList; if(roundedCorner) { - vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER 1\n"; - fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER 1\n"; + vertexShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_ROUNDED_CORNER\n"; } if(blur) { - vertexShaderPrefixList += "#define IS_REQUIRED_BLUR 1\n"; - fragmentShaderPrefixList += "#define IS_REQUIRED_BLUR 1\n"; + vertexShaderPrefixList += "#define IS_REQUIRED_BLUR\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_BLUR\n"; } if(borderline) { - vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n"; - fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n"; + vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_BORDERLINE\n"; } - shader = Shader::New(Dali::Shader::GetVertexShaderPrefix() + vertexShaderPrefixList + SHADER_COLOR_VISUAL_SHADER_VERT.data(), + 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); } @@ -274,22 +289,39 @@ Dali::Property ColorVisual::OnGetPropertyObject(Dali::Property::Key key) if((key.type == Property::Key::INDEX && key.indexKey == DevelColorVisual::Property::BLUR_RADIUS) || (key.type == Property::Key::STRING && key.stringKey == BLUR_RADIUS_NAME)) { - mBlurRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_NAME, mBlurRadius); - - mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + const bool updateShader = !mImpl->mCustomShader && !IsBlurRequired(); - mNeedBlurRadius = true; + // Blur is animated now. we always have to use blur feature. + mAlwaysUsingBlurRadius = true; - // Change shader - UpdateShader(); + if(updateShader) + { + // Update each values to renderer + DownCast(mImpl->mRenderer).RegisterBlurRadiusUniform(); + mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BLUR_RADIUS, mBlurRadius); - return Dali::Property(mImpl->mRenderer, mBlurRadiusIndex); + // Change shader + UpdateShader(); + } + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + return Dali::Property(mImpl->mRenderer, DecoratedVisualRenderer::Property::BLUR_RADIUS); } Handle handle; return Dali::Property(handle, Property::INVALID_INDEX); } +bool ColorVisual::IsBlurRequired() const +{ + float blurRadius = mBlurRadius; + if(mImpl->mRenderer) + { + // Update values from Renderer + blurRadius = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::BLUR_RADIUS); + } + return mAlwaysUsingBlurRadius || !EqualsZero(blurRadius); +} + } // namespace Internal } // namespace Toolkit