[NUI] (CanvasView) Support rasterization request manually + rasterization asychronously
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 18 Jun 2024 04:33:49 +0000 (13:33 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 26 Jun 2024 11:10:20 +0000 (20:10 +0900)
Let we allow to user request rasterizatoin manually, not for automatically updated engine side.

If we set that value as true, RequestRasterization should be called.

required dali patch:
https://review.tizen.org/gerrit/c/platform/core/uifw/dali-toolkit/+/312975
https://review.tizen.org/gerrit/c/platform/core/uifw/dali-csharp-binder/+/312976

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/internal/Interop/Interop.CanvasView.cs
src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/CanvasView.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CanvasViewSample.cs

index 2ba1520..88ae53f 100755 (executable)
@@ -41,8 +41,17 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_CanvasView_RemoveAllDrawables")]
             public static extern void RemoveAllDrawables(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_CanvasView_RequestRasterization")]
+            public static extern void RequestRasterization(global::System.Runtime.InteropServices.HandleRef jarg1);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_CanvasView_Property_VIEWBOX_get")]
             public static extern int PropertyViewBoxGet();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_CanvasView_Property_SYNCHRONOUS_LOADING_get")]
+            public static extern int PropertySynchronousLoadingGet();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_CanvasView_Property_RASTERIZATION_REQUEST_MANUALLY_get")]
+            public static extern int PropertyRasterizationRequestManuallyGet();
         }
     }
 }
index a9f6cf2..9537eea 100755 (executable)
@@ -49,12 +49,54 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
             return instance.InternalViewBox;
         }
 
+        /// <summary>
+        /// SynchronousLoadingProperty
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static BindableProperty SynchronousLoadingProperty = null;
+        internal static void SetInternalSynchronousLoadingProperty(BindableObject bindable, object oldValue, object newValue)
+        {
+            var instance = (Tizen.NUI.BaseComponents.VectorGraphics.CanvasView)bindable;
+            if (newValue != null)
+            {
+                instance.InternalSynchronousLoading = (bool)newValue;
+            }
+        }
+        internal static object GetInternalSynchronousLoadingProperty(BindableObject bindable)
+        {
+            var instance = (Tizen.NUI.BaseComponents.VectorGraphics.CanvasView)bindable;
+            return instance.InternalSynchronousLoading;
+        }
+
+        /// <summary>
+        /// RasterizationRequestManuallyProperty
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static BindableProperty RasterizationRequestManuallyProperty = null;
+        internal static void SetInternalRasterizationRequestManuallyProperty(BindableObject bindable, object oldValue, object newValue)
+        {
+            var instance = (Tizen.NUI.BaseComponents.VectorGraphics.CanvasView)bindable;
+            if (newValue != null)
+            {
+                instance.InternalRasterizationRequestManually = (bool)newValue;
+            }
+        }
+        internal static object GetInternalRasterizationRequestManuallyProperty(BindableObject bindable)
+        {
+            var instance = (Tizen.NUI.BaseComponents.VectorGraphics.CanvasView)bindable;
+            return instance.InternalRasterizationRequestManually;
+        }
+
         static CanvasView()
         {
             if (NUIApplication.IsUsingXaml)
             {
                 ViewBoxProperty = BindableProperty.Create(nameof(ViewBox), typeof(Tizen.NUI.Size2D), typeof(Tizen.NUI.BaseComponents.VectorGraphics.CanvasView), null,
                   propertyChanged: SetInternalViewBoxProperty, defaultValueCreator: GetInternalViewBoxProperty);
+                SynchronousLoadingProperty = BindableProperty.Create(nameof(ViewBox), typeof(bool), typeof(Tizen.NUI.BaseComponents.VectorGraphics.CanvasView), true,
+                  propertyChanged: SetInternalSynchronousLoadingProperty, defaultValueCreator: GetInternalSynchronousLoadingProperty);
+                RasterizationRequestManuallyProperty = BindableProperty.Create(nameof(ViewBox), typeof(bool), typeof(Tizen.NUI.BaseComponents.VectorGraphics.CanvasView), false,
+                  propertyChanged: SetInternalRasterizationRequestManuallyProperty, defaultValueCreator: GetInternalRasterizationRequestManuallyProperty);
             }
         }
 
@@ -170,6 +212,110 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
         }
 
         /// <summary>
+        /// Whether we rasterize CanvasView synchronously or not.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool SynchronousLoading
+        {
+            get
+            {
+                if (NUIApplication.IsUsingXaml)
+                {
+                    return (bool)GetValue(SynchronousLoadingProperty);
+                }
+                else
+                {
+                    return (bool)GetInternalSynchronousLoadingProperty(this);
+                }
+            }
+            set
+            {
+                if (NUIApplication.IsUsingXaml)
+                {
+                    SetValue(SynchronousLoadingProperty, value);
+                }
+                else
+                {
+                    SetInternalSynchronousLoadingProperty(this, null, value);
+                }
+                NotifyPropertyChanged();
+            }
+        }
+
+        private bool InternalSynchronousLoading
+        {
+            get
+            {
+                bool retVal = true;
+                PropertyValue synchronousLoadingPropertyValue = GetProperty(Interop.CanvasView.PropertySynchronousLoadingGet());
+                synchronousLoadingPropertyValue?.Get(out retVal);
+                synchronousLoadingPropertyValue?.Dispose();
+                return retVal;
+            }
+            set
+            {
+                PropertyValue setVal = new Tizen.NUI.PropertyValue(value);
+                SetProperty(Interop.CanvasView.PropertySynchronousLoadingGet(), setVal);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                setVal?.Dispose();
+            }
+        }
+
+        /// <summary>
+        /// Whether we rasterize CanvasView manually or not.
+        /// </summary>
+        /// <remarks>
+        /// If true, need to call <see cref="RequestRasterization()"/> to rasterize CanvasView.
+        /// If false, CanvasView will be rasterized automatically even if we don't call <see cref="RequestRasterization()"/>.
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool RasterizationRequestManually
+        {
+            get
+            {
+                if (NUIApplication.IsUsingXaml)
+                {
+                    return (bool)GetValue(RasterizationRequestManuallyProperty);
+                }
+                else
+                {
+                    return (bool)GetInternalRasterizationRequestManuallyProperty(this);
+                }
+            }
+            set
+            {
+                if (NUIApplication.IsUsingXaml)
+                {
+                    SetValue(RasterizationRequestManuallyProperty, value);
+                }
+                else
+                {
+                    SetInternalRasterizationRequestManuallyProperty(this, null, value);
+                }
+                NotifyPropertyChanged();
+            }
+        }
+
+        private bool InternalRasterizationRequestManually
+        {
+            get
+            {
+                bool retVal = false;
+                PropertyValue rasterizationRequestManuallyValue = GetProperty(Interop.CanvasView.PropertyRasterizationRequestManuallyGet());
+                rasterizationRequestManuallyValue?.Get(out retVal);
+                rasterizationRequestManuallyValue?.Dispose();
+                return retVal;
+            }
+            set
+            {
+                PropertyValue setVal = new Tizen.NUI.PropertyValue(value);
+                SetProperty(Interop.CanvasView.PropertyRasterizationRequestManuallyGet(), setVal);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                setVal?.Dispose();
+            }
+        }
+
+        /// <summary>
         /// Add drawable object to the CanvasView.
         /// This method is similar to registration. The added shape is drawn on the inner canvas.
         /// </summary>
@@ -218,5 +364,15 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             drawables.Clear();
         }
+
+        /// <summary>
+        /// Reqeust rasterization manually to the CanvasView.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void RequestRasterization()
+        {
+            Interop.CanvasView.RequestRasterization(View.getCPtr(this));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
     }
 }
index 63b3c34..5970c50 100644 (file)
@@ -37,6 +37,8 @@ namespace Tizen.NUI.Samples
             };
             window.Add(root);
 
+            window.KeyEvent += WindowKeyEvent;
+
             canvasView = new CanvasView(window.Size)
             {
                 Size = window.Size,
@@ -262,9 +264,12 @@ namespace Tizen.NUI.Samples
         {
             if (root != null)
             {
-                timer.Stop();
-                NUIApplication.GetDefaultWindow().Remove(root);
-                canvasView.Dispose();
+                Window window = NUIApplication.GetDefaultWindow();
+                window.KeyEvent -= WindowKeyEvent;
+                window.Remove(root);
+
+                timer?.Stop();
+                canvasView?.Dispose();
                 root.Dispose();
             }
         }
@@ -289,7 +294,29 @@ namespace Tizen.NUI.Samples
 
             count++;
 
+            if(canvasView.RasterizationRequestManually)
+            {
+                canvasView.RequestRasterization();
+            }
+
             return true;
         }
+
+        private void WindowKeyEvent(object sender, Window.KeyEventArgs e)
+        {
+            if (e.Key.State == Key.StateType.Down)
+            {
+                if (e.Key.KeyPressedName == "1")
+                {
+                    canvasView.SynchronousLoading =!canvasView.SynchronousLoading;
+                    log.Error(tag, $"CanvasView.SynchronousLoading --> {canvasView.SynchronousLoading}\n");
+                }
+                else if (e.Key.KeyPressedName == "2")
+                {
+                    canvasView.RasterizationRequestManually =!canvasView.RasterizationRequestManually;
+                    log.Error(tag, $"CanvasView.RasterizationRequestManually --> {canvasView.RasterizationRequestManually}\n");
+                }
+            }
+        }
     }
 }