Merge "Remove obsolete and non functional SizeChanged signal from actor" into tizen
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / gaussian-blur-view / gaussian-blur-view-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H__
2 #define __DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <sstream>
23 #include <cmath>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 class GaussianBlurView;
36
37 namespace Internal
38 {
39
40 /**
41  * GaussianBlurView implementation class
42  */
43 class GaussianBlurView : public Control
44 {
45 public:
46
47   /**
48    * @copydoc Dali::Toolkit::GaussianBlurView::GaussianBlurView
49    */
50   GaussianBlurView();
51
52   /**
53    * @copydoc Dali::Toolkit::GaussianBlurView::GaussianBlurView
54    */
55   GaussianBlurView(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
56                    const float downsampleWidthScale, const float downsampleHeightScale,
57                    bool blurUserImage);
58
59   /**
60    * @copydoc Dali::Toolkit::GaussianBlurView::~GaussianBlurView
61    */
62   virtual ~GaussianBlurView();
63
64   /**
65    * @copydoc Dali::Toolkit::GaussianBlurView::New
66    */
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,
70                                               bool blurUserImage);
71
72   void Add(Actor child);
73   void Remove(Actor child);
74
75   void Activate();
76   void ActivateOnce();
77   void Deactivate();
78
79   void SetUserImageAndOutputRenderTarget(Image inputImage, FrameBufferImage outputRenderTarget);
80
81   Property::Index GetBlurStrengthPropertyIndex() const {return mBlurStrengthPropertyIndex;}
82   FrameBufferImage GetBlurredRenderTarget() const;
83
84   /// @copydoc Dali::Toolkit::GaussianBlurView::SetBackgroundColor(const Vector4&)
85   void SetBackgroundColor( const Vector4& color );
86
87   /// @copydoc Dali::Toolkit::GaussianBlurView::GetBackgroundColor
88   Vector4 GetBackgroundColor() const;
89
90   void AllocateResources();
91   void CreateRenderTasks();
92   void RemoveRenderTasks();
93   Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal& FinishedSignal();
94
95 private:
96
97   virtual void OnInitialize();
98   virtual void OnControlSizeSet(const Vector3& targetSize);
99   virtual void OnStageDisconnection();
100
101   virtual void OnControlStageConnection();
102
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;
108
109   void OnRenderTaskFinished(Dali::RenderTask& renderTask);
110
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
115
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;
122
123   /////////////////////////////////////////////////////////////
124   // if this is set to true, we blur a user supplied image rather than rendering and blurring children
125   bool mBlurUserImage:1;
126
127   /////////////////////////////////////////////////////////////
128   // if this is set to true, set the render tasks to refresh once
129   bool mRenderOnce:1;
130
131   /////////////////////////////////////////////////////////////
132   // background fill color
133   Vector4 mBackgroundColor;
134
135   /////////////////////////////////////////////////////////////
136   // for checking if we need to reallocate render targets
137   Vector2 mTargetSize;
138   Vector2 mLastSize;
139
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
142   Actor mChildrenRoot;
143
144   /////////////////////////////////////////////////////////////
145   // for mapping offscreen renders to render target sizes
146   CameraActor mRenderFullSizeCamera;
147   CameraActor mRenderDownsampledCamera;
148
149   /////////////////////////////////////////////////////////////
150   // for rendering all user added children to offscreen target
151   FrameBufferImage mRenderTargetForRenderingChildren;
152   RenderTask mRenderChildrenTask;
153
154   /////////////////////////////////////////////////////////////
155   // for rendering separated blur passes to offscreen targets
156   FrameBufferImage mRenderTarget1;
157   FrameBufferImage mRenderTarget2;
158
159   ShaderEffect mHorizBlurShader;
160   ShaderEffect mVertBlurShader;
161
162   ImageActor mImageActorHorizBlur;
163   ImageActor mImageActorVertBlur;
164
165   RenderTask mHorizBlurTask;
166   RenderTask mVertBlurTask;
167
168   /////////////////////////////////////////////////////////////
169   // for compositing blur and children renders to offscreen target
170   ImageActor mImageActorComposite;
171   RenderTask mCompositeTask;
172
173   /////////////////////////////////////////////////////////////
174   // for holding blurred result
175   ImageActor mTargetActor;
176
177   /////////////////////////////////////////////////////////////
178   // for animating fade in / out of blur, hiding internal implementation but allowing user to set via GaussianBlurView interface
179   Property::Index mBlurStrengthPropertyIndex;
180
181   /////////////////////////////////////////////////////////////
182   // User can specify image to blur and output target, so we can use GaussianBlurView for arbitrary blur processes
183   Image mUserInputImage;
184   FrameBufferImage mUserOutputRenderTarget;
185
186   Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal mFinishedSignal; ///< Signal emitted when blur has completed.
187 private:
188
189   // Undefined copy constructor.
190   GaussianBlurView( const GaussianBlurView& );
191
192   // Undefined assignment operator.
193   GaussianBlurView& operator=( const GaussianBlurView& );
194 };
195
196 } // namespace Internal
197
198
199 // Helpers for public-api forwarding methods
200 inline Toolkit::Internal::GaussianBlurView& GetImpl( Toolkit::GaussianBlurView& obj )
201 {
202   DALI_ASSERT_ALWAYS(obj);
203   Dali::RefObject& handle = obj.GetImplementation();
204   return static_cast<Toolkit::Internal::GaussianBlurView&>(handle);
205 }
206
207 inline const Toolkit::Internal::GaussianBlurView& GetImpl( const Toolkit::GaussianBlurView& obj )
208 {
209   DALI_ASSERT_ALWAYS(obj);
210   const Dali::RefObject& handle = obj.GetImplementation();
211   return static_cast<const Toolkit::Internal::GaussianBlurView&>(handle);
212 }
213
214
215 } // namespace Toolkit
216
217 } // namespace Dali
218
219 #endif // __DALI_TOOLKIT_INTERNAL_GAUSSIAN_BLUR_EFFECT_H__