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] Lazy Update CornerRadius/Borderline #5437

Merged
merged 1 commit into from
Aug 2, 2023
Merged
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
26 changes: 17 additions & 9 deletions src/Tizen.NUI/src/public/BaseComponents/ImageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,13 +1344,15 @@ internal override void ApplyCornerRadius()

if (backgroundExtraData == null) return;


// Update corner radius properties to image by ActionUpdateProperty
if (backgroundExtraData.CornerRadius != null)
if (backgroundExtraDataUpdatedFlag.HasFlag(BackgroundExtraDataUpdatedFlag.ContentsCornerRadius))
{
Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, ImageView.Property.IMAGE, Visual.Property.CornerRadius, Vector4.getCPtr(backgroundExtraData.CornerRadius));
if (backgroundExtraData.CornerRadius != null)
{
Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, ImageView.Property.IMAGE, Visual.Property.CornerRadius, Vector4.getCPtr(backgroundExtraData.CornerRadius));
}
Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, Visual.Property.CornerRadiusPolicy, (int)backgroundExtraData.CornerRadiusPolicy);
}
Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, Visual.Property.CornerRadiusPolicy, (int)backgroundExtraData.CornerRadiusPolicy);
}

internal override void ApplyBorderline()
Expand All @@ -1359,11 +1361,13 @@ internal override void ApplyBorderline()

if (backgroundExtraData == null) return;


// Update borderline properties to image by ActionUpdateProperty
Interop.View.InternalUpdateVisualPropertyFloat(this.SwigCPtr, ImageView.Property.IMAGE, Visual.Property.BorderlineWidth, backgroundExtraData.BorderlineWidth);
Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, ImageView.Property.IMAGE, Visual.Property.BorderlineColor, Vector4.getCPtr(backgroundExtraData.BorderlineColor ?? Color.Black));
Interop.View.InternalUpdateVisualPropertyFloat(this.SwigCPtr, ImageView.Property.IMAGE, Visual.Property.BorderlineOffset, backgroundExtraData.BorderlineOffset);
if (backgroundExtraDataUpdatedFlag.HasFlag(BackgroundExtraDataUpdatedFlag.ContentsBorderline))
{
// Update borderline properties to image by ActionUpdateProperty
Interop.View.InternalUpdateVisualPropertyFloat(this.SwigCPtr, ImageView.Property.IMAGE, Visual.Property.BorderlineWidth, backgroundExtraData.BorderlineWidth);
Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, ImageView.Property.IMAGE, Visual.Property.BorderlineColor, Vector4.getCPtr(backgroundExtraData.BorderlineColor ?? Color.Black));
Interop.View.InternalUpdateVisualPropertyFloat(this.SwigCPtr, ImageView.Property.IMAGE, Visual.Property.BorderlineOffset, backgroundExtraData.BorderlineOffset);
}
}

internal ResourceLoadingStatusType GetResourceStatus()
Expand Down Expand Up @@ -1633,6 +1637,10 @@ protected virtual void UpdateImage()
}
}

// We already applied background extra data now.
backgroundExtraDataUpdatedFlag &= ~BackgroundExtraDataUpdatedFlag.ContentsCornerRadius;
backgroundExtraDataUpdatedFlag &= ~BackgroundExtraDataUpdatedFlag.ContentsBorderline;

// Do Fitting Buffer when desired dimension is set
// TODO : Couldn't we do this job in dali-engine side.
if (_desired_width != -1 && _desired_height != -1)
Expand Down
38 changes: 33 additions & 5 deletions src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,25 @@ public partial class View

view.backgroundExtraData = null;

// Background extra data is not valid anymore. We should ignore lazy UpdateBackgroundExtraData
view.backgroundExtraDataUpdatedFlag = BackgroundExtraDataUpdatedFlag.None;
if (view.backgroundExtraDataUpdateProcessAttachedFlag)
{
ProcessorController.Instance.ProcessorOnceEvent -= view.UpdateBackgroundExtraData;
view.backgroundExtraDataUpdateProcessAttachedFlag = false;
}

propertyValue.Dispose();
propertyValue = null;
}
},
defaultValueCreator: (bindable) =>
{
var view = (View)bindable;

// Sync as current properties
view?.UpdateBackgroundExtraData();

PropertyMap tmp = new PropertyMap();
var propertyValue = Object.GetProperty(view.SwigCPtr, Property.BACKGROUND);
propertyValue.Get(tmp);
Expand Down Expand Up @@ -1876,6 +1888,9 @@ public partial class View
{
var view = (View)bindable;

// Sync as current properties
view?.UpdateBackgroundExtraData();

PropertyMap map = new PropertyMap();
Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.SHADOW).Get(map);

Expand Down Expand Up @@ -1907,6 +1922,9 @@ public partial class View
{
var view = (View)bindable;

// Sync as current properties
view?.UpdateBackgroundExtraData();

PropertyMap map = new PropertyMap();
Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.SHADOW).Get(map);

Expand All @@ -1922,7 +1940,7 @@ public partial class View
{
var view = (View)bindable;
(view.backgroundExtraData ?? (view.backgroundExtraData = new BackgroundExtraData())).CornerRadius = (Vector4)newValue;
view.ApplyCornerRadius();
view.UpdateBackgroundExtraData(BackgroundExtraDataUpdatedFlag.CornerRadius);
},
defaultValueCreator: (bindable) =>
{
Expand All @@ -1941,7 +1959,7 @@ public partial class View

if (view.backgroundExtraData.CornerRadius != null)
{
view.ApplyCornerRadius();
view.UpdateBackgroundExtraData(BackgroundExtraDataUpdatedFlag.CornerRadius);
}
},
defaultValueCreator: (bindable) =>
Expand All @@ -1958,7 +1976,7 @@ public partial class View
{
var view = (View)bindable;
(view.backgroundExtraData ?? (view.backgroundExtraData = new BackgroundExtraData())).BorderlineWidth = (float)newValue;
view.ApplyBorderline();
view.UpdateBackgroundExtraData(BackgroundExtraDataUpdatedFlag.Borderline);
},
defaultValueCreator: (bindable) =>
{
Expand Down Expand Up @@ -2032,7 +2050,7 @@ public partial class View
{
var view = (View)bindable;
(view.backgroundExtraData ?? (view.backgroundExtraData = new BackgroundExtraData())).BorderlineOffset = (float)newValue;
view.ApplyBorderline();
view.UpdateBackgroundExtraData(BackgroundExtraDataUpdatedFlag.Borderline);
},
defaultValueCreator: (bindable) =>
{
Expand Down Expand Up @@ -2576,6 +2594,8 @@ private void SetBackgroundImage(string value)
{
if (string.IsNullOrEmpty(value))
{
backgroundExtraDataUpdatedFlag &= ~BackgroundExtraDataUpdatedFlag.Background;

var empty = new PropertyValue();
// Clear background
Object.SetProperty(SwigCPtr, Property.BACKGROUND, empty);
Expand Down Expand Up @@ -2629,6 +2649,8 @@ private void SetBackgroundImage(string value)
map.Add(Visual.Property.Type, imageType);
}

backgroundExtraDataUpdatedFlag &= ~BackgroundExtraDataUpdatedFlag.Background;

var mapValue = new PropertyValue(map);
Object.SetProperty(SwigCPtr, Property.BACKGROUND, mapValue);

Expand Down Expand Up @@ -2679,6 +2701,9 @@ private void SetBackgroundImageBorder(Rectangle value)
map[Visual.Property.Type] = new PropertyValue((int)Visual.Type.NPatch);
}

// Background extra data flag is not meanful anymore.
backgroundExtraDataUpdatedFlag &= ~BackgroundExtraDataUpdatedFlag.Background;

Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.BACKGROUND, new PropertyValue(map));
}

Expand All @@ -2691,7 +2716,7 @@ private void SetBorderlineColor(Color value)

(backgroundExtraData ?? (backgroundExtraData = new BackgroundExtraData())).BorderlineColor = value;

ApplyBorderline();
UpdateBackgroundExtraData(BackgroundExtraDataUpdatedFlag.Borderline);
}

private void SetBackgroundColor(Color value)
Expand Down Expand Up @@ -2727,6 +2752,8 @@ private void SetBackgroundColor(Color value)
.Add(Visual.Property.BorderlineColor, borderlineColor)
.Add(Visual.Property.BorderlineOffset, borderlineOffset);

backgroundExtraDataUpdatedFlag &= ~BackgroundExtraDataUpdatedFlag.Background;

var mapValue = new PropertyValue(map);
Object.SetProperty(SwigCPtr, Property.BACKGROUND, mapValue);

