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] Vulkan: Top line of text is cropped sometimes in wonderous app #128624

Closed
gaaclarke opened this issue Jun 9, 2023 · 36 comments · Fixed by flutter/engine#42792 or flutter/engine#43919
Assignees
Labels
e: impeller Impeller rendering backend issues and features requests engine flutter/engine repository. See also e: labels. P1 High-priority issues at the top of the work list team-engine Owned by Engine team triaged-engine Triaged by Engine team

Comments

@gaaclarke
Copy link
Member

description

I've seen this with the opengles backend and the vulkan backend. It's shown up in a couple places in the app, not just here.

I checked against the skia backend and this was not a problem.

doctor

[✓] Flutter (Channel main, 3.12.0-3.0.pre.44, on macOS 13.4 22F66 darwin-arm64, locale en)
    • Flutter version 3.12.0-3.0.pre.44 on channel main at /Users/aaclarke/dev/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e84fa2ce47 (4 hours ago), 2023-06-09 23:06:21 +0500
    • Engine revision bc6e047570
    • Dart version 3.1.0 (build 3.1.0-180.0.dev)
    • DevTools version 2.24.0

engine version

64d0cc34e7949bd6e5b3891670e124c5cb233fa0

os

Android

screenshot

Screenshot_20230609-143436

cc @bdero

@gaaclarke gaaclarke added engine flutter/engine repository. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Jun 9, 2023
@github-project-automation github-project-automation bot moved this to 🤔 Needs Triage in Impeller Jun 9, 2023
@bdero
Copy link
Member

bdero commented Jun 9, 2023

Is this happening on the Metal backend too? If that's the case, then this is definitely a regression introduced after the 3.10 branch cut.

@bdero
Copy link
Member

bdero commented Jun 9, 2023

I checked wondrous at engine head and am not reproducing it on iOS.

Screen Shot 2023-06-09 at 4 26 00 PM

@bdero bdero changed the title [Impeller] Top line of text is cropped sometimes in wonderous app [Impeller] Vulkan: Top line of text is cropped sometimes in wonderous app Jun 9, 2023
@bdero bdero added the e: vulkan label Jun 9, 2023
@bdero bdero moved this from 🤔 Needs Triage to 🖖 Vulkan in Impeller Jun 9, 2023
@bdero bdero removed the e: vulkan label Jun 9, 2023
@gaaclarke

This comment was marked as off-topic.

@bdero

This comment was marked as off-topic.

@gaaclarke

This comment was marked as off-topic.

@bdero

This comment was marked as off-topic.

@jonahwilliams
Copy link
Member

Please check if this is fixed after flutter/engine#42746 lands

@jonahwilliams
Copy link
Member

(I cannot repro it before or after, but it probably depends on screen size)

@gaaclarke

This comment was marked as off-topic.

@jonahwilliams

This comment was marked as off-topic.

@chinmaygarde
Copy link
Member

Closing as fixed in flutter/engine#42746. We can re-open if this happens again.

@github-project-automation github-project-automation bot moved this from 🖖 Vulkan to ✅ Done in Impeller Jun 12, 2023
@jonahwilliams jonahwilliams reopened this Jun 12, 2023
@github-project-automation github-project-automation bot moved this from ✅ Done to 🤔 Needs Triage in Impeller Jun 12, 2023
@jonahwilliams
Copy link
Member

I can repro this, will need a slightly different fix

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 27, 2023
@jonahwilliams
Copy link
Member

Also does not repro on iPhone 13.

@jonahwilliams
Copy link
Member

Not only that, but the text itself is jittery as I scroll which does not happen on Pixels either. I wonder if there is some sort of "helpful" correction being applied somewhere? Though I'm not sure where that would be.

@gaaclarke

This comment was marked as off-topic.

@jonahwilliams
Copy link
Member

From running locally, I can see that the glyphs in the atlas are rendered right against the edge of the glyph atlas, obviously cutting off parts of the glyph and/or antialiased pixels on some of them. Given that we should be rendering everything with 2px padding it seems like something is off...

@jonahwilliams
Copy link
Member

Something I am noticing is that on Android Skia starts from the bottom of the atlas...

@chinmaygarde chinmaygarde moved this from 🤔 Needs Triage to 🐞 Bugs in Impeller Jun 27, 2023
@chinmaygarde chinmaygarde added this to the Impeller on Android milestone Jun 27, 2023
@chinmaygarde
Copy link
Member

Perhaps this is caused by incorrect UV mapping needing after we added the 2px padding? Also, atlases on Android generated by Skia won't use the CoreText. There could be differences in glyph AA in atlases. So maybe we need more padding perhaps?

@jonahwilliams
Copy link
Member

I tried adding more padding but it made no difference :( . I think the glyph bounds themselves are wrong or need some other adjustment

@jason-simmons
Copy link
Member

Reproduced this on a Pixel 3.

The glyphs render correctly if I remove the sk_font.setHinting(SkFontHinting::kSlight) call in text_render_context_skia.cc.

@jonahwilliams
Copy link
Member

FYI @bdero

IRC the goal of adding that flag was better fidelity on iOS at the time, but obvs its not helping us on Android so we could disable it with an ifdef for now.

That said, we should probably figure out how to handle these flags correctly.

@jonahwilliams
Copy link
Member

If I comment out that line, then I can still reproduce this issue on an S10 on Flutter gallery. ☹️

@github-project-automation github-project-automation bot moved this from 🐞 Bugs to ✅ Done in Impeller Jun 28, 2023
@jonahwilliams jonahwilliams reopened this Jun 28, 2023
@github-project-automation github-project-automation bot moved this from ✅ Done to 🤔 Needs Triage in Impeller Jun 28, 2023
@chinmaygarde chinmaygarde added the P1 High-priority issues at the top of the work list label Jul 5, 2023
@chinmaygarde chinmaygarde moved this from 🤔 Needs Triage to 🐞 Bugs in Impeller Jul 6, 2023
@flutter-triage-bot flutter-triage-bot bot added team-engine Owned by Engine team triaged-engine Triaged by Engine team labels Jul 8, 2023
@chinmaygarde
Copy link
Member

Just adding a note that glyph offsets on Android are also reproducible with stroked text (perhaps even more so?). This is perhaps the same underlying issue.

@bdero bdero self-assigned this Jul 22, 2023
@github-project-automation github-project-automation bot moved this from 🐞 Bugs to ✅ Done in Impeller Jul 22, 2023
bdero added a commit to flutter/engine that referenced this issue Jul 22, 2023
Resolves flutter/flutter#128624.

It turns out that `SkFont::getBounds()` snaps results to integers on
Android, but not iOS. By scaling the font up and scaling the resulting
per-glyph bounds back down, we can ensure that the results are always
precise enough.

I also found errors with our usage of the computed bounds, but those
were comparatively minor fixes.
@github-actions
Copy link

github-actions bot commented Aug 5, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2023
@jason-simmons
Copy link
Member

Looked into the behavior of the flutter/engine@4ad970f patch.

Skia is rounding the font metrics to integers in the SkScalerContext. Specifically, when SkScalerContext constructs an SkGlyph it calls SkScalerContext::SaturateGlyphBounds, which does an SkRect::roundOut on the glyph's bounds rectangle.

flutter/engine@4ad970f is changing the font's size to 100000 to compute metrics and then scaling the metrics down to the original font size. With larger metric values, there will be less loss of precision due to the SkScalerContext rounding.

When given a huge font size like that Skia actually builds the glyphs at a smaller size and then applies scaling to produce the large size. SkStrikeSpec::MakeCanonicalized calls ShouldDrawAsPath, which checks whether the font exceeds various limits that require path rendering. If so, MakeCanonicalized creates a font using a standard size for path rendering. That size is SkFontPriv::kCanonicalTextSizeForPaths, which is defined as 64.

Impeller should get the same results by obtaining the metrics from a font of size 64 instead of 100000. Or Impeller may be able to further improve the precision by using a size larger than 64 but less than the threshold that triggers ShouldDrawAsPath.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
e: impeller Impeller rendering backend issues and features requests engine flutter/engine repository. See also e: labels. P1 High-priority issues at the top of the work list team-engine Owned by Engine team triaged-engine Triaged by Engine team
Projects
No open projects
Archived in project
5 participants