Skip to content
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 new unresolvedCodePoints API from skia. #41991

Merged
merged 4 commits into from
May 16, 2023

Conversation

eyebrowsoffire
Copy link
Contributor

NOTE: this works off of a skia CL that is not merged yet, so we shouldn't merge this until it actually lands in skia and rolls into the engine. See https://skia-review.googlesource.com/c/skia/+/695716

@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label May 12, 2023
DEPS Outdated
@@ -18,7 +18,7 @@ vars = {
'llvm_git': 'https://llvm.googlesource.com',
# OCMock is for testing only so there is no google clone
'ocmock_git': 'https://github.com/erikdoe/ocmock.git',
'skia_revision': '539fb10d7cfb3e73ae43bdedba7d11b2012f5446',
'skia_revision': '787af31b18ff9ba2e3627758c95accdd390776eb',
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a reminder to revert this before submitting.

Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

I have some questions but the PR looks good to me!

Comment on lines +121 to +124
List<int>.generate(
missingCodePointCount,
(int index) => codePointBuffer[index]
)
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is going to be a common occurrence, consider making an extension method for it:

extension PointerToList<T extends NativeType> on Pointer<T> {
  List<T> toList(int length) {
    return List<T>.generate(length, (int index) => this[index]);
  }
}

but when I tried this, the analyzer didn't like this[index] apparently because the [] operator is defined as a separate extension for each T 😞

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 think probably the reason this is failing is because the T in Pointer<T> the native type, but the T in List<T> is probably the dart type (int in this case). That makes this kind of difficult to create a generic helper for.

paragraphLayout(handle, constraints.width);
if (!_hasCheckedForMissingCodePoints) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Quick question: is it possible for paragraphGetUnresolvedCodePoints to return a different result for the same paragraph later? E.g. when extra fallback fonts are downloaded.

I guess what I'm really asking is whether there's ever a case where we need to reset paragraphGetUnresolvedCodePoints to false.

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 don't believe it can. The reason is that you can't actually change the list of font families on the text styles or paragraph style once it is a paragraph, that's specified at the ParagraphBuilder stage. Once you've already created the paragraph, the only way to add more fallback fonts to it is by actually rebuilding the paragraph with new text styles.

external int paragraphGetUnresolvedCodePoints(
ParagraphHandle handle,
Pointer<Uint32> outCodePoints,
int outLength,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what this third outLength parameter is for. Could you clarify please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

outLength is the length of the outCodePoints buffer that we are passing to the API. This is so that the C++ code doesn't overwrite the buffer into some other region of the memory. However... because we actually got that value from the C++ code in the first place, it is true that we can just omit this parameter altogether and the C++ code can always trust that the buffer is exactly the length that is needed. I can remove it if you think it's confusing, I think this is just my standard "C memory safety" guardrails I automatically added.

}
int outIndex = 0;
for (SkUnichar character : paragraph->unresolvedCodepoints()) {
if (outIndex < outLength) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see. Hmm this is a bit confusing and could use a better name or an API change.

For example, it might be a good idea to split this into 2 APIs:

  • bool paragraph_hasUnresolvedCodePoints(Paragraph* paragraph)
  • int paragraph_getUnresolvedCodePoints(Paragraph* paragraph, SkUnichar* outCodePoints)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A boolean is actually not good enough, we want the API to return the length of the buffer needed to hold all the code points so we can allocate the correct amount. This pattern is actually pretty common for C APIs, where the user of the API passes in null first, and the API returns the size of the buffer needed to hold the output, and then the user allocates that memory and calls the API a second time with the actual buffer to have it filled.

Comment on lines +132 to +134
if (!outCodePoints) {
return paragraph->unresolvedCodepoints().size();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, it looks like you are handling the case of hasUnresolvedCodePoints here. Is there really a need for outLength?

@eyebrowsoffire eyebrowsoffire marked this pull request as ready for review May 16, 2023 05:17
@eyebrowsoffire eyebrowsoffire added the autosubmit Merge PR when tree becomes green via auto submit App label May 16, 2023
@auto-submit auto-submit bot merged commit 2ff91f3 into flutter:main May 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 16, 2023
zanderso pushed a commit to flutter/flutter that referenced this pull request May 16, 2023
…sions) (#126961)

Manual roll requested by zra@google.com

flutter/engine@fe24767...1c775e3

2023-05-16 zanderso@users.noreply.github.com Revert "[ios_platform_view]
only recycle maskView when the view is applying mutators"
(flutter/engine#42080)
2023-05-16 gspencergoog@users.noreply.github.com [macOS] Wait for
binding to be ready before requesting exits from framework
(flutter/engine#41753)
2023-05-16 gspencergoog@users.noreply.github.com [linux] Wait for
binding to be ready before requesting exits from framework
(flutter/engine#41782)
2023-05-16 jacksongardner@google.com Initial support for images in
Skwasm (flutter/engine#42019)
2023-05-16 jacksongardner@google.com Use new `unresolvedCodePoints` API
from skia. (flutter/engine#41991)
2023-05-16 jason-simmons@users.noreply.github.com Convert public API
NativeFieldWrapper classes to abstract interfaces (flutter/engine#41945)
2023-05-16 737941+loic-sharma@users.noreply.github.com [Windows] Add
force redraw to the C++ client wrapper (flutter/engine#42061)
2023-05-16 godofredoc@google.com Fix drone_dimension
host_engine_builder. (flutter/engine#42068)
2023-05-16 godofredoc@google.com Add linux_clang_tidy builder.
(flutter/engine#41990)
2023-05-16 ychris@google.com [ios_platform_view] only recycle maskView
when the view is applying mutators (flutter/engine#41573)

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 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
CaseyHillers pushed a commit to CaseyHillers/flutter that referenced this pull request May 24, 2023
…sions) (flutter#126961)

Manual roll requested by zra@google.com

flutter/engine@fe24767...1c775e3

2023-05-16 zanderso@users.noreply.github.com Revert "[ios_platform_view]
only recycle maskView when the view is applying mutators"
(flutter/engine#42080)
2023-05-16 gspencergoog@users.noreply.github.com [macOS] Wait for
binding to be ready before requesting exits from framework
(flutter/engine#41753)
2023-05-16 gspencergoog@users.noreply.github.com [linux] Wait for
binding to be ready before requesting exits from framework
(flutter/engine#41782)
2023-05-16 jacksongardner@google.com Initial support for images in
Skwasm (flutter/engine#42019)
2023-05-16 jacksongardner@google.com Use new `unresolvedCodePoints` API
from skia. (flutter/engine#41991)
2023-05-16 jason-simmons@users.noreply.github.com Convert public API
NativeFieldWrapper classes to abstract interfaces (flutter/engine#41945)
2023-05-16 737941+loic-sharma@users.noreply.github.com [Windows] Add
force redraw to the C++ client wrapper (flutter/engine#42061)
2023-05-16 godofredoc@google.com Fix drone_dimension
host_engine_builder. (flutter/engine#42068)
2023-05-16 godofredoc@google.com Add linux_clang_tidy builder.
(flutter/engine#41990)
2023-05-16 ychris@google.com [ios_platform_view] only recycle maskView
when the view is applying mutators (flutter/engine#41573)

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 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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants