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 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public static readonly BindableProperty GaussianBlurViewProperty = BindableProperty.Create(nameof(BlurStrength), typeof(float), typeof(GaussianBlurView), default(float), propertyChanged: (bindable, oldValue, newValue) =>
37 var gaussianBlurView = (GaussianBlurView)bindable;
40 Tizen.NUI.Object.SetProperty(gaussianBlurView.swigCPtr, gaussianBlurView.GetBlurStrengthPropertyIndex(), new Tizen.NUI.PropertyValue((float)newValue));
43 defaultValueCreator: (bindable) =>
45 var gaussianBlurView = (GaussianBlurView)bindable;
47 Tizen.NUI.Object.GetProperty(gaussianBlurView.swigCPtr, gaussianBlurView.GetBlurStrengthPropertyIndex()).Get(out temp);
50 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
52 internal GaussianBlurView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
54 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
57 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(GaussianBlurView obj)
59 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
62 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
64 Interop.GaussianBlurView.DeleteGaussianBlurView(swigCPtr);
68 /// Dispose GaussianBlurView and all children on it.
70 /// <param name="type">Dispose type.</param>
71 /// <since_tizen> 6 </since_tizen>
72 protected override void Dispose(DisposeTypes type)
79 //Release your own unmanaged resources here.
80 //You should not access any managed member here except static instance.
81 //because the execution order of Finalizes is non-deterministic.
82 if (finishedCallback != null)
84 FinishedSignal().Disconnect(finishedCallback);
90 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
91 private delegate void FinishedCallbackType(IntPtr application);
92 private DaliEventHandler<object, EventArgs> finishedEventHandler;
93 private FinishedCallbackType finishedCallback;
96 /// If ActivateOnce has been called, then connect to this signal to be notified when the target actor has been rendered.
98 /// <since_tizen> 6 </since_tizen>
99 [EditorBrowsable(EditorBrowsableState.Never)]
100 public event DaliEventHandler<object, EventArgs> Finished
104 // Restricted to only one listener
105 if (finishedEventHandler == null)
107 finishedCallback = new FinishedCallbackType(OnFinished);
108 FinishedSignal().Connect(finishedCallback);
110 finishedEventHandler += value;
115 finishedEventHandler -= value;
117 if (finishedEventHandler == null && FinishedSignal().Empty() == false)
119 FinishedSignal().Disconnect(finishedCallback);
124 // Callback for GaussianBlurView FinishedSignal
125 private void OnFinished(IntPtr data)
127 EventArgs e = new EventArgs();
129 if (finishedEventHandler != null)
131 //here we send all data to user event handlers
132 finishedEventHandler(this, e);
137 /// The BlurStrength property. A value of 0.0 is zero blur and 1.0 is full blur. Default is 1.0.
138 /// if you set the blur to 0.0, the result will be no blur BUT the internal rendering will still be happening.
139 /// If you wish to turn the blur off, you should remove the GaussianBlurView object from the window also.
141 /// <since_tizen> 6 </since_tizen>
142 [EditorBrowsable(EditorBrowsableState.Never)]
143 public float BlurStrength
147 return (float)GetValue(GaussianBlurViewProperty);
151 SetValue(GaussianBlurViewProperty, value);
152 NotifyPropertyChanged();
159 [EditorBrowsable(EditorBrowsableState.Never)]
160 public GaussianBlurView() : this(Interop.GaussianBlurView.New(), true)
162 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
166 /// Constructor with parameters.
168 /// <param name="numSamples">The size of the Gaussian blur kernel (number of samples in horizontal / vertical blur directions)</param>
169 /// <param name="blurBellCurveWidth">
170 /// 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
171 /// 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
172 /// 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
173 /// 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
174 /// have close to zero weights.
176 /// <param name="renderTargetPixelFormat">The pixel format of the render targets we are using to perform the blur.</param>
177 /// <param name="downsampleWidthScale">
178 /// width scale factor applied during the blur process, scaling the size of the source image to the size of the final blurred image output.
179 /// Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
181 /// <param name="downsampleHeightScale">
182 /// 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.
183 /// Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
185 /// <param name="blurUserImage">
186 /// 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
187 /// SetUserImageAndOutputRenderTarget().
189 /// <since_tizen> 6 </since_tizen>
190 [EditorBrowsable(EditorBrowsableState.Never)]
191 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)
193 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199 /// <since_tizen> 6 </since_tizen>
200 [EditorBrowsable(EditorBrowsableState.Never)]
201 public GaussianBlurView(GaussianBlurView handle) : this(Interop.GaussianBlurView.NewGaussianBlurView(GaussianBlurView.getCPtr(handle)), true)
203 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207 /// Start rendering the GaussianBlurView. Must be called after you Add() it to the window.
209 /// <since_tizen> 6 </since_tizen>
210 [EditorBrowsable(EditorBrowsableState.Never)]
211 public void Activate()
213 Interop.GaussianBlurView.Activate(swigCPtr);
214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218 /// Render the GaussianBlurView once.
219 /// Must be called after you Add() it to the window.
220 /// Listen to the Finished signal to determine when the rendering has completed.
222 /// <since_tizen> 6 </since_tizen>
223 [EditorBrowsable(EditorBrowsableState.Never)]
224 public void ActivateOnce()
226 Interop.GaussianBlurView.ActivateOnce(swigCPtr);
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231 /// Stop rendering the GaussianBlurView. Must be called after you Remove() it from the window.
233 /// <since_tizen> 6 </since_tizen>
234 [EditorBrowsable(EditorBrowsableState.Never)]
235 public void Deactivate()
237 Interop.GaussianBlurView.Deactivate(swigCPtr);
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241 private int GetBlurStrengthPropertyIndex()
243 int ret = Interop.GaussianBlurView.GetBlurStrengthPropertyIndex(swigCPtr);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 internal void SetBackgroundColor(Vector4 color)
251 Interop.GaussianBlurView.SetBackgroundColor(swigCPtr, Vector4.getCPtr(color));
252 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255 internal Vector4 GetBackgroundColor()
257 Vector4 ret = new Vector4(Interop.GaussianBlurView.GetBackgroundColor(swigCPtr), true);
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262 private GaussianBlurViewSignal FinishedSignal()
264 GaussianBlurViewSignal ret = new GaussianBlurViewSignal(Interop.GaussianBlurView.FinishedSignal(swigCPtr), false);
265 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269 internal void SetUserImageAndOutputRenderTarget(Texture inputTexture, FrameBuffer outputRenderTarget)
271 Interop.GaussianBlurView.SetUserImageAndOutputRenderTarget(swigCPtr, Texture.getCPtr(inputTexture), FrameBuffer.getCPtr(outputRenderTarget));
272 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();