Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] round scale for glyph atlas cache to 2 decimal places. #43752

Merged
merged 10 commits into from
Jul 25, 2023

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams
Copy link
Member Author

Maybe this is OK? 🤷‍♂️

@jonahwilliams jonahwilliams requested a review from bdero July 18, 2023 00:38
Copy link
Member

@bdero bdero left a comment

Choose a reason for hiding this comment

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

I haven't tried it out, but something like this should be OK

@@ -25,6 +25,11 @@ TextContents::TextContents() = default;

TextContents::~TextContents() = default;

// static
Scalar TextContents::RoundFontScale(Scalar value) {
return std::round(value * 10.0) / 10.0;
Copy link
Member

@bdero bdero Jul 18, 2023

Choose a reason for hiding this comment

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

I think this snapping would need to be done on a logarithmic scale (apply log, apply snapping, invert log w/ exponential)? Also, the snapping precision would need to somehow incorporate the text frame's font size as well.

For example, the difference between 0.1 and 0.2 is potentially huge, getting worse as the given font size increases.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm thats a good point. I'll need to investigate this a bit more.

Copy link
Member Author

Choose a reason for hiding this comment

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

okay, after much thinking I've come up with an OK solution.... round to one decimal if the point size is < 25, Round to two decimals if > 50. 🤷‍♂️

@jonahwilliams jonahwilliams requested a review from bdero July 24, 2023 19:35
return std::round(scale * 10) / 10;
}
return std::round(scale * 100) / 100;
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this covers all cases, would something like this work?

// The point_size is multiplied into the total scale of the font later,
// and so we need to linearly increase the step precision as the point size increases.
auto precision = 20 * point_size; // The constant here may need to be adjusted for best perf.
return std::pow(kE, std::round(std::log(scale) * precision) / precision);

image

https://www.desmos.com/calculator/sqpcws9bfv

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 curve is going to introduce a lot of churn for values that are already fairly stable.

For the default text scale of 3.5x (the DPR) we can end up converting this to 3.49908 or 3.50127 based on the exact text scale. I don't we're going to be able to use an log based rounding.

@jonahwilliams
Copy link
Member Author

Running though flutter gallery, I'm looking at how much error we introduce by rounding. For example on one page we round 3.04602 -> 3.

E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.414219, 0.38833)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0, 0)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.215739, 0.414219)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.258887, 0.310664)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.258887, 0.310664)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.293405, 0.414219)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0862956, 0.422848)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.310664, 0.310664)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.293405, 0.302035)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.258887, 0.310664)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.310664, 0.422848)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0604069, 0.414219)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.302035, 0.310664)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0, 0)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.172591, 0.302035)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.302035, 0.310664)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.215739, 0.371071)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.258887, 0.310664)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0862956, 0.422848)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0604069, 0.414219)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0, 0)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.258887, 0.310664)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.310664, 0.414219)
E/flutter (21011): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.310664, 0.414219)

That results in almost half a pixel difference in some cases, though others are much smaller.

@jonahwilliams
Copy link
Member Author

If I round to two decimal places, that gives way less error, naturally:

E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(96)] 3.04602->3.05
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0288233, 0.053671)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0258416, 0.0516832)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0198781, 0.0377685)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.010933, 0.0506893)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0258416, 0.0377685)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0248477, 0.0387624)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(96)] 3.04602->3.05
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0357807, 0.0335444)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0, 0)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0186358, 0.0357807)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0223629, 0.0268355)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0223629, 0.0268355)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0253446, 0.0357807)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.00745431, 0.0365261)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0268355, 0.0268355)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0253446, 0.0260901)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0223629, 0.0268355)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0268355, 0.0365261)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.00521801, 0.0357807)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0260901, 0.0268355)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0, 0)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0149086, 0.0260901)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0260901, 0.0268355)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0186358, 0.0320535)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0223629, 0.0268355)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.00745431, 0.0365261)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.00521801, 0.0357807)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0, 0)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0223629, 0.0268355)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0268355, 0.0357807)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0268355, 0.0357807)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(96)] 3.5->3.5

@jonahwilliams
Copy link
Member Author

If I blow up the text size to the largest possible supported system size, the errors stay pretty OK looking at 2 decimal places

E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(96)] 3.39525->3.4
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.128199, 0.120186)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0, 0)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0667702, 0.128199)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0801243, 0.0961491)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0801243, 0.0961491)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0908075, 0.128199)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0267081, 0.13087)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0961491, 0.0961491)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0908075, 0.0934783)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0801243, 0.0961491)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0961491, 0.13087)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0186957, 0.128199)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0934783, 0.0961491)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(96)] 3.39525->3.4
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0534162, 0.0934783)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0934783, 0.0961491)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0667702, 0.114845)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0801243, 0.0961491)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0267081, 0.13087)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0186957, 0.128199)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0, 0)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0801243, 0.0961491)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0961491, 0.128199)
E/flutter (21427): [ERROR:flutter/impeller/typographer/text_frame.cc(101)] (0.0961491, 0.128199)

@jonahwilliams jonahwilliams changed the title [Impeller] round scale for glyph atlas cache to 1 decimal place. [Impeller] round scale for glyph atlas cache to 2 decimal places. Jul 25, 2023
@jonahwilliams
Copy link
Member Author

2 decimal places of rounding is also sufficient to prevent the glyph atlas from filling up by scrolling through the cards on flutter/gallery.

Copy link
Member

@bdero bdero left a comment

Choose a reason for hiding this comment

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

If it seems like it won't introduce fidelity issues for reasonable scale/point_size inputs, I say let's go for it.

Maybe include your error calculation/debug print code, but commented out? That may come in handy later.

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 25, 2023
@auto-submit auto-submit bot merged commit f5fbfa8 into flutter:main Jul 25, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 25, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jul 25, 2023
…131283)

flutter/engine@0a5c6cd...f5fbfa8

2023-07-25 jonahwilliams@google.com [Impeller] round scale for glyph atlas cache to 2 decimal places. (flutter/engine#43752)
2023-07-25 skia-flutter-autoroll@skia.org Roll ANGLE from 7ae6458b664f to 2d5fb09d7f0a (2 revisions) (flutter/engine#44002)
2023-07-25 skia-flutter-autoroll@skia.org Roll Skia from 04ab62b4f8c9 to eb5b5bc4fb86 (2 revisions) (flutter/engine#44001)
2023-07-25 skia-flutter-autoroll@skia.org Roll ANGLE from e8c8c5651223 to 7ae6458b664f (1 revision) (flutter/engine#43999)
2023-07-25 bdero@google.com [Impeller] Use basis of effect transform in MatrixFilter. (flutter/engine#43990)
2023-07-25 skia-flutter-autoroll@skia.org Roll Fuchsia Mac SDK from DO73K2Twew-a51xHm... to 0StTjIqUxGkc3nOWT... (flutter/engine#43996)
2023-07-25 skia-flutter-autoroll@skia.org Roll ANGLE from 1b17c91e4231 to e8c8c5651223 (2 revisions) (flutter/engine#43997)
2023-07-25 skia-flutter-autoroll@skia.org Roll Skia from 81ea617ee386 to 04ab62b4f8c9 (1 revision) (flutter/engine#43994)

Also rolling transitive DEPS:
  fuchsia/sdk/core/mac-amd64 from DO73K2Twew-a to 0StTjIqUxGkc

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
LouiseHsu pushed a commit to LouiseHsu/flutter that referenced this pull request Jul 31, 2023
…lutter#131283)

flutter/engine@0a5c6cd...f5fbfa8

2023-07-25 jonahwilliams@google.com [Impeller] round scale for glyph atlas cache to 2 decimal places. (flutter/engine#43752)
2023-07-25 skia-flutter-autoroll@skia.org Roll ANGLE from 7ae6458b664f to 2d5fb09d7f0a (2 revisions) (flutter/engine#44002)
2023-07-25 skia-flutter-autoroll@skia.org Roll Skia from 04ab62b4f8c9 to eb5b5bc4fb86 (2 revisions) (flutter/engine#44001)
2023-07-25 skia-flutter-autoroll@skia.org Roll ANGLE from e8c8c5651223 to 7ae6458b664f (1 revision) (flutter/engine#43999)
2023-07-25 bdero@google.com [Impeller] Use basis of effect transform in MatrixFilter. (flutter/engine#43990)
2023-07-25 skia-flutter-autoroll@skia.org Roll Fuchsia Mac SDK from DO73K2Twew-a51xHm... to 0StTjIqUxGkc3nOWT... (flutter/engine#43996)
2023-07-25 skia-flutter-autoroll@skia.org Roll ANGLE from 1b17c91e4231 to e8c8c5651223 (2 revisions) (flutter/engine#43997)
2023-07-25 skia-flutter-autoroll@skia.org Roll Skia from 81ea617ee386 to 04ab62b4f8c9 (1 revision) (flutter/engine#43994)

Also rolling transitive DEPS:
  fuchsia/sdk/core/mac-amd64 from DO73K2Twew-a to 0StTjIqUxGkc

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
vashworth pushed a commit to vashworth/flutter that referenced this pull request Aug 2, 2023
…lutter#131283)

flutter/engine@0a5c6cd...f5fbfa8

2023-07-25 jonahwilliams@google.com [Impeller] round scale for glyph atlas cache to 2 decimal places. (flutter/engine#43752)
2023-07-25 skia-flutter-autoroll@skia.org Roll ANGLE from 7ae6458b664f to 2d5fb09d7f0a (2 revisions) (flutter/engine#44002)
2023-07-25 skia-flutter-autoroll@skia.org Roll Skia from 04ab62b4f8c9 to eb5b5bc4fb86 (2 revisions) (flutter/engine#44001)
2023-07-25 skia-flutter-autoroll@skia.org Roll ANGLE from e8c8c5651223 to 7ae6458b664f (1 revision) (flutter/engine#43999)
2023-07-25 bdero@google.com [Impeller] Use basis of effect transform in MatrixFilter. (flutter/engine#43990)
2023-07-25 skia-flutter-autoroll@skia.org Roll Fuchsia Mac SDK from DO73K2Twew-a51xHm... to 0StTjIqUxGkc3nOWT... (flutter/engine#43996)
2023-07-25 skia-flutter-autoroll@skia.org Roll ANGLE from 1b17c91e4231 to e8c8c5651223 (2 revisions) (flutter/engine#43997)
2023-07-25 skia-flutter-autoroll@skia.org Roll Skia from 81ea617ee386 to 04ab62b4f8c9 (1 revision) (flutter/engine#43994)

Also rolling transitive DEPS:
  fuchsia/sdk/core/mac-amd64 from DO73K2Twew-a to 0StTjIqUxGkc

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Impeller] Glyph atlas caching based on scale is unstable.
2 participants