Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NUI] Create ImageVisual synchronously if AlphaMaskURL use generated ImageUrl #6520

Open
wants to merge 1 commit into
base: DevelNUI
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 93 additions & 15 deletions src/Tizen.NUI/src/public/BaseComponents/ImageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ private static string ConvertResourceUrl(ref string value)
// Collection of image-sensitive properties, and need to update C# side cache value.
private static readonly List<int> cachedNUIImageViewPropertyKeyList = new List<int> {
ImageVisualProperty.URL,
ImageVisualProperty.AlphaMaskURL,
ImageVisualProperty.DesiredWidth,
ImageVisualProperty.DesiredHeight,
ImageVisualProperty.FastTrackUploading,
Expand All @@ -155,8 +156,9 @@ private static string ConvertResourceUrl(ref string value)
private bool imagePropertyUpdateProcessAttachedFlag = false;
private Rectangle _border;

// Development Guide : Please make ensure that these 4 values are matched with current image.
// Development Guide : Please make ensure that these 5 values are matched with current image.
private string _resourceUrl = "";
private string _alphaMaskUrl = "";
private int _desired_width = -1;
private int _desired_height = -1;
private bool _fastTrackUploading = false;
Expand Down Expand Up @@ -858,6 +860,7 @@ private MaskingModeType InternalMaskingMode
/// - Seamless visual change didn't supported.<br />
/// - Alpha masking didn't supported. If you try, It will load as normal case.<br />
/// - Synchronous loading didn't supported. If you try, It will load as normal case.<br />
/// - Synchronous sizing didn't supported. If you try, It will load as normal case.<br />
/// - Reload action didn't supported. If you try, It will load as normal case.<br />
/// - Atlas loading didn't supported. If you try, It will load as normal case.<br />
/// - Custom shader didn't supported. If you try, It will load as normal case.
Expand Down Expand Up @@ -910,7 +913,7 @@ private bool InternalFastTrackUploading
UpdateImage(ImageVisualProperty.FastTrackUploading, setValue);
setValue?.Dispose();

if (_fastTrackUploading && !string.IsNullOrEmpty(_resourceUrl))
if (SynchronousVisualCreationRequired())
{
// Special case. If user set FastTrackUploading mean, user want to upload image As-Soon-As-Possible.
// Create ImageVisual synchronously.
Expand Down Expand Up @@ -983,6 +986,36 @@ public void SetImage(string url)
{
UpdateImage(ImageVisualProperty.URL, urlValue, false);
}
if (_desired_width != -1)
{
_desired_width = -1;
using (PropertyValue desiredWidthValue = new PropertyValue(_desired_width))
{
UpdateImage(ImageVisualProperty.DesiredWidth, desiredWidthValue, false);
}
}
if (_desired_height != -1)
{
_desired_height = -1;
using (PropertyValue desiredHeightValue = new PropertyValue(_desired_height))
{
UpdateImage(ImageVisualProperty.DesiredHeight, desiredHeightValue, false);
}
}
if (_fastTrackUploading)
{
_fastTrackUploading = false;
using (PropertyValue fastTrackUploadingValue = new PropertyValue(_fastTrackUploading))
{
UpdateImage(ImageVisualProperty.FastTrackUploading, fastTrackUploadingValue, false);
}
}
if (!string.IsNullOrEmpty(_alphaMaskUrl))
{
_alphaMaskUrl = "";
using PropertyValue emptyValue = new PropertyValue();
UpdateImage(ImageVisualProperty.AlphaMaskURL, emptyValue, false);
}
imagePropertyUpdatedFlag = false;
}

Expand Down Expand Up @@ -1090,17 +1123,13 @@ private string InternalAlphaMaskURL
{
get
{
string ret = "";

PropertyValue maskUrl = GetCachedImageVisualProperty(ImageVisualProperty.AlphaMaskURL);
maskUrl?.Get(out ret);
maskUrl?.Dispose();

return ret;
return _alphaMaskUrl;
}
set
{
PropertyValue setValue = new PropertyValue(value ?? "");
_alphaMaskUrl = value ?? "";

PropertyValue setValue = new PropertyValue(_alphaMaskUrl);
UpdateImage(ImageVisualProperty.AlphaMaskURL, setValue);
// When we never set CropToMask property before, we should set default value as true.
using (PropertyValue cropToMask = GetCachedImageVisualProperty(ImageVisualProperty.CropToMask))
Expand All @@ -1112,6 +1141,11 @@ private string InternalAlphaMaskURL
}
}
setValue?.Dispose();

if (SynchronousVisualCreationRequired())
{
UpdateImage();
}
}
}

