Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked the way we are clipping dirty rects with CompositionTarget #14806

Merged
merged 2 commits into from
Mar 5, 2024

Conversation

kekekeks
Copy link
Member

@kekekeks kekekeks commented Mar 4, 2024

  1. CompositionTarget now expects the drawing context to be using device units rather than scaled units
  2. CompositionTarget now tracks dirty rects using device coordinates
  3. Added a special mode that enforces a layer to be used for rendering (workaround for Slider with custom style leaves spots outside of its bounds #14270 / https://issues.skia.org/issues/327877721)
  4. Added a special mode that utilizes SKRegion for tracking dirty rects and clipping (as opposed to expanding a single clip rect)
  5. Added a way for CompositionCustomVisualHandler to access the current clip rect (transformed to visual coordinate space)
  6. Added CompositionOptions class to be used with AppBuilder.With

@kekekeks kekekeks marked this pull request as draft March 4, 2024 08:59
@kekekeks kekekeks marked this pull request as ready for review March 4, 2024 09:02
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0045561-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0045585-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0045593-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0045601-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@@ -172,7 +172,8 @@ private void UpdateCore()
v.SynchronizeCompositionChildVisuals();
_dirty.Clear();
_recalculateChildren.Clear();
CompositionTarget.Size = _root.ClientSize;

CompositionTarget.PixelSize = PixelSize.FromSizeRounded(_root.ClientSize, _root.RenderScaling);
Copy link
Member

Choose a reason for hiding this comment

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

In some backends, like Browser, we can get this pixel size without doing roundtrip of scaling conversion. See https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry/devicePixelContentBoxSize

Possibly, toplevel itself should report its pixel size?

Copy link
Member Author

@kekekeks kekekeks Mar 5, 2024

Choose a reason for hiding this comment

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

Yes, but I've decided against touching every single backend including ones I can't really test (especially since that we want this PR in 11.1 for SE needs).

Copy link
Member

Choose a reason for hiding this comment

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

I meant more moving PixelSize.FromSizeRounded to the TopLevel level, instead of updating each backend at once. It can be done gradually, once main API is there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will devicePixelContentBoxSize match the ClientSize that we are using for layout purposes?

Copy link
Member

Choose a reason for hiding this comment

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

devicePixelContentBoxSize itself returns pixel size that can be used to set render size of the html canvas.
Since our ClientSize is scaled, right now we divide devicePixelContentBoxSize by scaling factor.
https://github.com/AvaloniaUI/Avalonia/blob/master/src/Browser/Avalonia.Browser/AvaloniaView.cs#L473

Copy link
Member

Choose a reason for hiding this comment

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

Can be done in separated PR

@@ -95,6 +100,11 @@ public static Rect ToAvaloniaRect(this SKRect r)
{
return new Rect(r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top);
}

public static PixelRect ToAvaloniaPixelRect(this SKRectI r)
Copy link
Member

Choose a reason for hiding this comment

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

Note: all of these extensions are public for some reason. But it's too late to change that.

@maxkatz6
Copy link
Member

maxkatz6 commented Mar 5, 2024

CompositionTarget now expects the drawing context to be using device units rather than scaled units

Does it affect current drawing context API consumers? I.e. custom drawn controls.

@kekekeks
Copy link
Member Author

kekekeks commented Mar 5, 2024

Drawing API always uses the control-local coordinate space. The current change moves TopLevel-wide DPI scaling from DrawingContext to CompositionTarget itself.

Right now it doesn't affect built-in scaling for user-created drawing contexts like one returned from RenderTargetBitmap.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0045653-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0045671-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0045675-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 added this pull request to the merge queue Mar 5, 2024
@maxkatz6 maxkatz6 removed this pull request from the merge queue due to a manual request Mar 5, 2024
@maxkatz6 maxkatz6 merged commit 4dbb165 into master Mar 5, 2024
7 checks passed
@maxkatz6 maxkatz6 deleted the feature/integer-clip-2 branch March 5, 2024 21:37
@llfab
Copy link
Sponsor

llfab commented Mar 8, 2024

Tested on latest Avalonia source vs. 11.0.9. Seems the problem is solved on latest source. Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants