[NUI] Applicatoin.FlushUpdateMessage
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 21 Aug 2023 01:44:28 +0000 (10:44 +0900)
committerSeoyeon2Kim <34738918+Seoyeon2Kim@users.noreply.github.com>
Tue, 22 Aug 2023 06:52:05 +0000 (15:52 +0900)
Add new API to relayout & flush update/render thread messages.

It is for advanced app developer.
This API will flush all queued messages and rendering well.
But if we call it frequency, it will occure main thread overhead.

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/internal/Application/Application.cs
src/Tizen.NUI/src/internal/Interop/Interop.Application.cs
src/Tizen.NUI/src/public/Application/NUIApplication.cs
src/Tizen.NUI/src/public/Application/NUIWidgetApplication.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DaliDemo/DaliDemo.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/FlushApplicationMessageSample.cs [new file with mode: 0644]

index e296361..ec28235 100755 (executable)
@@ -1845,6 +1845,12 @@ namespace Tizen.NUI
             return ret;
         }
 
+        public void FlushUpdateMessages()
+        {
+            Interop.Application.FlushUpdateMessages(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
         [EditorBrowsable(EditorBrowsableState.Never)]
         public static List<Window> GetWindowList()
         {
index 3c87e70..d453dba 100755 (executable)
@@ -98,6 +98,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Application_New_WithWindowData")]
             public static extern global::System.IntPtr New(int argc, string argv, string styleSheet, bool uiThread, global::System.Runtime.InteropServices.HandleRef windowData);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Application_FlushUpdateMessages")]
+            public static extern void FlushUpdateMessages(global::System.Runtime.InteropServices.HandleRef jarg1);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GetScreenSize")]
             public static extern global::System.IntPtr GetScreenSize();
         }
index c38af3a..457b591 100755 (executable)
@@ -469,6 +469,20 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Flush render/update thread messages synchronously.
+        /// </summary>
+        /// <remarks>
+        /// This function will relayout forcibily.
+        /// This function is used for advanced developer. It will make main-thread overhead if you call this function frequencely.
+        /// </remarks>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void FlushUpdateMessages()
+        {
+            ApplicationHandle.FlushUpdateMessages();
+        }
+
+        /// <summary>
         /// Sets the number of frames per render.
         /// </summary>
         /// <param name="numberOfVSyncsPerRender">The number of vsyncs between successive renders.</param>
index 0ffc3a1..81ab91c 100755 (executable)
@@ -125,6 +125,20 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Flush render/update thread messages synchronously.
+        /// </summary>
+        /// <remarks>
+        /// This function will relayout forcibily.
+        /// This function is used for advanced developer. It will make main-thread overhead if you call this function frequencely.
+        /// </remarks>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void FlushUpdateMessages()
+        {
+            ApplicationHandle.FlushUpdateMessages();
+        }
+
+        /// <summary>
         /// Overrides this method if want to handle OnLocaleChanged behavior.
         /// </summary>
         /// <since_tizen> 4 </since_tizen>
index 86d9f89..0e530c5 100755 (executable)
@@ -76,6 +76,11 @@ namespace Tizen.NUI.Samples
                 string exceptionMessage = "Unknown!";
                 try
                 {
+                    // Hard coding to set NUIApplication into IExample
+                    if(name == "Tizen.NUI.Samples.FlushApplicationMessageSample")
+                    {
+                        (example as FlushApplicationMessageSample)?.SetCurrentApplication(this);
+                    }
                     example.Activate();
                 }
                 catch (Exception e)
diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/FlushApplicationMessageSample.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/FlushApplicationMessageSample.cs
new file mode 100644 (file)
index 0000000..3b08462
--- /dev/null
@@ -0,0 +1,69 @@
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+using System.Threading;
+
+namespace Tizen.NUI.Samples
+{
+    public class FlushApplicationMessageSample : IExample
+    {
+        private View root;
+        private TextLabel textLabel;
+        private NUIApplication application;
+
+        public void SetCurrentApplication(Tizen.NUI.NUIApplication application)
+        {
+            Tizen.Log.Error("NUITEST", $"SetCurrentApplication {application}\n");
+            this.application = application;
+        }
+
+        public Tizen.NUI.NUIApplication GetCurrentApplication()
+        {
+            Tizen.Log.Error("NUITEST", $"GetCurrentApplication {application}\n");
+            return application;
+        }
+
+        public void Activate()
+        {
+            Window window = NUIApplication.GetDefaultWindow();
+
+            root = new View()
+            {
+                Size = window.Size,
+                BackgroundColor = new Color(0.8f, 0.8f, 0.8f, 0.6f),
+                ParentOrigin = ParentOrigin.Center,
+                PivotPoint = PivotPoint.Center,
+                PositionUsesPivotPoint = true,
+            };
+            window.Add(root);
+
+            textLabel = new TextLabel()
+            {
+                Text = "SceneOn",
+            };
+
+            root.Add(textLabel);
+            Tizen.Log.Error("NUITEST", "SceneOn\n");
+
+            textLabel.Text = "Sleep 5 seconds";
+
+            GetCurrentApplication()?.FlushUpdateMessages();
+            Tizen.Log.Error("NUITEST", "FlushUpdateMessages\n");
+
+            Tizen.Log.Error("NUITEST", "Sleep 5 seconds\n");
+            Thread.Sleep(5000); /// sleep 5 seconds
+            Tizen.Log.Error("NUITEST", "Sleep done\n");
+
+            textLabel.Text = "Sleep done!\n";
+        }
+
+        public void Deactivate()
+        {
+            if (root != null)
+            {
+                NUIApplication.GetDefaultWindow().Remove(root);
+                root.Dispose();
+            }
+        }
+    }
+}