[NUI] Add GaussianBlurView (#1344)
authorneostom432 <31119276+neostom432@users.noreply.github.com>
Wed, 29 Jan 2020 11:32:37 +0000 (20:32 +0900)
committerGitHub <noreply@github.com>
Wed, 29 Jan 2020 11:32:37 +0000 (20:32 +0900)
* [NUI] Add GaussianBlurView

Add GaussianBlurView.

For now user can use this class internally, because APIs are all hidden.

* [NUI] make private function to internal in GaussianBlurView

Co-authored-by: krown <neostom432@nate.com>
src/Tizen.NUI/src/internal/GaussianBlurView.cs

index abc819e..fa49a21 100755 (executable)
 using System;
 using System.Runtime.InteropServices;
 using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
+
+using System.ComponentModel;
 
 namespace Tizen.NUI
 {
-    internal class GaussianBlurView : View
+    /// <summary>
+    /// GaussianBlurView is a class for applying a render process that blurs an image.
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class GaussianBlurView : View
     {
+        /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty GaussianBlurViewProperty = BindableProperty.Create(nameof(BlurStrength), typeof(float), typeof(GaussianBlurView), default(float), propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            var gaussianBlurView = (GaussianBlurView)bindable;
+            if (newValue != null)
+            {
+                Tizen.NUI.Object.SetProperty(gaussianBlurView.swigCPtr, gaussianBlurView.GetBlurStrengthPropertyIndex(), new Tizen.NUI.PropertyValue((float)newValue));
+            }
+        },
+        defaultValueCreator: (bindable) =>
+        {
+            var gaussianBlurView = (GaussianBlurView)bindable;
+            float temp;
+            Tizen.NUI.Object.GetProperty(gaussianBlurView.swigCPtr, gaussianBlurView.GetBlurStrengthPropertyIndex()).Get(out temp);
+            return temp;
+        });
+        private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
         internal GaussianBlurView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.GaussianBlurView.GaussianBlurView_SWIGUpcast(cPtr), cMemoryOwn)
         {
+            swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
         }
 
         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(GaussianBlurView obj)
@@ -37,57 +64,59 @@ namespace Tizen.NUI
             Interop.GaussianBlurView.delete_GaussianBlurView(swigCPtr);
         }
 
-        /// <since_tizen> 3 </since_tizen>
-        public class FinishedEventArgs : EventArgs
+        /// <summary>
+        /// Dispose GaussianBlurView and all children on it.
+        /// </summary>
+        /// <param name="type">Dispose type.</param>
+        /// <since_tizen> 6 </since_tizen>
+        protected override void Dispose(DisposeTypes type)
         {
-            private GaussianBlurView _gaussianBlurView;
+            if (disposed)
+            {
+                return;
+            }
 
-            /// <since_tizen> 3 </since_tizen>
-            public GaussianBlurView GaussianBlurView
+            //Release your own unmanaged resources here.
+            //You should not access any managed member here except static instance.
+            //because the execution order of Finalizes is non-deterministic.
+            if (_finishedCallback != null)
             {
-                get
-                {
-                    return _gaussianBlurView;
-                }
-                set
-                {
-                    _gaussianBlurView = value;
-                }
+                FinishedSignal().Disconnect(_finishedCallback);
             }
+
+            base.Dispose(type);
         }
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        private delegate void FinishedEventCallbackDelegate(IntPtr application);
-        private DaliEventHandler<object, FinishedEventArgs> _gaussianFinishedEventHandler;
-        private FinishedEventCallbackDelegate _gaussianFinishedEventCallbackDelegate;
+        private delegate void FinishedCallbackType(IntPtr application);
+        private DaliEventHandler<object, EventArgs> _finishedEventHandler;
+        private FinishedCallbackType _finishedCallback;
 
-        public event DaliEventHandler<object, FinishedEventArgs> Finished
+        /// <summary>
+        /// If ActivateOnce has been called, then connect to this signal to be notified when the target actor has been rendered.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event DaliEventHandler<object, EventArgs> Finished
         {
             add
             {
-                lock (this)
+                // Restricted to only one listener
+                if (_finishedEventHandler == null)
                 {
-                    // Restricted to only one listener
-                    if (_gaussianFinishedEventHandler == null)
-                    {
-                        _gaussianFinishedEventHandler += value;
-
-                        _gaussianFinishedEventCallbackDelegate = new FinishedEventCallbackDelegate(OnFinished);
-                        this.FinishedSignal().Connect(_gaussianFinishedEventCallbackDelegate);
-                    }
+                    _finishedCallback = new FinishedCallbackType(OnFinished);
+                    FinishedSignal().Connect(_finishedCallback);
                 }
+                _finishedEventHandler += value;
             }
 
             remove
             {
-                lock (this)
-                {
-                    if (_gaussianFinishedEventHandler != null)
-                    {
-                        this.FinishedSignal().Disconnect(_gaussianFinishedEventCallbackDelegate);
-                    }
+                _finishedEventHandler -= value;
 
-                    _gaussianFinishedEventHandler -= value;
+                if (_finishedEventHandler == null && FinishedSignal().Empty() == false)
+                {
+                    FinishedSignal().Disconnect(_finishedCallback);
                 }
             }
         }
@@ -95,118 +124,157 @@ namespace Tizen.NUI
         // Callback for GaussianBlurView FinishedSignal
         private void OnFinished(IntPtr data)
         {
-            FinishedEventArgs e = new FinishedEventArgs();
-
-            // Populate all members of "e" (FinishedEventArgs) with real data
-            e.GaussianBlurView = Registry.GetManagedBaseHandleFromNativePtr(data) as GaussianBlurView;
+            EventArgs e = new EventArgs();
 
-            if (_gaussianFinishedEventHandler != null)
+            if (_finishedEventHandler != null)
             {
                 //here we send all data to user event handlers
-                _gaussianFinishedEventHandler(this, e);
+                _finishedEventHandler(this, e);
             }
         }
 
-        public GaussianBlurView() : this(Interop.GaussianBlurView.GaussianBlurView_New__SWIG_0(), true)
+        /// <summary>
+        /// The BlurStrength property. A value of 0.0 is zero blur and 1.0 is full blur. Default is 1.0.
+        /// 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 the GaussianBlurView object from the window also.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public float BlurStrength
         {
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            get
+            {
+                return (float)GetValue(GaussianBlurViewProperty);
+            }
+            set
+            {
+                SetValue(GaussianBlurViewProperty, value);
+                NotifyPropertyChanged();
+            }
         }
 
-        public GaussianBlurView(uint numSamples, float blurBellCurveWidth, PixelFormat renderTargetPixelFormat, float downsampleWidthScale, float downsampleHeightScale, bool blurUserImage) : this(Interop.GaussianBlurView.GaussianBlurView_New__SWIG_1(numSamples, blurBellCurveWidth, (int)renderTargetPixelFormat, downsampleWidthScale, downsampleHeightScale, blurUserImage), true)
+        /// <summary>
+        /// Constructor
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public GaussianBlurView() : this(Interop.GaussianBlurView.GaussianBlurView_New__SWIG_0(), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        public GaussianBlurView(uint numSamples, float blurBellCurveWidth, PixelFormat renderTargetPixelFormat, float downsampleWidthScale, float downsampleHeightScale) : this(Interop.GaussianBlurView.GaussianBlurView_New__SWIG_2(numSamples, blurBellCurveWidth, (int)renderTargetPixelFormat, downsampleWidthScale, downsampleHeightScale), true)
+        /// <summary>
+        /// Constructor with parameters.
+        /// </summary>
+        /// <param name="numSamples">The size of the Gaussian blur kernel (number of samples in horizontal / vertical blur directions)</param>
+        /// <param name="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
+        /// 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
+        /// 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
+        /// 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
+        /// have close to zero weights.
+        /// </param>
+        /// <param name="renderTargetPixelFormat">The pixel format of the render targets we are using to perform the blur.</param>
+        /// <param name="downsampleWidthScale">
+        ///  width scale factor applied during the blur process, scaling the size of the source image to the size of the final blurred image output.
+        ///  Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
+        /// </param>
+        /// <param name="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.
+        /// Useful for downsampling - trades visual quality for processing speed. A value of 1.0f results in no scaling applied.
+        /// </param>
+        /// <param name="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
+        /// SetUserImageAndOutputRenderTarget().
+        /// </param>
+        /// <since_tizen> 6 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public GaussianBlurView(uint numSamples, float blurBellCurveWidth, PixelFormat renderTargetPixelFormat, float downsampleWidthScale, float downsampleHeightScale, bool blurUserImage) : this(Interop.GaussianBlurView.GaussianBlurView_New__SWIG_1(numSamples, blurBellCurveWidth, (int)renderTargetPixelFormat, downsampleWidthScale, downsampleHeightScale, blurUserImage), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        /// <summary>
+        /// Copy constructor
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public GaussianBlurView(GaussianBlurView handle) : this(Interop.GaussianBlurView.new_GaussianBlurView__SWIG_1(GaussianBlurView.getCPtr(handle)), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        public GaussianBlurView Assign(GaussianBlurView ZoomView)
-        {
-            GaussianBlurView ret = new GaussianBlurView(Interop.GaussianBlurView.GaussianBlurView_Assign(swigCPtr, GaussianBlurView.getCPtr(ZoomView)), false);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
-        }
-
-        public static GaussianBlurView DownCast(BaseHandle handle)
-        {
-            GaussianBlurView ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as GaussianBlurView;
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
-        }
-
-        public new void Add(View child)
-        {
-            Interop.GaussianBlurView.GaussianBlurView_Add(swigCPtr, View.getCPtr(child));
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
-        public new void Remove(View child)
-        {
-            Interop.GaussianBlurView.GaussianBlurView_Remove(swigCPtr, View.getCPtr(child));
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
+        /// <summary>
+        /// Start rendering the GaussianBlurView. Must be called after you Add() it to the window.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public void Activate()
         {
             Interop.GaussianBlurView.GaussianBlurView_Activate(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        /// <summary>
+        /// Render the GaussianBlurView once.
+        /// Must be called after you Add() it to the window.
+        /// Only works with a gaussian blur view created with blurUserImage = true.
+        /// Listen to the Finished signal to determine when the rendering has completed.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public void ActivateOnce()
         {
             Interop.GaussianBlurView.GaussianBlurView_ActivateOnce(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        /// <summary>
+        /// Stop rendering the GaussianBlurView. Must be called after you Remove() it from the window.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public void Deactivate()
         {
             Interop.GaussianBlurView.GaussianBlurView_Deactivate(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        public void SetUserImageAndOutputRenderTarget(Texture inputTexture, FrameBuffer outputRenderTarget)
+        private int GetBlurStrengthPropertyIndex()
         {
-            Interop.GaussianBlurView.GaussianBlurView_SetUserImageAndOutputRenderTarget(swigCPtr, Texture.getCPtr(inputTexture), FrameBuffer.getCPtr(outputRenderTarget));
+            int ret = Interop.GaussianBlurView.GaussianBlurView_GetBlurStrengthPropertyIndex(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
         }
 
-        public int GetBlurStrengthPropertyIndex()
+
+        internal void SetBackgroundColor(Vector4 color)
         {
-            int ret = Interop.GaussianBlurView.GaussianBlurView_GetBlurStrengthPropertyIndex(swigCPtr);
+            Interop.GaussianBlurView.GaussianBlurView_SetBackgroundColor(swigCPtr, Vector4.getCPtr(color));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
         }
 
-        public FrameBufferImage GetBlurredRenderTarget()
+        internal Vector4 GetBackgroundColor()
         {
-            FrameBufferImage ret = new FrameBufferImage(Interop.GaussianBlurView.GaussianBlurView_GetBlurredRenderTarget(swigCPtr), true);
+            Vector4 ret = new Vector4(Interop.GaussianBlurView.GaussianBlurView_GetBackgroundColor(swigCPtr), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
-        public void SetBackgroundColor(Vector4 color)
+        private GaussianBlurViewSignal FinishedSignal()
         {
-            Interop.GaussianBlurView.GaussianBlurView_SetBackgroundColor(swigCPtr, Vector4.getCPtr(color));
+            GaussianBlurViewSignal ret = new GaussianBlurViewSignal(Interop.GaussianBlurView.GaussianBlurView_FinishedSignal(swigCPtr), false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
         }
 
-        public Vector4 GetBackgroundColor()
+        internal void SetUserImageAndOutputRenderTarget(Texture inputTexture, FrameBuffer outputRenderTarget)
         {
-            Vector4 ret = new Vector4(Interop.GaussianBlurView.GaussianBlurView_GetBackgroundColor(swigCPtr), true);
+            Interop.GaussianBlurView.GaussianBlurView_SetUserImageAndOutputRenderTarget(swigCPtr, Texture.getCPtr(inputTexture), FrameBuffer.getCPtr(outputRenderTarget));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
         }
-
-        public GaussianBlurViewSignal FinishedSignal()
+        internal FrameBufferImage GetBlurredRenderTarget()
         {
-            GaussianBlurViewSignal ret = new GaussianBlurViewSignal(Interop.GaussianBlurView.GaussianBlurView_FinishedSignal(swigCPtr), false);
+            FrameBufferImage ret = new FrameBufferImage(Interop.GaussianBlurView.GaussianBlurView_GetBlurredRenderTarget(swigCPtr), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }