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=31e0c55257e8f7c7ca4dba11022c26924349283f;hp=9ce3a29ce69c0b45600d2b294dc251608c9edd0b;hb=48000ec3ab1ca2d1f8001d192112e32357bb1dfc;hpb=f2039d47f9bed8104575da80a2ecf0bb6e37ff8d diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 9ce3a29..31e0c55 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -23,7 +23,7 @@ #include //INTERNAL INCLUDES -#include +#include #include #include #include @@ -39,6 +39,27 @@ namespace Toolkit { namespace Internal { +namespace +{ +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 +{ + 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)); @@ -51,8 +72,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) { } @@ -87,15 +107,6 @@ void ColorVisual::DoSetProperties(const Property::Map& propertyMap) } } - 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) { @@ -103,17 +114,33 @@ 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.RegisterProperty(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) { - // 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); @@ -129,7 +156,6 @@ 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); if(mImpl->mRenderer && mBlurRadiusIndex != Property::INVALID_INDEX) { @@ -156,28 +182,11 @@ 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: - { - const Property::Map* map = attributes.GetMap(); - if(map) - { - DoSetProperties(*map); - } - break; - } - } -} - void ColorVisual::UpdateShader() { if(mImpl->mRenderer) { - Shader shader = GetShader(); + Shader shader = GenerateShader(); mImpl->mRenderer.SetShader(shader); } } @@ -186,7 +195,7 @@ void ColorVisual::OnInitialize() { Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY); - Shader shader = GetShader(); + Shader shader = GenerateShader(); mImpl->mRenderer = Renderer::New(geometry, shader); @@ -205,35 +214,55 @@ void ColorVisual::OnInitialize() mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT); } -Shader ColorVisual::GetShader() +Shader ColorVisual::GenerateShader() const { Shader shader; - if(!EqualsZero(mBlurRadius) || mNeedBlurRadius) + 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) { - shader = mFactoryCache.GetShader(VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER); - if(!shader) + shaderTypeFlag |= ColorVisualRequireFlag::BORDERLINE; + } + + shaderType = SHADER_TYPE_TABLE[shaderTypeFlag]; + 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"; + } + if(blur) + { + vertexShaderPrefixList += "#define IS_REQUIRED_BLUR 1\n"; + fragmentShaderPrefixList += "#define IS_REQUIRED_BLUR 1\n"; + } + if(borderline) { - 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_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; @@ -251,9 +280,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();