From 3648bfb4915a2c1982c4ab9e8a301d2365c034f1 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Wed, 26 Apr 2023 18:10:39 +0900 Subject: [PATCH] [NUI] Reuse internally created Key/Touch and reuse it To reduce the GC call for each Event getter, let we create Key/Touch only one time for each window, and reuse it. Signed-off-by: Eunki, Hong --- .../src/internal/Interop/Interop.Window.cs | 6 ++++++ src/Tizen.NUI/src/public/Window/Window.cs | 23 ++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.Window.cs b/src/Tizen.NUI/src/internal/Interop/Interop.Window.cs index d7b9acf..31fda4f 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.Window.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.Window.cs @@ -314,6 +314,12 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_GetLastTouchEvent")] public static extern global::System.IntPtr GetLastTouchEvent(global::System.Runtime.InteropServices.HandleRef window); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_InternalRetrievingLastKeyEvent")] + public static extern void InternalRetrievingLastKeyEvent(global::System.Runtime.InteropServices.HandleRef window, global::System.Runtime.InteropServices.HandleRef key); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_InternalRetrievingLastTouchEvent")] + public static extern void InternalRetrievingLastTouchEvent(global::System.Runtime.InteropServices.HandleRef window, global::System.Runtime.InteropServices.HandleRef touch); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_SetNeedsRotationCompletedAcknowledgement")] public static extern void SetNeedsRotationCompletedAcknowledgement(global::System.Runtime.InteropServices.HandleRef window, bool needAcknowledgement); diff --git a/src/Tizen.NUI/src/public/Window/Window.cs b/src/Tizen.NUI/src/public/Window/Window.cs index f844968..01e2ffd 100755 --- a/src/Tizen.NUI/src/public/Window/Window.cs +++ b/src/Tizen.NUI/src/public/Window/Window.cs @@ -41,6 +41,8 @@ namespace Tizen.NUI private string windowTitle; private List childLayers = new List(); private LayoutController localController; + private Key internalLastKeyEvent; + private Touch internalLastTouchEvent; static internal bool IsSupportedMultiWindow() { @@ -1849,9 +1851,13 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public Key GetLastKeyEvent() { - Key ret = new Key(Interop.Window.GetLastKeyEvent(SwigCPtr), false); + if(internalLastKeyEvent == null) + { + internalLastKeyEvent = new Key(); + } + Interop.Window.InternalRetrievingLastKeyEvent(SwigCPtr, internalLastKeyEvent.SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; + return internalLastKeyEvent; } /// @@ -1861,9 +1867,13 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public Touch GetLastTouchEvent() { - Touch ret = new Touch(Interop.Window.GetLastTouchEvent(SwigCPtr), false); + if(internalLastTouchEvent == null) + { + internalLastTouchEvent = new Touch(); + } + Interop.Window.InternalRetrievingLastTouchEvent(SwigCPtr, internalLastTouchEvent.SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; + return internalLastTouchEvent; } /// @@ -1947,6 +1957,11 @@ namespace Tizen.NUI childLayers.Clear(); localController?.Dispose(); + + internalLastKeyEvent?.Dispose(); + internalLastKeyEvent = null; + internalLastTouchEvent?.Dispose(); + internalLastTouchEvent = null; } -- 2.7.4