From 1d7d93845e15839fdf18ef36fb7a795392f64e5c Mon Sep 17 00:00:00 2001 From: "dongsug.song" Date: Mon, 18 Oct 2021 17:01:19 +0900 Subject: [PATCH] [NUI] Change for Size2D property to own internalSize2D which is cashed to prevent making repeated Size2D instance --- src/Tizen.NUI/Tizen.NUI.csproj | 7 +++ src/Tizen.NUI/Tizen.NUI.sln | 6 +++ src/Tizen.NUI/src/public/BaseComponents/View.cs | 13 ++--- .../public/BaseComponents/ViewBindableProperty.cs | 61 ++++++++++++++-------- .../src/public/BaseComponents/ViewEvent.cs | 13 +++-- .../src/public/BaseComponents/ViewInternal.cs | 2 + src/Tizen.NUI/src/public/Common/PropertyValue.cs | 38 ++++++++++++++ src/Tizen.NUI/src/public/Common/Size2D.cs | 36 +++++++++++++ 8 files changed, 141 insertions(+), 35 deletions(-) diff --git a/src/Tizen.NUI/Tizen.NUI.csproj b/src/Tizen.NUI/Tizen.NUI.csproj index 55bd751..7ff82e1 100755 --- a/src/Tizen.NUI/Tizen.NUI.csproj +++ b/src/Tizen.NUI/Tizen.NUI.csproj @@ -42,4 +42,11 @@ + + + + + diff --git a/src/Tizen.NUI/Tizen.NUI.sln b/src/Tizen.NUI/Tizen.NUI.sln index 382d9c5..e094980 100755 --- a/src/Tizen.NUI/Tizen.NUI.sln +++ b/src/Tizen.NUI/Tizen.NUI.sln @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Applications.Componen EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.System.Information", "..\Tizen.System.Information\Tizen.System.Information.csproj", "{AD4B56C0-01B2-4ED0-9DBD-6CF233D16FF4}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Applications.ThemeManager", "..\Tizen.Applications.ThemeManager\Tizen.Applications.ThemeManager.csproj", "{F57F6911-C581-49CA-80A5-9B5DDDAE3D40}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {AD4B56C0-01B2-4ED0-9DBD-6CF233D16FF4}.Debug|Any CPU.Build.0 = Debug|Any CPU {AD4B56C0-01B2-4ED0-9DBD-6CF233D16FF4}.Release|Any CPU.ActiveCfg = Release|Any CPU {AD4B56C0-01B2-4ED0-9DBD-6CF233D16FF4}.Release|Any CPU.Build.0 = Release|Any CPU + {F57F6911-C581-49CA-80A5-9B5DDDAE3D40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F57F6911-C581-49CA-80A5-9B5DDDAE3D40}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F57F6911-C581-49CA-80A5-9B5DDDAE3D40}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F57F6911-C581-49CA-80A5-9B5DDDAE3D40}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index f00d363..67091da 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -51,6 +51,9 @@ namespace Tizen.NUI.BaseComponents // List of constraints private Constraint widthConstraint = null; private Constraint heightConstraint = null; + + private Size2D internalSize2D = null; + static View() { RegisterPropertyGroup(PositionProperty, positionPropertyGroup); @@ -989,17 +992,15 @@ namespace Tizen.NUI.BaseComponents { get { - Size2D temp = (Size2D)GetValue(Size2DProperty); - int width = temp.Width; - int height = temp.Height; + var temp = (Size2D)GetValue(Size2DProperty); if (this.Layout == null) { - if (width < 0) { width = 0; } - if (height < 0) { height = 0; } + if (temp.Width < 0) { temp.Width = 0; } + if (temp.Height < 0) { temp.Height = 0; } } - return new Size2D(OnSize2DChanged, width, height); + return temp; } set { diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs index 755a331..38be66e 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs @@ -607,26 +607,43 @@ namespace Tizen.NUI.BaseComponents /// Size2DProperty /// [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty Size2DProperty = BindableProperty.Create(nameof(Size2D), typeof(Size2D), typeof(View), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) => - { - var view = (View)bindable; - if (newValue != null) + public static readonly BindableProperty Size2DProperty = BindableProperty.Create(nameof(Size2D), typeof(Size2D), typeof(View), null, + propertyChanged: ((bindable, oldValue, newValue) => { - Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.SIZE, new Tizen.NUI.PropertyValue(new Size((Size2D)newValue))); - view.widthPolicy = ((Size2D)newValue).Width; - view.heightPolicy = ((Size2D)newValue).Height; + View view = (View)bindable; + if (newValue != null) + { + view.SetSize(((Size2D)newValue).Width, ((Size2D)newValue).Height, 0); - view.layout?.RequestLayout(); - } - }), - defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => - { - var view = (View)bindable; - Size temp = new Size(0.0f, 0.0f, 0.0f); - Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.SIZE).Get(temp); - Size2D size = new Size2D((int)temp.Width, (int)temp.Height); - return size; - })); + view.widthPolicy = ((Size2D)newValue).Width; + view.heightPolicy = ((Size2D)newValue).Height; + + view.layout?.RequestLayout(); + } + }), + defaultValueCreator: ((bindable) => + { + View view = (View)bindable; + var tmp = new Size(0, 0, 0); + Object.GetProperty(view.SwigCPtr, Property.SIZE).Get(tmp); + + int tmpWidth = (int)tmp?.Width; + int tmpHeight = (int)tmp?.Height; + tmp?.Dispose(); + tmp = null; + + if (view.internalSize2D == null) + { + view.internalSize2D = new Size2D(view.OnSize2DChanged, tmpWidth, tmpHeight); + } + else + { + if (view.internalSize2D.Width != tmpWidth) { view.internalSize2D.Width = tmpWidth; } + if (view.internalSize2D.Height != tmpHeight) { view.internalSize2D.Height = tmpHeight; } + } + return view.internalSize2D; + }) + ); /// /// OpacityProperty @@ -1160,9 +1177,9 @@ namespace Tizen.NUI.BaseComponents var view = (View)bindable; if (newValue != null) { - if((ResizePolicyType)newValue == ResizePolicyType.KeepSizeFollowingParent) + if ((ResizePolicyType)newValue == ResizePolicyType.KeepSizeFollowingParent) { - if(view.widthConstraint == null) + if (view.widthConstraint == null) { view.widthConstraint = new EqualConstraintWithParentFloat((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.SizeWidth, View.Property.SizeWidth); view.widthConstraint.Apply(); @@ -1220,9 +1237,9 @@ namespace Tizen.NUI.BaseComponents var view = (View)bindable; if (newValue != null) { - if((ResizePolicyType)newValue == ResizePolicyType.KeepSizeFollowingParent) + if ((ResizePolicyType)newValue == ResizePolicyType.KeepSizeFollowingParent) { - if(view.heightConstraint == null) + if (view.heightConstraint == null) { view.heightConstraint = new EqualConstraintWithParentFloat((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.SizeHeight, View.Property.SizeHeight); view.heightConstraint.Apply(); diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs index dbb35d4..02dd2c3 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs @@ -710,19 +710,18 @@ namespace Tizen.NUI.BaseComponents private void OnSize2DChanged(int? width, int? height) { - PropertyValue temp; + PropertyValue temp = null; if (width != null) { - temp = new Tizen.NUI.PropertyValue((float)width); - Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeWidth, temp); - temp.Dispose(); + temp = new PropertyValue((float)width); + Object.SetProperty(SwigCPtr, Property.SizeWidth, temp); } if (height != null) { - temp = new Tizen.NUI.PropertyValue((float)height); - Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeHeight, temp); - temp.Dispose(); + temp = new PropertyValue((float)height); + Object.SetProperty(SwigCPtr, Property.SizeHeight, temp); } + temp?.Dispose(); } private void OnMinimumSizeChanged(int? width, int? height) diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs index e25aa9f..92f20cc 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs @@ -1120,6 +1120,8 @@ namespace Tizen.NUI.BaseComponents } //_mergedStyle = null; + + internalSize2D?.Dispose(); if (type == DisposeTypes.Explicit) { diff --git a/src/Tizen.NUI/src/public/Common/PropertyValue.cs b/src/Tizen.NUI/src/public/Common/PropertyValue.cs index 78499e3..1de77d9 100755 --- a/src/Tizen.NUI/src/public/Common/PropertyValue.cs +++ b/src/Tizen.NUI/src/public/Common/PropertyValue.cs @@ -15,6 +15,7 @@ * */ +using System; using System.ComponentModel; namespace Tizen.NUI @@ -243,6 +244,43 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } + + /// + /// Hidden API (Inhouse API). + /// Dispose. + /// + /// + /// Following the guide of https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose. + /// This will replace "protected virtual void Dispose(DisposeTypes type)" which is exactly same in functionality. + /// + /// true in order to free managed objects + // Protected implementation of Dispose pattern. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void Dispose(bool disposing) + { + if (disposed) + { + return; + } + + //perform dipose here without being added to DisposeQueue. + if (SwigCMemOwn && SwigCPtr.Handle != IntPtr.Zero) + { + if (disposing) + { + base.Dispose(DisposeTypes.Explicit); + } + else + { + base.Dispose(DisposeTypes.Implicit); + } + } + + base.Dispose(disposing); + } + + + /// /// An extension to the property value class that allows us to create a /// Property value from a C# object, for example, integer, float, or string.
diff --git a/src/Tizen.NUI/src/public/Common/Size2D.cs b/src/Tizen.NUI/src/public/Common/Size2D.cs index 782e112..d50854f 100755 --- a/src/Tizen.NUI/src/public/Common/Size2D.cs +++ b/src/Tizen.NUI/src/public/Common/Size2D.cs @@ -69,6 +69,42 @@ namespace Tizen.NUI internal delegate void Size2DChangedCallback(int? width, int? height); /// + /// Hidden API (Inhouse API). + /// Dispose. + /// + /// + /// Following the guide of https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose. + /// This will replace "protected virtual void Dispose(DisposeTypes type)" which is exactly same in functionality. + /// + /// true in order to free managed objects + // Protected implementation of Dispose pattern. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void Dispose(bool disposing) + { + if (disposed) + { + return; + } + + callback = null; + + //perform dipose here without being added to DisposeQueue. + if (SwigCMemOwn && SwigCPtr.Handle != IntPtr.Zero) + { + if (disposing) + { + base.Dispose(DisposeTypes.Explicit); + } + else + { + base.Dispose(DisposeTypes.Implicit); + } + } + + base.Dispose(disposing); + } + + /// /// The property for the width component of a size. /// /// -- 2.7.4