[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 e296361ec4e1247d2db94ac3edcbc20f202fcb91..ec28235ef6bd71c2f537b710278bc9165c578724 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 3c87e7057a495cc09e8f97fee6ad87ae67c47a6c..d453dba39ac66d6a674cf4a303b7571c9df489ca 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 c38af3a9c94256f3510488d6c81fa6c341c7a189..457b5916e093fa07e304a19959b31646dceeb13e 100755 (executable)
@@ -468,6 +468,20 @@ namespace Tizen.NUI
             return ((NUICoreBackend)this.Backend).AddIdle(func);
         }
 
+        /// <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>
index 0ffc3a13c5f776cd1a5e2233186084b24f4ebd06..81ab91c65302d7bec0edf48f150051d3068e11fc 100755 (executable)
@@ -124,6 +124,20 @@ namespace Tizen.NUI
             base.Exit();
         }
 
+        /// <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>
index 86d9f89eef0f9c246372c0e5f8fdf8ab4d2ebaed..0e530c5e63a08fc0e38fccf0097c4531b4c554a5 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();
+            }
+        }
+    }
+}