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/dali.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
36 class GaussianBlurView;
42 * GaussianBlurView implementation class
44 class GaussianBlurView : public Control
49 * @copydoc Dali::Toolkit::GaussianBlurView::GaussianBlurView
54 * @copydoc Dali::Toolkit::GaussianBlurView::GaussianBlurView
56 GaussianBlurView(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
57 const float downsampleWidthScale, const float downsampleHeightScale,
61 * @copydoc Dali::Toolkit::GaussianBlurView::~GaussianBlurView
63 virtual ~GaussianBlurView();
66 * @copydoc Dali::Toolkit::GaussianBlurView::New
68 static Dali::Toolkit::GaussianBlurView New();
69 static Dali::Toolkit::GaussianBlurView New( const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
70 const float downsampleWidthScale, const float downsampleHeightScale,
73 void Add(Actor child);
74 void Remove(Actor child);
80 void SetUserImageAndOutputRenderTarget(Image inputImage, FrameBufferImage outputRenderTarget);
82 Property::Index GetBlurStrengthPropertyIndex() const {return mBlurStrengthPropertyIndex;}
83 FrameBufferImage GetBlurredRenderTarget() const;
85 /// @copydoc Dali::Toolkit::GaussianBlurView::SetBackgroundColor(const Vector4&)
86 void SetBackgroundColor( const Vector4& color );
88 /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
89 Vector4 GetBackgroundColor() const;
91 void AllocateResources();
92 void CreateRenderTasks();
93 void RemoveRenderTasks();
94 Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal& FinishedSignal();
98 virtual void OnInitialize();
99 virtual void OnControlSizeSet(const Vector3& targetSize);
100 virtual void OnStageDisconnection();
102 virtual void OnControlStageConnection();
104 void SetBlurBellCurveWidth(float blurBellCurveWidth);
105 float CalcGaussianWeight(float x);
106 void SetShaderConstants();
107 std::string GetSampleOffsetsPropertyName( unsigned int index ) const;
108 std::string GetSampleWeightsPropertyName( unsigned int index ) const;
110 void OnRenderTaskFinished(Dali::RenderTask& renderTask);
112 /////////////////////////////////////////////////////////////
113 unsigned int mNumSamples; // number of blur samples in each of horiz/vert directions
114 float mBlurBellCurveWidth; // constant used when calculating the gaussian weights
115 Pixel::Format mPixelFormat; // pixel format used by render targets
117 /////////////////////////////////////////////////////////////
118 // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
119 float mDownsampleWidthScale;
120 float mDownsampleHeightScale;
121 float mDownsampledWidth;
122 float mDownsampledHeight;
124 /////////////////////////////////////////////////////////////
125 // if this is set to true, we blur a user supplied image rather than rendering and blurring children
126 bool mBlurUserImage:1;
128 /////////////////////////////////////////////////////////////
129 // if this is set to true, set the render tasks to refresh once
132 /////////////////////////////////////////////////////////////
133 // background fill color
134 Vector4 mBackgroundColor;
136 /////////////////////////////////////////////////////////////
137 // for checking if we need to reallocate render targets
141 /////////////////////////////////////////////////////////////
142 // 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
145 /////////////////////////////////////////////////////////////
146 // for mapping offscreen renders to render target sizes
147 CameraActor mRenderFullSizeCamera;
148 CameraActor mRenderDownsampledCamera;
150 /////////////////////////////////////////////////////////////
151 // for rendering all user added children to offscreen target
152 FrameBufferImage mRenderTargetForRenderingChildren;
153 RenderTask mRenderChildrenTask;
155 /////////////////////////////////////////////////////////////
156 // for rendering separated blur passes to offscreen targets
157 FrameBufferImage mRenderTarget1;
158 FrameBufferImage mRenderTarget2;
160 ShaderEffect mHorizBlurShader;
161 ShaderEffect mVertBlurShader;
163 ImageActor mImageActorHorizBlur;
164 ImageActor mImageActorVertBlur;
166 RenderTask mHorizBlurTask;
167 RenderTask mVertBlurTask;
169 /////////////////////////////////////////////////////////////
170 // for compositing blur and children renders to offscreen target
171 ImageActor mImageActorComposite;
172 RenderTask mCompositeTask;
174 /////////////////////////////////////////////////////////////
175 // for holding blurred result
176 ImageActor mTargetActor;
178 /////////////////////////////////////////////////////////////
179 // for animating fade in / out of blur, hiding internal implementation but allowing user to set via GaussianBlurView interface
180 Property::Index mBlurStrengthPropertyIndex;
182 /////////////////////////////////////////////////////////////
183 // User can specify image to blur and output target, so we can use GaussianBlurView for arbitrary blur processes
184 Image mUserInputImage;
185 FrameBufferImage mUserOutputRenderTarget;
187 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
200 // Helpers for public-api forwarding methods
201 inline Toolkit::Internal::GaussianBlurView& GetImpl( Toolkit::GaussianBlurView& obj )
203 DALI_ASSERT_ALWAYS(obj);
204 Dali::RefObject& handle = obj.GetImplementation();
205 return static_cast<Toolkit::Internal::GaussianBlurView&>(handle);
208 inline const Toolkit::Internal::GaussianBlurView& GetImpl( const Toolkit::GaussianBlurView& obj )
210 DALI_ASSERT_ALWAYS(obj);
211 const Dali::RefObject& handle = obj.GetImplementation();
212 return static_cast<const Toolkit::Internal::GaussianBlurView&>(handle);
216 } // namespace Toolkit
220 #endif // __DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H__