Skip to content

refactor: Refactor brushes - #12896

Merged
MartinZikmund merged 6 commits into
unoplatform:masterfrom
Youssef1313:gradient-brush
Jul 24, 2023
Merged

MartinZikmund merged 6 commits into
unoplatform:masterfrom
Youssef1313:gradient-brush

Conversation

@Youssef1313

@Youssef1313 Youssef1313 commented Jul 15, 2023 •

Copy link
Copy Markdown
Member

GitHub Issue (If applicable): closes #12601. Partially addresses #8891

PR Type

What kind of change does this PR introduce?

What is the current behavior?

What is the new behavior?

Copilot Summary

🤖 Generated by Copilot at 16c26cf

This pull request refactors various controls and classes to use the weak event proxy pattern for subscribing to brush changes, which improves memory management and performance. It also adds a new test class for the GradientBrush feature and a new base class for implementing the weak event proxy pattern. It deletes two unused files and fixes some minor issues with image brushes.

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

@github-actions github-actions Bot added platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform area/skia ✏️ Categorizes an issue or PR as relevant to Skia labels Jul 15, 2023
@Youssef1313
Youssef1313 force-pushed the gradient-brush branch 3 times, most recently from 3caa435 to ba26db0 Compare July 15, 2023 23:11
@Youssef1313

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown

No commit pushedDate could be found for PR 12896 in repo unoplatform/uno

@Youssef1313
Youssef1313 force-pushed the gradient-brush branch 5 times, most recently from 2880830 to 8739409 Compare July 19, 2023 09:37
@github-actions github-actions Bot added the area/build Categorizes an issue or PR as relevant to build infrastructure label Jul 20, 2023
@Youssef1313
Youssef1313 marked this pull request as ready for review July 20, 2023 12:56
Comment thread src/Uno.UI/UI/Xaml/Media/Brush.cs Resolved
@MartinZikmund

Copy link
Copy Markdown
Member

Looks good to me!

@MartinZikmund

Copy link
Copy Markdown
Member

Only thing I just realized now - could we introduce some race condition in case the brush is unsubscribed during GC / Java finalizer? As we could be removing handler from the event at the same time as adding another one on the UI thread, theoretically? @jeromelaban

@Youssef1313

Copy link
Copy Markdown
Member Author

Test failure on iOS:

Color at (0,0) is not expected
expected: FF0000FF #FF0000FF
actual  : FF0533FF #FF0533FF
tolerance: 5
difference: 51

The actual color is still bluish, meaning the GradientStop change propagated correctly. But I don't know why iOS diverges so much from blue. Anyway, that doesn't look like an issue with this PR, so I'll adjust tolerance for iOS.

@MartinZikmund
MartinZikmund enabled auto-merge July 24, 2023 07:38
@MartinZikmund
MartinZikmund merged commit dca49da into unoplatform:master Jul 24, 2023
@Youssef1313
Youssef1313 deleted the gradient-brush branch July 24, 2023 08:59
Action onInvalidateRender = () => backgroundLayer.FillColor = Brush.GetFallbackColor(background);
background.InvalidateRender += onInvalidateRender;
onInvalidateRender();
new DisposableAction(() => background.InvalidateRender -= onInvalidateRender)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Youssef1313 disposables.Add(() => background.InvalidateRender -= onInvalidateRender) should be available available to use.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeromelaban It should be the same functionality? or is there any difference?

Martin will be refactoring BorderLayerRenderer anyway.

Comment on lines +36 to +40
~Panel()
{
_backgroundBrushChangedProxy?.Unsubscribe();
_borderBrushChangedProxy?.Unsubscribe();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Youssef1313 I don't think this is necessary. The proxy itself should be collected and that should be enough for the unsubscription to happen.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The brushes hold a reference to the proxy via the event subscription. So long living brushes will cause proxies to leak unless the control calls Unsubscribe.

Comment on lines +42 to +47
protected override void JavaFinalize()
{
_backgroundBrushChangedProxy?.Unsubscribe();
_borderBrushChangedProxy?.Unsubscribe();
base.JavaFinalize();
}

@jeromelaban jeromelaban Jul 25, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Youssef1313 Same here, if javafinalize is called, the .NET GC should be invoked soon after.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to make sure we don't access a disposed object between collecting the native object and the managed object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build Categorizes an issue or PR as relevant to build infrastructure area/skia ✏️ Categorizes an issue or PR as relevant to Skia kind/documentation platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WASM: Binding to a GradientStop Color on a LinearGradientBrush does not display the colour.

3 participants