X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fcolor%2Fcolor-visual.cpp;h=492f20330a4f5eef68bbd2ae7a1853eaed849bf8;hb=70510385d88cfbd5c232117d8436ca74c523e172;hp=2058e1b9da68ed98b2a3c07ee870099fcfc7f411;hpb=b5b774f066e74e54a2e6f4bf923d1501f21f1284;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 2058e1b..492f203 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) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -20,16 +20,18 @@ // EXTERNAL INCLUDES #include -#include +#include //INTERNAL INCLUDES #include #include #include +#include #include #include #include #include +#include namespace Dali { @@ -40,47 +42,6 @@ namespace Toolkit namespace Internal { -namespace -{ - -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - uniform mediump mat4 uMvpMatrix;\n - uniform mediump vec3 uSize;\n - \n - - //Visual size and offset - uniform mediump vec2 offset;\n - uniform mediump vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - - vec4 ComputeVertexPosition()\n - {\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n - vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n - return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n - }\n - - void main()\n - {\n - gl_Position = uMvpMatrix * ComputeVertexPosition();\n - }\n -); - -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - uniform lowp float opacity;\n - \n - void main()\n - {\n - gl_FragColor = vec4(mixColor, opacity)*uColor;\n - }\n -); -} - ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties ) { ColorVisualPtr colorVisualPtr( new ColorVisual( factoryCache ) ); @@ -88,9 +49,12 @@ ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache, const Propert return colorVisualPtr; } -ColorVisual::ColorVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache ), - mRenderIfTransparent( false ) +ColorVisual::ColorVisual(VisualFactoryCache& factoryCache) +: Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::COLOR), + mBlurRadius(0.0f), + mBlurRadiusIndex(Property::INVALID_INDEX), + mRenderIfTransparent(false), + mNeedBlurRadius(false) { } @@ -133,9 +97,18 @@ void ColorVisual::DoSetProperties( const Property::Map& propertyMap ) 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 ) + { + if( !blurRadiusValue->Get( mBlurRadius ) ) + { + DALI_LOG_ERROR( "ColorVisual:DoSetProperties:: BLUR_RADIUS property has incorrect type: %d\n", blurRadiusValue->GetType() ); + } + } } -void ColorVisual::DoSetOnStage( Actor& actor ) +void ColorVisual::DoSetOnScene( Actor& actor ) { InitializeRenderer(); @@ -150,12 +123,36 @@ void ColorVisual::DoSetOnStage( Actor& actor ) ResourceReady( Toolkit::Visual::ResourceStatus::READY ); } +void ColorVisual::DoSetOffScene(Actor& actor) +{ + if(mImpl->mRenderer && mBlurRadiusIndex != Property::INVALID_INDEX) + { + // Update values from Renderer + mBlurRadius = mImpl->mRenderer.GetProperty(mBlurRadiusIndex); + } + + actor.RemoveRenderer(mImpl->mRenderer); + mImpl->mRenderer.Reset(); + mBlurRadiusIndex = Property::INVALID_INDEX; +} + 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) + { + // Update values from Renderer + float blurRadius = mImpl->mRenderer.GetProperty(mBlurRadiusIndex); + map.Insert(Toolkit::DevelColorVisual::Property::BLUR_RADIUS, blurRadius); + } + else + { + map.Insert(Toolkit::DevelColorVisual::Property::BLUR_RADIUS, mBlurRadius); + } } void ColorVisual::DoCreateInstancePropertyMap( Property::Map& map ) const @@ -163,7 +160,6 @@ void ColorVisual::DoCreateInstancePropertyMap( Property::Map& map ) const // Do nothing } - void ColorVisual::OnSetTransform() { if( mImpl->mRenderer ) @@ -172,31 +168,113 @@ void ColorVisual::OnSetTransform() } } -void ColorVisual::InitializeRenderer() +void ColorVisual::OnDoAction( const Property::Index actionId, const Property::Value& attributes ) { - Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY ); + // 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; + } + } +} - Shader shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER ); - if( !shader ) +void ColorVisual::UpdateShader() +{ + if(mImpl->mRenderer) { - shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); - mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER, shader ); + Shader shader = GetShader(); + mImpl->mRenderer.SetShader(shader); } +} + +void ColorVisual::InitializeRenderer() +{ + Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY ); - mImpl->mRenderer = Renderer::New( geometry, shader ); + Shader shader = GetShader(); + + mImpl->mRenderer = Renderer::New(geometry, shader); // 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 = DevelHandle::RegisterProperty( mImpl->mRenderer, Toolkit::ColorVisual::Property::MIX_COLOR, MIX_COLOR, Vector3(mImpl->mMixColor) ); + mImpl->mMixColorIndex = mImpl->mRenderer.RegisterProperty(Toolkit::ColorVisual::Property::MIX_COLOR, MIX_COLOR, Vector3(mImpl->mMixColor)); - if( mImpl->mMixColor.a < 1.f ) + if(!EqualsZero(mBlurRadius)) { - mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); + mBlurRadiusIndex = mImpl->mRenderer.RegisterProperty(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.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT); +} + +Shader ColorVisual::GetShader() +{ + Shader shader; + if(!EqualsZero(mBlurRadius) || mNeedBlurRadius) + { + 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 ); + } + } + else if( !IsRoundedCornerRequired() ) + { + 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 ); + } + } + else + { + shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER ); + if( !shader ) + { + 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 ); + } + } + + return shader; +} + +Dali::Property ColorVisual::OnGetPropertyObject(Dali::Property::Key key) +{ + if(!mImpl->mRenderer) + { + Handle handle; + return Dali::Property(handle, Property::INVALID_INDEX); + } + + 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); + + mNeedBlurRadius = true; + + // Change shader + UpdateShader(); + + return Dali::Property(mImpl->mRenderer, mBlurRadiusIndex); + } + + Handle handle; + return Dali::Property(handle, Property::INVALID_INDEX); } } // namespace Internal