Repository navigation
fonts: Give workers their own font context - #50049
Conversation
|
To me it seems like this PR is identical to the other one, as this one also has only 1 commit. Does the other PR maybe include both already? |
f38fb31 to
54cf70e
Compare
|
This PR builds on #50046, so it includes its two commits. The new part is the last commit, "fonts: Give workers their own font context". It shows all three now. |
Dedicated and shared workers used to share the page's `FontContext`, so a font loading in a worker made the page's `document.fonts.ready` wait for it. Now each of these workers gets its own empty `FontContext`, and fonts loaded with `self.fonts` are stored there. Their WebRender resources are freed when the worker shuts down. This also fixes loading a second `FontFace` for a URL that was already loaded for the same family. Signed-off-by: rogerkorantenng <[email protected]>
54cf70e to
d9a7695
Compare
| @@ -1,5 +1,4 @@ | |||
| [2d.text.measure.getActualBoundingBox.tentative.html] | |||
| expected: ERROR | |||
| [Test TextMetrics::getActualBoundingBox(), with text align left , and 0px letter spacing.] | |||
There was a problem hiding this comment.
These subtests call two canvas methods Servo doesn't have yet: getActualBoundingBox() here, and ctx.shapeText() in the other file. So they fail with "not a function". Both methods are still experimental in the spec.
Before this PR, the test didn't even get that far. Each subtest loads the same font again, and that second load failed, so the whole file errored. This PR fixes the second load, so now only the missing methods fail.
I can open an issue for the missing methods and look into them separately if that's useful.
| self.with_module_map(|module_map| std::mem::take(&mut *module_map.borrow_mut())); | ||
|
|
||
| // Dedicated and shared workers have their own font context (service workers share one), | ||
| // so free the WebRender font resources it created. |
There was a problem hiding this comment.
In a follow-up PR, can you add a memory leak test to tests/wpt/mozilla/tests/memory that creates these workers, loads a fontface and when it tears down, ensures there are no memory leaks?
Dedicated and shared workers used to share the page's
FontContext. Fonts a worker loaded could end up in the page, and a font loading in a worker made the page'sdocument.fonts.readywait for it. Now each of these workers gets its own emptyFontContext, which matches the spec ("Within a Worker document, the font source is initially empty") and what Firefox does. Fonts loaded withself.fontsare stored there, and their WebRender resources are freed when the worker shuts down, like the layout thread does for pages. Service workers already have their ownFontContext, so they're unchanged.This also fixes loading a second
FontFacefor a URL that was already loaded for the same family. That failed with "Failed to load font data" on pages too, because script loads skipped URLs that were already loaded.Testing: a page's
document.fonts.readyno longer waits for a slow font in a worker (7 ms instead of 2.7 s). With #49915 applied locally, a worker's canvas draws with the font the worker loaded, and can't see fonts loaded by the page. I also created and closed 20 workers that each load a font and draw text. Two page tests that loaded the sameFontFacetwice no longer error, and the WPTworkersand canvas text tests still pass.This builds on #50046, so its commits are included here until that one lands.
Part of #49892