Bug 1265568 - Don't require component alpha layers for text with -moz-osx-font-smoothing:grayscale. r=jfkthame,mattwoodrow
authorMarkus Stange <mstange@themasta.com>
Mon, 18 Apr 2016 19:41:50 -0400
changeset 331765 8c65edcc96d01f8f3864392d92faca52f1a30fd2
parent 331764 3732da92e8fccb4cc5dc7cdb615877c07e4dcbb9
child 331766 4a0e32f4856906445492002e444085f52803f25a
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame, mattwoodrow
bugs1265568
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1265568 - Don't require component alpha layers for text with -moz-osx-font-smoothing:grayscale. r=jfkthame,mattwoodrow MozReview-Commit-ID: KujmkbgadPo
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxPlatformMac.h
layout/generic/nsTextFrame.cpp
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -393,16 +393,22 @@ public:
      * change per gecko process, while the process is live.  If so the
      * results are not defined.
      *
      * NB: this bit is only honored by the FT2 backend, currently.
      */
     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
      */
     bool UseCmapsDuringSystemFallback();
 
     /**
      * Whether to render SVG glyphs within an OpenType font wrapper
      */
     bool OpenTypeSVGEnabled();
--- a/gfx/thebes/gfxPlatformMac.h
+++ b/gfx/thebes/gfxPlatformMac.h
@@ -59,16 +59,21 @@ public:
     virtual bool CanRenderContentToDataSurface() const override {
       return true;
     }
 
     virtual bool SupportsApzWheelInput() const override {
       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
       // BasicCompositor.
       return true;
     }
 
     virtual bool UseProgressivePaint() override;
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -4690,16 +4690,26 @@ public:
     }
   }
   virtual void Paint(nsDisplayListBuilder* aBuilder,
                      nsRenderingContext* aCtx) override;
   NS_DISPLAY_DECL_NAME("Text", TYPE_TEXT)
 
   virtual nsRect GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder) override
   {
+    if (gfxPlatform::GetPlatform()->RespectsFontStyleSmoothing()) {
+      // 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.
+      nsTextFrame* f = static_cast<nsTextFrame*>(mFrame);
+      const nsStyleFont* fontStyle = f->StyleFont();
+      if (fontStyle->mFont.smoothing == NS_FONT_SMOOTHING_GRAYSCALE) {
+        return nsRect();
+      }
+    }
     bool snap;
     return GetBounds(aBuilder, &snap);
   }
 
   virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) override;
 
   virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
                                          const nsDisplayItemGeometry* aGeometry,