From cea1f03937b84ab2ac2551d13e28e91c2ddfa728 Mon Sep 17 00:00:00 2001 From: "Seungho, Baek" Date: Wed, 20 May 2020 17:50:54 +0900 Subject: [PATCH] Recreate resources after blur is deactivated. - Currently, each resources are created only the size is changed. - But, if the Blur is deactivated, the resources are reset and we need to create each resource again when the blur is re-activated. Change-Id: Ie8eab91e571439d6db74b6f39f43e0016a277416 Signed-off-by: Seungho, Baek --- .../src/dali-toolkit/utc-Dali-GaussianBlurView.cpp | 42 +++++- .../gaussian-blur-view/gaussian-blur-view-impl.cpp | 156 +++++++++++---------- 2 files changed, 120 insertions(+), 78 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-GaussianBlurView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-GaussianBlurView.cpp index 0a483a0..170a17c 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-GaussianBlurView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-GaussianBlurView.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 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. @@ -190,6 +190,46 @@ int UtcDaliGaussianBlurActivateDeactivate(void) } // Positive test case for a method +int UtcDaliGaussianBlurActivateDeactivateRepeat(void) +{ + ToolkitTestApplication application; + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + tet_infoline("UtcDaliGaussianBlurActivateDeactivateRepeat"); + + Toolkit::GaussianBlurView view = Toolkit::GaussianBlurView::New(); + DALI_TEST_CHECK( view ); + + view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + view.SetSize(Stage::GetCurrent().GetSize()); + view.Add(Actor::New()); + Stage::GetCurrent().Add(view); + view.Activate(); + + application.SendNotification(); + application.Render(20); + + DALI_TEST_CHECK( gl.GetLastGenTextureId() == 3 ); + + view.Deactivate(); + + application.SendNotification(); + application.Render(20); + + DALI_TEST_CHECK( gl.GetLastGenTextureId() == 3 ); + + view.Activate(); + + application.SendNotification(); + application.Render(20); + + DALI_TEST_CHECK( gl.GetLastGenTextureId() == 6 ); + + END_TEST; +} + +// Positive test case for a method int UtcDaliGaussianBlurViewSetGetBackgroundColor(void) { ToolkitTestApplication application; 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 62aca10..1b47c68 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 @@ -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. @@ -386,72 +386,68 @@ void GaussianBlurView::OnChildRemove( Actor& child ) void GaussianBlurView::AllocateResources() { - // size of render targets etc is based on the size of this actor, ignoring z - if(mTargetSize != mLastSize) - { - mLastSize = mTargetSize; + mLastSize = mTargetSize; + + // get size of downsampled render targets + mDownsampledWidth = mTargetSize.width * mDownsampleWidthScale; + mDownsampledHeight = mTargetSize.height * mDownsampleHeightScale; + + // Create and place a camera for the renders corresponding to the (potentially downsampled) render targets' size + mRenderDownsampledCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW); + // TODO: how do we pick a reasonable value for near clip? Needs to relate to normal camera the user renders with, but we don't have a handle on it + mRenderDownsampledCamera.SetNearClippingPlane(1.0f); + mRenderDownsampledCamera.SetAspectRatio(mDownsampledWidth / mDownsampledHeight); + mRenderDownsampledCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor - // get size of downsampled render targets - mDownsampledWidth = mTargetSize.width * mDownsampleWidthScale; - mDownsampledHeight = mTargetSize.height * mDownsampleHeightScale; + mRenderDownsampledCamera.SetPosition(0.0f, 0.0f, ((mDownsampledHeight * 0.5f) / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f))); - // Create and place a camera for the renders corresponding to the (potentially downsampled) render targets' size - mRenderDownsampledCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW); + // setup for normal operation + if(!mBlurUserImage) + { + // Create and place a camera for the children render, corresponding to its render target size + mRenderFullSizeCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW); // TODO: how do we pick a reasonable value for near clip? Needs to relate to normal camera the user renders with, but we don't have a handle on it - mRenderDownsampledCamera.SetNearClippingPlane(1.0f); - mRenderDownsampledCamera.SetAspectRatio(mDownsampledWidth / mDownsampledHeight); - mRenderDownsampledCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor - - mRenderDownsampledCamera.SetPosition(0.0f, 0.0f, ((mDownsampledHeight * 0.5f) / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f))); - - // setup for normal operation - if(!mBlurUserImage) - { - // Create and place a camera for the children render, corresponding to its render target size - mRenderFullSizeCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW); - // TODO: how do we pick a reasonable value for near clip? Needs to relate to normal camera the user renders with, but we don't have a handle on it - mRenderFullSizeCamera.SetNearClippingPlane(1.0f); - mRenderFullSizeCamera.SetAspectRatio(mTargetSize.width / mTargetSize.height); - mRenderFullSizeCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor - - 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 = FrameBuffer::New( mTargetSize.width, mTargetSize.height, FrameBuffer::Attachment::NONE ); - Texture texture = Texture::New( TextureType::TEXTURE_2D, mPixelFormat, unsigned(mTargetSize.width), unsigned(mTargetSize.height) ); - mRenderTargetForRenderingChildren.AttachColorTexture( texture ); - - // Set actor for performing a horizontal blur - SetRendererTexture( mHorizBlurActor.GetRendererAt(0), mRenderTargetForRenderingChildren ); - - // Create offscreen buffer for vert blur pass - mRenderTarget1 = FrameBuffer::New( mDownsampledWidth, mDownsampledHeight, FrameBuffer::Attachment::NONE ); - texture = Texture::New(TextureType::TEXTURE_2D, mPixelFormat, unsigned(mDownsampledWidth), unsigned(mDownsampledHeight)); - mRenderTarget1.AttachColorTexture( texture ); - - // use the completed blur in the first buffer and composite with the original child actors render - SetRendererTexture( mCompositingActor.GetRendererAt(0), mRenderTarget1 ); - - // set up target actor for rendering result, i.e. the blurred image - SetRendererTexture( mTargetActor.GetRendererAt(0), mRenderTargetForRenderingChildren ); - } - - // Create offscreen buffer for horiz blur pass - mRenderTarget2 = FrameBuffer::New( mDownsampledWidth, mDownsampledHeight, FrameBuffer::Attachment::NONE ); - Texture texture = Texture::New(TextureType::TEXTURE_2D, mPixelFormat, unsigned(mDownsampledWidth), unsigned(mDownsampledHeight)); - mRenderTarget2.AttachColorTexture( texture ); - - // size needs to match render target - mHorizBlurActor.SetSize(mDownsampledWidth, mDownsampledHeight); - - // size needs to match render target - mVertBlurActor.SetSize(mDownsampledWidth, mDownsampledHeight); - SetRendererTexture( mVertBlurActor.GetRendererAt(0), mRenderTarget2 ); - - // set gaussian blur up for new sized render targets - SetShaderConstants(); + mRenderFullSizeCamera.SetNearClippingPlane(1.0f); + mRenderFullSizeCamera.SetAspectRatio(mTargetSize.width / mTargetSize.height); + mRenderFullSizeCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor + + 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 = FrameBuffer::New( mTargetSize.width, mTargetSize.height, FrameBuffer::Attachment::NONE ); + Texture texture = Texture::New( TextureType::TEXTURE_2D, mPixelFormat, unsigned(mTargetSize.width), unsigned(mTargetSize.height) ); + mRenderTargetForRenderingChildren.AttachColorTexture( texture ); + + // Set actor for performing a horizontal blur + SetRendererTexture( mHorizBlurActor.GetRendererAt(0), mRenderTargetForRenderingChildren ); + + // Create offscreen buffer for vert blur pass + mRenderTarget1 = FrameBuffer::New( mDownsampledWidth, mDownsampledHeight, FrameBuffer::Attachment::NONE ); + texture = Texture::New(TextureType::TEXTURE_2D, mPixelFormat, unsigned(mDownsampledWidth), unsigned(mDownsampledHeight)); + mRenderTarget1.AttachColorTexture( texture ); + + // use the completed blur in the first buffer and composite with the original child actors render + SetRendererTexture( mCompositingActor.GetRendererAt(0), mRenderTarget1 ); + + // set up target actor for rendering result, i.e. the blurred image + SetRendererTexture( mTargetActor.GetRendererAt(0), mRenderTargetForRenderingChildren ); } + + // Create offscreen buffer for horiz blur pass + mRenderTarget2 = FrameBuffer::New( mDownsampledWidth, mDownsampledHeight, FrameBuffer::Attachment::NONE ); + Texture texture = Texture::New(TextureType::TEXTURE_2D, mPixelFormat, unsigned(mDownsampledWidth), unsigned(mDownsampledHeight)); + mRenderTarget2.AttachColorTexture( texture ); + + // size needs to match render target + mHorizBlurActor.SetSize(mDownsampledWidth, mDownsampledHeight); + + // size needs to match render target + mVertBlurActor.SetSize(mDownsampledWidth, mDownsampledHeight); + SetRendererTexture( mVertBlurActor.GetRendererAt(0), mRenderTarget2 ); + + // set gaussian blur up for new sized render targets + SetShaderConstants(); } void GaussianBlurView::CreateRenderTasks() @@ -533,11 +529,14 @@ void GaussianBlurView::RemoveRenderTasks() void GaussianBlurView::Activate() { - // make sure resources are allocated and start the render tasks processing - Self().Add( mInternalRoot ); - AllocateResources(); - CreateRenderTasks(); - mActivated = true; + if( !mActivated ) + { + // make sure resources are allocated and start the render tasks processing + Self().Add( mInternalRoot ); + AllocateResources(); + CreateRenderTasks(); + mActivated = true; + } } void GaussianBlurView::ActivateOnce() @@ -549,15 +548,18 @@ void GaussianBlurView::ActivateOnce() void GaussianBlurView::Deactivate() { - // stop render tasks processing - // Note: render target resources are automatically freed since we set the Image::Unused flag - mInternalRoot.Unparent(); - RemoveRenderTasks(); - mRenderTargetForRenderingChildren.Reset(); - mRenderTarget1.Reset(); - mRenderTarget2.Reset(); - mRenderOnce = false; - mActivated = false; + if( mActivated ) + { + // stop render tasks processing + // Note: render target resources are automatically freed since we set the Image::Unused flag + mInternalRoot.Unparent(); + mRenderTargetForRenderingChildren.Reset(); + mRenderTarget1.Reset(); + mRenderTarget2.Reset(); + RemoveRenderTasks(); + mRenderOnce = false; + mActivated = false; + } } void GaussianBlurView::SetBlurBellCurveWidth(float blurBellCurveWidth) -- 2.7.4