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

[Impeller] Snap glyph positions to screen space pixels and map UVs correctly #40912

Merged
merged 3 commits into from Apr 5, 2023

Conversation

bdero
Copy link
Member

@bdero bdero commented Apr 4, 2023

Resolves flutter/flutter#121887.

Hoo boy, this one took longer than I'd like to admit to figure out. Improvements:

  1. Properly snap the vertex positions to the screen space pixel grid by keeping track of screen space.
  2. Glyph positions are converted to screen space and rounded; glyph sizes are converted to "local" (no translation) screen space and rounded up.
  3. UVs are properly mapped to the atlas with a half texel offset so that we sample in the middle of texels.
  4. Only use these rounding behaviors when the transform is translation-scale (which is when we nearest sample). In particular, 2 only works for affine matrices.

I think we can come through and remove more CPU cycles here, but wanted to land this since it finally fixes the problem where we skip sampling rows/columns in glyphs.

Before:

Untitled2.mov

After:

Untitled1.mov

@bdero bdero self-assigned this Apr 4, 2023
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM!

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

Changes reported for pull request #40912 at sha 4784512

@chinmaygarde
Copy link
Member

This golden issue seems related
Screenshot 2023-04-04 at 1 34 17 PM

@bdero
Copy link
Member Author

bdero commented Apr 5, 2023

Once the text gets far enough away (I believe when it passes behind the singularity) it seems to flip to the other side and start coming inward.

We used to apply this same transform to the position on the GPU, but now we're doing it on the CPU, so I suspect something is overflowing or not getting clamped correctly in our matrix utils on the CPU. Looking into it.

image

@bdero
Copy link
Member Author

bdero commented Apr 5, 2023

Figured it out. I was doing a vec2 transform instead of a vec4 transform, and so we were resetting the projective coord prior to the final transform to clip space.

@bdero bdero merged commit db23c3f into flutter:main Apr 5, 2023
37 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 5, 2023
CaseyHillers pushed a commit to flutter/flutter that referenced this pull request Apr 5, 2023
…124200)

flutter/engine@4219c72...db23c3f

2023-04-05 bdero@google.com [Impeller] Snap glyph positions to screen
space pixels and map UVs correctly (flutter/engine#40912)
2023-04-05 chris@bracken.jp [macOS] Handle termination in
FlutterAppDelegate (flutter/engine#40929)
2023-04-05 skia-flutter-autoroll@skia.org Manual roll Dart SDK from
f97b9d9b2f64 to beff36793081 (1 revision) (flutter/engine#40934)
2023-04-05 chillers@google.com Revert "[web] remove obsolete object
caches; simplify native object management" (flutter/engine#40937)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jonahwilliams@google.com,rmistry@google.com,zra@google.com on
the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
exaby73 pushed a commit to NevercodeHQ/flutter that referenced this pull request Apr 17, 2023
…lutter#124200)

flutter/engine@4219c72...db23c3f

2023-04-05 bdero@google.com [Impeller] Snap glyph positions to screen
space pixels and map UVs correctly (flutter/engine#40912)
2023-04-05 chris@bracken.jp [macOS] Handle termination in
FlutterAppDelegate (flutter/engine#40929)
2023-04-05 skia-flutter-autoroll@skia.org Manual roll Dart SDK from
f97b9d9b2f64 to beff36793081 (1 revision) (flutter/engine#40934)
2023-04-05 chillers@google.com Revert "[web] remove obsolete object
caches; simplify native object management" (flutter/engine#40937)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jonahwilliams@google.com,rmistry@google.com,zra@google.com on
the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Archived in project
3 participants