Skip to content

[Android] GraphicsView scaling after canvas.ResetState - fix2#31198

Closed
kubaflo wants to merge 28 commits intodotnet:mainfrom
kubaflo:fix-31182
Closed

[Android] GraphicsView scaling after canvas.ResetState - fix2#31198
kubaflo wants to merge 28 commits intodotnet:mainfrom
kubaflo:fix-31182

Conversation

@kubaflo
Copy link
Copy Markdown
Contributor

@kubaflo kubaflo commented Aug 16, 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 AI and others added 27 commits August 15, 2025 23:25
…lates (dotnet#30275)

* Initial plan

* Fix iOS Custom Entitlements File override issue - respect user-defined CodesignEntitlements

Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>

* Add MSBuild tests for CodesignEntitlements fix

- Added SingleProject_CodesignEntitlementsRespected test to verify custom CodesignEntitlements property is preserved
- Added SingleProject_DefaultEntitlementsUsedWhenNoCustomSet test to verify default behavior still works
- Tests validate the fix for issue dotnet#30221 where custom entitlements were being overridden

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
…tnet#23665)

Context: https://github.com/davidortinau/AllTheLists

Profiling @davidortinau's app, I noticed the "Check-ins" sample felt
the slowest on Android.

One thing I noticed while scrolling:

    98.75ms (0.90%) Microsoft.Maui!Microsoft.Maui.Handlers.ImageHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect)
    67.11ms (0.61%) Mono.Android!Android.Widget.ImageView.ScaleType.get_CenterCrop()

In this case, `PlatformArrange()` is called a lot for every `<Image/>`:

    if (PlatformView.GetScaleType() == ImageView.ScaleType.CenterCrop)
    {
        var (left, top, right, bottom) = PlatformView.Context!.ToPixels(frame);
        var clipRect = new Android.Graphics.Rect(0, 0, right - left, bottom - top);
        PlatformView.ClipBounds = clipRect;
    }

`ImageView.ScaleType` is a class, and so and some bookkeeping is done
to lookup *the same* C# instance for a Java object. We can make this a
bit better by writing a new Java method:

    public static boolean isImageViewCenterCrop(@nonnull ImageView imageView) {
        return imageView.getScaleType() == ImageView.ScaleType.CENTER_CROP;
    }

Next, let's make a `PlatformView.ToPixels()` extension method that can
avoid calling `View.Context` for the same reason.

Lastly, we can make a `PlatformInterop.SetClipBounds()` method to avoid
creating a `Android.Graphics.Rect` object in C#.

With these changes, I can only see the topmost `PlatformArrange()`
method now:

    2.93ms (0.03%) Microsoft.Maui!Microsoft.Maui.Handlers.ImageHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect)

This should improve the layout performance of all .NET MAUI `<Image/>`
on Android. I also "banned" `GetScaleType()` in `eng/BannedSymbols.txt`.
…ds remaining threshold (dotnet#29763)

* Fix for 29740

* Update Issue29740.cs

* Update src/Controls/tests/TestCases.HostApp/Issues/Issue29740.cs

indentation changes

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>

* Update src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29740.cs

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>

---------

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
* Fixed the picker view items source does not display on mac platform

* Added the test case

* Added the output images.

* Fixed the picker view items source does not display on mac platform

* Added the test case

* Added the output images.

* Create ShouldDisplayPickerItemsWhenOpeningPicker.png

Added the output image on windows platform

* Ignore the test case on catalyst platform

* Added the test case for mac platform

* Added the macOS output image

* Added the comment line for fix.
* [iOS] Fixed hidden indicator

* [iOS] Fixed hidden indicator
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…st (dotnet#29569)

* [Android] Input controls should not change keyboard visibility - test

* searchBar

* CR fixes
* [Android] Top bar item colors - fix

* Avoid tab icon tint for FontImageSource on Android

Prevents applying TabIconTint when the tab icon is a FontImageSource, as it manages its own color. This ensures correct icon coloring for font-based icons in TabbedPageManager.
* Gradient background with ImageButton

* Update GradientBackgroundShouldWorkWithImageButton.png
* MenuItem color fix

* Added UI test

* Added snapshots

* Updated Mac snapshot
* [iOS] Thumb image improvements

* Added snapshots
* add support to dismiss the prompt with enter on keyboard

* Windows only

---------

Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
* Initial plan

* Fix CarouselView layout constraint issues on Mac Catalyst

Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>

* Add missing image

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
Co-authored-by: Rui Marinho <me@ruimarinho.net>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…not properly work - fix (dotnet#31100)

* Call UpdateLayout in MapIsGrouped on iOS

Added a call to handler.UpdateLayout() in the MapIsGrouped method to ensure the layout is refreshed when the grouping state changes in CollectionViewHandler2 for iOS.

* Added a UITest
* optimize JS escaping

* add tests

* copy to HybridWebView

* use conditional compilation

* Update src/Controls/tests/DeviceTests/Elements/WebView/WebViewTests.cs

Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>

* Move tests

* use common WebViewHelper class

* add missing using

* fix build

* Fix CI

* More tests

---------

Co-authored-by: Edward Miller <symbiogenisis@outlook.com>
Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
* Changing shape background color with dataTrigger

* Refactor
…1183)

Addresses issue dotnet#31182 where GraphicsView would draw at half size after calling canvas.ResetState() on Android. ScalingCanvas now preserves the initial scale and restores it after ResetState and RestoreState. Added related test cases to verify correct drawing behavior.
…dotnet#27801)

* Fixed the Border Rendering issues in CollectionViewHandler2

* Remove the unwanted namspace

* Removed UI test and added the device test

* Resolved the build errors

* Registered the cv2 handler inside the test to avoid other test failures

* Added a Assert.NotNull test

* Resolved the conflicts
@kubaflo kubaflo requested a review from a team as a code owner August 16, 2025 01:11
@kubaflo kubaflo requested review from StephaneDelcroix and removed request for a team August 16, 2025 01:11
@kubaflo kubaflo requested a review from jsuarezruiz August 16, 2025 01:11
@kubaflo kubaflo self-assigned this Aug 16, 2025
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Aug 16, 2025
@PureWeen
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@kubaflo kubaflo changed the base branch from inflight/current to inflight/candidate August 16, 2025 22:00
@PureWeen
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Copy Markdown
Member

@kubaflo to get the candidate build in a green state I've reverted this PR on the candidate build for now

Let's give this one a fresh start against main and get it green their and then merge that into inflight

Copy link
Copy Markdown
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

Eliminates an unnecessary call to _scalingCanvas.Scale in PlatformGraphicsView. The scaling is already handled by adjusting the dirtyRect dimensions, preventing double scaling.

TextTransform Property Does Not Apply at Runtime When TextType="Html" Is Set on Label (dotnet#29700)
@kubaflo kubaflo changed the base branch from inflight/candidate to main August 19, 2025 22:29
@kubaflo
Copy link
Copy Markdown
Contributor Author

kubaflo commented Aug 19, 2025

Closed in favour of #31244

@kubaflo kubaflo closed this Aug 19, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Sep 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution

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)