Bug 1414125 - Use local clip instead of ClipNode in TextDrawTarget; r?Gankro draft
authorKevin Chen <kechen@mozilla.com>
Tue, 16 Jan 2018 17:54:57 +0800
changeset 721343 279fee7a9ccd7cd2b1aae288710dacbc6ff74835
parent 720739 a3887394965f161d011eebc74e8987a653366e4b
child 746309 57e7b4e05c8b7ef649124425582d57ce7b83927c
push id95810
push userbmo:kechen@mozilla.com
push dateWed, 17 Jan 2018 06:10:15 +0000
reviewersGankro
bugs1414125
milestone59.0a1
Bug 1414125 - Use local clip instead of ClipNode in TextDrawTarget; r?Gankro MozReview-Commit-ID: 7eV5T7n5rWM
layout/generic/TextDrawTarget.h
layout/reftests/selection/reftest.list
layout/reftests/text-shadow/reftest.list
--- a/layout/generic/TextDrawTarget.h
+++ b/layout/generic/TextDrawTarget.h
@@ -63,17 +63,17 @@ public:
     LayoutDeviceRect layoutBoundsRect = LayoutDeviceRect::FromAppUnits(
         aBounds, appUnitsPerDevPixel);
     LayoutDeviceRect layoutClipRect = layoutBoundsRect;
     mBoundsRect = aSc.ToRelativeLayoutRect(layoutBoundsRect);
 
     // Add 1 pixel of dirty area around clip rect to allow us to paint
     // antialiased pixels beyond the measured text extents.
     layoutClipRect.Inflate(1);
-    mClipRect = aSc.ToRelativeLayoutRect(layoutClipRect);
+    mClipStack.AppendElement(layoutClipRect);
 
     mBackfaceVisible = !aItem->BackfaceIsHidden();
 
     mBuilder.Save();
   }
 
   // Prevent this from being copied
   TextDrawTarget(const TextDrawTarget& src) = delete;
@@ -130,37 +130,37 @@ public:
                   && std::is_standard_layout<std::remove_reference<decltype(glyphs[0])>>::value
                   && sizeof(aBuffer.mGlyphs[0]) == sizeof(glyphs[0])
                   && sizeof(aBuffer.mGlyphs[0].mPosition) == sizeof(glyphs[0].point)
                   , "glyph buf types don't match");
 
     wr::GlyphOptions glyphOptions;
     glyphOptions.render_mode = wr::ToFontRenderMode(aOptions.mAntialiasMode, GetPermitSubpixelAA());
 
-    mManager->WrBridge()->PushGlyphs(mBuilder, glyphs, aFont,
-                                     color, mSc, mBoundsRect, mClipRect,
-                                     mBackfaceVisible, &glyphOptions);
+    mManager->WrBridge()->PushGlyphs(mBuilder, glyphs, aFont, color, mSc,
+                                     mBoundsRect, ClipRect(), mBackfaceVisible,
+                                     &glyphOptions);
   }
 
   void
   PushClipRect(const Rect &aRect) override {
-    auto rect = mSc.ToRelativeLayoutRect(LayoutDeviceRect::FromUnknownRect(aRect));
-    auto clipId = mBuilder.DefineClip(Nothing(), Nothing(), rect);
-    mBuilder.PushClip(clipId);
+    LayoutDeviceRect rect = LayoutDeviceRect::FromUnknownRect(aRect);
+    rect = rect.Intersect(mClipStack.LastElement());
+    mClipStack.AppendElement(rect);
   }
 
   void
   PopClip() override {
-    mBuilder.PopClip();
+    mClipStack.RemoveElementAt(mClipStack.Length() - 1);
   }
 
   void
   AppendShadow(const wr::Shadow& aShadow)
   {
-    mBuilder.PushShadow(mBoundsRect, mClipRect, mBackfaceVisible, aShadow);
+    mBuilder.PushShadow(mBoundsRect, ClipRect(), mBackfaceVisible, aShadow);
     mHasShadows = true;
   }
 
   void
   TerminateShadows()
   {
     if (mHasShadows) {
       mBuilder.PopAllShadows();
@@ -168,17 +168,17 @@ public:
     }
   }
 
   void
   AppendSelectionRect(const LayoutDeviceRect& aRect, const Color& aColor)
   {
     auto rect = wr::ToLayoutRect(aRect);
     auto color = wr::ToColorF(aColor);
-    mBuilder.PushRect(rect, mClipRect, mBackfaceVisible, color);
+    mBuilder.PushRect(rect, ClipRect(), mBackfaceVisible, color);
   }
 
 
   // This function is basically designed to slide into the decoration drawing
   // code of nsCSSRendering with minimum disruption, to minimize the
   // chances of implementation drift. As such, it mostly looks like a call
   // to a skia-style StrokeLine method: two end-points, with a thickness
   // and style. Notably the end-points are *centered* in the block direction,
@@ -230,17 +230,17 @@ public:
       // Wavy lines should go through AppendWavyDecoration
       case NS_STYLE_TEXT_DECORATION_STYLE_WAVY:
       // Double lines should be lowered to two solid lines
       case NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE:
       default:
         MOZ_CRASH("TextDrawTarget received unsupported line style");
     }
 
-    mBuilder.PushLine(mClipRect, mBackfaceVisible, decoration);
+    mBuilder.PushLine(ClipRect(), mBackfaceVisible, decoration);
   }
 
   // Seperated out from AppendDecoration because Wavy Lines are completely
   // different, and trying to merge the concept is more of a mess than it's
   // worth.
   void
   AppendWavyDecoration(const Rect& aBounds,
                        const float aThickness,
@@ -253,20 +253,24 @@ public:
       LayoutDeviceRect::FromUnknownRect(aBounds));
     decoration.wavyLineThickness = aThickness;
     decoration.color = wr::ToColorF(aColor);
     decoration.orientation = aVertical
       ? wr::LineOrientation::Vertical
       : wr::LineOrientation::Horizontal;
     decoration.style = wr::LineStyle::Wavy;
 
-    mBuilder.PushLine(mClipRect, mBackfaceVisible, decoration);
+    mBuilder.PushLine(ClipRect(), mBackfaceVisible, decoration);
   }
 
 private:
+  wr::LayerRect ClipRect()
+  {
+    return mSc.ToRelativeLayoutRect(mClipStack.LastElement());
+  }
   // Whether anything unsupported was encountered. Currently:
   //
   // * Synthetic bold/italics
   // * SVG fonts
   // * Unserializable fonts
   // * Tofu glyphs
   // * Pratial ligatures
   // * Text writing-mode
@@ -278,17 +282,17 @@ private:
 
   // Things used to push to webrender
   wr::DisplayListBuilder& mBuilder;
   const layers::StackingContextHelper& mSc;
   layers::WebRenderLayerManager* mManager;
 
   // Computed facts
   wr::LayerRect mBoundsRect;
-  wr::LayerRect mClipRect;
+  nsTArray<LayoutDeviceRect> mClipStack;
   bool mBackfaceVisible;
 
   // The rest of this is dummy implementations of DrawTarget's API
 public:
   DrawTargetType GetType() const override {
     return DrawTargetType::SOFTWARE_RASTER;
   }
 
--- a/layout/reftests/selection/reftest.list
+++ b/layout/reftests/selection/reftest.list
@@ -29,17 +29,17 @@ random-if(Android) needs-focus != pseudo
 # These tests uses Highlight and HighlightText color keywords, they are not same as text selection color on Mac.
 random-if(Android) fails-if(cocoaWidget) needs-focus == non-themed-widget.html non-themed-widget-ref.html
 random-if(Android) fails-if(cocoaWidget) needs-focus == themed-widget.html themed-widget-ref.html
 == addrange-1.html addrange-ref.html
 fuzzy-if(skiaContent,1,1200) == addrange-2.html addrange-ref.html
 == splitText-normalize.html splitText-normalize-ref.html
 == modify-range.html modify-range-ref.html
 == dom-mutations.html dom-mutations-ref.html
-fuzzy-if(OSX==1010,9,1) fuzzy-if(OSX&&skiaContent,6,1) fuzzy-if(skiaContent&&!OSX,1,2138) fails-if(webrender) == trailing-space-1.html trailing-space-1-ref.html # Bug 1414125
+fuzzy-if(OSX==1010,9,1) fuzzy-if(OSX&&skiaContent,6,1) fuzzy-if(skiaContent&&!OSX,1,2138) == trailing-space-1.html trailing-space-1-ref.html
 != invalidation-1-ref.html invalidation-2-ref.html
 == invalidation-1a.html invalidation-1-ref.html
 == invalidation-1b.html invalidation-1-ref.html
 == invalidation-1c.html invalidation-1-ref.html
 == invalidation-1d.html invalidation-1-ref.html
 == invalidation-1e.html invalidation-1-ref.html
 == invalidation-1f.html invalidation-1-ref.html
 == invalidation-2a.html invalidation-2-ref.html
--- a/layout/reftests/text-shadow/reftest.list
+++ b/layout/reftests/text-shadow/reftest.list
@@ -8,17 +8,17 @@ random-if(Android) == basic-negcoord.xul
 == blur-opacity.html blur-opacity-ref.html
 
 == basic.html basic-ref.html
 == basic-negcoord.html basic-negcoord-ref.html
 == basic-opacity.html basic-opacity-ref.html
 != blur.html blur-notref.html
 == color-inherit.html color-inherit-ref.html
 == color-parserorder.html color-parserorder-ref.html
-fails-if(webrender) == decorations-multiple-zorder.html decorations-multiple-zorder-ref.html # Bug 1414125
+== decorations-multiple-zorder.html decorations-multiple-zorder-ref.html
 == multiple-noblur.html multiple-noblur-ref.html
 == quirks-decor-noblur.html quirks-decor-noblur-ref.html
 == standards-decor-noblur.html standards-decor-noblur-ref.html
 == padding-decoration.html padding-decoration-ref.html
 == textindent.html textindent-ref.html
 == lineoverflow.html lineoverflow-ref.html
 
 == overflow-not-scrollable-1.html overflow-not-scrollable-1-ref.html