From 257cfd9290f1b235a7b3e46db35b2e58fcf0ad00 Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Tue, 18 Jul 2017 20:55:41 -0700 Subject: [PATCH] #416: M1265568 M1305036 --- gfx/thebes/gfxPlatform.h | 6 ++++++ gfx/thebes/gfxPlatformMac.h | 5 +++++ layout/generic/TextOverflow.cpp | 19 +++++++++++++++++++ layout/generic/nsTextFrame.cpp | 12 ++++++++++++ 4 files changed, 42 insertions(+) diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index e4325e46b..0ce966519 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -403,6 +403,12 @@ public: */ virtual bool RequiresLinearZoom() { return false; } + /** + * Whether the frame->StyleFont().mFont.smoothing field is respected by + * text rendering on this platform. + */ + virtual bool RespectsFontStyleSmoothing() const { return false; } + /** * Whether to check all font cmaps during system font fallback */ diff --git a/gfx/thebes/gfxPlatformMac.h b/gfx/thebes/gfxPlatformMac.h index 089186ce7..4e6e5426d 100644 --- a/gfx/thebes/gfxPlatformMac.h +++ b/gfx/thebes/gfxPlatformMac.h @@ -100,6 +100,11 @@ public: return true; } + bool RespectsFontStyleSmoothing() const override { + // gfxMacFont respects the font smoothing hint. + return true; + } + bool RequiresAcceleratedGLContextForCompositorOGL() const override { // On OS X in a VM, unaccelerated CompositorOGL shows black flashes, so we // require accelerated GL for CompositorOGL but allow unaccelerated GL for diff --git a/layout/generic/TextOverflow.cpp b/layout/generic/TextOverflow.cpp index 8111c6d78..5a1db5929 100644 --- a/layout/generic/TextOverflow.cpp +++ b/layout/generic/TextOverflow.cpp @@ -180,6 +180,25 @@ public: nsLayoutUtils::GetTextShadowRectsUnion(mRect, mFrame); return mRect.Union(shadowRect); } + + virtual nsRect GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder) override + { +#ifdef XP_MACOSX + { +#else + if (gfxPlatform::GetPlatform()->RespectsFontStyleSmoothing()) { +#endif + // On OS X, web authors can turn off subpixel text rendering using the + // CSS property -moz-osx-font-smoothing. If they do that, we don't need + // to use component alpha layers for the affected text. + if (mFrame->StyleFont()->mFont.smoothing == NS_FONT_SMOOTHING_GRAYSCALE) { + return nsRect(); + } + } + bool snap; + return GetBounds(aBuilder, &snap); + } + virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) override; diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 349866f35..819ffd1ee 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -4680,6 +4680,18 @@ public: virtual nsRect GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder) override { +#ifdef XP_MACOSX + { +#else + if (gfxPlatform::GetPlatform()->RespectsFontStyleSmoothing()) { +#endif + // On OS X, web authors can turn off subpixel text rendering using the + // CSS property -moz-osx-font-smoothing. If they do that, we don't need + // to use component alpha layers for the affected text. + if (mFrame->StyleFont()->mFont.smoothing == NS_FONT_SMOOTHING_GRAYSCALE) { + return nsRect(); + } + } bool snap; return GetBounds(aBuilder, &snap); }