Stop using ImageActor in GaussianBlur, Bloom & SuperBlur
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / gaussian-blur-view / gaussian-blur-view.h
1 #ifndef __DALI_TOOLKIT_GAUSSIAN_BLUR_EFFECT_H__
2 #define __DALI_TOOLKIT_GAUSSIAN_BLUR_EFFECT_H__
3
4 /*
5  * Copyright (c) 2015 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 <dali/public-api/actors/camera-actor.h>
23 #include <dali/public-api/common/dali-vector.h>
24 #include <dali/public-api/images/frame-buffer-image.h>
25 #include <dali/public-api/render-tasks/render-task.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/public-api/controls/control.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal DALI_INTERNAL
37 {
38
39 /**
40  * GaussianBlurView implementation class
41  */
42 class GaussianBlurView;
43
44 /**
45  * BloomView implementation class - requires access to private methods
46  */
47 class BloomView;
48
49 } // namespace Internal
50 /**
51  * @addtogroup dali_toolkit_controls_gaussian_blur_view
52  * @{
53  */
54
55 /**
56  *
57  * GaussianBlurView is a class for applying a render process that blurs an image.
58  *
59  * Basic idea:-
60  *
61  * 1) The GaussianBlurView object will render all its child actors offscreen.\n
62  * 2) The GaussianBlurView object then blurs the result of step 1), using a two pass separated Gaussian blur.\n
63  * 3) The GaussianBlurView object then composites the blur from step 2) with the child actors image from step 1). See GetBlurStrengthPropertyIndex() for more info.\n
64  * 4) The GaussianBlurView object gets rendered automatically, either to the screen via the default render task, or via a RenderTask the user has created for
65  * e.g. further offscreen rendering.
66  *
67  * Fundamentally, the GaussianBlurView is simply an Actor in the normal actor tree that affects all of its children. It should be added to your Actor tree and manipulated in the
68  * normal ways. It can be considered a 'portal' in the sense that all child actors are clipped to the GaussianBlurView actor bounds.
69  *
70  * ************\n
71  * NB: It is essential to remove the GaussianBlurView from the stage and also to call Deactivate() on it when you are not using it. This will ensure that resources are freed and
72  * rendering stops.\n
73  * ************\n
74  *
75  * Usage example:-
76  *
77  *  // initialise\n
78  *  GaussianBlurView gaussianBlurView = GaussianBlurView::New();\n
79  *
80  *  // create and add some visible actors to the GaussianBlurView, all these child actors will therefore get blurred.\n
81  *  Image image = Image::New(...);\n
82  *  ImageActor imageActor = ImageActor::New(image);\n
83  *  gaussianBlurView.Add(imageActor);\n
84  *  ...\n
85  *
86  *  // Start rendering the GaussianBlurView\n
87  *  Stage::GetCurrent().Add(gaussianBlurView);\n
88  *  gaussianBlurView.Activate();\n
89  *  ...\n
90  *
91  *  // animate the strength of the blur - this can fade between no blur and full blur. See GetBlurStrengthPropertyIndex().\n
92  *  Animation blurAnimation = Animation::New( ... );\n
93  *  blurAnimation.AnimateTo( Property( gaussianBlurView, gaussianBlurView.GetBlurStrengthPropertyIndex() ), ... );\n
94  *  blurAnimation.Play();\n
95  *
96  *  ...\n
97  *  // Stop rendering the GaussianBlurView\n
98  *  Stage::GetCurrent().Remove(gaussianBlurView);\n
99  *  gaussianBlurView.Deactivate();\n
100  */
101 class DALI_IMPORT_API GaussianBlurView : public Control
102 {
103 public:
104   /**
105    * Signal type for notifications
106    */
107   typedef Signal< void (GaussianBlurView source) > GaussianBlurViewSignal;
108
109   /**
110    * Create an uninitialized GaussianBlurView; this can be initialized with GaussianBlurView::New()
111    * Calling member functions with an uninitialized Dali::Object is not allowed.
112    */
113   GaussianBlurView();
114
115   /**
116    * Copy constructor. Creates another handle that points to the same real object
117    */
118   GaussianBlurView(const GaussianBlurView& handle);
119
120   /**
121    * Assignment operator. Changes this handle to point to another real object
122    */
123   GaussianBlurView& operator=(const GaussianBlurView& ZoomView);
124
125   /**
126    * @brief Destructor
127    *
128    * This is non-virtual since derived Handle types must not contain data or virtual methods.
129    */
130   ~GaussianBlurView();
131
132   /**
133    * Downcast an Object handle to GaussianBlurView. If handle points to a GaussianBlurView the
134    * downcast produces valid handle. If not the returned handle is left uninitialized.
135    * @param[in] handle Handle to an object
136    * @return handle to a GaussianBlurView or an uninitialized handle
137    */
138   static GaussianBlurView DownCast( BaseHandle handle );
139
140   /**
141   * Create an initialized GaussianBlurView, using default settings. The default settings are:-\n
142   *
143   * numSamples = 5\n
144   * blurBellCurveWidth = 1.5\n
145   * renderTargetPixelFormat = RGB888\n
146   * downsampleWidthScale = 0.5\n
147   * downsampleHeightScale = 0.5\n
148   * blurUserImage = false
149   * @return A handle to a newly allocated Dali resource
150   */
151   static GaussianBlurView New();
152
153   /**
154   * Create an initialized GaussianBlurView.
155   * @param numSamples The size of the Gaussian blur kernel (number of samples in horizontal / vertical blur directions).
156   * @param blurBellCurveWidth The constant controlling the Gaussian function, must be > 0.0. Controls the width of the bell curve, i.e. the look of the blur and also indirectly
157   * the amount of blurriness Smaller numbers for a tighter curve. Useful values in the range [0.5..3.0] - near the bottom of that range the curve is weighted heavily towards
158   * the centre pixel of the kernel (so there won't be much blur), near the top of that range the pixels have nearly equal weighting (closely approximating a box filter
159   * therefore). Values close to zero result in the bell curve lying almost entirely within a single pixel, in other words there will be basically no blur as neighbouring pixels
160   * have close to zero weights.
161   * @param renderTargetPixelFormat The pixel format of the render targets we are using to perform the blur.
162   * @param downsampleWidthScale The width scale factor applied during the blur process, scaling the size of the source image to the size of the final blurred image output.
163   * Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
164   * @param downsampleHeightScale The height scale factor applied during the blur process, scaling the size of the source image to the size of the final blurred image output.
165   * Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
166   * @param blurUserImage If this is set to true, the GaussianBlurView object will operate in a special mode that allows the user to blur an image of their choice. See
167   * SetUserImageAndOutputRenderTarget().
168   * @return A handle to a newly allocated Dali resource
169   */
170   static GaussianBlurView New(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
171                               const float downsampleWidthScale, const float downsampleHeightScale,
172                               bool blurUserImage = false);
173
174   /**
175    * Adds a child Actor to this Actor.
176    * NOTE! if the child already has a parent, it will be removed from old parent
177    * and reparented to this actor. This may change childs position, color, shader effect,
178    * scale etc as it now inherits them from this actor
179    * @pre This Actor (the parent) has been initialized.
180    * @pre The child actor has been initialized.
181    * @pre The child actor is not the same as the parent actor.
182    * @pre The actor is not the Root actor
183    * @param [in] child The child.
184    * @post The child will be referenced by its parent. This means that the child will be kept alive,
185    * even if the handle passed into this method is reset or destroyed.
186    */
187   void Add(Actor child);
188
189   /**
190    * Removes a child Actor from this Actor.
191    * If the actor was not a child of this actor, this is a no-op.
192    * @pre This Actor (the parent) has been initialized.
193    * @pre The child actor is not the same as the parent actor.
194    * @param [in] child The child.
195    */
196   void Remove(Actor child);
197
198   /**
199    * Start rendering the GaussianBlurView. Must be called after you Add() it to the stage.
200    */
201   void Activate();
202
203   /**
204    * Render the GaussianBlurView once. Must be called after you Add() it to the stage.
205    * Only works with a gaussian blur view created with blurUserImage = true.
206    * Listen to the Finished signal to determine when the rendering has completed.
207    */
208   void ActivateOnce();
209
210   /**
211    * Stop rendering the GaussianBlurView. Must be called after you Remove() it from the stage.
212    */
213   void Deactivate();
214
215   /**
216    * Sets a custom image to be blurred and a render target to receive the blurred result. If this is called the children of the GaussianBlurObject will not be rendered blurred,
217    * instead the inputImage will get blurred.
218    * To retrieve the blurred image the user can either pass a handle on a render target they own as the second parameter to SetUserImageAndOutputRenderTarget( ... ), or they
219    * can pass NULL for this parameter and instead call GetBlurredRenderTarget() which will return a handle on a render target created internally to the GaussianBlurView object.
220    * @pre This object was created with a New( ... ) call where the blurUserImage argument was set to true. If this was not the case an exception will be thrown.
221    * @param inputImage The image that the user wishes to blur.
222    * @param outputRenderTarget A render target to receive the blurred result. Passing NULL is allowed. See also GetBlurredRenderTarget().
223    */
224   void SetUserImageAndOutputRenderTarget(Image inputImage, FrameBufferImage outputRenderTarget);
225
226   /**
227    * Get the index of the property that can be used to fade the blur in / out. This is the overall strength of the blur.
228    * User can use this to animate the blur. A value of 0.0 is zero blur and 1.0 is full blur. Default is 1.0.
229    * Note that if you set the blur to 0.0, the result will be no blur BUT the internal rendering will still be happening. If you wish to turn the blur off, you should remove
230    * the GaussianBlurView object from the stage also.
231    * @return Index of the property that can be used to fade the blur in / out
232    */
233   Dali::Property::Index GetBlurStrengthPropertyIndex() const;
234
235   /**
236    * Get the final blurred image.
237    * Use can call this function to get the blurred result as an image, to use as they wish. It is not necessary to call this unless you specifically require it.
238    * @pre The user must call Activate() before the render target will be returned.
239    * @return A handle on the blurred image, contained in a render target.
240    */
241   FrameBufferImage GetBlurredRenderTarget() const;
242
243   /**
244   * Set background color for the view. The background will be filled with this color.
245   * @param[in] color The background color.
246   */
247   void SetBackgroundColor( const Vector4& color );
248
249   /**
250   * Get the background color.
251   * @return The background color.
252   */
253   Vector4 GetBackgroundColor() const;
254
255 public: // Signals
256   /**
257    * If ActivateOnce has been called, then connect to this signal to be notified when the
258    * target actor has been rendered.
259    * @return The Finished signal
260    */
261   GaussianBlurViewSignal& FinishedSignal();
262
263 public:
264
265   /**
266    * Creates a handle using the Toolkit::Internal implementation.
267    * @param[in]  implementation  The UI Control implementation.
268    */
269   DALI_INTERNAL GaussianBlurView( Internal::GaussianBlurView& implementation );
270
271   /**
272    * Allows the creation of this UI Control from an Internal::CustomActor pointer.
273    * @param[in]  internal  A pointer to the internal CustomActor.
274    */
275   DALI_INTERNAL GaussianBlurView( Dali::Internal::CustomActor* internal );
276
277 };
278
279 /**
280  * @}
281  */
282 } // namespace Toolkit
283
284 } // namespace Dali
285
286 #endif // __DALI_TOOLKIT_GAUSSIAN_BLUR_EFFECT_H__