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

Conversation

jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Aug 26, 2023

Fixes flutter/flutter#133388

Just use the TextBounds that Skia gives us. These are slightly larger but already computed. If the larger bounds are a problem we can go back to Impeller computed bounds, but using a cached computation.

Skia

flutter_02

Impeller

flutter_03

@jonahwilliams
Copy link
Contributor Author

Its easier for this to land after #45090

Comment on lines -60 to -65
case SkTextBlobRunIterator::kDefault_Positioning:
FML_DLOG(ERROR) << "Unimplemented.";
break;
case SkTextBlobRunIterator::kHorizontal_Positioning:
FML_DLOG(ERROR) << "Unimplemented.";
break;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we're never going to use these, I deleted them and left it for the default.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have a slight preference for removing the default so that we know if Skia adds some other value to this that we could be handling.

font.getBounds(glyphs, glyph_count, glyph_bounds.data(), nullptr);

std::vector<TextRun::GlyphPosition> positions;
positions.reserve(glyph_count);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allocate the right amount of storage once rather than appending.

Copy link
Contributor

Choose a reason for hiding this comment

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

Put this as a comment in the code instead of in the PR review

Copy link
Contributor Author

Choose a reason for hiding this comment

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

feels like

/// the int
int a = 0;

Copy link
Contributor

Choose a reason for hiding this comment

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

🤷🏼. My point is if you think it's important enough to call out in the review, it's probably better as a comment :)

Defer to you, definitely a micro-nit.


namespace impeller {

TextFrame::TextFrame() = default;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default constructor is no glyphs, empty bounds, no color. Which should be perfectly safe.

return font_;
}

bool TextRun::HasColor() const {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to track this per run.

namespace impeller {

TextFrame MakeTextFrameFromTextBlobSkia(const sk_sp<SkTextBlob>& blob);
std::optional<TextFrame> MakeTextFrameFromTextBlobSkia(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this optional so that we can avoid creating TextContents at all if the textblob is nullptr for some reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto above, comment in the code :)

@chinmaygarde chinmaygarde changed the title [Impeller] cache Skia text bounds computation. [Impeller] Cache Skia text bounds computation. Aug 28, 2023
@jonahwilliams jonahwilliams marked this pull request as ready for review August 28, 2023 20:49
Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

font.getBounds(glyphs, glyph_count, glyph_bounds.data(), nullptr);

std::vector<TextRun::GlyphPosition> positions;
positions.reserve(glyph_count);
Copy link
Contributor

Choose a reason for hiding this comment

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

Put this as a comment in the code instead of in the PR review

namespace impeller {

TextFrame MakeTextFrameFromTextBlobSkia(const sk_sp<SkTextBlob>& blob);
std::optional<TextFrame> MakeTextFrameFromTextBlobSkia(
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto above, comment in the code :)

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2023
@auto-submit auto-submit bot merged commit 57162a5 into flutter:main Aug 28, 2023
@jonahwilliams jonahwilliams deleted the cache_bounds branch August 28, 2023 22:25
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 28, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 28, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 28, 2023
…133516)

flutter/engine@a7a4c1c...bd2132a

2023-08-28 [email protected] Roll Skia from 335f748463db to 66e367b12e96 (1 revision) (flutter/engine#45189)
2023-08-28 [email protected] [Impeller] Cache Skia text bounds computation. (flutter/engine#45150)
2023-08-28 [email protected] Roll Skia from 83f6fbad8a38 to 335f748463db (1 revision) (flutter/engine#45186)

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 [email protected],[email protected],[email protected] 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
gaaclarke pushed a commit to gaaclarke/engine that referenced this pull request Aug 30, 2023
Fixes flutter/flutter#133388

Just use the TextBounds that Skia gives us. These are slightly larger but already computed. If the larger bounds are a problem we can go back to Impeller computed bounds, but using a cached computation.

### Skia
![flutter_02](https://github.com/flutter/engine/assets/8975114/c1824eb3-bd82-47b0-a6af-282e51419a00)

### Impeller
![flutter_03](https://github.com/flutter/engine/assets/8975114/bb2eff8c-ae6e-4c59-90a5-228f8a115dca)
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] TextFrame::getBounds() is wrong and/or slow
3 participants