1 #ifndef DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H
2 #define DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
24 #include <dali/public-api/object/property-map.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/devel-api/controls/gaussian-blur-view/gaussian-blur-view.h>
29 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
37 class GaussianBlurView;
43 * GaussianBlurView implementation class
45 class GaussianBlurView : public Control
50 * @copydoc Dali::Toolkit::GaussianBlurView::GaussianBlurView
55 * @copydoc Dali::Toolkit::GaussianBlurView::GaussianBlurView
57 GaussianBlurView(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
58 const float downsampleWidthScale, const float downsampleHeightScale,
62 * @copydoc Dali::Toolkit::GaussianBlurView::~GaussianBlurView
64 virtual ~GaussianBlurView();
67 * @copydoc Dali::Toolkit::GaussianBlurView::New
69 static Dali::Toolkit::GaussianBlurView New();
70 static Dali::Toolkit::GaussianBlurView New( const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
71 const float downsampleWidthScale, const float downsampleHeightScale,
78 void SetUserImageAndOutputRenderTarget(Texture inputImage, FrameBuffer outputRenderTarget);
80 Property::Index GetBlurStrengthPropertyIndex() const {return mBlurStrengthPropertyIndex;}
81 FrameBuffer GetBlurredRenderTarget() const;
83 /// @copydoc Dali::Toolkit::GaussianBlurView::SetBackgroundColor(const Vector4&)
84 void SetBackgroundColor( const Vector4& color );
86 /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
87 Vector4 GetBackgroundColor() const;
89 void AllocateResources();
90 void CreateRenderTasks();
91 void RemoveRenderTasks();
92 Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal& FinishedSignal();
96 void OnInitialize() override;
97 void OnSizeSet(const Vector3& targetSize) override;
100 * @copydoc Control::OnChildAdd()
102 void OnChildAdd( Actor& child ) override;
105 * @copydoc Control::OnChildRemove()
107 void OnChildRemove( Actor& child ) override;
109 void SetBlurBellCurveWidth(float blurBellCurveWidth);
110 float CalcGaussianWeight(float x);
111 void SetShaderConstants();
112 std::string GetSampleOffsetsPropertyName( unsigned int index ) const;
113 std::string GetSampleWeightsPropertyName( unsigned int index ) const;
115 void OnRenderTaskFinished(Dali::RenderTask& renderTask);
117 /////////////////////////////////////////////////////////////
118 unsigned int mNumSamples; // number of blur samples in each of horiz/vert directions
119 float mBlurBellCurveWidth; // constant used when calculating the gaussian weights
120 Pixel::Format mPixelFormat; // pixel format used by render targets
122 /////////////////////////////////////////////////////////////
123 // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
124 float mDownsampleWidthScale;
125 float mDownsampleHeightScale;
126 float mDownsampledWidth;
127 float mDownsampledHeight;
129 /////////////////////////////////////////////////////////////
130 // if this is set to true, we blur a user supplied image rather than rendering and blurring children
131 bool mBlurUserImage:1;
133 /////////////////////////////////////////////////////////////
134 // if this is set to true, set the render tasks to refresh once
137 /////////////////////////////////////////////////////////////
138 // background fill color
139 Vector4 mBackgroundColor;
141 /////////////////////////////////////////////////////////////
142 // for checking if we need to reallocate render targets
146 /////////////////////////////////////////////////////////////
147 // 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
149 // for creating a subtree for the internal actors
152 /////////////////////////////////////////////////////////////
153 // for mapping offscreen renders to render target sizes
154 CameraActor mRenderFullSizeCamera;
155 CameraActor mRenderDownsampledCamera;
157 /////////////////////////////////////////////////////////////
158 // for rendering all user added children to offscreen target
159 FrameBuffer mRenderTargetForRenderingChildren;
160 RenderTask mRenderChildrenTask;
162 /////////////////////////////////////////////////////////////
163 // for rendering separated blur passes to offscreen targets
164 FrameBuffer mRenderTarget1;
165 FrameBuffer mRenderTarget2;
167 Actor mHorizBlurActor;
168 Actor mVertBlurActor;
170 RenderTask mHorizBlurTask;
171 RenderTask mVertBlurTask;
173 /////////////////////////////////////////////////////////////
174 // for compositing blur and children renders to offscreen target
175 Actor mCompositingActor;
176 RenderTask mCompositeTask;
178 /////////////////////////////////////////////////////////////
179 // for holding blurred result
182 /////////////////////////////////////////////////////////////
183 // for animating fade in / out of blur, hiding internal implementation but allowing user to set via GaussianBlurView interface
184 Property::Index mBlurStrengthPropertyIndex;
186 /////////////////////////////////////////////////////////////
187 // User can specify image to blur and output target, so we can use GaussianBlurView for arbitrary blur processes
188 Texture mUserInputImage;
189 FrameBuffer mUserOutputRenderTarget;
191 Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal mFinishedSignal; ///< Signal emitted when blur has completed.
196 // Undefined copy constructor.
197 GaussianBlurView( const GaussianBlurView& );
199 // Undefined assignment operator.
200 GaussianBlurView& operator=( const GaussianBlurView& );
203 } // namespace Internal
206 // Helpers for public-api forwarding methods
207 inline Toolkit::Internal::GaussianBlurView& GetImpl( Toolkit::GaussianBlurView& obj )
209 DALI_ASSERT_ALWAYS(obj);
210 Dali::RefObject& handle = obj.GetImplementation();
211 return static_cast<Toolkit::Internal::GaussianBlurView&>(handle);
214 inline const Toolkit::Internal::GaussianBlurView& GetImpl( const Toolkit::GaussianBlurView& obj )
216 DALI_ASSERT_ALWAYS(obj);
217 const Dali::RefObject& handle = obj.GetImplementation();
218 return static_cast<const Toolkit::Internal::GaussianBlurView&>(handle);
222 } // namespace Toolkit
226 #endif // DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H