这是indexloc提供的服务,不要输入任何密码
Skip to content

Fixed translated text's subpixel alignment. #162824

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

Merged
merged 10 commits into from
Feb 7, 2025

Conversation

gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented Feb 6, 2025

fixes #162776
fixes #149652

Previously we weren't calculating the subpixel offset correctly. We weren't using the transform of the object being drawn to get global coordinates, now we are.

Video of #149652 after PR

gotit.mov

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems engine flutter/engine repository. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Feb 6, 2025
@gaaclarke gaaclarke force-pushed the subpixel-translation-fix branch from 3cd5c84 to 037a0af Compare February 6, 2025 18:58
@gaaclarke gaaclarke marked this pull request as ready for review February 6, 2025 22:29
@gaaclarke
Copy link
Member Author

There is some cleanup that needs to come to the font rendering code. I'm not happy with how this is all laid out but this is the minimal change to fix the issue. We can consider refactors later.

  1. I want to remove scale and offset from TextFrame and just rely on the transform
  2. I don't like the text frame "per frame data", that should just come in the arguments instead of getting stored on the text frame


// Checks that the left most edge of the glyph is fading out as we push
// it to the right by fractional pixels.
TEST_P(DlGoldenTest, SubpixelScaledTranslated) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the test that would actually fail before this change, the other passed.

@@ -452,7 +452,8 @@ TypographerContextSkia::CollectNewGlyphs(
for (const auto& glyph_position : run.GetGlyphPositions()) {
Point subpixel = TextFrame::ComputeSubpixelPosition(
glyph_position, scaled_font.font.GetAxisAlignment(),
frame->GetOffset(), frame->GetScale());
frame->GetTransform() *
Matrix::MakeTranslation(frame->GetOffset()));
Copy link
Member Author

Choose a reason for hiding this comment

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

This is annoying, the transform here doesn't include the offset, but when you go to render it in TextContents it has the offset included.

Copy link
Contributor

@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!

const uint32_t* ptr = reinterpret_cast<const uint32_t*>(img->GetBytes());
for (size_t i = 0; i < img->GetHeight(); ++i) {
for (int32_t j = 0; j < static_cast<int32_t>(img->GetWidth()); ++j) {
if (((*ptr & 0x00ffffff) != 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, of course

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, sir

@gaaclarke
Copy link
Member Author

Weird, something is going on with the vulkan renderer where we are getting zero values in the blue channel. We should look into that. For now I switched to the green channel which works as expected locally.

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 7, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 7, 2025
Copy link
Contributor

auto-submit bot commented Feb 7, 2025

autosubmit label was removed for flutter/flutter/162824, because - The status or check suite Mac mac_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 7, 2025
Copy link
Contributor

auto-submit bot commented Feb 7, 2025

autosubmit label was removed for flutter/flutter/162824, because - The status or check suite Linux linux_web_engine_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 7, 2025
@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 7, 2025
@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.

For more guidance, visit Writing a golden file test for package:flutter.

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

Changes reported for pull request #162824 at sha 7e0ef41

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
gaaclarke added a commit to gaaclarke/flutter that referenced this pull request Feb 11, 2025
fixes flutter#162776
fixes flutter#149652

Previously we weren't calculating the subpixel offset correctly. We
weren't using the transform of the object being drawn to get global
coordinates, now we are.

## Video of flutter#149652 after PR



https://github.com/user-attachments/assets/3e9063d5-f70c-46d0-a7a4-892819b247b8



## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
gaaclarke added a commit to gaaclarke/flutter that referenced this pull request Feb 11, 2025
fixes flutter#162776
fixes flutter#149652

Previously we weren't calculating the subpixel offset correctly. We
weren't using the transform of the object being drawn to get global
coordinates, now we are.

## Video of flutter#149652 after PR



https://github.com/user-attachments/assets/3e9063d5-f70c-46d0-a7a4-892819b247b8



## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
@gaaclarke gaaclarke mentioned this pull request Feb 11, 2025
9 tasks
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
auto-submit bot pushed a commit that referenced this pull request Feb 20, 2025
This is a cherry-pick for all the changes that went into fixing #149652

It looks like a lot but most of it is testing and refactoring.

## PRs included
- #161625
- #162351
- #162415
- #162555
- #162824

## Impacted Users

All users of Impeller.

## Impact Description

Animating text with translations and scales can cause:
  - jitter between glyphs
  - jitter between glyphs and the baseline
  - artifacts when rendering glyphs at non integer scales

## Workaround

Use skia.

## Risk

Since this edits how text is rendered, the risk is pretty high.  The actual changes are small and there are unit tests for them.  Golden test coverage for cherry-picks is not complete and text rendering golden coverage for android is problematic.

## Test Coverage

Yes.

## Validation Steps

The reproduction code in #149652 is good.
Fintasys pushed a commit to Fintasys/flutter that referenced this pull request May 14, 2025
This is a cherry-pick for all the changes that went into fixing flutter#149652

It looks like a lot but most of it is testing and refactoring.

- flutter#161625
- flutter#162351
- flutter#162415
- flutter#162555
- flutter#162824

All users of Impeller.

Animating text with translations and scales can cause:
  - jitter between glyphs
  - jitter between glyphs and the baseline
  - artifacts when rendering glyphs at non integer scales

Use skia.

Since this edits how text is rendered, the risk is pretty high.  The actual changes are small and there are unit tests for them.  Golden test coverage for cherry-picks is not complete and text rendering golden coverage for android is problematic.

Yes.

The reproduction code in flutter#149652 is good.
CodixNinja pushed a commit to CodixNinja/flutter that referenced this pull request May 15, 2025
This is a cherry-pick for all the changes that went into fixing flutter/flutter#149652

It looks like a lot but most of it is testing and refactoring.

## PRs included
- flutter/flutter#161625
- flutter/flutter#162351
- flutter/flutter#162415
- flutter/flutter#162555
- flutter/flutter#162824

## Impacted Users

All users of Impeller.

## Impact Description

Animating text with translations and scales can cause:
  - jitter between glyphs
  - jitter between glyphs and the baseline
  - artifacts when rendering glyphs at non integer scales

## Workaround

Use skia.

## Risk

Since this edits how text is rendered, the risk is pretty high.  The actual changes are small and there are unit tests for them.  Golden test coverage for cherry-picks is not complete and text rendering golden coverage for android is problematic.

## Test Coverage

Yes.

## Validation Steps

The reproduction code in flutter/flutter#149652 is good.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems e: impeller Impeller rendering backend issues and features requests engine flutter/engine repository. See also e: labels. will affect goldens Changes to golden files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Subpixel fonts getting different results when translated versus offset [Impeller] Jittery glyphs when animating text transformation
2 participants