Closed Bug 1400721 Opened 7 years ago Closed 7 years ago

Skia mishandles FreeType 2.8.1 patent-free subpixel rendering

Categories

(Core :: Graphics: Text, defect, P3)

All
Linux
defect

Tracking

()

RESOLVED FIXED
mozilla57
Tracking Status
firefox-esr52 56+ fixed
firefox55 --- wontfix
firefox56 --- fixed
firefox57 - fixed

People

(Reporter: heftig, Assigned: lsalzman)

References

Details

(Whiteboard: [gfx-noted])

Attachments

(1 file)

As noted at https://sourceforge.net/projects/freetype/files/freetype2/2.8.1/, FreeType 2.8.1 ships with a new LCD subpixel rendering technique called Harmony that evades the ClearType patents by not requiring (and supporting) filtering:

>  - By default, FreeType now offers high quality LCD-optimized
>    output without resorting to ClearType techniques of resolution
>    tripling and filtering. In this method, called Harmony, each
>    color channel is generated separately after shifting the glyph
>    outline, capitalizing on the fact that the color grids on LCD
>    panels are shifted by a third of a pixel. This output is
>    indistinguishable from ClearType with a light 3-tap filter. 

This technique is enabled by default, and the code urges packagers not to enable the (still available) patented rendering mode.


FreeType 2.8.1 also changed how the padding for LCD bitmaps is calculated:

>  - The internal representation of buffers for LCD rendering has
>    changed (to be more precise, the amount of padding gets computed
>    differently). Applications that use the FreeType API are not
>    affected.

Skia breaks FreeType's API by replacing the rendering buffer with its own. As a result, text rendering broke with some glyphs being shifted and cut off. The padding change happened before the introduction of Harmony; Skia implemented a workaround that was effective for the patented mode. The upstream bug for this is https://bugs.chromium.org/p/skia/issues/detail?id=6663. Firefox received a backport of this in bug 1393467.

Unfortunately rendering breaks again with similar results when FreeType is compiled with the patent-free mode.
Priority: -- → P3
See Also: → 1393467
Whiteboard: [gfx-noted]
The problem stems from the fact that FreeType 2.8.1 built without the previous LCD filtering support will report that LCD filters are unimplemented. This disables our previous workaround that added padding to the glyph to accommodate any padding the LCD filter may add.

Yet even though it reports LCD filters are unimplemented, it will still add padding now because of the new patent-free LCD filtering that is always used.

The simple solution here is to make the check for adding the padding less specific. If we're doing subpixel AA on the glyph, then always try to pad it. This is less brittle and more future-proof than trying to do a version check. Bug 1393467 made it safe to do this as if for any reason the mask renders with less or no padding, things will get clipped appropriately.
Assignee: nobody → lsalzman
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Attachment #8909448 - Flags: review?(jmuizelaar)
Attachment #8909448 - Flags: review?(jmuizelaar) → review+
Pushed by lsalzman@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/9a26478b9034
fix Skia's glyph LCD filter padding for FreeType 2.8.1. r=jrmuizel
https://hg.mozilla.org/mozilla-central/rev/9a26478b9034
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
Comment on attachment 8909448 [details] [diff] [review]
fix Skia's glyph LCD filter padding for FreeType 2.8.1

Approval Request Comment
[Feature/Bug causing the regression]: Preexisting condition affecting all releases.
[User impact if declined]: Broken subpixel anti-aliasing of fonts with newer versions of FreeType on Linux.
[Is this code covered by automated tests?]: yes
[Has the fix been verified in Nightly?]: yes, verified by reporter
[Needs manual test from QE? If yes, steps to reproduce]: no
[List of other uplifts needed for the feature/fix]: no
[Is the change risky?]: no
[Why is the change risky/not risky?]: Just expands the scope of the upstream Skia fix we applied in bug 1393467 to work in this new scenario.
[String changes made/needed]: none
Attachment #8909448 - Flags: approval-mozilla-esr52?
Attachment #8909448 - Flags: approval-mozilla-beta?
Comment on attachment 8909448 [details] [diff] [review]
fix Skia's glyph LCD filter padding for FreeType 2.8.1

56 is on mozilla-release now.
Attachment #8909448 - Flags: approval-mozilla-beta? → approval-mozilla-release?
Comment on attachment 8909448 [details] [diff] [review]
fix Skia's glyph LCD filter padding for FreeType 2.8.1

Fix for upcoming version of FreeType, looks pretty safe. Thanks for the explanation in the patch.
Attachment #8909448 - Flags: approval-mozilla-release? → approval-mozilla-release+
Comment on attachment 8909448 [details] [diff] [review]
fix Skia's glyph LCD filter padding for FreeType 2.8.1

I guess it makes sense to get this in esr52 for distros that ship the latest freetype.
Attachment #8909448 - Flags: approval-mozilla-esr52? → approval-mozilla-esr52+
(In reply to Lee Salzman [:lsalzman] from comment #4)
> [Is this code covered by automated tests?]: yes
> [Has the fix been verified in Nightly?]: yes, verified by reporter
> [Needs manual test from QE? If yes, steps to reproduce]: no

Setting qe-verify- based on Lee's assessment on manual testing needs and the fact that this fix has automated coverage.
Flags: qe-verify-
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: