Bug 1625606 - Use Skia's mac font smoothing handling. r=aosmond

Currently we try to alternate between light-on-dark and dark-on-light
text rendering masks on macOS depending on text colors. Historically,
this matched earlier versions of macOS reasonably well. In successive
versions of macOS, however, this approximation appears to have broken
down and no longer gives correct results.

Given that recent macOS versions no longer promotes font-smoothing at
all, it seems more reasonable to match Skia's font smoothing handling
because it appears to better work with these more recent versions while
requiring us to have less special code to do so.

Differential Revision: https://phabricator.services.mozilla.com/D229444
This commit is contained in:
Lee Salzman
2024-11-19 18:38:48 +00:00
parent c253bca53c
commit 74b950eaf9
15 changed files with 46 additions and 98 deletions

View File

@@ -4336,27 +4336,17 @@ static DeviceColor QuantizePreblendColor(const DeviceColor& aColor,
int32_t r = int32_t(aColor.r * 255.0f + 0.5f);
int32_t g = int32_t(aColor.g * 255.0f + 0.5f);
int32_t b = int32_t(aColor.b * 255.0f + 0.5f);
// Ensure that even if two values would normally quantize to the same bucket,
// that the reference value within the bucket still allows for accurate
// determination of whether light-on-dark or dark-on-light rasterization will
// be used (as on macOS).
bool lightOnDark = r >= 85 && g >= 85 && b >= 85 && r + g + b >= 2 * 255;
// Skia only uses the high 3 bits of each color component to cache preblend
// ramp tables.
constexpr int32_t lumBits = 3;
constexpr int32_t ceilMask = (1 << (8 - lumBits)) - 1;
constexpr int32_t floorMask = ((1 << lumBits) - 1) << (8 - lumBits);
if (!aUseSubpixelAA) {
// If not using subpixel AA, then quantize only the luminance, stored in the
// G channel.
g = (r * 54 + g * 183 + b * 19) >> 8;
g |= ceilMask;
// Still distinguish between light and dark in the key.
r = b = lightOnDark ? 255 : 0;
} else if (lightOnDark) {
r |= ceilMask;
g |= ceilMask;
b |= ceilMask;
g &= floorMask;
r = g;
b = g;
} else {
r &= floorMask;
g &= floorMask;
@@ -4415,8 +4405,7 @@ bool SharedContextWebgl::DrawGlyphsAccel(ScaledFont* aFont,
#endif
// If the font has bitmaps, use the color directly. Otherwise, the texture
// will hold a grayscale mask, so encode the key's subpixel and light-or-dark
// state in the color.
// holds a grayscale mask, so encode the key's subpixel state in the color.
const Matrix& currentTransform = mCurrentTarget->GetTransform();
IntPoint quantizeScale = QuantizeScale(aFont, currentTransform);
Matrix quantizeTransform = currentTransform;