/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
#include <dali/integration-api/debug.h>
// INTERNAL_INCLUDES
-#include <dali-toolkit/internal/visuals/visual-impl.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/internal/visuals/visual-factory-impl.h>
namespace //Unnamed namespace
{
} // unnamed namespace
SuperBlurView::SuperBlurView( unsigned int blurLevels )
-: Control( ControlBehaviour( DISABLE_SIZE_NEGOTIATION ) ),
+: Control( ControlBehaviour( DISABLE_SIZE_NEGOTIATION | DISABLE_STYLE_CHANGE_SIGNALS ) ),
mTargetSize( Vector2::ZERO ),
mBlurStrengthPropertyIndex(Property::INVALID_INDEX),
mBlurLevels( blurLevels ),
DALI_ASSERT_ALWAYS( mBlurLevels > 0 && " Minimal blur level is one, otherwise no blur is needed" );
mGaussianBlurView.assign( blurLevels, Toolkit::GaussianBlurView() );
mBlurredImage.assign( blurLevels, FrameBufferImage() );
- mRenderers.assign( blurLevels+1, Toolkit::Visual() );
+ mVisuals.assign( blurLevels+1, Toolkit::Visual::Base() );
}
SuperBlurView::~SuperBlurView()
void SuperBlurView::SetImage(Image inputImage)
{
- if( mTargetSize == Vector2::ZERO || mInputImage == inputImage)
+ mInputImage = inputImage;
+ if( mTargetSize == Vector2::ZERO )
{
return;
}
ClearBlurResource();
- mInputImage = inputImage;
Actor self( Self() );
- InitializeVisual( self, mRenderers[0], mInputImage );
- mRenderers[0].SetDepthIndex(0);
- SetShaderEffect( mRenderers[0] );
- if( self.OnStage() )
- {
- mRenderers[0].SetOnStage( self );
- }
+
+ mVisuals[0] = Toolkit::VisualFactory::Get().CreateVisual( mInputImage );
+ DevelControl::RegisterVisual( *this, 0, mVisuals[0], 0 ); // Will clean up previously registered visuals for this index.
+ // custom shader is not applied on the original image.
BlurImage( 0, inputImage);
for(unsigned int i=1; i<mBlurLevels;i++)
mResourcesCleared = true;
}
}
-void SuperBlurView::SetShaderEffect( Toolkit::Visual& renderer )
+void SuperBlurView::SetShaderEffect( Toolkit::Visual::Base& visual )
{
Property::Map shaderMap;
std::stringstream verterShaderString;
shaderMap[ "fragmentShader" ] = FRAGMENT_SHADER;
- Internal::Visual& rendererImpl = GetImplementation( renderer );
- rendererImpl.SetCustomShader( shaderMap );
+ Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
+ visualImpl.SetCustomShader( shaderMap );
}
void SuperBlurView::OnSizeSet( const Vector3& targetSize )
{
mTargetSize = Vector2(targetSize);
- Toolkit::VisualFactory rendererFactory = Toolkit::VisualFactory::Get();
Actor self = Self();
for( unsigned int i = 1; i <= mBlurLevels; i++ )
{
float exponent = static_cast<float>(i);
mBlurredImage[i-1] = 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 );
- InitializeVisual( self, mRenderers[i], mBlurredImage[i - 1] );
- mRenderers[ i ].SetDepthIndex( i );
- SetShaderEffect( mRenderers[ i ] );
+ GAUSSIAN_BLUR_RENDER_TARGET_PIXEL_FORMAT );
+
+ mVisuals[i] = Toolkit::VisualFactory::Get().CreateVisual( mBlurredImage[i - 1] );
+ DevelControl::RegisterVisual( *this, i, mVisuals[i], int( i ) ); // Will clean up existing visual with same index.
+ SetShaderEffect( mVisuals[i] );
}
if( mInputImage )
{
SetImage( mInputImage );
}
-
- if( self.OnStage() )
- {
- for( unsigned int i = 1; i <= mBlurLevels; i++ )
- {
- mRenderers[i].SetOnStage( self );
- }
- }
}
+
+ Control::OnSizeSet( targetSize );
}
void SuperBlurView::OnStageConnection( int depth )
{
- Control::OnStageConnection( depth );
-
if( mTargetSize == Vector2::ZERO )
{
return;
}
+ // Exception to the rule, chaining up first ensures visuals have SetOnStage called to create their renderers
+ Control::OnStageConnection( depth );
+
Actor self = Self();
- if( mRenderers[0] )
+ for(unsigned int i=0; i<=mBlurLevels;i++)
{
- mRenderers[0].SetOnStage( self );
- }
- for(unsigned int i=1; i<=mBlurLevels;i++)
- {
- if( mRenderers[i] )
+ // Note that the renderer indices are depending on the order they been added to the actor
+ // which might be different from the blur level of its texture.
+ // We can check the depth index of the renderer to know which blurred image it renders.
+ // All visuals WILL have renderers at this point as we are simply creating visuals with an Image handle.
+ Renderer renderer = self.GetRendererAt( i );
+ int depthIndex = renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX);
+ if( depthIndex > 0 )
{
- mRenderers[i].SetOnStage( self );
+ Property::Index index = renderer.RegisterProperty( ALPHA_UNIFORM_NAME, 0.f );
+ Constraint constraint = Constraint::New<float>( renderer, index, ActorOpacityConstraint(mBlurLevels, depthIndex-1) );
+ constraint.AddSource( Source( self, mBlurStrengthPropertyIndex ) );
+ constraint.Apply();
}
-
- Renderer renderer = self.GetRendererAt( i );
- Property::Index index = renderer.RegisterProperty( ALPHA_UNIFORM_NAME, 0.f );
- Constraint constraint = Constraint::New<float>( renderer, index, ActorOpacityConstraint(mBlurLevels, i-1) );
- constraint.AddSource( Source( self, mBlurStrengthPropertyIndex ) );
- constraint.Apply();
}
}
-void SuperBlurView::OnStageDisconnection( )
-{
- if( mTargetSize == Vector2::ZERO )
- {
- return;
- }
-
- Actor self = Self();
- for(unsigned int i=0; i<mBlurLevels+1;i++)
- {
- mRenderers[i].SetOffStage( self );
- }
-
- Control::OnStageDisconnection();
-}
-
Vector3 SuperBlurView::GetNaturalSize()
{
if( mInputImage )