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.
24 #include <dali/public-api/object/property-map.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>
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,
74 void Add(Actor child);
75 void Remove(Actor child);
81 void SetUserImageAndOutputRenderTarget(Image inputImage, FrameBufferImage outputRenderTarget);
83 Property::Index GetBlurStrengthPropertyIndex() const {return mBlurStrengthPropertyIndex;}
84 FrameBufferImage GetBlurredRenderTarget() const;
86 /// @copydoc Dali::Toolkit::GaussianBlurView::SetBackgroundColor(const Vector4&)
87 void SetBackgroundColor( const Vector4& color );
89 /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
90 Vector4 GetBackgroundColor() const;
92 void AllocateResources();
93 void CreateRenderTasks();
94 void RemoveRenderTasks();
95 Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal& FinishedSignal();
99 virtual void OnInitialize();
100 virtual void OnSizeSet(const Vector3& targetSize);
103 * @copydoc Control::OnChildAdd()
105 virtual void OnChildAdd( Actor& child );
108 * @copydoc Control::OnChildRemove()
110 virtual void OnChildRemove( Actor& child );
112 void SetBlurBellCurveWidth(float blurBellCurveWidth);
113 float CalcGaussianWeight(float x);
114 void SetShaderConstants();
115 std::string GetSampleOffsetsPropertyName( unsigned int index ) const;
116 std::string GetSampleWeightsPropertyName( unsigned int index ) const;
118 void OnRenderTaskFinished(Dali::RenderTask& renderTask);
120 /////////////////////////////////////////////////////////////
121 unsigned int mNumSamples; // number of blur samples in each of horiz/vert directions
122 float mBlurBellCurveWidth; // constant used when calculating the gaussian weights
123 Pixel::Format mPixelFormat; // pixel format used by render targets
125 /////////////////////////////////////////////////////////////
126 // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
127 float mDownsampleWidthScale;
128 float mDownsampleHeightScale;
129 float mDownsampledWidth;
130 float mDownsampledHeight;
132 /////////////////////////////////////////////////////////////
133 // if this is set to true, we blur a user supplied image rather than rendering and blurring children
134 bool mBlurUserImage:1;
136 /////////////////////////////////////////////////////////////
137 // if this is set to true, set the render tasks to refresh once
140 /////////////////////////////////////////////////////////////
141 // background fill color
142 Vector4 mBackgroundColor;
144 /////////////////////////////////////////////////////////////
145 // for checking if we need to reallocate render targets
149 /////////////////////////////////////////////////////////////
150 // 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
152 // for creating a subtree for the internal actors
155 /////////////////////////////////////////////////////////////
156 // for mapping offscreen renders to render target sizes
157 CameraActor mRenderFullSizeCamera;
158 CameraActor mRenderDownsampledCamera;
160 /////////////////////////////////////////////////////////////
161 // for rendering all user added children to offscreen target
162 FrameBufferImage mRenderTargetForRenderingChildren;
163 RenderTask mRenderChildrenTask;
165 /////////////////////////////////////////////////////////////
166 // for rendering separated blur passes to offscreen targets
167 FrameBufferImage mRenderTarget1;
168 FrameBufferImage mRenderTarget2;
170 Toolkit::ImageView mImageViewHorizBlur;
171 Toolkit::ImageView mImageViewVertBlur;
173 Property::Map mCustomShader;
175 RenderTask mHorizBlurTask;
176 RenderTask mVertBlurTask;
178 /////////////////////////////////////////////////////////////
179 // for compositing blur and children renders to offscreen target
180 Toolkit::ImageView mImageViewComposite;
181 RenderTask mCompositeTask;
183 /////////////////////////////////////////////////////////////
184 // for holding blurred result
185 Toolkit::ImageView mTargetActor;
187 /////////////////////////////////////////////////////////////
188 // for animating fade in / out of blur, hiding internal implementation but allowing user to set via GaussianBlurView interface
189 Property::Index mBlurStrengthPropertyIndex;
191 /////////////////////////////////////////////////////////////
192 // User can specify image to blur and output target, so we can use GaussianBlurView for arbitrary blur processes
193 Image mUserInputImage;
194 FrameBufferImage mUserOutputRenderTarget;
196 Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal mFinishedSignal; ///< Signal emitted when blur has completed.
201 // Undefined copy constructor.
202 GaussianBlurView( const GaussianBlurView& );
204 // Undefined assignment operator.
205 GaussianBlurView& operator=( const GaussianBlurView& );
208 } // namespace Internal
211 // Helpers for public-api forwarding methods
212 inline Toolkit::Internal::GaussianBlurView& GetImpl( Toolkit::GaussianBlurView& obj )
214 DALI_ASSERT_ALWAYS(obj);
215 Dali::RefObject& handle = obj.GetImplementation();
216 return static_cast<Toolkit::Internal::GaussianBlurView&>(handle);
219 inline const Toolkit::Internal::GaussianBlurView& GetImpl( const Toolkit::GaussianBlurView& obj )
221 DALI_ASSERT_ALWAYS(obj);
222 const Dali::RefObject& handle = obj.GetImplementation();
223 return static_cast<const Toolkit::Internal::GaussianBlurView&>(handle);
227 } // namespace Toolkit
231 #endif // __DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H__