-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Use client ICU data with skwasm. #42018
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
@@ -583,6 +584,7 @@ class SkwasmParagraphBuilder implements ui.ParagraphBuilder { | |||
|
|||
@override | |||
void addText(String text) { | |||
_allText += text; |
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.
The reason we didn't do this with CanvasKit is that SkParagraphBuilder
can add other parts of text that your _allText
won't capture. E.g:
So the line/word/grapheme breaks that you calculate will be off.
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.
Gah, you're right. I actually looked through the implementation to see if anything else affected the text, but I guess I missed that. I'll fix it
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 believe StringBuffer
would be significantly more efficient, too. (unless browsers already implement zero-copy concatenation?)
@override | ||
ui.Paragraph build() { | ||
_addSegmenterData(_allText); |
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 is where you would call ParagraphBuilder::getText()
_addSegmenterData(_allText); | |
_addSegmenterData(paragraphBuilderGetText(handle)); |
Keep in mind that getText()
returns the text in UTF8 format which isn't compatible with Dart strings. So it needs to be converted to UTF16. See here:
engine/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart
Lines 2650 to 2655 in dffc480
@JS('getText') | |
external JSString _getTextUtf8(); | |
String getTextUtf8() => _getTextUtf8().toDart; | |
// SkParagraphBuilder.getText() returns a utf8 string, we need to decode it | |
// into a utf16 string. | |
String getText() => utf8.decode(getTextUtf8().codeUnits); |
for (int i = 0; i < lineBreaks.length; i++) { | ||
final LineBreakFragment fragment = lineBreaks[i]; | ||
lineBreakPointer[i + 1].position = fragment.end; | ||
lineBreakPointer[i + 1].lineBreakType = fragment.type == LineBreakType.mandatory ? 100 : 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.
Consider using constants instead of 0
and 100
literals.
# In Chromium browsers, we can use the browser's APIs to get the necessary | ||
# ICU data. | ||
skia_use_icu = false | ||
skia_use_client_icu = true |
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.
So Skwasm is supposed to only run in Chromium? If yes, can we throw a meaningful error that says "Skwasm is only supported on Chromium"?
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 is basically covered by flutter/flutter#122978 and is something that would have to be implemented at the flutter.js/framework/flutter tool level.
SKWASM_EXPORT std::vector<SkUnicode::LineBreakBefore>* lineBreakBuffer_create( | ||
size_t length) { | ||
return new std::vector<SkUnicode::LineBreakBefore>( | ||
length, {0, SkUnicode::LineBreakType::kSoftLineBreak}); |
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.
Can we do this initialization of the first two items in _addLineBreakData
so it's all in one place? I don't think there's a significant performance difference either way, right?
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 is basically just zero-initialization of the vector. I have to provide some value here anyway in the C++ code to populate each element in the vector in the first place. I could add something that sets the first line break to 0, 0
in _addLineBreakData
, but it's basically pointless since it's already 0, 0
.
That's a lot of scary looking code to not have any tests, but test-exempt: this code will be covered by existing tests once it is turned on |
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.
LGTM!
…126968) flutter/engine@1c775e3...87a03e1 2023-05-16 [email protected] [Impeller] Use 32 bit Gaussian function in the 2-pass blur (flutter/engine#42069) 2023-05-16 [email protected] Roll Skia from 9b0e912a1cb9 to 88d7a68694d9 (13 revisions) (flutter/engine#42081) 2023-05-16 [email protected] Use client ICU data with skwasm. (flutter/engine#42018) 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] 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#126968) flutter/engine@1c775e3...87a03e1 2023-05-16 [email protected] [Impeller] Use 32 bit Gaussian function in the 2-pass blur (flutter/engine#42069) 2023-05-16 [email protected] Roll Skia from 9b0e912a1cb9 to 88d7a68694d9 (13 revisions) (flutter/engine#42081) 2023-05-16 [email protected] Use client ICU data with skwasm. (flutter/engine#42018) 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] 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
This implements flutter/flutter#126340
For now, I am keeping this implementation simple without any extra caching. I may add caching later based on profiling results.