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=93fb35bc6ac4ca14c83dbdaee06d0ba834759f53;hp=233a79c3877a5c4e93d42d91f9dfa1122565db13;hb=f546dd5d83a968e573f8f053a01ce43df32c71a0;hpb=a76b6c2b9fc30dd5e8f5f7e0cfd2537e274fd71e 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 233a79c..93fb35b 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. @@ -23,19 +23,20 @@ #include #include #include -#include +#include #include #include #include -#include #include #include #include #include +#include // INTERNAL INCLUDES #include #include +#include // TODO: // pixel format / size - set from JSON @@ -206,19 +207,6 @@ Toolkit::GaussianBlurView GaussianBlurView::New(const unsigned int numSamples, c return handle; } -///////////////////////////////////////////////////////////// -// for creating a subtree for all user added child actors, so that we can have them exclusive to the mRenderChildrenTask and our other actors exclusive to our other tasks -// DEPRECATED: overloading Actor::Add()/Remove() not nice since breaks polymorphism. Need another method to pass ownership of added child actors to our internal actor root. -void GaussianBlurView::Add(Actor child) -{ - mChildrenRoot.Add(child); -} - -void GaussianBlurView::Remove(Actor child) -{ - mChildrenRoot.Remove(child); -} - void GaussianBlurView::SetUserImageAndOutputRenderTarget(Texture inputImage, FrameBuffer outputRenderTarget) { // can only do this if the GaussianBlurView object was created with this parameter set @@ -259,8 +247,8 @@ Vector4 GaussianBlurView::GetBackgroundColor() const void GaussianBlurView::OnInitialize() { // root actor to parent all user added actors, needed to allow us to set that subtree as exclusive for our child render task - mChildrenRoot.SetParentOrigin(ParentOrigin::CENTER); - mInternalRoot.SetParentOrigin(ParentOrigin::CENTER); + mChildrenRoot.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER ); + mInternalRoot.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER ); ////////////////////////////////////////////////////// // Create shaders @@ -275,13 +263,13 @@ void GaussianBlurView::OnInitialize() // Create an actor for performing a horizontal blur on the texture mHorizBlurActor = Actor::New(); - mHorizBlurActor.SetParentOrigin(ParentOrigin::CENTER); + mHorizBlurActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER ); Renderer renderer = CreateRenderer( BASIC_VERTEX_SOURCE, fragmentSource.c_str() ); mHorizBlurActor.AddRenderer( renderer ); // Create an actor for performing a vertical blur on the texture mVertBlurActor = Actor::New(); - mVertBlurActor.SetParentOrigin(ParentOrigin::CENTER); + mVertBlurActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER ); renderer = CreateRenderer( BASIC_VERTEX_SOURCE, fragmentSource.c_str() ); mVertBlurActor.AddRenderer( renderer ); @@ -293,8 +281,8 @@ void GaussianBlurView::OnInitialize() if(!mBlurUserImage) { mCompositingActor = Actor::New(); - mCompositingActor.SetParentOrigin(ParentOrigin::CENTER); - mCompositingActor.SetOpacity(GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH); // ensure alpha is enabled for this object and set default value + mCompositingActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER ); + mCompositingActor.SetProperty( Actor::Property::OPACITY,GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH); // ensure alpha is enabled for this object and set default value renderer = CreateRenderer( BASIC_VERTEX_SOURCE, BASIC_FRAGMENT_SOURCE ); mCompositingActor.AddRenderer( renderer ); @@ -304,7 +292,7 @@ void GaussianBlurView::OnInitialize() // Create an image view for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task mTargetActor = Actor::New(); - mTargetActor.SetParentOrigin(ParentOrigin::CENTER); + mTargetActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER ); renderer = CreateRenderer( BASIC_VERTEX_SOURCE, BASIC_FRAGMENT_SOURCE ); mTargetActor.AddRenderer( renderer ); @@ -312,7 +300,7 @@ void GaussianBlurView::OnInitialize() // Create cameras for the renders corresponding to the view size mRenderFullSizeCamera = CameraActor::New(); mRenderFullSizeCamera.SetInvertYAxis( true ); - mRenderFullSizeCamera.SetParentOrigin(ParentOrigin::CENTER); + mRenderFullSizeCamera.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER ); ////////////////////////////////////////////////////// // Connect to actor tree @@ -325,7 +313,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); + mRenderDownsampledCamera.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER ); ////////////////////////////////////////////////////// // Connect to actor tree @@ -333,6 +321,11 @@ void GaussianBlurView::OnInitialize() mInternalRoot.Add( mHorizBlurActor ); mInternalRoot.Add( mVertBlurActor ); mInternalRoot.Add( mRenderDownsampledCamera ); + + DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) { + return std::unique_ptr< Dali::Accessibility::Accessible >( + new Control::Impl::AccessibleImpl( actor, Dali::Accessibility::Role::FILLER ) ); + } ); } @@ -340,19 +333,19 @@ void GaussianBlurView::OnSizeSet(const Vector3& targetSize) { mTargetSize = Vector2(targetSize); - mChildrenRoot.SetSize(targetSize); + mChildrenRoot.SetProperty( Actor::Property::SIZE, targetSize); if( !mBlurUserImage ) { - mCompositingActor.SetSize(targetSize); - mTargetActor.SetSize(targetSize); + mCompositingActor.SetProperty( Actor::Property::SIZE, targetSize); + mTargetActor.SetProperty( Actor::Property::SIZE, targetSize); // Children render camera must move when GaussianBlurView object is resized. This is since we cannot change render target size - so we need to remap the child actors' rendering // accordingly so they still exactly fill the render target. Note that this means the effective resolution of the child render changes as the GaussianBlurView object changes // size, this is the trade off for not being able to modify render target size // Change camera z position based on GaussianBlurView actor height float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f); - mRenderFullSizeCamera.SetZ(mTargetSize.height * cameraPosConstraintScale); + mRenderFullSizeCamera.SetProperty( Actor::Property::POSITION_Z, mTargetSize.height * cameraPosConstraintScale); } @@ -385,72 +378,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; + // 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); + // 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 + + mRenderDownsampledCamera.SetProperty( Actor::Property::POSITION, Vector3(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 - mRenderDownsampledCamera.SetNearClippingPlane(1.0f); - mRenderDownsampledCamera.SetAspectRatio(mDownsampledWidth / mDownsampledHeight); - mRenderDownsampledCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor + mRenderFullSizeCamera.SetNearClippingPlane(1.0f); + mRenderFullSizeCamera.SetAspectRatio(mTargetSize.width / mTargetSize.height); + mRenderFullSizeCamera.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))); + float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f); + mRenderFullSizeCamera.SetProperty( Actor::Property::POSITION, Vector3(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale)); - // 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 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 ); - // 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 ); + // Set actor for performing a horizontal blur + SetRendererTexture( mHorizBlurActor.GetRendererAt(0), mRenderTargetForRenderingChildren ); - // size needs to match render target - mHorizBlurActor.SetSize(mDownsampledWidth, mDownsampledHeight); + // 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 ); - // size needs to match render target - mVertBlurActor.SetSize(mDownsampledWidth, mDownsampledHeight); - SetRendererTexture( mVertBlurActor.GetRendererAt(0), mRenderTarget2 ); + // use the completed blur in the first buffer and composite with the original child actors render + SetRendererTexture( mCompositingActor.GetRendererAt(0), mRenderTarget1 ); - // set gaussian blur up for new sized render targets - SetShaderConstants(); + // 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.SetProperty( Actor::Property::SIZE, Vector2(mDownsampledWidth, mDownsampledHeight) ); + + // size needs to match render target + mVertBlurActor.SetProperty( Actor::Property::SIZE, Vector2(mDownsampledWidth, mDownsampledHeight) ); + SetRendererTexture( mVertBlurActor.GetRendererAt(0), mRenderTarget2 ); + + // set gaussian blur up for new sized render targets + SetShaderConstants(); } void GaussianBlurView::CreateRenderTasks() @@ -469,6 +458,11 @@ void GaussianBlurView::CreateRenderTasks() mRenderChildrenTask.SetCameraActor(mRenderFullSizeCamera); mRenderChildrenTask.SetFrameBuffer( mRenderTargetForRenderingChildren ); + + if( mRenderOnce ) + { + mRenderChildrenTask.SetRefreshRate(RenderTask::REFRESH_ONCE); + } } // perform a horizontal blur targeting the second buffer @@ -480,7 +474,7 @@ void GaussianBlurView::CreateRenderTasks() mHorizBlurTask.SetClearColor( mBackgroundColor ); mHorizBlurTask.SetCameraActor(mRenderDownsampledCamera); mHorizBlurTask.SetFrameBuffer( mRenderTarget2 ); - if( mRenderOnce && mBlurUserImage ) + if( mRenderOnce || ( mRenderOnce && mBlurUserImage ) ) { mHorizBlurTask.SetRefreshRate(RenderTask::REFRESH_ONCE); } @@ -501,7 +495,7 @@ void GaussianBlurView::CreateRenderTasks() { mVertBlurTask.SetFrameBuffer( mRenderTarget1 ); } - if( mRenderOnce && mBlurUserImage ) + if( mRenderOnce || ( mRenderOnce && mBlurUserImage ) ) { mVertBlurTask.SetRefreshRate(RenderTask::REFRESH_ONCE); mVertBlurTask.FinishedSignal().Connect( this, &GaussianBlurView::OnRenderTaskFinished ); @@ -517,6 +511,11 @@ void GaussianBlurView::CreateRenderTasks() mCompositeTask.SetCameraActor(mRenderFullSizeCamera); mCompositeTask.SetFrameBuffer( mRenderTargetForRenderingChildren ); + + if( mRenderOnce ) + { + mCompositeTask.SetRefreshRate(RenderTask::REFRESH_ONCE); + } } } @@ -532,31 +531,37 @@ 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() { - DALI_ASSERT_ALWAYS(mBlurUserImage); // Only works with blurring image mode. + Deactivate(); mRenderOnce = true; Activate(); } 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)