X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fsuper-blur-view%2Fsuper-blur-view-impl.cpp;h=80714d08236d0fd35bf05161c436ec34485624bc;hp=cd36331d3a6e282412bc7d330a35bc91503fb86e;hb=8a647e87a01c5c78451653c1264a9eea81ac9b20;hpb=a073ebfd862b49692c8e6d7dff2b128e62a4f6df diff --git a/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp b/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp index cd36331..80714d0 100644 --- a/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp +++ b/dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 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. @@ -21,12 +21,22 @@ // EXTERNAL INCLUDES #include #include -#include +#include +#include #include -#include +#include +#include #include #include +// INTERNAL_INCLUDES +#include +#include +#include +#include +#include +#include + namespace //Unnamed namespace { @@ -37,10 +47,24 @@ const unsigned int GAUSSIAN_BLUR_DEFAULT_NUM_SAMPLES = 11; const unsigned int GAUSSIAN_BLUR_NUM_SAMPLES_INCREMENTATION = 10; const float GAUSSIAN_BLUR_BELL_CURVE_WIDTH = 4.5f; const float GAUSSIAN_BLUR_BELL_CURVE_WIDTH_INCREMENTATION = 5.f; -const Pixel::Format GAUSSIAN_BLUR_RENDER_TARGET_PIXEL_FORMAT = Pixel::RGB888; +const Pixel::Format GAUSSIAN_BLUR_RENDER_TARGET_PIXEL_FORMAT = Pixel::RGBA8888; const float GAUSSIAN_BLUR_DOWNSAMPLE_WIDTH_SCALE = 0.5f; const float GAUSSIAN_BLUR_DOWNSAMPLE_HEIGHT_SCALE = 0.5f; +const char* ALPHA_UNIFORM_NAME( "uAlpha" ); +const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( + varying mediump vec2 vTexCoord;\n + uniform sampler2D sTexture;\n + uniform lowp vec4 uColor;\n + uniform lowp float uAlpha;\n + \n + void main()\n + {\n + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n + gl_FragColor.a *= uAlpha; + }\n +); + /** * The constraint is used to blend the group of blurred images continuously with a unified blur strength property value which ranges from zero to one. */ @@ -56,17 +80,17 @@ struct ActorOpacityConstraint void operator()( float& current, const PropertyInputContainer& inputs ) { float blurStrength = inputs[0]->GetFloat(); - if(blurStrength <= mRange.x) + if(blurStrength < mRange.x) { - current = 1.f; + current = 0.f; } else if(blurStrength > mRange.y) { - current = 0.f; + current = 1.f; } else { - current = ( mRange.y - blurStrength) / ( mRange.y - mRange.x ); + current = ( blurStrength - mRange.x) / ( mRange.y - mRange.x ); } } @@ -97,23 +121,28 @@ BaseHandle Create() // Setup properties, signals and actions using the type-registry. DALI_TYPE_REGISTRATION_BEGIN( Toolkit::SuperBlurView, Toolkit::Control, Create ) -DALI_PROPERTY_REGISTRATION( Toolkit, SuperBlurView, "image", MAP, IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, SuperBlurView, "imageUrl", STRING, IMAGE_URL ) DALI_TYPE_REGISTRATION_END() } // unnamed namespace SuperBlurView::SuperBlurView( unsigned int blurLevels ) -: Control( ControlBehaviour( DISABLE_SIZE_NEGOTIATION ) ), - mBlurLevels( blurLevels ), +: Control( ControlBehaviour( DISABLE_SIZE_NEGOTIATION | DISABLE_STYLE_CHANGE_SIGNALS ) ), + mTargetSize( Vector2::ZERO ), mBlurStrengthPropertyIndex(Property::INVALID_INDEX), - mResourcesCleared( true ), - mTargetSize( Vector2::ZERO ) + mBlurLevels( blurLevels ), + mResourcesCleared( true ) { DALI_ASSERT_ALWAYS( mBlurLevels > 0 && " Minimal blur level is one, otherwise no blur is needed" ); - mGaussianBlurView.assign( blurLevels, NULL ); - mBlurredImage.assign( blurLevels, FrameBufferImage() ); - mImageActors.assign( blurLevels + 1, ImageActor() ); + mGaussianBlurView.assign( blurLevels, Toolkit::GaussianBlurView() ); + mBlurredImage.assign( blurLevels, FrameBuffer() ); + mRenderers.assign( blurLevels+1, Dali::Renderer() ); + + DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) { + return std::unique_ptr< Dali::Accessibility::Accessible >( + new Control::Impl::AccessibleImpl( actor, Dali::Accessibility::Role::FILLER ) ); + } ); } SuperBlurView::~SuperBlurView() @@ -137,49 +166,36 @@ Toolkit::SuperBlurView SuperBlurView::New( unsigned int blurLevels ) void SuperBlurView::OnInitialize() { - mBlurStrengthPropertyIndex = Self().RegisterProperty( "blurStrength", 0.f ); - - DALI_ASSERT_ALWAYS( mImageActors.size() == mBlurLevels+1 && "must synchronize the ImageActor group if blur levels got changed " ); - for(unsigned int i=0; i<=mBlurLevels;i++) - { - mImageActors[i] = ImageActor::New( ); - mImageActors[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mImageActors[i].SetParentOrigin( ParentOrigin::CENTER ); - mImageActors[i].SetZ(-static_cast(i)*0.01f); - mImageActors[i].SetColorMode( USE_OWN_MULTIPLY_PARENT_ALPHA ); - Self().Add( mImageActors[i] ); - } - - for(unsigned int i=0; i < mBlurLevels; i++) - { - Constraint constraint = Constraint::New( mImageActors[i], Actor::Property::COLOR_ALPHA, ActorOpacityConstraint(mBlurLevels, i) ); - constraint.AddSource( ParentSource( mBlurStrengthPropertyIndex ) ); - constraint.Apply(); - } + Actor self( Self() ); - Self().SetSize(Stage::GetCurrent().GetSize()); + mBlurStrengthPropertyIndex = self.RegisterProperty( "blurStrength", 0.f ); } -void SuperBlurView::SetImage(Image inputImage) +void SuperBlurView::SetTexture( Texture texture ) { - DALI_ASSERT_ALWAYS( mImageActors.size() == mBlurLevels+1 && "must synchronize the ImageActor group if blur levels got changed " ); - DALI_ASSERT_ALWAYS( mBlurredImage.size() == mBlurLevels && "must synchronize the blurred image group if blur levels got changed " ); + mInputTexture = texture; + + if( mTargetSize == Vector2::ZERO ) + { + return; + } ClearBlurResource(); - mImageActors[0].SetImage( inputImage ); + Actor self( Self() ); - for(unsigned int i=1; i<=mBlurLevels;i++) - { - mImageActors[i].SetImage( mBlurredImage[i-1] ); - } + BlurTexture( 0, mInputTexture ); + SetRendererTexture( mRenderers[0], texture ); - BlurImage( 0, inputImage); - for(unsigned int i=1; i0 && level<=mBlurLevels ); - return mBlurredImage[level-1]; + + FrameBuffer frameBuffer = mBlurredImage[level-1]; + + return frameBuffer.GetColorTexture(); } -void SuperBlurView::BlurImage( unsigned int idx, Image image ) +void SuperBlurView::BlurTexture( unsigned int idx, Texture texture ) { DALI_ASSERT_ALWAYS( mGaussianBlurView.size()>idx ); mGaussianBlurView[idx] = Toolkit::GaussianBlurView::New( GAUSSIAN_BLUR_DEFAULT_NUM_SAMPLES+GAUSSIAN_BLUR_NUM_SAMPLES_INCREMENTATION*idx, GAUSSIAN_BLUR_BELL_CURVE_WIDTH + GAUSSIAN_BLUR_BELL_CURVE_WIDTH_INCREMENTATION*static_cast(idx), GAUSSIAN_BLUR_RENDER_TARGET_PIXEL_FORMAT, GAUSSIAN_BLUR_DOWNSAMPLE_WIDTH_SCALE, GAUSSIAN_BLUR_DOWNSAMPLE_HEIGHT_SCALE, true ); - mGaussianBlurView[idx].SetParentOrigin(ParentOrigin::CENTER); - mGaussianBlurView[idx].SetSize(mTargetSize); - mGaussianBlurView[idx].SetUserImageAndOutputRenderTarget( image, mBlurredImage[idx] ); + mGaussianBlurView[idx].SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER ); + mGaussianBlurView[idx].SetProperty( Actor::Property::SIZE, mTargetSize ); + Stage::GetCurrent().Add( mGaussianBlurView[idx] ); + + mGaussianBlurView[idx].SetUserImageAndOutputRenderTarget( texture, mBlurredImage[idx] ); + + mGaussianBlurView[idx].ActivateOnce(); if( idx == mBlurLevels-1 ) { mGaussianBlurView[idx].FinishedSignal().Connect( this, &SuperBlurView::OnBlurViewFinished ); } - Stage::GetCurrent().Add( mGaussianBlurView[idx] ); - mGaussianBlurView[idx].ActivateOnce(); } void SuperBlurView::OnBlurViewFinished( Toolkit::GaussianBlurView blurView ) @@ -246,7 +267,6 @@ void SuperBlurView::ClearBlurResource() { Stage::GetCurrent().Remove( mGaussianBlurView[i] ); mGaussianBlurView[i].Deactivate(); - mGaussianBlurView[i].Reset(); } mResourcesCleared = true; } @@ -258,13 +278,86 @@ void SuperBlurView::OnSizeSet( const Vector3& targetSize ) { mTargetSize = Vector2(targetSize); - for(unsigned int i=0; i(i); + + unsigned int width = mTargetSize.width/std::pow(2.f,exponent); + unsigned int height = mTargetSize.height/std::pow(2.f,exponent); + + mBlurredImage[i-1] = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE ); + Texture texture = Texture::New( TextureType::TEXTURE_2D, GAUSSIAN_BLUR_RENDER_TARGET_PIXEL_FORMAT, unsigned(width), unsigned(height) ); + mBlurredImage[i-1].AttachColorTexture( texture ); + } + + if( mInputTexture ) { - float exponent = static_cast(i+1); - mBlurredImage[i] = FrameBufferImage::New( mTargetSize.width/std::pow(2.f,exponent) , mTargetSize.height/std::pow(2.f,exponent), - GAUSSIAN_BLUR_RENDER_TARGET_PIXEL_FORMAT, Dali::Image::NEVER ); + SetTexture( mInputTexture ); } } + + Control::OnSizeSet( targetSize ); +} + +void SuperBlurView::OnSceneConnection( int depth ) +{ + if( mTargetSize == Vector2::ZERO ) + { + return; + } + + // Exception to the rule, chaining up first ensures visuals have SetOnScene called to create their renderers + Control::OnSceneConnection( depth ); + + Actor self = Self(); + + for(unsigned int i=0; i 0 ) + { + Renderer renderer = mRenderers[i]; + Property::Index index = renderer.RegisterProperty( ALPHA_UNIFORM_NAME, 0.f ); + Constraint constraint = Constraint::New( renderer, index, ActorOpacityConstraint(mBlurLevels, i-1) ); + constraint.AddSource( Source( self, mBlurStrengthPropertyIndex ) ); + constraint.Apply(); + } + } + + if( mInputTexture ) + { + SetRendererTexture( mRenderers[0], mInputTexture ); + unsigned int i = 1; + for(; i