X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fgaussian-blur-view%2Fgaussian-blur-view-impl.cpp;h=0cdde3404312d2f37fd2f2a84484f131b34172e9;hp=0720226aef46318fdc82a0e38e765ed79da1e683;hb=1acdb36279de888dcef999e0e0e1460babdd983a;hpb=8fef10ea440a32a1536b485dc7a035f9defa537c diff --git a/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp b/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp index 0720226..0cdde34 100644 --- a/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp +++ b/dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp @@ -21,11 +21,12 @@ // EXTERNAL INCLUDES #include #include -#include #include #include #include +#include #include +#include #include #include @@ -40,7 +41,6 @@ // Manager object - re-use render targets if there are multiple GaussianBlurViews created - ///////////////////////////////////////////////////////// // IMPLEMENTATION NOTES @@ -85,31 +85,33 @@ BaseHandle Create() return Toolkit::GaussianBlurView::New(); } -TypeRegistration mType( typeid(Toolkit::GaussianBlurView), typeid(Toolkit::Control), Create ); - +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::GaussianBlurView, Toolkit::Control, Create ) +DALI_TYPE_REGISTRATION_END() const unsigned int GAUSSIAN_BLUR_VIEW_DEFAULT_NUM_SAMPLES = 5; const float GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_BELL_CURVE_WIDTH = 1.5f; const Pixel::Format GAUSSIAN_BLUR_VIEW_DEFAULT_RENDER_TARGET_PIXEL_FORMAT = Pixel::RGBA8888; const float GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH = 1.0f; // default, fully blurred -const std::string GAUSSIAN_BLUR_VIEW_STRENGTH_PROPERTY_NAME("GaussianBlurStrengthPropertyName"); +const char* const GAUSSIAN_BLUR_VIEW_STRENGTH_PROPERTY_NAME = "GaussianBlurStrengthPropertyName"; const float GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_WIDTH_SCALE = 0.5f; const float GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_HEIGHT_SCALE = 0.5f; const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f; const char* const GAUSSIAN_BLUR_FRAGMENT_SOURCE = + "varying mediump vec2 vTexCoord;\n" + "uniform sampler2D sTexture;\n" + "uniform lowp vec4 uColor;\n" "uniform mediump vec2 uSampleOffsets[NUM_SAMPLES];\n" "uniform mediump float uSampleWeights[NUM_SAMPLES];\n" "void main()\n" "{\n" - " mediump vec4 col;\n" - " col = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y) + uSampleOffsets[0]) * uSampleWeights[0]; \n" - " for (int i=1; i( Actor::Property::COLOR_ALPHA, ParentSource(mBlurStrengthPropertyIndex), EqualToConstraintFloat()); - mImageActorComposite.ApplyConstraint(blurStrengthConstraint); + Constraint blurStrengthConstraint = Constraint::New( mImageActorComposite, Actor::Property::COLOR_ALPHA, EqualToConstraint()); + blurStrengthConstraint.AddSource( ParentSource(mBlurStrengthPropertyIndex) ); + blurStrengthConstraint.Apply(); // Create an ImageActor for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task - mTargetActor = ImageActor::New(); + mTargetActor = Toolkit::ImageView::New(); mTargetActor.SetParentOrigin(ParentOrigin::CENTER); - mTargetActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME - ////////////////////////////////////////////////////// // Create cameras for the renders corresponding to the view size mRenderFullSizeCamera = CameraActor::New(); + mRenderFullSizeCamera.SetInvertYAxis( true ); mRenderFullSizeCamera.SetParentOrigin(ParentOrigin::CENTER); @@ -326,6 +312,7 @@ void GaussianBlurView::OnInitialize() ////////////////////////////////////////////////////// // Create camera for the renders corresponding to the (potentially downsampled) render targets' size mRenderDownsampledCamera = CameraActor::New(); + mRenderDownsampledCamera.SetInvertYAxis( true ); mRenderDownsampledCamera.SetParentOrigin(ParentOrigin::CENTER); @@ -338,33 +325,7 @@ void GaussianBlurView::OnInitialize() } -/** - * ZrelativeToYconstraint - * - * f(current, property, scale) = Vector3(current.x, current.y, property.y * scale) - */ -struct ZrelativeToYconstraint -{ - ZrelativeToYconstraint( float scale ) - : mScale( scale ) - {} - - Vector3 operator()(const Vector3& current, - const PropertyInput& property) - { - Vector3 v; - - v.x = current.x; - v.y = current.y; - v.z = property.GetVector3().y * mScale; - - return v; - } - - float mScale; -}; - -void GaussianBlurView::OnControlSizeSet(const Vector3& targetSize) +void GaussianBlurView::OnSizeSet(const Vector3& targetSize) { mTargetSize = Vector2(targetSize); @@ -384,10 +345,11 @@ void GaussianBlurView::OnControlSizeSet(const Vector3& targetSize) } - // if we are already on stage, need to update render target sizes now to reflect the new size of this actor - if(Self().OnStage()) + // if we have already activated the blur, need to update render target sizes now to reflect the new size of this actor + if(mActivated) { - AllocateResources(); + Deactivate(); + Activate(); } } @@ -408,8 +370,6 @@ void GaussianBlurView::AllocateResources() mRenderDownsampledCamera.SetNearClippingPlane(1.0f); mRenderDownsampledCamera.SetAspectRatio(mDownsampledWidth / mDownsampledHeight); mRenderDownsampledCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor - // Point the camera back into the scene - mRenderDownsampledCamera.SetRotation(Quaternion(M_PI, Vector3::YAXIS)); mRenderDownsampledCamera.SetPosition(0.0f, 0.0f, ((mDownsampledHeight * 0.5f) / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f))); @@ -422,20 +382,18 @@ void GaussianBlurView::AllocateResources() mRenderFullSizeCamera.SetNearClippingPlane(1.0f); mRenderFullSizeCamera.SetAspectRatio(mTargetSize.width / mTargetSize.height); mRenderFullSizeCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor - // Point the camera back into the scene - mRenderFullSizeCamera.SetRotation(Quaternion(M_PI, Vector3::YAXIS)); float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f); mRenderFullSizeCamera.SetPosition(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale); // create offscreen buffer of new size to render our child actors to - mRenderTargetForRenderingChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::UNUSED ); + mRenderTargetForRenderingChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat ); // Set ImageActor for performing a horizontal blur on the texture mImageActorHorizBlur.SetImage( mRenderTargetForRenderingChildren ); // Create offscreen buffer for vert blur pass - mRenderTarget1 = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat, Dali::Image::UNUSED ); + mRenderTarget1 = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat ); // use the completed blur in the first buffer and composite with the original child actors render mImageActorComposite.SetImage( mRenderTarget1 ); @@ -445,7 +403,7 @@ void GaussianBlurView::AllocateResources() } // Create offscreen buffer for horiz blur pass - mRenderTarget2 = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat, Dali::Image::UNUSED ); + mRenderTarget2 = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat ); // size needs to match render target mImageActorHorizBlur.SetSize(mDownsampledWidth, mDownsampledHeight); @@ -484,6 +442,8 @@ void GaussianBlurView::CreateRenderTasks() mHorizBlurTask.SetInputEnabled( false ); mHorizBlurTask.SetClearEnabled( true ); mHorizBlurTask.SetClearColor( mBackgroundColor ); + mHorizBlurTask.SetCameraActor(mRenderDownsampledCamera); + mHorizBlurTask.SetTargetFrameBuffer( mRenderTarget2 ); if( mRenderOnce && mBlurUserImage ) { mHorizBlurTask.SetRefreshRate(RenderTask::REFRESH_ONCE); @@ -496,6 +456,15 @@ void GaussianBlurView::CreateRenderTasks() mVertBlurTask.SetInputEnabled( false ); mVertBlurTask.SetClearEnabled( true ); mVertBlurTask.SetClearColor( mBackgroundColor ); + mVertBlurTask.SetCameraActor(mRenderDownsampledCamera); + if(mUserOutputRenderTarget) + { + mVertBlurTask.SetTargetFrameBuffer( mUserOutputRenderTarget ); + } + else + { + mVertBlurTask.SetTargetFrameBuffer( mRenderTarget1 ); + } if( mRenderOnce && mBlurUserImage ) { mVertBlurTask.SetRefreshRate(RenderTask::REFRESH_ONCE); @@ -513,19 +482,6 @@ void GaussianBlurView::CreateRenderTasks() mCompositeTask.SetCameraActor(mRenderFullSizeCamera); mCompositeTask.SetTargetFrameBuffer( mRenderTargetForRenderingChildren ); } - - mHorizBlurTask.SetCameraActor(mRenderDownsampledCamera); - mVertBlurTask.SetCameraActor(mRenderDownsampledCamera); - - mHorizBlurTask.SetTargetFrameBuffer( mRenderTarget2 ); - if(mUserOutputRenderTarget) - { - mVertBlurTask.SetTargetFrameBuffer( mUserOutputRenderTarget ); - } - else - { - mVertBlurTask.SetTargetFrameBuffer( mRenderTarget1 ); - } } void GaussianBlurView::RemoveRenderTasks() @@ -538,25 +494,12 @@ void GaussianBlurView::RemoveRenderTasks() taskList.RemoveTask(mCompositeTask); } -void GaussianBlurView::OnStageDisconnection() -{ - // TODO: can't call this here, since SetImage() calls fails similarly to above - // Need to fix the stage connection so this callback can be used arbitrarily. At that point we can simplify the API by removing the need for Activate() / Deactivate() - //Deactivate(); -} - -void GaussianBlurView::OnControlStageConnection() -{ - // TODO: can't call this here, since SetImage() calls fail to connect images to stage, since parent chain not fully on stage yet - // Need to fix the stage connection so this callback can be used arbitrarily. At that point we can simplify the API by removing the need for Activate() / Deactivate() - //Activate(); -} - void GaussianBlurView::Activate() { // make sure resources are allocated and start the render tasks processing AllocateResources(); CreateRenderTasks(); + mActivated = true; } void GaussianBlurView::ActivateOnce() @@ -571,7 +514,11 @@ void GaussianBlurView::Deactivate() // stop render tasks processing // Note: render target resources are automatically freed since we set the Image::Unused flag RemoveRenderTasks(); + mRenderTargetForRenderingChildren.Reset(); + mRenderTarget1.Reset(); + mRenderTarget2.Reset(); mRenderOnce = false; + mActivated = false; } void GaussianBlurView::SetBlurBellCurveWidth(float blurBellCurveWidth) @@ -630,11 +577,11 @@ void GaussianBlurView::SetShaderConstants() Vector2 yAxis(0.0f, 1.0f); for (i = 0; i < mNumSamples; ++i ) { - mHorizBlurShader.SetUniform( GetSampleOffsetsPropertyName( i ), uvOffsets[ i ] * xAxis ); - mHorizBlurShader.SetUniform( GetSampleWeightsPropertyName( i ), weights[ i ] ); + mImageActorHorizBlur.RegisterProperty( GetSampleOffsetsPropertyName( i ), uvOffsets[ i ] * xAxis ); + mImageActorHorizBlur.RegisterProperty( GetSampleWeightsPropertyName( i ), weights[ i ] ); - mVertBlurShader.SetUniform( GetSampleOffsetsPropertyName( i ), uvOffsets[ i ] * yAxis ); - mVertBlurShader.SetUniform( GetSampleWeightsPropertyName( i ), weights[ i ] ); + mImageActorVertBlur.RegisterProperty( GetSampleOffsetsPropertyName( i ), uvOffsets[ i ] * yAxis ); + mImageActorVertBlur.RegisterProperty( GetSampleWeightsPropertyName( i ), weights[ i ] ); } delete[] uvOffsets;