Expand Down Expand Up @@ -2803,6 +2830,7 @@ private void SetOpacity(float? value)

private void SetShadow(ShadowBase value)
{
backgroundExtraDataUpdatedFlag &= ~BackgroundExtraDataUpdatedFlag.Shadow;
Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)SwigCPtr, View.Property.SHADOW, value == null ? new PropertyValue() : value.ToPropertyValue(this));
}
}
Expand Down
141 changes: 130 additions & 11 deletions src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ public partial class View
{
internal string styleName;

[Flags]
internal enum BackgroundExtraDataUpdatedFlag : byte
{
BackgroundCornerRadius = 1 << 0,
BackgroundBorderline = 1 << 1,
ShadowCornerRadius = 1 << 2,
ContentsCornerRadius = 1 << 3, /// Subclass cases.
ContentsBorderline = 1 << 4, /// Subclass cases.

Background = BackgroundCornerRadius | BackgroundBorderline,
Shadow = ShadowCornerRadius,

CornerRadius = BackgroundCornerRadius | ShadowCornerRadius | ContentsCornerRadius,
Borderline = BackgroundBorderline | ContentsBorderline,

None = 0,
All = Background | Shadow,
}

internal BackgroundExtraDataUpdatedFlag backgroundExtraDataUpdatedFlag = BackgroundExtraDataUpdatedFlag.None;

private bool backgroundExtraDataUpdateProcessAttachedFlag = false;

internal virtual LayoutItem CreateDefaultLayout()
{
return new AbsoluteLayout();
Expand Down Expand Up @@ -1058,12 +1081,21 @@ internal bool IsTopLevelView()
/// </summary>
internal bool IsBackgroundEmpty()
{

int visualType = (int)Visual.Type.Invalid;
Interop.View.InternalRetrievingVisualPropertyInt(this.SwigCPtr, Property.BACKGROUND, Visual.Property.Type, out visualType);
return visualType == (int)Visual.Type.Invalid;
}

/// <summary>
/// Check whether Current view don't has ShadowVisual or not.
/// </summary>
internal bool IsShadowEmpty()
{
int visualType = (int)Visual.Type.Invalid;
Interop.View.InternalRetrievingVisualPropertyInt(this.SwigCPtr, Property.SHADOW, Visual.Property.Type, out visualType);
return visualType == (int)Visual.Type.Invalid;
}

internal void SetKeyInputFocus()
{
Interop.ViewInternal.SetKeyInputFocus(SwigCPtr);
Expand Down Expand Up @@ -1151,28 +1183,105 @@ internal ResourceLoadingStatusType GetBackgroundResourceStatus()
return (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.BACKGROUND);
}

/// <summary>
/// Lazy call to UpdateBackgroundExtraData.
/// Collect Properties need to be update, and set properties that starts the Processing.
/// </summary>
internal virtual void UpdateBackgroundExtraData(BackgroundExtraDataUpdatedFlag flag)
{
if (backgroundExtraData == null)
{
return;
}

if (!backgroundExtraDataUpdatedFlag.HasFlag(flag))
{
backgroundExtraDataUpdatedFlag |= flag;
if (!backgroundExtraDataUpdateProcessAttachedFlag)
{
backgroundExtraDataUpdateProcessAttachedFlag = true;
ProcessorController.Instance.ProcessorOnceEvent += UpdateBackgroundExtraData;
// Call process hardly.
ProcessorController.Instance.Awake();
}
}
}

/// <summary>
/// Callback function to Lazy UpdateBackgroundExtraData.
/// </summary>
private void UpdateBackgroundExtraData(object source, EventArgs e)
{
// Note : To allow event attachment during UpdateBackgroundExtraData, let we make flag as false before call UpdateBackgroundExtraData().
backgroundExtraDataUpdateProcessAttachedFlag = false;
UpdateBackgroundExtraData();
}

/// <summary>
/// Update background extra data properties synchronously.
/// After call this API, All background extra data properties updated.
/// </summary>
internal virtual void UpdateBackgroundExtraData()
{
if (backgroundExtraData == null)
{
return;
}

if (IsShadowEmpty())
{
backgroundExtraDataUpdatedFlag &= ~BackgroundExtraDataUpdatedFlag.Shadow;
}
if (!Rectangle.IsNullOrZero(backgroundExtraData.BackgroundImageBorder))
{
backgroundExtraDataUpdatedFlag &= ~BackgroundExtraDataUpdatedFlag.Background;
}

if (backgroundExtraDataUpdatedFlag == BackgroundExtraDataUpdatedFlag.None)
{
return;
}

if ((backgroundExtraDataUpdatedFlag & BackgroundExtraDataUpdatedFlag.Borderline) != BackgroundExtraDataUpdatedFlag.None)
{
ApplyBorderline();
}
if ((backgroundExtraDataUpdatedFlag & BackgroundExtraDataUpdatedFlag.CornerRadius) != BackgroundExtraDataUpdatedFlag.None)
{
ApplyCornerRadius();
}
backgroundExtraDataUpdatedFlag = BackgroundExtraDataUpdatedFlag.None;
}

/// TODO open as a protected level
internal virtual void ApplyCornerRadius()
{
if (backgroundExtraData == null) return;


// Update corner radius properties to background and shadow by ActionUpdateProperty
if (backgroundExtraData.CornerRadius != null)
if (backgroundExtraDataUpdatedFlag.HasFlag(BackgroundExtraDataUpdatedFlag.BackgroundCornerRadius))
{
Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.CornerRadius, Vector4.getCPtr(backgroundExtraData.CornerRadius));
Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, View.Property.SHADOW, Visual.Property.CornerRadius, Vector4.getCPtr(backgroundExtraData.CornerRadius));
if (backgroundExtraData.CornerRadius != null)
{
Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.CornerRadius, Vector4.getCPtr(backgroundExtraData.CornerRadius));
}
Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.CornerRadiusPolicy, (int)backgroundExtraData.CornerRadiusPolicy);
}
if (backgroundExtraDataUpdatedFlag.HasFlag(BackgroundExtraDataUpdatedFlag.ShadowCornerRadius))
{
if (backgroundExtraData.CornerRadius != null)
{
Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, View.Property.SHADOW, Visual.Property.CornerRadius, Vector4.getCPtr(backgroundExtraData.CornerRadius));
}
Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, View.Property.SHADOW, Visual.Property.CornerRadiusPolicy, (int)backgroundExtraData.CornerRadiusPolicy);
}
Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.CornerRadiusPolicy, (int)backgroundExtraData.CornerRadiusPolicy);
Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, View.Property.SHADOW, Visual.Property.CornerRadiusPolicy, (int)backgroundExtraData.CornerRadiusPolicy);
}

/// TODO open as a protected level
internal virtual void ApplyBorderline()
{
if (backgroundExtraData == null) return;


// ActionUpdateProperty works well only if BACKGROUND visual setup before.
// If view don't have BACKGROUND visual, we set transparent background color in default.
if (IsBackgroundEmpty())
Expand All @@ -1185,9 +1294,12 @@ internal virtual void ApplyBorderline()
}

// Update borderline properties to background by ActionUpdateProperty
Interop.View.InternalUpdateVisualPropertyFloat(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.BorderlineWidth, backgroundExtraData.BorderlineWidth);
Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.BorderlineColor, Vector4.getCPtr(backgroundExtraData.BorderlineColor ?? Color.Black));
Interop.View.InternalUpdateVisualPropertyFloat(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.BorderlineOffset, backgroundExtraData.BorderlineOffset);
if (backgroundExtraDataUpdatedFlag.HasFlag(BackgroundExtraDataUpdatedFlag.BackgroundBorderline))
{
Interop.View.InternalUpdateVisualPropertyFloat(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.BorderlineWidth, backgroundExtraData.BorderlineWidth);
Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.BorderlineColor, Vector4.getCPtr(backgroundExtraData.BorderlineColor ?? Color.Black));
Interop.View.InternalUpdateVisualPropertyFloat(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.BorderlineOffset, backgroundExtraData.BorderlineOffset);
}
}

/// <summary>
Expand Down Expand Up @@ -1335,6 +1447,13 @@ protected override void Dispose(DisposeTypes type)
view.InternalParent = null;
}

backgroundExtraDataUpdatedFlag = BackgroundExtraDataUpdatedFlag.None;
if (backgroundExtraDataUpdateProcessAttachedFlag)
{
ProcessorController.Instance.ProcessorOnceEvent -= UpdateBackgroundExtraData;
backgroundExtraDataUpdateProcessAttachedFlag = false;
}

LayoutCount = 0;

NUILog.Debug($"[Dispose] View.Dispose({type}) END");
Expand Down