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=9863364499f51325be4ea2b672fa34399f1e61e9;hb=38f0ea9fcdf1dc5037144fa19c8a52316c8af763;hpb=8d0ccc12714da58e6e2c971188b221ed2158d658 diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 9863364..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. @@ -23,8 +23,8 @@ #include //INTERNAL INCLUDES -#include #include +#include #include #include #include @@ -41,14 +41,16 @@ namespace Internal { namespace { +const int CUSTOM_PROPERTY_COUNT(6); // Blur Radius + border/corner + 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 @@ -72,7 +74,7 @@ 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,27 @@ void ColorVisual::DoSetProperties(const Property::Map& propertyMap) { DALI_LOG_ERROR("ColorVisual:DoSetProperties:: BLUR_RADIUS property has incorrect type: %d\n", blurRadiusValue->GetType()); } + + if(mBlurRadiusIndex != Property::INVALID_INDEX) + { + 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(); + } } } @@ -153,28 +176,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 +208,30 @@ void ColorVisual::OnInitialize() 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::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 = !EqualsZero(mBlurRadius) || mAlwaysUsingBlurRadius; + int shaderTypeFlag = ColorVisualRequireFlag::DEFAULT; if(roundedCorner) { @@ -236,27 +249,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"; + 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"; + vertexShaderPrefixList += "#define IS_REQUIRED_BLUR 1\n"; fragmentShaderPrefixList += "#define IS_REQUIRED_BLUR 1\n"; } if(borderline) { - vertexShaderPrefixList += "#define IS_REQUIRED_BORDERLINE 1\n"; + 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(), + 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); } @@ -276,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();