1 #ifndef DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H
2 #define DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H
5 * Copyright (c) 2021 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.
22 #include <dali/public-api/object/property-map.h>
27 #include <dali-toolkit/devel-api/controls/gaussian-blur-view/gaussian-blur-view.h>
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
35 class GaussianBlurView;
40 * GaussianBlurView implementation class
42 class GaussianBlurView : public Control
46 * @copydoc Dali::Toolkit::GaussianBlurView::GaussianBlurView
51 * @copydoc Dali::Toolkit::GaussianBlurView::GaussianBlurView
53 GaussianBlurView(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat, const float downsampleWidthScale, const float downsampleHeightScale, bool blurUserImage);
56 * @copydoc Dali::Toolkit::GaussianBlurView::~GaussianBlurView
58 virtual ~GaussianBlurView();
61 * @copydoc Dali::Toolkit::GaussianBlurView::New
63 static Dali::Toolkit::GaussianBlurView New();
64 static Dali::Toolkit::GaussianBlurView New(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat, const float downsampleWidthScale, const float downsampleHeightScale, bool blurUserImage);
70 void SetUserImageAndOutputRenderTarget(Texture inputImage, FrameBuffer outputRenderTarget);
72 Property::Index GetBlurStrengthPropertyIndex() const
74 return mBlurStrengthPropertyIndex;
76 FrameBuffer GetBlurredRenderTarget() const;
78 /// @copydoc Dali::Toolkit::GaussianBlurView::SetBackgroundColor(const Vector4&)
79 void SetBackgroundColor(const Vector4& color);
81 /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
82 Vector4 GetBackgroundColor() const;
84 void AllocateResources();
85 void CreateRenderTasks();
86 void RemoveRenderTasks();
87 Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal& FinishedSignal();
90 void OnInitialize() override;
91 void OnSizeSet(const Vector3& targetSize) override;
94 * @copydoc Control::OnChildAdd()
96 void OnChildAdd(Actor& child) override;
99 * @copydoc Control::OnChildRemove()
101 void OnChildRemove(Actor& child) override;
103 void SetBlurBellCurveWidth(float blurBellCurveWidth);
104 float CalcGaussianWeight(float x);
105 void SetShaderConstants();
106 std::string GetSampleOffsetsPropertyName(unsigned int index) const;
107 std::string GetSampleWeightsPropertyName(unsigned int index) const;
109 void OnRenderTaskFinished(Dali::RenderTask& renderTask);
111 /////////////////////////////////////////////////////////////
112 unsigned int mNumSamples; // number of blur samples in each of horiz/vert directions
113 float mBlurBellCurveWidth; // constant used when calculating the gaussian weights
114 Pixel::Format mPixelFormat; // pixel format used by render targets
116 /////////////////////////////////////////////////////////////
117 // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
118 float mDownsampleWidthScale;
119 float mDownsampleHeightScale;
120 float mDownsampledWidth;
121 float mDownsampledHeight;
123 /////////////////////////////////////////////////////////////
124 // if this is set to true, we blur a user supplied image rather than rendering and blurring children
125 bool mBlurUserImage : 1;
127 /////////////////////////////////////////////////////////////
128 // if this is set to true, set the render tasks to refresh once
129 bool mRenderOnce : 1;
131 /////////////////////////////////////////////////////////////
132 // background fill color
133 Vector4 mBackgroundColor;
135 /////////////////////////////////////////////////////////////
136 // for checking if we need to reallocate render targets
140 /////////////////////////////////////////////////////////////
141 // 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
143 // for creating a subtree for the internal actors
146 /////////////////////////////////////////////////////////////
147 // for mapping offscreen renders to render target sizes
148 CameraActor mRenderFullSizeCamera;
149 CameraActor mRenderDownsampledCamera;
151 /////////////////////////////////////////////////////////////
152 // for rendering all user added children to offscreen target
153 FrameBuffer mRenderTargetForRenderingChildren;
154 RenderTask mRenderChildrenTask;
156 /////////////////////////////////////////////////////////////
157 // for rendering separated blur passes to offscreen targets
158 FrameBuffer mRenderTarget1;
159 FrameBuffer mRenderTarget2;
161 Actor mHorizBlurActor;
162 Actor mVertBlurActor;
164 RenderTask mHorizBlurTask;
165 RenderTask mVertBlurTask;
167 /////////////////////////////////////////////////////////////
168 // for compositing blur and children renders to offscreen target
169 Actor mCompositingActor;
170 RenderTask mCompositeTask;
172 /////////////////////////////////////////////////////////////
173 // for holding blurred result
176 /////////////////////////////////////////////////////////////
177 // for animating fade in / out of blur, hiding internal implementation but allowing user to set via GaussianBlurView interface
178 Property::Index mBlurStrengthPropertyIndex;
180 /////////////////////////////////////////////////////////////
181 // User can specify image to blur and output target, so we can use GaussianBlurView for arbitrary blur processes
182 Texture mUserInputImage;
183 FrameBuffer mUserOutputRenderTarget;
185 Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal mFinishedSignal; ///< Signal emitted when blur has completed.
190 // Undefined copy constructor.
191 GaussianBlurView(const GaussianBlurView&);
193 // Undefined assignment operator.
194 GaussianBlurView& operator=(const GaussianBlurView&);
197 } // namespace Internal
199 // Helpers for public-api forwarding methods
200 inline Toolkit::Internal::GaussianBlurView& GetImpl(Toolkit::GaussianBlurView& obj)
202 DALI_ASSERT_ALWAYS(obj);
203 Dali::RefObject& handle = obj.GetImplementation();
204 return static_cast<Toolkit::Internal::GaussianBlurView&>(handle);
207 inline const Toolkit::Internal::GaussianBlurView& GetImpl(const Toolkit::GaussianBlurView& obj)
209 DALI_ASSERT_ALWAYS(obj);
210 const Dali::RefObject& handle = obj.GetImplementation();
211 return static_cast<const Toolkit::Internal::GaussianBlurView&>(handle);
214 } // namespace Toolkit
218 #endif // DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H