1 #ifndef __DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H__
2 #define __DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H__
5 * Copyright (c) 2014 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.
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
35 class GaussianBlurView;
41 * GaussianBlurView implementation class
43 class GaussianBlurView : public Control
48 * @copydoc Dali::Toolkit::GaussianBlurView::GaussianBlurView
53 * @copydoc Dali::Toolkit::GaussianBlurView::GaussianBlurView
55 GaussianBlurView(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
56 const float downsampleWidthScale, const float downsampleHeightScale,
60 * @copydoc Dali::Toolkit::GaussianBlurView::~GaussianBlurView
62 virtual ~GaussianBlurView();
65 * @copydoc Dali::Toolkit::GaussianBlurView::New
67 static Dali::Toolkit::GaussianBlurView New();
68 static Dali::Toolkit::GaussianBlurView New( const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
69 const float downsampleWidthScale, const float downsampleHeightScale,
72 void Add(Actor child);
73 void Remove(Actor child);
79 void SetUserImageAndOutputRenderTarget(Image inputImage, FrameBufferImage outputRenderTarget);
81 Property::Index GetBlurStrengthPropertyIndex() const {return mBlurStrengthPropertyIndex;}
82 FrameBufferImage GetBlurredRenderTarget() const;
84 /// @copydoc Dali::Toolkit::GaussianBlurView::SetBackgroundColor(const Vector4&)
85 void SetBackgroundColor( const Vector4& color );
87 /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
88 Vector4 GetBackgroundColor() const;
90 void AllocateResources();
91 void CreateRenderTasks();
92 void RemoveRenderTasks();
93 Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal& FinishedSignal();
97 virtual void OnInitialize();
98 virtual void OnSizeSet(const Vector3& targetSize);
100 void SetBlurBellCurveWidth(float blurBellCurveWidth);
101 float CalcGaussianWeight(float x);
102 void SetShaderConstants();
103 std::string GetSampleOffsetsPropertyName( unsigned int index ) const;
104 std::string GetSampleWeightsPropertyName( unsigned int index ) const;
106 void OnRenderTaskFinished(Dali::RenderTask& renderTask);
108 /////////////////////////////////////////////////////////////
109 unsigned int mNumSamples; // number of blur samples in each of horiz/vert directions
110 float mBlurBellCurveWidth; // constant used when calculating the gaussian weights
111 Pixel::Format mPixelFormat; // pixel format used by render targets
113 /////////////////////////////////////////////////////////////
114 // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
115 float mDownsampleWidthScale;
116 float mDownsampleHeightScale;
117 float mDownsampledWidth;
118 float mDownsampledHeight;
120 /////////////////////////////////////////////////////////////
121 // if this is set to true, we blur a user supplied image rather than rendering and blurring children
122 bool mBlurUserImage:1;
124 /////////////////////////////////////////////////////////////
125 // if this is set to true, set the render tasks to refresh once
128 /////////////////////////////////////////////////////////////
129 // background fill color
130 Vector4 mBackgroundColor;
132 /////////////////////////////////////////////////////////////
133 // for checking if we need to reallocate render targets
137 /////////////////////////////////////////////////////////////
138 // 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
141 /////////////////////////////////////////////////////////////
142 // for mapping offscreen renders to render target sizes
143 CameraActor mRenderFullSizeCamera;
144 CameraActor mRenderDownsampledCamera;
146 /////////////////////////////////////////////////////////////
147 // for rendering all user added children to offscreen target
148 FrameBufferImage mRenderTargetForRenderingChildren;
149 RenderTask mRenderChildrenTask;
151 /////////////////////////////////////////////////////////////
152 // for rendering separated blur passes to offscreen targets
153 FrameBufferImage mRenderTarget1;
154 FrameBufferImage mRenderTarget2;
156 ShaderEffect mHorizBlurShader;
157 ShaderEffect mVertBlurShader;
159 ImageActor mImageActorHorizBlur;
160 ImageActor mImageActorVertBlur;
162 RenderTask mHorizBlurTask;
163 RenderTask mVertBlurTask;
165 /////////////////////////////////////////////////////////////
166 // for compositing blur and children renders to offscreen target
167 ImageActor mImageActorComposite;
168 RenderTask mCompositeTask;
170 /////////////////////////////////////////////////////////////
171 // for holding blurred result
172 ImageActor mTargetActor;
174 /////////////////////////////////////////////////////////////
175 // for animating fade in / out of blur, hiding internal implementation but allowing user to set via GaussianBlurView interface
176 Property::Index mBlurStrengthPropertyIndex;
178 /////////////////////////////////////////////////////////////
179 // User can specify image to blur and output target, so we can use GaussianBlurView for arbitrary blur processes
180 Image mUserInputImage;
181 FrameBufferImage mUserOutputRenderTarget;
183 Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal mFinishedSignal; ///< Signal emitted when blur has completed.
186 // Undefined copy constructor.
187 GaussianBlurView( const GaussianBlurView& );
189 // Undefined assignment operator.
190 GaussianBlurView& operator=( const GaussianBlurView& );
193 } // namespace Internal
196 // Helpers for public-api forwarding methods
197 inline Toolkit::Internal::GaussianBlurView& GetImpl( Toolkit::GaussianBlurView& obj )
199 DALI_ASSERT_ALWAYS(obj);
200 Dali::RefObject& handle = obj.GetImplementation();
201 return static_cast<Toolkit::Internal::GaussianBlurView&>(handle);
204 inline const Toolkit::Internal::GaussianBlurView& GetImpl( const Toolkit::GaussianBlurView& obj )
206 DALI_ASSERT_ALWAYS(obj);
207 const Dali::RefObject& handle = obj.GetImplementation();
208 return static_cast<const Toolkit::Internal::GaussianBlurView&>(handle);
212 } // namespace Toolkit
216 #endif // __DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H__