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

Conversation

@alanwutang11
Copy link
Contributor

@alanwutang11 alanwutang11 commented Oct 17, 2022

refactored FontCollection for both canvaskit and html.

With the refactor, it becomes possible to download fonts concurrently with wasm, resolving issue: flutter/flutter#105929

fontCollection refactor

Each font needs to be 1) downloaded and 2) registered before it can be used.

Previously, this process was done in one function call: registerFonts()

Now, downloading fonts happens in two separate function calls:

  1. downloadAsetFonts(AssetManager assetmanager) to download fonts
  2. registerDownloadedFonts() to register fonts

Breaking the previous registerFonts() into the two aforementioned steps allows the following functions to be called concurrently:

  1. download fonts with downloadAsetFonts(AssetManager assetmanager)
  2. download wasm with canvaskit = await downloadCanvasKit()

All affected tests were refactored as well.

Before:
173461040-d1724d8b-4134-43f2-a523-daa95449ecc8

After:
Screen Shot 2022-10-17 at 1 59 14 PM

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label Oct 17, 2022
@flutter-dashboard
Copy link

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.

Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

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

You should check that the fonts are downloaded early when using the HTML renderer as well (--web-renderer=html).

I think the FontCollection interface is overdue for a refactoring since the names of the methods don't match what is actually happening.

The new FontCollection should contain:

  1. loadFontFromList: this is required since Flutter gives developers an API to load a new font. This needs to be Future<void> because the HTML font collection uses an API which is Future
  2. downloadAssetFonts: this should be Future<void> and complete when all of the fonts which are read from the FontManifest.json have been downloaded.
  3. debugDownloadTestFonts: does what debugRegisterTestFonts does now.
  4. registerDownloadedFonts: In this step you register all of the fonts which were downloaded in downloadAssetFonts with the renderer (in the CanvasKit case, this is where you make the SkTypeface and register it with the TypefaceFontProvider. I don't think this needs to be Future<void>, it could probably just be void.

During initialization you would do Future.wait([initializeRenderer, fontCollection.downloadAssetFonts]) and then after that call registerDownloadedFonts.

@alanwutang11 alanwutang11 force-pushed the download-font-concurrently branch from 90de99f to 347acef Compare October 21, 2022 21:49
@alanwutang11 alanwutang11 force-pushed the download-font-concurrently branch from 2cc506c to 2126463 Compare October 21, 2022 22:03
Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

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

Needs more work to fix polyfill version

@skia-gold
Copy link

Gold has detected about 2 new digest(s) on patchset 4.
View them at https://flutter-engine-gold.skia.org/cl/github/36813

@skia-gold
Copy link

Gold has detected about 2 new digest(s) on patchset 5.
View them at https://flutter-engine-gold.skia.org/cl/github/36813

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

Changes reported for pull request #36813 at sha b2b1a4e

Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

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

Mostly LGTM just one more change

Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

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

LGTM

@alanwutang11 alanwutang11 added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 24, 2022
@auto-submit auto-submit bot merged commit 7577fd4 into flutter:main Oct 24, 2022
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 platform-web Code specifically for the web engine will affect goldens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants