KEMBAR78
[Android] GraphicsView scaling after canvas.ResetState by kubaflo · Pull Request #31244 · dotnet/maui · GitHub
Skip to content

Conversation

@kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Aug 19, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

Follow-up to #31183

While reviewing the snapshots, I noticed that without calling canvas.ResetState(); in the Draw method, the rendered content size was doubled.

public void Draw(ICanvas canvas, RectF dirtyRect)
{
    canvas.ResetState();
}

This change removes the unnecessary call to _scalingCanvas.Scale in PlatformGraphicsView. Scaling is already accounted for in the ResetState() method

Issues Fixed

Fixes #31182

Before After

@Copilot Copilot AI review requested due to automatic review settings August 19, 2025 22:37
@kubaflo kubaflo requested a review from a team as a code owner August 19, 2025 22:37
@kubaflo kubaflo self-assigned this Aug 19, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a GraphicsView scaling issue on Android where content was being rendered at half size after calling canvas.ResetState(). The fix involves modifying the ScalingCanvas to preserve initial scale values when resetting state, eliminating the need for manual scaling in PlatformGraphicsView.

  • Adds initial scale tracking to ScalingCanvas with new constructor parameter
  • Removes redundant manual scaling call in PlatformGraphicsView.Draw method
  • Adds comprehensive UI test to verify the fix

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/Graphics/src/Graphics/ScalingCanvas.cs Adds initial scale tracking fields and constructor to preserve scale during ResetState()
src/Graphics/src/Graphics/Platforms/Android/PlatformGraphicsView.cs Removes redundant Scale() call and uses new ScalingCanvas constructor with scale parameter
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31182.cs Adds NUnit test to verify GraphicsView renders at correct size after ResetState()
src/Controls/tests/TestCases.HostApp/Issues/Issue31182.cs Adds test page with GraphicsView that calls ResetState() to reproduce the issue

_blurrableCanvas = _canvas as IBlurrableCanvas;
}

internal ScalingCanvas(ICanvas wrapped, float scale) : this(wrapped)
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

This introduces a new public API constructor that could be a breaking change. Consider marking this constructor as internal to prevent external usage, or ensure this is documented as a new API addition if intended for public consumption.

Copilot uses AI. Check for mistakes.

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Aug 19, 2025
@dotnet-policy-service
Copy link
Contributor

Hey there @@kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@kubaflo kubaflo added platform/android area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing and removed community ✨ Community Contribution labels Aug 19, 2025
@PureWeen
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

public void GraphicsViewShouldDrawAtFullSize()
{
App.WaitForElement("label");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Pending snapshot on Windows and Android. Running a build.

Copy link
Contributor

Choose a reason for hiding this comment

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

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Test failing on Android:

   at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2530
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2547
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 743
   at Microsoft.Maui.TestCases.Tests.Issues.Issue31182.GraphicsViewShouldDrawAtFullSize() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31182.cs:line 17
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

public void GraphicsViewShouldDrawAtFullSize()
{
App.WaitForElement("label");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

image

public void GraphicsViewShouldDrawAtFullSize()
{
App.WaitForElement("label");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Test failing on Android:

   at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2530
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2547
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 743
   at Microsoft.Maui.TestCases.Tests.Issues.Issue31182.GraphicsViewShouldDrawAtFullSize() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31182.cs:line 17
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

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

Labels

area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] GraphicsView draws at half size after canvas.ResetState() (issue appears on second Draw)

3 participants