-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] round scale for glyph atlas cache to 2 decimal places. #43752
Conversation
Maybe this is OK? 🤷♂️ |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. 🤷♂️
return std::round(scale * 10) / 10; | ||
} | ||
return std::round(scale * 100) / 100; | ||
} |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
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.
That results in almost half a pixel difference in some cases, though others are much smaller. |
If I round to two decimal places, that gives way less error, naturally:
|
If I blow up the text size to the largest possible supported system size, the errors stay pretty OK looking at 2 decimal places
|
2 decimal places of rounding is also sufficient to prevent the glyph atlas from filling up by scrolling through the cards on flutter/gallery. |
There was a problem hiding this 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.
…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
…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
…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
Fixes flutter/flutter#130750