2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Runtime.InteropServices;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Binding;
22 using System.ComponentModel;
27 /// GaussianBlurView is a class for applying a render process that blurs an image.
29 /// <since_tizen> 6 </since_tizen>
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public class GaussianBlurView : View
33 static GaussianBlurView()
35 if (NUIApplication.IsUsingXaml)
37 BlurStrengthProperty = BindableProperty.Create(nameof(BlurStrength), typeof(float), typeof(GaussianBlurView), default(float),
38 propertyChanged: SetInternalBlurStrengthProperty, defaultValueCreator: GetInternalBlurStrengthProperty);
43 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
44 [EditorBrowsable(EditorBrowsableState.Never)]
45 public static BindableProperty BlurStrengthProperty = null;
46 internal static void SetInternalBlurStrengthProperty(BindableObject bindable, object oldValue, object newValue)
48 var gaussianBlurView = (GaussianBlurView)bindable;
51 Tizen.NUI.Object.SetProperty(gaussianBlurView.SwigCPtr, gaussianBlurView.GetBlurStrengthPropertyIndex(), new Tizen.NUI.PropertyValue((float)newValue));
54 internal static object GetInternalBlurStrengthProperty(BindableObject bindable)
56 var gaussianBlurView = (GaussianBlurView)bindable;
58 Tizen.NUI.Object.GetProperty(gaussianBlurView.SwigCPtr, gaussianBlurView.GetBlurStrengthPropertyIndex()).Get(out temp);
62 internal GaussianBlurView(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn)
66 internal GaussianBlurView(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, cRegister)
70 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
72 Interop.GaussianBlurView.DeleteGaussianBlurView(swigCPtr);
76 /// Dispose GaussianBlurView and all children on it.
78 /// <param name="type">Dispose type.</param>
79 /// <since_tizen> 6 </since_tizen>
80 protected override void Dispose(DisposeTypes type)
87 //Release your own unmanaged resources here.
88 //You should not access any managed member here except static instance.
89 //because the execution order of Finalizes is non-deterministic.
90 if (finishedCallback != null)
92 FinishedSignal().Disconnect(finishedCallback);
98 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
99 private delegate void FinishedCallbackType(IntPtr application);
100 private DaliEventHandler<object, EventArgs> finishedEventHandler;
101 private FinishedCallbackType finishedCallback;
104 /// If ActivateOnce has been called, then connect to this signal to be notified when the target actor has been rendered.
106 /// <since_tizen> 6 </since_tizen>
107 [EditorBrowsable(EditorBrowsableState.Never)]
108 public event DaliEventHandler<object, EventArgs> Finished
112 // Restricted to only one listener
113 if (finishedEventHandler == null)
115 finishedCallback = new FinishedCallbackType(OnFinished);
116 FinishedSignal().Connect(finishedCallback);
118 finishedEventHandler += value;
123 finishedEventHandler -= value;
125 if (finishedEventHandler == null && FinishedSignal().Empty() == false)
127 FinishedSignal().Disconnect(finishedCallback);
132 // Callback for GaussianBlurView FinishedSignal
133 private void OnFinished(IntPtr data)
135 EventArgs e = new EventArgs();
137 if (finishedEventHandler != null)
139 //here we send all data to user event handlers
140 finishedEventHandler(this, e);
145 /// The BlurStrength property. A value of 0.0 is zero blur and 1.0 is full blur. Default is 1.0.
146 /// if you set the blur to 0.0, the result will be no blur BUT the internal rendering will still be happening.
147 /// If you wish to turn the blur off, you should remove the GaussianBlurView object from the window also.
149 /// <since_tizen> 6 </since_tizen>
150 [EditorBrowsable(EditorBrowsableState.Never)]
151 public float BlurStrength
155 if (NUIApplication.IsUsingXaml)
157 return (float)GetValue(BlurStrengthProperty);
161 return (float)GetInternalBlurStrengthProperty(this);
166 if (NUIApplication.IsUsingXaml)
168 SetValue(BlurStrengthProperty, value);
172 SetInternalBlurStrengthProperty(this, null, value);
174 NotifyPropertyChanged();
181 [EditorBrowsable(EditorBrowsableState.Never)]
182 public GaussianBlurView() : this(Interop.GaussianBlurView.New(), true)
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188 /// Constructor with parameters.
190 /// <param name="numSamples">The size of the Gaussian blur kernel (number of samples in horizontal / vertical blur directions)</param>
191 /// <param name="blurBellCurveWidth">
192 /// 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
193 /// 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
194 /// 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
195 /// 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
196 /// have close to zero weights.
198 /// <param name="renderTargetPixelFormat">The pixel format of the render targets we are using to perform the blur.</param>
199 /// <param name="downsampleWidthScale">
200 /// width scale factor applied during the blur process, scaling the size of the source image to the size of the final blurred image output.
201 /// Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
203 /// <param name="downsampleHeightScale">
204 /// 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.
205 /// Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
207 /// <param name="blurUserImage">
208 /// 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
209 /// SetUserImageAndOutputRenderTarget().
211 /// <since_tizen> 6 </since_tizen>
212 [EditorBrowsable(EditorBrowsableState.Never)]
213 public GaussianBlurView(uint numSamples, float blurBellCurveWidth, PixelFormat renderTargetPixelFormat, float downsampleWidthScale, float downsampleHeightScale, bool blurUserImage) : this(Interop.GaussianBlurView.New(numSamples, blurBellCurveWidth, (int)renderTargetPixelFormat, downsampleWidthScale, downsampleHeightScale, blurUserImage), true)
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221 /// <since_tizen> 6 </since_tizen>
222 [EditorBrowsable(EditorBrowsableState.Never)]
223 public GaussianBlurView(GaussianBlurView handle) : this(Interop.GaussianBlurView.NewGaussianBlurView(GaussianBlurView.getCPtr(handle)), true, false)
225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229 /// Start rendering the GaussianBlurView. Must be called after you Add() it to the window.
231 /// <since_tizen> 6 </since_tizen>
232 [EditorBrowsable(EditorBrowsableState.Never)]
233 public void Activate()
235 Interop.GaussianBlurView.Activate(SwigCPtr);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240 /// Render the GaussianBlurView once.
241 /// Must be called after you Add() it to the window.
242 /// Listen to the Finished signal to determine when the rendering has completed.
244 /// <since_tizen> 6 </since_tizen>
245 [EditorBrowsable(EditorBrowsableState.Never)]
246 public void ActivateOnce()
248 Interop.GaussianBlurView.ActivateOnce(SwigCPtr);
249 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253 /// Stop rendering the GaussianBlurView. Must be called after you Remove() it from the window.
255 /// <since_tizen> 6 </since_tizen>
256 [EditorBrowsable(EditorBrowsableState.Never)]
257 public void Deactivate()
259 Interop.GaussianBlurView.Deactivate(SwigCPtr);
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 private int GetBlurStrengthPropertyIndex()
265 int ret = Interop.GaussianBlurView.GetBlurStrengthPropertyIndex(SwigCPtr);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 internal void SetBackgroundColor(Vector4 color)
273 Interop.GaussianBlurView.SetBackgroundColor(SwigCPtr, Vector4.getCPtr(color));
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277 internal Vector4 GetBackgroundColor()
279 Vector4 ret = new Vector4(Interop.GaussianBlurView.GetBackgroundColor(SwigCPtr), true);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284 private GaussianBlurViewSignal FinishedSignal()
286 GaussianBlurViewSignal ret = new GaussianBlurViewSignal(Interop.GaussianBlurView.FinishedSignal(SwigCPtr), false);
287 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 internal void SetUserImageAndOutputRenderTarget(Texture inputTexture, FrameBuffer outputRenderTarget)
293 Interop.GaussianBlurView.SetUserImageAndOutputRenderTarget(SwigCPtr, Texture.getCPtr(inputTexture), FrameBuffer.getCPtr(outputRenderTarget));
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();