Repository navigation
Font fallback - #20506
Font fallback#20506
Conversation
|
Heads up! This PR modifies the following files:
|
|
This looks amazing! \o/ |
|
Reviewed 17 of 23 files at r1. components/gfx/platform/freetype/font.rs, line 102 at r1 (raw file):
One of the reasons for making FT always load via memory here was so that the layout threads would never block on a synchronous file load. The idea was that the font cache thread would responsible for providing these. I'm not sure if that's really relevant or feasible, but that was the original idea, I think. components/gfx/text/util.rs, line 156 at r1 (raw file):
nit: could just be unicode_plane(codepoint) == 2 and remove the true / false here, unless there's more conditions to come in the future. Comments from Reviewable |
|
Partial review only so far - I'll try to work through the trickier bits today or tomorrow. Will need @mbrubeck to take a look at some of the text files that I'm not familiar with too. |
|
Reviewed 6 of 23 files at r1. components/layout/text.rs, line 218 at r1 (raw file):
Should get @mbrubeck to check this. Comments from Reviewable |
|
Reviewed the remaining files, they look good to me. I think it'd be worth getting @mbrubeck to do a quick pass over this too, as I'm not very up to date on text / font handling in Servo. My main question is related to the thread the font load occurs on (mentioned above). |
Thanks for the explanation. I note that the windows and macos implementations end up calling into platform APIs in this situation, do you know of calling those APIs results in any disk I/O? Without this change I observed a big slowdown on Linux where the bytes of all the fallback fonts would be passed over the ipc-channel. The slowdown was mostly due to the CPU cost of serialization and deserialization. Performance was a lot better when I tried the One thing it is worth pointing out, is that by the time a layout thread does the file read, the file has already been read by the font cache thread. Therefore, we might hope that the data is already in an OS cache and it might be that no actual disk reads need to occur. I don't know enough about how this works to make any firm statements about that though. Another thing to say is that I'm testing this on a laptop with an SSD hard drive, so I'm probably less likely to notice disk I/O slowdowns. Do you have any suggestions about how I could/should investigate this further so we can decide what the best approach is? |
|
I should add: when I looked into the bytes-over-IPC thing, I realised that the font code had originally been developed before a multiprocess architecture was implemented. Therefore, at the time, those bytes were not getting serialized or sent to a different process. Then, the multiprocess architecture came along and converted everything to IPC channels. I thought that perhaps it wasn't intentionally decided that the bytes should go over IPC, but instead just a consequence of how the code had evolved. It just seemed quite surprising to me to do this, but it might be that it's actually fine if we use |
|
You're exactly right - the original font code was built before any consideration for multi-process / ipc-channel, and serializing the bytes over the ipc channel was a side effect of that. I think it's fine to move the file read into the font contexts at this stage - this is certainly a big improvement on what we have now. We can re-consider the design of how / where we fetch the bytes as a separate issue for later - it's a big topic by itself. There's no other blockers from me, but it would be good to get @mbrubeck to do a quick pass over this before merging - he has much more experience with the Servo text / layout code than me. |
|
@bors-servo r+ Looks good to me. Thanks for this! |
|
📌 Commit e15d3e1 has been approved by |
Font fallback This implements more complete support for font fallback, see #17267. r? @glennw @mbrubeck <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20506) <!-- Reviewable:end -->
|
💔 Test failed - mac-dev-unit |
|
e15d3e1 to
6679ebe
Compare
Done
This wasn't actually 100% necessary for the fallback to work, though it's useful in terms of not doing unnecessary fallbacks for non-printing characters. I've split it out into a separate commit which gives a better explanation of what it does.
I've added a comment to the code linking to this discussion.
Fixed |
|
@bors-servo r+ |
|
💔 Test failed - android |
|
@bors-servo try |
|
@bors-servo retry |
|
💔 Test failed - mac-rel-wpt1 |
Prior to this change, if none of the fonts specified in CSS contained a glyph for a codepoint, we tried only one fallback font. If that font didn't contain the glyph, we'd give up. With this change, we try multiple fonts in turn. The font names we try differ across each platform, and based on the codepoint we're trying to match. The current implementation is heavily inspired by the analogous code in Gecko, but I've used to ucd lib to make it more readable, whereas Gecko matches raw unicode ranges. This fixes some of the issues reported in servo#17267, although colour emoji support is not implemented. == Notes on changes to WPT metadata == === css/css-text/i18n/css3-text-line-break-opclns-* === A bunch of these have started failing on macos when they previously passed. These tests check that the browser automatically inserts line breaks near certain characters that are classified as "opening and closing punctuation". The idea is that if we have e.g. an opening parenthesis, it does not make sense for it to appear at the end of a line box; it should "stick" to the next character and go into the next line box. Before this change, a lot of these codepoints rendered as a missing glyph on Mac and Linux. In some cases, that meant that the test was passing. After this change, a bunch of these codepoints are now rendering glyphs on Mac (but not Linux). In some cases, the test should continue to pass where it previously did when rendering with the missing glyph. However, it seems this has also exposed a layout bug. The "ref" div in these tests contains a <br> element, and it seems that this, combined with these punctuation characters, makes the spacing between glyphs ever so slightly different to the "test" div. (Speculation: might be something to do with shaping?) Therefore I've had to mark a bunch of these tests failing on mac. === css/css-text/i18n/css3-text-line-break-baspglwj-* === Some of these previously passed on Mac due to a missing glyph. Now that we're rendering the correct glyph, they are failing. === css/css-text/word-break/word-break-normal-bo-000.html === The characters now render correctly on Mac, and the test is passing. But we do not find a suitable fallback font on Linux, so it is still failing on that platform. === css/css-text/word-break/word-break-break-all-007.html === This was previously passing on Mac, but only because missing character glyphs were rendered. Now that a fallback font is able to be found, it (correctly) fails. === mozilla/tests/css/font_fallback_* === These are new tests added in this commit. 01 and 02 are marked failing on Linux because the builders don't have the appropriate fonts installed (that will be a follow-up). Fix build errors from rebase FontTemplateDescriptor can no longer just derive(Hash). We need to implement it on each component part, because the components now generally wrap floats, which do not impl Hash because of NaN. However in this case we know that we won't have a NaN, so it is safe to manually impl Hash.
We can encounter control characters here, for example when processing a <pre> element which contains newlines. Control characters are inherently non-printing, therefore if we try to call find_by_codepoint for these characters we will end up triggering an unnecessary font fallback search.
FontTemplateData gets passed over IPC during the communication between FontContext and FontCacheThread. Serializing and deserializing these bytes is expensive, so this change ensures that we only do that when the bytes can't be read from disk. A similar strategy is already used on macos and windows. The performance problem was particularly noticeable after implenting font fallback, where the content process would potentially work through a list of fonts, trying to find one which contains a certain glyph. That could result in lots of font bytes going over IPC.
Before this change, if we needed to create a Font which we've already created, but at a new size, then we'd fetch the FontTemplateInfo again. If the bytes of the font are held in memory, then this could be expensive as we need to pass those bytes over IPC.
|
@bors-servo try |
|
💔 Test failed - linux-rel-wpt |
|
@bors-servo retry Reason: seems like a random crash: |
|
Rather than immediately retrying, it's best to rely on the grid to see what other test results are reported. In particular, retrying doesn't cancel any ongoing test runs so it also delays the rest of the queue. |
|
Ok, noted, I didn't realise that the previous build hadn't completely finished. |
|
Ok, the retry worked! (Maybe it didn't report here as I accidentally closed and reopened the PR...) Can I get a merge please? 🙏 😄 |
|
Homu is stuck on this PR, just trying to un-stick it. @bors-servo r- |
|
@bors-servo r=emilio,mbrubeck |
|
📌 Commit 3025a26 has been approved by |
|
💔 Test failed - mac-rel-wpt4 |
|
o_O we managed to crash |
|
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
This implements more complete support for font fallback, see #17267.
r? @glennw @mbrubeck
This change is