Expand Down Expand Up @@ -1911,7 +1945,21 @@ internal void SetImage(string url, Uint16Pair size)
}
using (PropertyValue desiredHeightValue = new PropertyValue(_desired_height))
{
UpdateImage(ImageVisualProperty.DesiredWidth, desiredHeightValue, false);
UpdateImage(ImageVisualProperty.DesiredHeight, desiredHeightValue, false);
}
if (_fastTrackUploading)
{
_fastTrackUploading = false;
using (PropertyValue fastTrackUploadingValue = new PropertyValue(_fastTrackUploading))
{
UpdateImage(ImageVisualProperty.FastTrackUploading, fastTrackUploadingValue, false);
}
}
if (!string.IsNullOrEmpty(_alphaMaskUrl))
{
_alphaMaskUrl = "";
using PropertyValue emptyValue = new PropertyValue();
UpdateImage(ImageVisualProperty.AlphaMaskURL, emptyValue, false);
}
imagePropertyUpdatedFlag = false;
}
Expand Down Expand Up @@ -2046,8 +2094,8 @@ private void SetResourceUrl(string value)
{
UpdateImage(ImageVisualProperty.URL, setValue);
}
// Special case. If we set GeneratedUrl, or FastTrackUploading, Create ImageVisual synchronously.
if (value.StartsWith("dali://") || value.StartsWith("enbuf://") || _fastTrackUploading)

if (SynchronousVisualCreationRequired())
{
UpdateImage();
}
Expand Down Expand Up @@ -2087,7 +2135,10 @@ private void RemoveImage()

// Update resourceUrl as empty value
_resourceUrl = "";
cachedImagePropertyMap[ImageVisualProperty.URL] = emptyValue;
if (cachedImagePropertyMap != null)
{
cachedImagePropertyMap[ImageVisualProperty.URL] = emptyValue;
}
}
}

Expand All @@ -2099,23 +2150,29 @@ internal void SetImageByPropertyMap(PropertyMap map)
cachedImagePropertyMap = null;
MergeCachedImageVisualProperty(map);

// Update _resourceUrl, _desired_width, _desired_height, _fastTrackUploading here.
// Update _resourceUrl, _alphaMaskUrl, _desired_width, _desired_height, _fastTrackUploading here.
// Those values are C# side cached value.
_desired_width = _desired_height = -1;
_fastTrackUploading = false;

