Skip to content

Commit

Permalink
chore: reordering logic in BorderVisual
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed May 16, 2024
1 parent 45c275a commit 9707b7a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
68 changes: 34 additions & 34 deletions src/Uno.UI.Composition/Composition/BorderVisual.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.UI.Composition;
/// </summary>
internal class BorderVisual(Compositor compositor) : ShapeVisual(compositor)
{
[ThreadStatic] // just in case we eventually use multiple ui threads.
[ThreadStatic] // this should be tied to the compositor
private static CompositionPathGeometry? _sharedPathGeometry;

// state received from BorderLayerRenderer
Expand Down Expand Up @@ -62,39 +62,6 @@ public bool UseInnerBorderBoundsAsAreaForBackground
set => SetProperty(ref _borderBrush, value);
}

private protected override void ApplyPostPaintingClipping(in SKCanvas canvas)
=> _childClipCausedByCornerRadius?.Apply(canvas, this);

internal override void Paint(in PaintingSession session)
{
_sharedPathGeometry ??= Compositor.CreatePathGeometry();
_sharedPathGeometry.Path ??= new CompositionPath(new SkiaGeometrySource2D());
var geometrySource = (SkiaGeometrySource2D)_sharedPathGeometry.Path.GeometrySource;

UpdatePathsAndCornerClip();

if (_backgroundShape is { } backgroundShape && _backgroundPath is { } backgroundPath)
{
backgroundShape.Geometry = _sharedPathGeometry; // will only do something the first time
geometrySource.Geometry = backgroundPath; // changing Geometry doesn't raise OnPropertyChanged or invalidate render.
session.Canvas.Save();
// it's necessary to clip the background because not all backgrounds are simple rounded rectangles with a solid color.
// E.g. effect brushes will draw outside the intended area if they're not clipped.
_backgroundClip?.Apply(session.Canvas, this);
backgroundShape.Render(in session);
session.Canvas.Restore();
}

base.Paint(in session);

if (_borderShape is { } borderShape && _borderPath is { } borderPath)
{
borderShape.Geometry = _sharedPathGeometry; // will only do something the first time
geometrySource.Geometry = borderPath; // changing Geometry doesn't raise OnPropertyChanged or invalidate render.
_borderShape?.Render(in session);
}
}

private protected override void OnPropertyChangedCore(string? propertyName, bool isSubPropertyChange)
{
// Call base implementation - Visual calls Compositor.InvalidateRender().
Expand Down Expand Up @@ -141,6 +108,39 @@ private protected override void OnPropertyChangedCore(string? propertyName, bool
}
}

internal override void Paint(in PaintingSession session)
{
_sharedPathGeometry ??= Compositor.CreatePathGeometry();
_sharedPathGeometry.Path ??= new CompositionPath(new SkiaGeometrySource2D());
var geometrySource = (SkiaGeometrySource2D)_sharedPathGeometry.Path.GeometrySource;

UpdatePathsAndCornerClip();

if (_backgroundShape is { } backgroundShape && _backgroundPath is { } backgroundPath)
{
backgroundShape.Geometry = _sharedPathGeometry; // will only do something the first time
geometrySource.Geometry = backgroundPath; // changing Geometry doesn't raise OnPropertyChanged or invalidate render.
session.Canvas.Save();
// it's necessary to clip the background because not all backgrounds are simple rounded rectangles with a solid color.
// E.g. effect brushes will draw outside the intended area if they're not clipped.
_backgroundClip?.Apply(session.Canvas, this);
backgroundShape.Render(in session);
session.Canvas.Restore();
}

base.Paint(in session);

if (_borderShape is { } borderShape && _borderPath is { } borderPath)
{
borderShape.Geometry = _sharedPathGeometry; // will only do something the first time
geometrySource.Geometry = borderPath; // changing Geometry doesn't raise OnPropertyChanged or invalidate render.
_borderShape?.Render(in session);
}
}

private protected override void ApplyPostPaintingClipping(in SKCanvas canvas)
=> _childClipCausedByCornerRadius?.Apply(canvas, this);

private void UpdatePathsAndCornerClip()
{
if (_borderPathValid && _backgroundPathValid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ partial class ScrollPresenter : IBorderInfoProvider
private BorderLayerRenderer _borderRenderer;
#endif

#if !__SKIA__
partial void InitializePartial()
{
#if !__SKIA__
_borderRenderer = new BorderLayerRenderer(this);
#endif
}
#endif

#if __SKIA__
private protected override ShapeVisual CreateElementVisual() => Compositor.GetSharedCompositor().CreateBorderVisual();
Expand Down

0 comments on commit 9707b7a

Please sign in to comment.