Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

[Skia.WPF] improve OnRenderSizeChanged() #168

Merged
merged 1 commit into from
Oct 2, 2021
Merged

Conversation

swharden
Copy link
Contributor

@swharden swharden commented Sep 11, 2021

This PR fixes a bug that causes the painted area not to match the window when resizing. If the OnRenderSizeChanged() override does not call its base implementation the SizeChanged event isn't raised and the dirty rectangle may be incorrectly sized when OnPaintSurface() is called. Note mono / SKElement.cs#L88-L93

WDSkiaGraphicsView inherits SKElement which inherits FrameworkElement

According to FrameworkElement.OnRenderSizeChanged() documentation:

You may still override OnRenderSizeChanged() in derived classes (it is protected but not sealed). Always call the base implementation to preserve the [layout] behavior mentioned above, unless you have very specific reasons for disabling default WPF framework-level rendering behavior. Failing to raise the SizeChanged event will cause non-standard layout behavior if using the standard WPF framework-level layout system implementation.

I realize this project is experimental/preview, so clarification on whether contributions are welcome at this time and if PRs must be accompanied by linked issues would be great! (#88)

Demonstrating the Issue

<skia:WDSkiaGraphicsView x:Name="GraphicsView" />
public partial class SandboxWindow : Window
{
    public SandboxWindow()
    {
        InitializeComponent();
        GraphicsView.Drawable = new BigX();
    }

    private class BigX : IDrawable
    {
        public void Draw(ICanvas canvas, RectangleF dirtyRect)
        {
            canvas.FillColor = Microsoft.Maui.Graphics.Colors.Navy;
            canvas.FillRectangle(dirtyRect);

            canvas.StrokeColor = Microsoft.Maui.Graphics.Colors.Yellow;
            canvas.DrawRectangle(dirtyRect);
            canvas.DrawLine(0, 0, dirtyRect.Width, dirtyRect.Height);
            canvas.DrawLine(dirtyRect.Width, 0, 0, dirtyRect.Height);
        }
    }
}

Before the Fix

Notice the white border around the filled area when resizing quickly
maui-whitespace-broken

After the Fix

Filled area exactly matches the window size
maui-whitespace-fixed

If the OnRenderSizeChanged() override does not call its base method the dirty rectangle may be incorrectly sized when OnPaintSurface() is called
@jonlipsky jonlipsky merged commit d091267 into dotnet:main Oct 2, 2021
@swharden swharden deleted the patch-1 branch October 2, 2021 22:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants