Skip to content

Conversation

@gaaclarke
Copy link
Member

issue: #149652

This makes #149652 better. It doesn't completely it better though, there is still a shrinking of whitespace at larger scales. Without this patch though the test will fail with many 3 pixel jumps between glyphs.

I think scaling in the thousands is reasonable so this is an adequate test.

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 related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Feb 1, 2025
@gaaclarke
Copy link
Member Author

Maybe this would be better off as a golden test.

@gaaclarke
Copy link
Member Author

I also wrote a golden test for this. When the test is written this way, gaps of 3 pixels are not seen. This PR however does reduce the number of times the expectation fails though from 16 to 11. So this PR does seem to have a positive effect.

namespace {
int32_t CalculateSpaceBetweenUI(const impeller::testing::Screenshot* img) {
  const uint32_t* ptr = reinterpret_cast<const uint32_t*>(img->GetBytes());
  ptr += img->GetWidth() * static_cast<int32_t>(img->GetHeight() / 2.0);
  std::vector<size_t> boundaries;
  uint32_t value = *ptr++;
  for (size_t i = 1; i < img->GetWidth(); ++i) {
    if (((*ptr & 0x00ffffff) != 0) != ((value & 0x00ffffff) != 0)) {
      boundaries.push_back(i);
    }
    value = *ptr++;
  }

  assert(boundaries.size() == 6);
  return boundaries[4] - boundaries[3];
}
} // namespace

TEST_P(DlGoldenTest, MaintainsSpace) {
  SetWindowSize(impeller::ISize(1024, 200));
  impeller::Scalar font_size = 300;
  auto callback = [&](const char* text,
                      impeller::Scalar scale) -> sk_sp<DisplayList> {
    DisplayListBuilder builder;
    DlPaint paint;
    paint.setColor(DlColor::ARGB(1, 0, 0, 0));
    builder.DrawPaint(paint);
    builder.Scale(scale, scale);
    RenderTextInCanvasSkia(&builder, text, "Roboto-Regular.ttf",
                           DlPoint::MakeXY(10, 300),
                           TextRenderOptions{
                               .font_size = font_size,
                           });
    return builder.Build();
  };

  std::optional<int32_t> space;
  for (int i = 0; i <= 100; ++i) {
    Scalar scale = 0.440 + i / 1000.0;
    std::unique_ptr<impeller::testing::Screenshot> right =
        MakeScreenshot(callback("ui", scale));
    right->WriteToPNG("/Users/aaclarke/foo.png");
    if (!right) {
      GTEST_SKIP() << "making screenshots not supported.";
    }

    int32_t diff = CalculateSpaceBetweenUI(right.get());
    if (space.has_value()) {
      EXPECT_TRUE(diff >= *space)
          << "i" << i << " diff:" << diff << " space:" << *space;
    }
    space = diff;
  }
}

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

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

auto-submit bot commented Feb 1, 2025

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

@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 #162555 at sha 27bf370

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Feb 1, 2025
@gaaclarke
Copy link
Member Author

I'm swapping out the geometry test for a pixel test. This is more accurate and shows the results nicer. Before this change we'd see the gap between glyphs shrink 2 pixels despite the scale increasing. Now we only see it decrease 1 pixel.

@gaaclarke gaaclarke added this pull request to the merge queue Feb 3, 2025
Merged via the queue into flutter:master with commit cebc34c Feb 3, 2025
175 of 176 checks passed
@gaaclarke gaaclarke deleted the glyph-atlas-fidelity branch February 3, 2025 22:06
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2025
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 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
issue: flutter#149652

This makes flutter#149652 better. It
doesn't completely it better though, there is still a shrinking of
whitespace at larger scales. Without this patch though the test will
fail with many 3 pixel jumps between glyphs.

I think scaling in the thousands is reasonable so this is an adequate
test.

## 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
issue: flutter#149652

This makes flutter#149652 better. It
doesn't completely it better though, there is still a shrinking of
whitespace at larger scales. Without this patch though the test will
fail with many 3 pixel jumps between glyphs.

I think scaling in the thousands is reasonable so this is an adequate
test.

## 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 related. See also e: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants