From 7c0d8442af66e707ef10f6d2ce9847a1c58a6958 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Mon, 21 Aug 2023 10:44:28 +0900 Subject: [PATCH] [NUI] Applicatoin.FlushUpdateMessage 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 --- .../src/internal/Application/Application.cs | 6 ++ .../src/internal/Interop/Interop.Application.cs | 3 + .../src/public/Application/NUIApplication.cs | 14 +++++ .../src/public/Application/NUIWidgetApplication.cs | 14 +++++ .../Tizen.NUI.Samples/Samples/DaliDemo/DaliDemo.cs | 5 ++ .../Samples/FlushApplicationMessageSample.cs | 69 ++++++++++++++++++++++ 6 files changed, 111 insertions(+) create mode 100644 test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/FlushApplicationMessageSample.cs diff --git a/src/Tizen.NUI/src/internal/Application/Application.cs b/src/Tizen.NUI/src/internal/Application/Application.cs index e296361..ec28235 100755 --- a/src/Tizen.NUI/src/internal/Application/Application.cs +++ b/src/Tizen.NUI/src/internal/Application/Application.cs @@ -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 GetWindowList() { diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.Application.cs b/src/Tizen.NUI/src/internal/Interop/Interop.Application.cs index 3c87e70..d453dba 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.Application.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.Application.cs @@ -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(); } diff --git a/src/Tizen.NUI/src/public/Application/NUIApplication.cs b/src/Tizen.NUI/src/public/Application/NUIApplication.cs index c38af3a..457b591 100755 --- a/src/Tizen.NUI/src/public/Application/NUIApplication.cs +++ b/src/Tizen.NUI/src/public/Application/NUIApplication.cs @@ -469,6 +469,20 @@ namespace Tizen.NUI } /// + /// Flush render/update thread messages synchronously. + /// + /// + /// This function will relayout forcibily. + /// This function is used for advanced developer. It will make main-thread overhead if you call this function frequencely. + /// + // 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(); + } + + /// /// Sets the number of frames per render. /// /// The number of vsyncs between successive renders. diff --git a/src/Tizen.NUI/src/public/Application/NUIWidgetApplication.cs b/src/Tizen.NUI/src/public/Application/NUIWidgetApplication.cs index 0ffc3a1..81ab91c 100755 --- a/src/Tizen.NUI/src/public/Application/NUIWidgetApplication.cs +++ b/src/Tizen.NUI/src/public/Application/NUIWidgetApplication.cs @@ -125,6 +125,20 @@ namespace Tizen.NUI } /// + /// Flush render/update thread messages synchronously. + /// + /// + /// This function will relayout forcibily. + /// This function is used for advanced developer. It will make main-thread overhead if you call this function frequencely. + /// + // 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(); + } + + /// /// Overrides this method if want to handle OnLocaleChanged behavior. /// /// 4 diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DaliDemo/DaliDemo.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DaliDemo/DaliDemo.cs index 86d9f89..0e530c5 100755 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DaliDemo/DaliDemo.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DaliDemo/DaliDemo.cs @@ -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 index 0000000..3b08462 --- /dev/null +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/FlushApplicationMessageSample.cs @@ -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(); + } + } + } +} -- 2.7.4