if (map != null)
{
_resourceUrl = "";
_alphaMaskUrl = "";
foreach (int key in cachedNUIImageViewPropertyKeyList)
{
using PropertyValue propertyValue = map.Find(key);
if (propertyValue != null)
{
// Note : Since ImageVisualProperty is not a constant value, we cannot use switch-case here.
if (key == ImageVisualProperty.URL)
{
propertyValue.Get(out _resourceUrl);
}
else if (key == ImageVisualProperty.AlphaMaskURL)
{
propertyValue.Get(out _alphaMaskUrl);
}
else if (key == ImageVisualProperty.DesiredWidth)
{
propertyValue.Get(out _desired_width);
Expand Down Expand Up @@ -2406,6 +2463,27 @@ private void OnResourceLoaded(IntPtr view)
}
}

private bool SynchronousVisualCreationRequired()
{
// Special case. If we set GeneratedUrl, or FastTrackUploading, Create ImageVisual synchronously.
if (!string.IsNullOrEmpty(_resourceUrl))
{
if (_fastTrackUploading)
{
return true;
}
if (_resourceUrl.StartsWith("dali://") || _resourceUrl.StartsWith("enbuf://"))
{
return true;
}
if (!string.IsNullOrEmpty(_alphaMaskUrl) && (_alphaMaskUrl.StartsWith("dali://") || _alphaMaskUrl.StartsWith("enbuf://")))
{
return true;
}
}
return false;
}

/// <summary>
/// Event arguments of resource ready.
/// </summary>
Expand Down
44 changes: 40 additions & 4 deletions src/Tizen.NUI/src/public/Visuals/VisualObject/ImageVisual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public string ResourceUrl

UpdateVisualProperty((int)Tizen.NUI.ImageVisualProperty.URL, new PropertyValue(value));

// Special case. If set GeneratedUrl, or FastTrackUploading, Create ImageVisual synchronously.
if (value.StartsWith("dali://") || value.StartsWith("enbuf://") || FastTrackUploading)
if (SynchronousVisualCreationRequired())
{
UpdateVisualPropertyMap();
}
Expand Down Expand Up @@ -202,11 +201,26 @@ public bool SynchronousSizing
/// Optional.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string AlphaMaskURL
public string AlphaMaskUrl
{
set
{
UpdateVisualProperty((int)Tizen.NUI.ImageVisualProperty.AlphaMaskURL, string.IsNullOrEmpty(value) ? null : new PropertyValue(value));

// When we never set CropToMask property before, we should set default value as true.
using (PropertyValue cropToMask = GetCachedVisualProperty((int)Tizen.NUI.ImageVisualProperty.CropToMask))
{
if (cropToMask == null)
{
using PropertyValue setCropValue = new PropertyValue(true);
UpdateVisualProperty((int)Tizen.NUI.ImageVisualProperty.CropToMask, setCropValue);
}
}

if (SynchronousVisualCreationRequired())
{
UpdateVisualPropertyMap();
}
}
get
{
Expand Down Expand Up @@ -284,6 +298,7 @@ public Tizen.NUI.BaseComponents.ImageView.MaskingModeType MaskingMode
/// - Seamless visual change didn't supported.<br />
/// - Alpha masking didn't supported. If you try, It will load as normal case.<br />
/// - Synchronous loading didn't supported. If you try, It will load as normal case.<br />
/// - Synchronous sizing didn't supported. If you try, It will load as normal case.<br />
/// - Reload action didn't supported. If you try, It will load as normal case.<br />
/// - Atlas loading didn't supported. If you try, It will load as normal case.<br />
/// - Custom shader didn't supported. If you try, It will load as normal case.
Expand All @@ -295,7 +310,7 @@ public bool FastTrackUploading
{
UpdateVisualProperty((int)Tizen.NUI.ImageVisualProperty.FastTrackUploading, new PropertyValue(value));

if (value && !string.IsNullOrEmpty(ResourceUrl))
if (value && isResourceUrlValid)
{
// Special case. If user set FastTrackUploading mean, user want to upload image As-Soon-As-Possible.
// Create ImageVisual synchronously.
Expand Down Expand Up @@ -623,6 +638,27 @@ internal override void OnVisualCreated()
temperalStoredPropertyMap = null;
}
}

private bool SynchronousVisualCreationRequired()
{
// Special case. If we set GeneratedUrl, or FastTrackUploading, Create ImageVisual synchronously.
if (isResourceUrlValid)
{
if (FastTrackUploading)
{
return true;
}
if (ResourceUrl.StartsWith("dali://") || ResourceUrl.StartsWith("enbuf://"))
{
return true;
}
if (!string.IsNullOrEmpty(AlphaMaskUrl) && (AlphaMaskUrl.StartsWith("dali://") || AlphaMaskUrl.StartsWith("enbuf://")))
{
return true;
}
}
return false;
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class EncodedImageTest : IExample
(DEMO_IMAGE_DIR + "../a.json", EncodedImageBuffer.ImageTypes.AnimatedVectorImage),
};

string TestMaskImage = DEMO_IMAGE_DIR + "Dali/DaliDemo/shape-circle.png";

public void Activate()
{
win = NUIApplication.GetDefaultWindow();
Expand Down Expand Up @@ -66,7 +68,18 @@ private async void SetImage(int index)

imageUrl = buffer?.GenerateUrl();
imageView.ResourceUrl = imageUrl?.ToString();
imageView.Play();

if (TestImages[index].Item2 == EncodedImageBuffer.ImageTypes.RegularImage)
{
var encodedMaskTask = CreateEncodedImageBufferAsync(TestMaskImage, EncodedImageBuffer.ImageTypes.RegularImage);
using var maskBuffer = await encodedMaskTask;
using var maskImageUrl = maskBuffer?.GenerateUrl();
imageView.AlphaMaskURL = maskImageUrl?.ToString();
}
else if (TestImages[index].Item2 == EncodedImageBuffer.ImageTypes.AnimatedVectorImage)
{
imageView.Play();
}

imageUrl?.Dispose();
buffer?.Dispose();
Expand Down
21 changes: 21 additions & 0 deletions test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/VisualTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class VisualTest : IExample
DEMO_IMAGE_DIR + "Dali/ContactCard/gallery-small-4.jpg",
DEMO_IMAGE_DIR + "Dali/ContactCard/gallery-small-5.jpg",
};
string MaskImageUrl = DEMO_IMAGE_DIR + "Dali/DaliDemo/shape-circle.png";

const float viewSizeWidth = 320.0f;
const float viewSizeHeight = 280.0f;
Expand Down Expand Up @@ -54,6 +55,7 @@ private void WinKeyEvent(object sender, Window.KeyEventArgs e)
{
if (e.Key.State == Key.StateType.Down)
{
Tizen.Log.Error("NUI", $"Key pressed. {e.Key.KeyPressedName}\n");
if (e.Key.KeyPressedName == "1")
{
Tizen.Log.Error("NUI", $"Reset scene\n");
Expand Down Expand Up @@ -104,6 +106,25 @@ private void WinKeyEvent(object sender, Window.KeyEventArgs e)
}
}
}
else if(e.Key.KeyPressedName == "7")
{
View focusedView = FocusManager.Instance.GetCurrentFocusView();
if(focusedView != null)
{
var mainVisual = focusedView.FindVisualByName("mainImage") as Visuals.ImageVisual;
if(mainVisual != null)
{
if(string.IsNullOrEmpty(mainVisual.AlphaMaskUrl))
{
mainVisual.AlphaMaskUrl = MaskImageUrl;
}
else
{
mainVisual.AlphaMaskUrl = null;
}
}
}
}
}
}

Expand Down
Loading