From fe7bb3a94379000569e12c3385cc3961d194d612 Mon Sep 17 00:00:00 2001 From: Eunki Hong Date: Fri, 8 Dec 2023 01:59:37 +0900 Subject: [PATCH] [NUI] Make ensure ImageView._resourceUrl is latest Previous code didn't assume that _resourceUrl value of ImageView was not a latest. - If we set ImageView by ```Image``` property, the _resourceUrl was updated when cached map updating. - When we try to get ResourceUrl gettor, we ask to cached map always. But PropertyValue.Get(out string) might spend long time if the URL length is long. It will make useless string copy, what we can reduce. Now We make every logic make ensure that _resourceUrl stored valid resource url. If this is validated, we can reduce some C# - Native networking. Signed-off-by: Eunki Hong --- .../src/public/BaseComponents/ImageView.cs | 88 ++++++++++++++++------ .../BaseComponents/ImageViewBindableProperty.cs | 15 +--- 2 files changed, 68 insertions(+), 35 deletions(-) diff --git a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs index 407d042..0611ba1 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs @@ -39,6 +39,7 @@ namespace Tizen.NUI.BaseComponents Property.Preload(); // Do nothing. Just call for load static values. var temporalCachedImagePropertyKeyList = cachedImagePropertyKeyList; + var temporalCachedNUIImageViewPropertyKeyList = cachedNUIImageViewPropertyKeyList; } private EventHandler _resourceReadyEventHandler; @@ -83,15 +84,26 @@ namespace Tizen.NUI.BaseComponents NpatchImageVisualProperty.Border, NpatchImageVisualProperty.BorderOnly, }; + + // Collection of image-sensitive properties, and need to update C# side cache value. + private static readonly List cachedNUIImageViewPropertyKeyList = new List { + ImageVisualProperty.URL, + ImageVisualProperty.DesiredWidth, + ImageVisualProperty.DesiredHeight, + ImageVisualProperty.FastTrackUploading, + }; internal PropertyMap cachedImagePropertyMap; internal bool imagePropertyUpdatedFlag = false; private bool imagePropertyUpdateProcessAttachedFlag = false; private Rectangle _border; + + // Development Guide : Please make ensure that these 4 values are matched with current image. private string _resourceUrl = ""; private int _desired_width = -1; private int _desired_height = -1; private bool _fastTrackUploading = false; + private TriggerableSelector resourceUrlSelector; private TriggerableSelector borderSelector; @@ -381,17 +393,9 @@ namespace Tizen.NUI.BaseComponents { if (_border == null) { - PropertyValue setValue = new Tizen.NUI.PropertyValue(value); - SetProperty(ImageView.Property.IMAGE, setValue); - - // Image properties are changed hardly. We should ignore lazy UpdateImage - imagePropertyUpdatedFlag = false; - cachedImagePropertyMap?.Dispose(); - cachedImagePropertyMap = null; - MergeCachedImageVisualProperty(value); + SetImageByPropertyMap(value); NotifyPropertyChanged(); - setValue?.Dispose(); } } } @@ -1486,14 +1490,14 @@ namespace Tizen.NUI.BaseComponents { if (_resourceUrl != ConvertResourceUrl(ref value)) { - _resourceUrl = value; - if (string.IsNullOrEmpty(_resourceUrl)) + if (string.IsNullOrEmpty(value)) { // Special case. If we set ResourceUrl as empty, Unregist visual. RemoveImage(); } else { + _resourceUrl = value; using (PropertyValue setValue = new PropertyValue(value)) { UpdateImage(ImageVisualProperty.URL, setValue); @@ -1527,9 +1531,7 @@ namespace Tizen.NUI.BaseComponents { // If previous resourceUrl was already empty, we don't need to do anything. just ignore. // Unregist and detach process only if previous resourceUrl was not empty - string currentResourceUrl = ""; - PropertyValue currentResourceUrlValue = GetCachedImageVisualProperty(ImageVisualProperty.URL); - if ((currentResourceUrlValue?.Get(out currentResourceUrl) ?? false) && !string.IsNullOrEmpty(currentResourceUrl)) + if (!string.IsNullOrEmpty(_resourceUrl)) { PropertyValue emptyValue = new PropertyValue(); @@ -1544,13 +1546,58 @@ namespace Tizen.NUI.BaseComponents imagePropertyUpdateProcessAttachedFlag = false; } // Update resourceUrl as empty value + _resourceUrl = ""; cachedImagePropertyMap[ImageVisualProperty.URL] = emptyValue; - - emptyValue?.Dispose(); } - currentResourceUrlValue?.Dispose(); } + internal void SetImageByPropertyMap(PropertyMap map) + { + // Image properties are changed hardly. We should ignore lazy UpdateImage + imagePropertyUpdatedFlag = false; + cachedImagePropertyMap?.Dispose(); + cachedImagePropertyMap = null; + MergeCachedImageVisualProperty(map); + + // Update _resourceUrl, _desired_width, _desired_height, _fastTrackUploading here. + // Those values are C# side cached value. + _desired_width = _desired_height = -1; + _fastTrackUploading = false; + + if (map != null) + { + _resourceUrl = ""; + foreach (int key in cachedNUIImageViewPropertyKeyList) + { + using PropertyValue propertyValue = map.Find(key); + if (propertyValue != null) + { + if (key == ImageVisualProperty.URL) + { + propertyValue.Get(out _resourceUrl); + } + else if (key == ImageVisualProperty.DesiredWidth) + { + propertyValue.Get(out _desired_width); + } + else if (key == ImageVisualProperty.DesiredHeight) + { + propertyValue.Get(out _desired_height); + } + else if (key == ImageVisualProperty.FastTrackUploading) + { + propertyValue.Get(out _fastTrackUploading); + } + } + } + + SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map)); + } + else + { + RemoveImage(); + } + } /// /// Lazy call to UpdateImage. /// Collect Properties need to be update, and set properties that starts the Processing. @@ -1689,7 +1736,7 @@ namespace Tizen.NUI.BaseComponents // TODO : Couldn't we do this job in dali-engine side. if (_desired_width != -1 && _desired_height != -1) { - if (_resourceUrl != null) + if (!string.IsNullOrEmpty(_resourceUrl)) { Size2D imageSize = ImageLoader.GetOriginalImageSize(_resourceUrl, true); if (imageSize.Height > 0 && imageSize.Width > 0 && _desired_width > 0 && _desired_height > 0) @@ -1800,11 +1847,6 @@ namespace Tizen.NUI.BaseComponents { // Update-or-Insert new value cachedImagePropertyMap[key] = value; - if (key == ImageVisualProperty.URL) - { - // Special case. If key is Url, update _resourceUrl here. - value.Get(out _resourceUrl); - } } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/ImageViewBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/ImageViewBindableProperty.cs index f8b8613..ab6e689 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ImageViewBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ImageViewBindableProperty.cs @@ -42,11 +42,8 @@ namespace Tizen.NUI.BaseComponents defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => { var imageView = (ImageView)bindable; - string ret = ""; - imageView.GetCachedImageVisualProperty(ImageVisualProperty.URL)?.Get(out ret); - - return ret; + return imageView?._resourceUrl ?? ""; })); /// Intenal used, will never be opened. @@ -77,7 +74,7 @@ namespace Tizen.NUI.BaseComponents if (ret && alphaMaskURL.StartsWith("*Resource*")) { alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource); - mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(alphaMaskURL)); + mmap.Insert(NDalic.ImageVisualAlphaMaskUrl, new PropertyValue(alphaMaskURL)); } ret = false; @@ -93,13 +90,7 @@ namespace Tizen.NUI.BaseComponents } if (imageView._border == null) { - // Image properties are changed hardly. We should ignore lazy UpdateImage - imageView.imagePropertyUpdatedFlag = false; - imageView.cachedImagePropertyMap?.Dispose(); - imageView.cachedImagePropertyMap = null; - imageView.MergeCachedImageVisualProperty(map); - - Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map)); + imageView.SetImageByPropertyMap(map); } } }), -- 2.7.4