Skip to content

Commit

Permalink
[NUI] Fast track uploading image
Browse files Browse the repository at this point in the history
Add new feature about flag that ImageView's image uploading faster.

Previously, NUI has some operations to support some kind of visual transition,
or calculate natural size for relayout, or etc.

This patch make a way to user that we need to upload image as soon as possible,
don't care about other platform supported features.

Signed-off-by: Eunki, Hong <[email protected]>
  • Loading branch information
Eunki, Hong authored and hinohie committed Jul 25, 2023
1 parent 68f7837 commit 447d862
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 4 deletions.
66 changes: 63 additions & 3 deletions src/Tizen.NUI/src/public/BaseComponents/ImageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private static string ConvertResourceUrl(ref string value)
ImageVisualProperty.SynchronousLoading,
Visual.Property.PremultipliedAlpha,
ImageVisualProperty.OrientationCorrection,
ImageVisualProperty.FastTrackUploading,
NpatchImageVisualProperty.Border,
NpatchImageVisualProperty.BorderOnly,
};
Expand All @@ -79,6 +80,7 @@ private static string ConvertResourceUrl(ref string value)
private string _resourceUrl = "";
private int _desired_width = -1;
private int _desired_height = -1;
private bool _fastTrackUploading = false;
private TriggerableSelector<string> resourceUrlSelector;
private TriggerableSelector<Rectangle> borderSelector;

Expand Down Expand Up @@ -610,6 +612,64 @@ private MaskingModeType InternalMaskingMode
}
}

/// <summary>
/// Gets or sets whether to apply fast track uploading or not.<br />
/// </summary>
/// <remarks>
/// If we use fast track uploading feature, It can upload texture without event-thead dependency. But also,<br />
/// - Texture size is invalid until ResourceReady signal comes.<br />
/// - Texture cannot be cached (We always try to load new image).<br />
/// - 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 />
/// - 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.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool FastTrackUploading
{
get
{
return (bool)GetValue(FastTrackUploadingProperty);
}
set
{
SetValue(FastTrackUploadingProperty, value);
NotifyPropertyChanged();
}
}

private bool InternalFastTrackUploading
{
get
{
PropertyValue fastTrackUploading = GetCachedImageVisualProperty(ImageVisualProperty.FastTrackUploading);
fastTrackUploading?.Get(out _fastTrackUploading);
fastTrackUploading?.Dispose();

return _fastTrackUploading;
}
set
{
if (_fastTrackUploading != value)
{
_fastTrackUploading = value;

PropertyValue setValue = new PropertyValue(_fastTrackUploading);
UpdateImage(ImageVisualProperty.FastTrackUploading, setValue);
setValue?.Dispose();

if (_fastTrackUploading && !string.IsNullOrEmpty(_resourceUrl))
{
// Special case. If user set FastTrackUploading mean, user want to upload image As-Soon-As-Possible.
// Create ImageVisual synchronously.
UpdateImage();
}
}
}
}

/// <summary>
/// Gets the loading state of the visual resource.
/// </summary>
Expand Down Expand Up @@ -1396,8 +1456,8 @@ private void SetResourceUrl(string value)
{
UpdateImage(ImageVisualProperty.URL, setValue);
}
// Special case. If we set GeneratedUrl, Create ImageVisual synchronously.
if (value.StartsWith("dali://") || value.StartsWith("enbuf://"))
// Special case. If we set GeneratedUrl, or FastTrackUploading, Create ImageVisual synchronously.
if (value.StartsWith("dali://") || value.StartsWith("enbuf://") || _fastTrackUploading)
{
UpdateImage();
}
Expand Down Expand Up @@ -1462,7 +1522,7 @@ protected virtual void UpdateImage(int key, PropertyValue value, bool requiredVi
// Update image property map value as inputed value.
if (key != 0)
{
if(!HasBody())
if (!HasBody())
{
// Throw exception if ImageView is disposed.
throw new global::System.InvalidOperationException("[NUI][ImageVIew] Someone try to change disposed ImageView's property.\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,24 @@ public partial class ImageView
return instance.InternalMaskingMode;
});

/// <summary>
/// FastTrackUploadingProperty
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty FastTrackUploadingProperty = BindableProperty.Create(nameof(FastTrackUploading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
{
var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
if (newValue != null)
{
instance.InternalFastTrackUploading = (bool)newValue;
}
},
defaultValueCreator: (bindable) =>
{
var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
return instance.InternalFastTrackUploading;
});

/// <summary>
/// ImageMapProperty
/// </summary>
Expand Down Expand Up @@ -537,7 +555,7 @@ public partial class ImageView
var imageView = (Tizen.NUI.BaseComponents.ImageView)bindable;
if (newValue != null)
{
Object.InternalSetPropertyString(imageView.SwigCPtr, ImageView.Property.PlaceHolderUrl, (string)newValue );
Object.InternalSetPropertyString(imageView.SwigCPtr, ImageView.Property.PlaceHolderUrl, (string)newValue);
}
},
defaultValueCreator: (bindable) =>
Expand Down
8 changes: 8 additions & 0 deletions src/Tizen.NUI/src/public/Visuals/VisualConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,14 @@ public struct ImageVisualProperty
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly int MaskingMode = NDalic.ImageVisualOrientationCorrection + 12;

/// <summary>
/// @brief Whether to uploading texture before ResourceReady signal emit or after texture load completed time.
/// @details Name "fastTrackUploading", type Property::BOOLEAN.
/// @note It is used in the ImageVisual. The default is false.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly int FastTrackUploading = NDalic.ImageVisualOrientationCorrection + 13;
}

/// <summary>
Expand Down

0 comments on commit 447d862

Please sign in to comment.