Remove obsolete and non functional SizeChanged signal from actor
[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) 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 <dali/public-api/actors/camera-actor.h>
23 #include <dali/public-api/actors/image-actor.h>
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/public-api/images/frame-buffer-image.h>
26 #include <dali/public-api/render-tasks/render-task.h>
27 #include <dali/public-api/shader-effects/shader-effect.h>
28
29 // INTERNAL INCLUDES
30 #include <dali-toolkit/public-api/controls/control.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal DALI_INTERNAL
39 {
40
41 /**
42  * GaussianBlurView implementation class
43  */
44 class GaussianBlurView;
45
46 /**
47  * BloomView implementation class - requires access to private methods
48  */
49 class BloomView;
50
51 } // namespace Internal
52
53 /**
54  *
55  * GaussianBlurView is a class for applying a render process that blurs an image.
56  *
57  * Basic idea:-
58  *
59  * 1) The GaussianBlurView object will render all its child actors offscreen.\n
60  * 2) The GaussianBlurView object then blurs the result of step 1), using a two pass separated Gaussian blur.\n
61  * 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
62  * 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
63  * e.g. further offscreen rendering.
64  *
65  * 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
66  * normal ways. It can be considered a 'portal' in the sense that all child actors are clipped to the GaussianBlurView actor bounds.
67  *
68  * ************\n
69  * 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
70  * rendering stops.\n
71  * ************\n
72  *
73  * Usage example:-
74  *
75  *  // initialise\n
76  *  GaussianBlurView gaussianBlurView = GaussianBlurView::New();\n
77  *
78  *  // create and add some visible actors to the GaussianBlurView, all these child actors will therefore get blurred.\n
79  *  Image image = Image::New(...);\n
80  *  ImageActor imageActor = ImageActor::New(image);\n
81  *  gaussianBlurView.Add(imageActor);\n
82  *  ...\n
83  *
84  *  // Start rendering the GaussianBlurView\n
85  *  Stage::GetCurrent().Add(gaussianBlurView);\n
86  *  gaussianBlurView.Activate();\n
87  *  ...\n
88  *
89  *  // animate the strength of the blur - this can fade between no blur and full blur. See GetBlurStrengthPropertyIndex().\n
90  *  Animation blurAnimation = Animation::New( ... );\n
91  *  blurAnimation.AnimateTo( Property( gaussianBlurView, gaussianBlurView.GetBlurStrengthPropertyIndex() ), ... );\n
92  *  blurAnimation.Play();\n
93  *
94  *  ...\n
95  *  // Stop rendering the GaussianBlurView\n
96  *  Stage::GetCurrent().Remove(gaussianBlurView);\n
97  *  gaussianBlurView.Deactivate();\n
98  */
99 class DALI_IMPORT_API GaussianBlurView : public Control
100 {
101 public:
102   /**
103    * Signal type for notifications
104    */
105   typedef Signal< void (GaussianBlurView source) > GaussianBlurViewSignal;
106
107   /**
108    * Create an uninitialized GaussianBlurView; this can be initialized with GaussianBlurView::New()
109    * Calling member functions with an uninitialized Dali::Object is not allowed.
110    */
111   GaussianBlurView();
112
113   /**
114    * Copy constructor. Creates another handle that points to the same real object
115    */
116   GaussianBlurView(const GaussianBlurView& handle);
117
118   /**
119    * Assignment operator. Changes this handle to point to another real object
120    */
121   GaussianBlurView& operator=(const GaussianBlurView& ZoomView);
122
123   /**
124    * @brief Destructor
125    *
126    * This is non-virtual since derived Handle types must not contain data or virtual methods.
127    */
128   ~GaussianBlurView();
129
130   /**
131    * Downcast an Object handle to GaussianBlurView. If handle points to a GaussianBlurView the
132    * downcast produces valid handle. If not the returned handle is left uninitialized.
133    * @param[in] handle Handle to an object
134    * @return handle to a GaussianBlurView or an uninitialized handle
135    */
136   static GaussianBlurView DownCast( BaseHandle handle );
137
138   /**
139   * Create an initialized GaussianBlurView, using default settings. The default settings are:-\n
140   *
141   * numSamples = 5\n
142   * blurBellCurveWidth = 1.5\n
143   * renderTargetPixelFormat = RGB888\n
144   * downsampleWidthScale = 0.5\n
145   * downsampleHeightScale = 0.5\n
146   * blurUserImage = false
147   * @return A handle to a newly allocated Dali resource
148   */
149   static GaussianBlurView New();
150
151   /**
152   * Create an initialized GaussianBlurView.
153   * @param numSamples The size of the Gaussian blur kernel (number of samples in horizontal / vertical blur directions).
154   * @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
155   * 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
156   * 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
157   * 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
158   * have close to zero weights.
159   * @param renderTargetPixelFormat The pixel format of the render targets we are using to perform the blur.
160   * @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.
161   * Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
162   * @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.
163   * Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
164   * @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
165   * SetUserImageAndOutputRenderTarget().
166   * @return A handle to a newly allocated Dali resource
167   */
168   static GaussianBlurView New(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
169                               const float downsampleWidthScale, const float downsampleHeightScale,
170                               bool blurUserImage = false);
171
172   /**
173    * Adds a child Actor to this Actor.
174    * NOTE! if the child already has a parent, it will be removed from old parent
175    * and reparented to this actor. This may change childs position, color, shader effect,
176    * scale etc as it now inherits them from this actor
177    * @pre This Actor (the parent) has been initialized.
178    * @pre The child actor has been initialized.
179    * @pre The child actor is not the same as the parent actor.
180    * @pre The actor is not the Root actor
181    * @param [in] child The child.
182    * @post The child will be referenced by its parent. This means that the child will be kept alive,
183    * even if the handle passed into this method is reset or destroyed.
184    * @post This may invalidate ActorContainer iterators.
185    */
186   void Add(Actor child);
187
188   /**
189    * Removes a child Actor from this Actor.
190    * If the actor was not a child of this actor, this is a no-op.
191    * @pre This Actor (the parent) has been initialized.
192    * @pre The child actor is not the same as the parent actor.
193    * @param [in] child The child.
194    * @post This may invalidate ActorContainer iterators.
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   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 } // namespace Toolkit
280
281 } // namespace Dali
282
283 #endif // __DALI_TOOLKIT_GAUSSIAN_BLUR_EFFECT_H__