Bug 1382896 - Align Gecko and WebRender code for 3d border colors. r=mstange
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 22 Sep 2018 07:18:34 +0200
changeset 496787 95dfb8f992a6a376ce53480c15b6a6c78df625b0
parent 496786 198999ea1b7962235bfc050b79e675a98cfd76a1
child 496788 178218e7b57ca24ceb7f6aca3674611012fa6b2c
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1382896, 1487407
milestone64.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 1382896 - Align Gecko and WebRender code for 3d border colors. r=mstange See the discussion in https://github.com/servo/webrender/issues/1280. I think we should do this sooner rather than later. Need to update a couple reftests to hardcode the new colors, waiting on try for that but should be trivial. This makes a few more tests pass which are just marked as failure in bug 1487407, because I implementing the border-collapsing reusing a bunch of Gecko code, including the table 3d border stuff. Differential Revision: https://phabricator.services.mozilla.com/D6565
gfx/webrender/src/border.rs
layout/base/nsCSSColorUtils.cpp
layout/base/nsCSSColorUtils.h
layout/painting/nsCSSRendering.cpp
layout/painting/nsCSSRendering.h
layout/painting/nsCSSRenderingBorders.cpp
layout/painting/nsCSSRenderingBorders.h
layout/reftests/table-bordercollapse/reftest.list
layout/tables/nsTableFrame.cpp
--- a/gfx/webrender/src/border.rs
+++ b/gfx/webrender/src/border.rs
@@ -209,21 +209,19 @@ impl BorderSideHelpers for BorderSide {
             _ => return self.color,
         };
 
         // The modulate colors below are not part of the specification. They are
         // derived from the Gecko source code and experimentation, and used to
         // modulate the colors in order to generate colors for the inset/outset
         // and groove/ridge border styles.
         //
-        // NOTE(emilio): Gecko at least takes the background color into
-        // account, should we do the same? Looks a bit annoying for this.
-        //
         // NOTE(emilio): If you change this algorithm, do the same change on
-        // get_colors_for_side in cs_border_segment.glsl.
+        // get_colors_for_side in cs_border_segment.glsl, and
+        // NS_GetSpecial3DColors in Gecko.
         if self.color.r != 0.0 || self.color.g != 0.0 || self.color.b != 0.0 {
             let scale = if lighter { 1.0 } else { 2.0 / 3.0 };
             return self.color.scale_rgb(scale)
         }
 
         let black = if lighter { 0.7 } else { 0.3 };
         ColorF::new(black, black, black, self.color.a)
     }
--- a/layout/base/nsCSSColorUtils.cpp
+++ b/layout/base/nsCSSColorUtils.cpp
@@ -14,96 +14,37 @@
 // from the xfe which was written originally by Eric Bina. So there.
 
 #define RED_LUMINOSITY        299
 #define GREEN_LUMINOSITY      587
 #define BLUE_LUMINOSITY       114
 #define INTENSITY_FACTOR      25
 #define LUMINOSITY_FACTOR     75
 
-#define MAX_COLOR             255
-#define COLOR_DARK_THRESHOLD  51
-#define COLOR_LIGHT_THRESHOLD 204
-
-#define COLOR_LITE_BS_FACTOR 45
-#define COLOR_LITE_TS_FACTOR 70
-
-#define COLOR_DARK_BS_FACTOR 30
-#define COLOR_DARK_TS_FACTOR 50
-
-#define LIGHT_GRAY NS_RGB(192, 192, 192)
-#define DARK_GRAY  NS_RGB(96, 96, 96)
-
-#define MAX_BRIGHTNESS  254
-#define MAX_DARKNESS     0
-
-void NS_GetSpecial3DColors(nscolor aResult[2],
-                           nscolor aBackgroundColor,
-                           nscolor aBorderColor)
+void NS_GetSpecial3DColors(nscolor aResult[2], nscolor aBorderColor)
 {
-
-  uint8_t f0, f1;
-  uint8_t r, g, b;
-
-  uint8_t rb = NS_GET_R(aBorderColor);
-  uint8_t gb = NS_GET_G(aBorderColor);
-  uint8_t bb = NS_GET_B(aBorderColor);
-
-  uint8_t a = NS_GET_A(aBorderColor);
+  const float kDarkerScale = 2.0 / 3.0;
 
-  // This needs to be optimized.
-  // Calculating background brightness again and again is
-  // a waste of time!!!. Just calculate it only once.
-  // .....somehow!!!
-
-  uint8_t red = NS_GET_R(aBackgroundColor);
-  uint8_t green = NS_GET_G(aBackgroundColor);
-  uint8_t blue = NS_GET_B(aBackgroundColor);
-
-  uint8_t elementBrightness = NS_GetBrightness(rb,gb,bb);
-  uint8_t backgroundBrightness = NS_GetBrightness(red, green, blue);
-
-
-  if (backgroundBrightness < COLOR_DARK_THRESHOLD) {
-    f0 = COLOR_DARK_BS_FACTOR;
-    f1 = COLOR_DARK_TS_FACTOR;
-	if(elementBrightness == MAX_DARKNESS)
-	{
-       rb = NS_GET_R(DARK_GRAY);
-       gb = NS_GET_G(DARK_GRAY);
-       bb = NS_GET_B(DARK_GRAY);
-	}
-  }else if (backgroundBrightness > COLOR_LIGHT_THRESHOLD) {
-    f0 = COLOR_LITE_BS_FACTOR;
-    f1 = COLOR_LITE_TS_FACTOR;
-	if(elementBrightness == MAX_BRIGHTNESS)
-	{
-       rb = NS_GET_R(LIGHT_GRAY);
-       gb = NS_GET_G(LIGHT_GRAY);
-       bb = NS_GET_B(LIGHT_GRAY);
-	}
-  }else {
-    f0 = COLOR_DARK_BS_FACTOR +
-      (backgroundBrightness *
-       (COLOR_LITE_BS_FACTOR - COLOR_DARK_BS_FACTOR) / MAX_COLOR);
-    f1 = COLOR_DARK_TS_FACTOR +
-      (backgroundBrightness *
-       (COLOR_LITE_TS_FACTOR - COLOR_DARK_TS_FACTOR) / MAX_COLOR);
+  uint8_t r = NS_GET_R(aBorderColor);
+  uint8_t g = NS_GET_G(aBorderColor);
+  uint8_t b = NS_GET_B(aBorderColor);
+  uint8_t a = NS_GET_A(aBorderColor);
+  if (r == 0 && g == 0 && b == 0) {
+    // 0.3 * black
+    aResult[0] = NS_RGBA(76, 76, 76, a);
+    // 0.7 * black
+    aResult[1] = NS_RGBA(178, 178, 178, a);
+    return;
   }
 
-
-  r = rb - (f0 * rb / 100);
-  g = gb - (f0 * gb / 100);
-  b = bb - (f0 * bb / 100);
-  aResult[0] = NS_RGBA(r, g, b, a);
-
-  r = rb + (f1 * (MAX_COLOR - rb) / 100);
-  g = gb + (f1 * (MAX_COLOR - gb) / 100);
-  b = bb + (f1 * (MAX_COLOR - bb) / 100);
-  aResult[1] = NS_RGBA(r, g, b, a);
+  aResult[0] = NS_RGBA(uint8_t(r * kDarkerScale),
+                       uint8_t(g * kDarkerScale),
+                       uint8_t(b * kDarkerScale),
+                       a);
+  aResult[1] = aBorderColor;
 }
 
 int NS_GetBrightness(uint8_t aRed, uint8_t aGreen, uint8_t aBlue)
 {
 
   uint8_t intensity = (aRed + aGreen + aBlue) / 3;
 
   uint8_t luminosity = NS_GetLuminosity(NS_RGB(aRed, aGreen, aBlue)) / 1000;
@@ -237,24 +178,8 @@ void NS_HSV2RGB(nscolor &aColor, uint16_
   aColor = NS_RGBA(r, g, b, aAlpha);
 }
 
 #undef RED_LUMINOSITY
 #undef GREEN_LUMINOSITY
 #undef BLUE_LUMINOSITY
 #undef INTENSITY_FACTOR
 #undef LUMINOSITY_FACTOR
-
-#undef MAX_COLOR
-#undef COLOR_DARK_THRESHOLD
-#undef COLOR_LIGHT_THRESHOLD
-
-#undef COLOR_LITE_BS_FACTOR
-#undef COLOR_LITE_TS_FACTOR
-
-#undef COLOR_DARK_BS_FACTOR
-#undef COLOR_DARK_TS_FACTOR
-
-#undef LIGHT_GRAY
-#undef DARK_GRAY
-
-#undef MAX_BRIGHTNESS
-#undef MAX_DARKNESS
--- a/layout/base/nsCSSColorUtils.h
+++ b/layout/base/nsCSSColorUtils.h
@@ -14,20 +14,18 @@
 // "Sufficient contrast" is determined by
 // "Techniques For Accessibility Evalution And Repair Tools".
 // See http://www.w3.org/TR/AERT#color-contrast
 #define NS_SUFFICIENT_LUMINOSITY_DIFFERENCE 125000
 #define NS_LUMINOSITY_DIFFERENCE(a, b) \
           int32_t(mozilla::Abs( \
             NS_GetLuminosity(a | 0xff000000) - NS_GetLuminosity(b | 0xff000000)))
 
-// To determine colors based on the background brightness and border color
-void NS_GetSpecial3DColors(nscolor aResult[2],
-                           nscolor aBackgroundColor,
-                           nscolor aBorderColor);
+// To determine 3D colors for groove / ridge borders based on the border color
+void NS_GetSpecial3DColors(nscolor aResult[2], nscolor aBorderColor);
 
 // Determins brightness for a specific color
 int NS_GetBrightness(uint8_t aRed, uint8_t aGreen, uint8_t aBlue);
 
 // Get Luminosity of a specific color. That is same as Y of YIQ color space.
 // The range of return value is 0 to 255000.
 int32_t NS_GetLuminosity(nscolor aColor);
 
--- a/layout/painting/nsCSSRendering.cpp
+++ b/layout/painting/nsCSSRendering.cpp
@@ -428,23 +428,16 @@ protected:
       }
       MOZ_ASSERT_UNREACHABLE("None of the frames is a descendant of this rtc?");
     }
     MOZ_ASSERT_UNREACHABLE("Do we have any other type of line container?");
     return false;
   }
 };
 
-/* Local functions */
-static nscolor
-MakeBevelColor(mozilla::Side whichSide,
-               uint8_t style,
-               nscolor aBackgroundColor,
-               nscolor aBorderColor);
-
 static InlineBackgroundData* gInlineBGData = nullptr;
 
 // Initialize any static variables used by nsCSSRendering.
 void
 nsCSSRendering::Init()
 {
   NS_ASSERTION(!gInlineBGData, "Init called twice");
   gInlineBGData = new InlineBackgroundData();
@@ -459,26 +452,25 @@ nsCSSRendering::Shutdown()
 }
 
 /**
  * Make a bevel color
  */
 static nscolor
 MakeBevelColor(mozilla::Side whichSide,
                uint8_t style,
-               nscolor aBackgroundColor,
                nscolor aBorderColor)
 {
 
   nscolor colors[2];
   nscolor theColor;
 
   // Given a background color and a border color
   // calculate the color used for the shading
-  NS_GetSpecial3DColors(colors, aBackgroundColor, aBorderColor);
+  NS_GetSpecial3DColors(colors, aBorderColor);
 
   if ((style == NS_STYLE_BORDER_STYLE_OUTSET) ||
       (style == NS_STYLE_BORDER_STYLE_RIDGE)) {
     // Flip colors for these two border styles
     switch (whichSide) {
       case eSideBottom:
         whichSide = eSideTop;
         break;
@@ -850,25 +842,16 @@ ConstructBorderRenderer(nsPresContext* a
                         const nsRect& aDirtyRect,
                         const nsRect& aBorderArea,
                         const nsStyleBorder& aStyleBorder,
                         Sides aSkipSides,
                         bool* aNeedsClip)
 {
   nsMargin border = aStyleBorder.GetComputedBorder();
 
-  // In NavQuirks mode we want to use the parent's context as a starting point
-  // for determining the background color.
-  bool quirks = aPresContext->CompatibilityMode() == eCompatibility_NavQuirks;
-  nsIFrame* bgFrame =
-    nsCSSRendering::FindNonTransparentBackgroundFrame(aForFrame, quirks);
-  ComputedStyle* bgContext = bgFrame->Style();
-  nscolor bgColor =
-    bgContext->GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor);
-
   // Compute the outermost boundary of the area that might be painted.
   // Same coordinate space as aBorderArea & aBGClipRect.
   nsRect joinedBorderArea = nsCSSRendering::BoxDecorationRectForBorder(
     aForFrame, aBorderArea, aSkipSides, &aStyleBorder);
   RectCornerRadii bgRadii;
   ::GetRadii(aForFrame, aStyleBorder, aBorderArea, joinedBorderArea, &bgRadii);
 
   PrintAsFormatString(" joinedBorderArea: %d %d %d %d\n",
@@ -938,17 +921,16 @@ ConstructBorderRenderer(nsPresContext* a
     document,
     aDrawTarget,
     dirtyRect,
     joinedBorderAreaPx,
     borderStyles,
     borderWidths,
     bgRadii,
     borderColors,
-    bgColor,
     !aForFrame->BackfaceIsHidden(),
     *aNeedsClip ? Some(NSRectToRect(aBorderArea, oneDevPixel)) : Nothing());
 }
 
 ImgDrawResult
 nsCSSRendering::PaintBorderWithStyleBorder(nsPresContext* aPresContext,
                                            gfxContext& aRenderingContext,
                                            nsIFrame* aForFrame,
@@ -1121,22 +1103,16 @@ nsCSSRendering::CreateBorderRendererForO
   // Get our ComputedStyle's color struct.
   const nsStyleOutline* ourOutline = aComputedStyle->StyleOutline();
 
   if (!ourOutline->ShouldPaintOutline()) {
     // Empty outline
     return Nothing();
   }
 
-  nsIFrame* bgFrame =
-    nsCSSRendering::FindNonTransparentBackgroundFrame(aForFrame, false);
-  ComputedStyle* bgContext = bgFrame->Style();
-  nscolor bgColor =
-    bgContext->GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor);
-
   nsRect innerRect;
   if (
 #ifdef MOZ_XUL
     aComputedStyle->GetPseudoType() == CSSPseudoElementType::XULTree
 #else
     false
 #endif
   ) {
@@ -1230,17 +1206,16 @@ nsCSSRendering::CreateBorderRendererForO
                          document,
                          dt,
                          dirtyRect,
                          oRect,
                          outlineStyles,
                          outlineWidths,
                          outlineRadii,
                          outlineColors,
-                         bgColor,
                          !aForFrame->BackfaceIsHidden(),
                          Nothing());
 
   return Some(br);
 }
 
 void
 nsCSSRendering::PaintOutline(nsPresContext* aPresContext,
@@ -1307,17 +1282,16 @@ nsCSSRendering::PaintFocus(nsPresContext
                          nullptr,
                          aDrawTarget,
                          focusRect,
                          focusRect,
                          focusStyles,
                          focusWidths,
                          focusRadii,
                          focusColors,
-                         NS_RGB(255, 0, 0),
                          true,
                          Nothing());
   br.DrawBorders();
 
   PrintAsStringNewline();
 }
 
 // Thebes Border Rendering Code End
@@ -3782,17 +3756,16 @@ GetDashInfo(nscoord aBorderLength,
     }
   }
 }
 
 void
 nsCSSRendering::DrawTableBorderSegment(DrawTarget& aDrawTarget,
                                        uint8_t aBorderStyle,
                                        nscolor aBorderColor,
-                                       nscolor aBGColor,
                                        const nsRect& aBorder,
                                        int32_t aAppUnitsPerDevPixel,
                                        mozilla::Side aStartBevelSide,
                                        nscoord aStartBevelOffset,
                                        mozilla::Side aEndBevelSide,
                                        nscoord aEndBevelOffset)
 {
   bool horizontal =
@@ -3881,17 +3854,16 @@ nsCSSRendering::DrawTableBorderSegment(D
       }
     }
     break;
   default:
     AutoTArray<SolidBeveledBorderSegment, 3> segments;
     GetTableBorderSolidSegments(segments,
                                 aBorderStyle,
                                 aBorderColor,
-                                aBGColor,
                                 aBorder,
                                 aAppUnitsPerDevPixel,
                                 aStartBevelSide,
                                 aStartBevelOffset,
                                 aEndBevelSide,
                                 aEndBevelOffset);
     for (const auto& segment : segments) {
       DrawSolidBorderSegment(aDrawTarget,
@@ -3907,17 +3879,16 @@ nsCSSRendering::DrawTableBorderSegment(D
   }
 }
 
 void
 nsCSSRendering::GetTableBorderSolidSegments(
     nsTArray<SolidBeveledBorderSegment>& aSegments,
     uint8_t       aBorderStyle,
     nscolor       aBorderColor,
-    nscolor       aBGColor,
     const nsRect& aBorder,
     int32_t       aAppUnitsPerDevPixel,
     mozilla::Side aStartBevelSide,
     nscoord       aStartBevelOffset,
     mozilla::Side aEndBevelSide,
     nscoord       aEndBevelOffset)
 {
   const bool horizontal = eSideTop == aStartBevelSide || eSideBottom == aStartBevelSide;
@@ -3947,17 +3918,17 @@ nsCSSRendering::GetTableBorderSolidSegme
                                                 aAppUnitsPerDevPixel, true) : 0;
       nscoord endBevel =   (aEndBevelOffset > 0)
                             ? RoundFloatToPixel(0.5f * (float)aEndBevelOffset,
                                                 aAppUnitsPerDevPixel, true) : 0;
       mozilla::Side ridgeGrooveSide = (horizontal) ? eSideTop : eSideLeft;
       // FIXME: In theory, this should use the visited-dependent
       // background color, but I don't care.
       nscolor bevelColor = MakeBevelColor(ridgeGrooveSide, aBorderStyle,
-                                          aBGColor, aBorderColor);
+                                          aBorderColor);
       nsRect rect(aBorder);
       nscoord half;
       if (horizontal) { // top, bottom
         half = RoundFloatToPixel(0.5f * (float)aBorder.height,
                                  aAppUnitsPerDevPixel);
         rect.height = half;
         if (eSideTop == aStartBevelSide) {
           rect.x += startBevel;
@@ -3991,17 +3962,17 @@ nsCSSRendering::GetTableBorderSolidSegme
         });
       }
 
       rect = aBorder;
       ridgeGrooveSide = (eSideTop == ridgeGrooveSide) ? eSideBottom : eSideRight;
       // FIXME: In theory, this should use the visited-dependent
       // background color, but I don't care.
       bevelColor = MakeBevelColor(ridgeGrooveSide, aBorderStyle,
-                                  aBGColor, aBorderColor);
+                                  aBorderColor);
       if (horizontal) {
         rect.y = rect.y + half;
         rect.height = aBorder.height - half;
         if (eSideBottom == aStartBevelSide) {
           rect.x += startBevel;
           rect.width -= startBevel;
         }
         if (eSideBottom == aEndBevelSide) {
--- a/layout/painting/nsCSSRendering.h
+++ b/layout/painting/nsCSSRendering.h
@@ -592,17 +592,16 @@ struct nsCSSRendering
   static void EndFrameTreesLocked();
 
   // Draw a border segment in the table collapsing border model with beveling
   // corners.
   static void DrawTableBorderSegment(
     DrawTarget& aDrawTarget,
     uint8_t aBorderStyle,
     nscolor aBorderColor,
-    nscolor aBGColor,
     const nsRect& aBorderRect,
     int32_t aAppUnitsPerDevPixel,
     mozilla::Side aStartBevelSide,
     nscoord aStartBevelOffset,
     mozilla::Side aEndBevelSide,
     nscoord aEndBevelOffset);
 
   // A single border bevel.
@@ -622,17 +621,16 @@ struct nsCSSRendering
   };
 
   // Collect the table border segments with beveling. Can't be called with
   // dashed / dotted borders, since we don't support beveling those.
   static void GetTableBorderSolidSegments(
       nsTArray<SolidBeveledBorderSegment>& aSegments,
       uint8_t aBorderStyle,
       nscolor aBorderColor,
-      nscolor aBGColor,
       const nsRect& aBorderRect,
       int32_t aAppUnitsPerDevPixel,
       mozilla::Side aStartBevelSide,
       nscoord aStartBevelOffset,
       mozilla::Side aEndBevelSide,
       nscoord aEndBevelOffset);
 
   // NOTE: pt, dirtyRect, lineSize, ascent, offset in the following
--- a/layout/painting/nsCSSRenderingBorders.cpp
+++ b/layout/painting/nsCSSRenderingBorders.cpp
@@ -78,28 +78,26 @@ ComputeBorderCornerDimensions(const Floa
 // given a corner index, get the previous and next corner index
 #define NEXT_CORNER(_s) Corner(((_s) + 1) & 3)
 #define PREV_CORNER(_s) Corner(((_s) + 3) & 3)
 
 // from the given base color and the background color, turn
 // color into a color for the given border pattern style
 static Color
 MakeBorderColor(nscolor aColor,
-                nscolor aBackgroundColor,
                 BorderColorStyle aBorderColorStyle);
 
 // Given a line index (an index starting from the outside of the
 // border going inwards) and an array of line styles, calculate the
 // color that that stripe of the border should be rendered in.
 static Color
 ComputeColorForLine(uint32_t aLineIndex,
                     const BorderColorStyle* aBorderColorStyle,
                     uint32_t aBorderColorStyleCount,
-                    nscolor aBorderColor,
-                    nscolor aBackgroundColor);
+                    nscolor aBorderColor);
 
 // little helper function to check if the array of 4 floats given are
 // equal to the given value
 static bool
 CheckFourFloatsEqual(const Float* vals, Float k)
 {
   return (vals[0] == k && vals[1] == k && vals[2] == k && vals[3] == k);
 }
@@ -175,26 +173,24 @@ nsCSSBorderRenderer::nsCSSBorderRenderer
                                          const nsIDocument* aDocument,
                                          DrawTarget* aDrawTarget,
                                          const Rect& aDirtyRect,
                                          Rect& aOuterRect,
                                          const uint8_t* aBorderStyles,
                                          const Float* aBorderWidths,
                                          RectCornerRadii& aBorderRadii,
                                          const nscolor* aBorderColors,
-                                         nscolor aBackgroundColor,
                                          bool aBackfaceIsVisible,
                                          const Maybe<Rect>& aClipRect)
   : mPresContext(aPresContext)
   , mDocument(aDocument)
   , mDrawTarget(aDrawTarget)
   , mDirtyRect(aDirtyRect)
   , mOuterRect(aOuterRect)
   , mBorderRadii(aBorderRadii)
-  , mBackgroundColor(aBackgroundColor)
   , mBackfaceIsVisible(aBackfaceIsVisible)
   , mLocalClip(aClipRect)
 {
   PodCopy(mBorderStyles, aBorderStyles, 4);
   PodCopy(mBorderWidths, aBorderWidths, 4);
   PodCopy(mBorderColors, aBorderColors, 4);
   mInnerRect = mOuterRect;
   mInnerRect.Deflate(Margin(
@@ -1248,51 +1244,47 @@ nsCSSBorderRenderer::FillSolidBorder(con
     if (aSides & (1 << i)) {
       MaybeSnapToDevicePixels(r[i], *mDrawTarget, true);
       mDrawTarget->FillRect(r[i], aColor);
     }
   }
 }
 
 Color
-MakeBorderColor(nscolor aColor,
-                nscolor aBackgroundColor,
-                BorderColorStyle aBorderColorStyle)
+MakeBorderColor(nscolor aColor, BorderColorStyle aBorderColorStyle)
 {
   nscolor colors[2];
   int k = 0;
 
   switch (aBorderColorStyle) {
     case BorderColorStyleNone:
       return Color(0.f, 0.f, 0.f, 0.f); // transparent black
 
     case BorderColorStyleLight:
       k = 1;
       MOZ_FALLTHROUGH;
     case BorderColorStyleDark:
-      NS_GetSpecial3DColors(colors, aBackgroundColor, aColor);
+      NS_GetSpecial3DColors(colors, aColor);
       return Color::FromABGR(colors[k]);
 
     case BorderColorStyleSolid:
     default:
       return Color::FromABGR(aColor);
   }
 }
 
 Color
 ComputeColorForLine(uint32_t aLineIndex,
                     const BorderColorStyle* aBorderColorStyle,
                     uint32_t aBorderColorStyleCount,
-                    nscolor aBorderColor,
-                    nscolor aBackgroundColor)
+                    nscolor aBorderColor)
 {
   NS_ASSERTION(aLineIndex < aBorderColorStyleCount, "Invalid lineIndex given");
 
-  return MakeBorderColor(
-    aBorderColor, aBackgroundColor, aBorderColorStyle[aLineIndex]);
+  return MakeBorderColor(aBorderColor, aBorderColorStyle[aLineIndex]);
 }
 
 void
 nsCSSBorderRenderer::DrawBorderSides(int aSides)
 {
   if (aSides == 0 || (aSides & ~eSideBitsAll) != 0) {
     NS_WARNING("DrawBorderSides: invalid sides!");
     return;
@@ -1563,18 +1555,17 @@ nsCSSBorderRenderer::DrawBorderSides(int
                           noMarginRight ? 0 : borderWidths[i][1],
                           noMarginBottom ? 0 : borderWidths[i][2],
                           noMarginLeft ? 0 : borderWidths[i][3]));
 
     if (borderColorStyle[i] != BorderColorStyleNone) {
       Color c = ComputeColorForLine(i,
                                     borderColorStyle,
                                     borderColorStyleCount,
-                                    borderRenderColor,
-                                    mBackgroundColor);
+                                    borderRenderColor);
       ColorPattern color(ToDeviceColor(c));
 
       FillSolidBorder(soRect, siRect, radii, borderWidths[i], aSides, color);
     }
 
     ComputeInnerRadii(radii, borderWidths[i], &radii);
 
     // And now soRect is the same as siRect, for the next line in.
@@ -3407,17 +3398,16 @@ nsCSSBorderRenderer::DrawBorders()
 
       // If we don't have anything complex going on in this corner,
       // then we can just fill the corner with a solid color, and avoid
       // the potentially expensive clip.
       if (simpleCornerStyle && IsZeroSize(mBorderRadii[corner]) &&
           IsSolidCornerStyle(mBorderStyles[sides[0]], corner)) {
         Color color = MakeBorderColor(
           mBorderColors[sides[0]],
-          mBackgroundColor,
           BorderColorStyleForSolidCorner(mBorderStyles[sides[0]], corner));
         mDrawTarget->FillRect(GetCornerRect(corner),
                               ColorPattern(ToDeviceColor(color)));
         continue;
       }
 
       // clip to the corner
       mDrawTarget->PushClipRect(GetCornerRect(corner));
--- a/layout/painting/nsCSSRenderingBorders.h
+++ b/layout/painting/nsCSSRenderingBorders.h
@@ -91,17 +91,16 @@ public:
                       const nsIDocument* aDocument,
                       DrawTarget* aDrawTarget,
                       const Rect& aDirtyRect,
                       Rect& aOuterRect,
                       const uint8_t* aBorderStyles,
                       const Float* aBorderWidths,
                       RectCornerRadii& aBorderRadii,
                       const nscolor* aBorderColors,
-                      nscolor aBackgroundColor,
                       bool aBackfaceIsVisible,
                       const mozilla::Maybe<Rect>& aClipRect);
 
   // draw the entire border
   void DrawBorders();
 
   void CreateWebRenderCommands(
     nsDisplayItem* aItem,
@@ -142,19 +141,16 @@ private:
   // the style and size of the border
   uint8_t mBorderStyles[4];
   Float mBorderWidths[4];
   RectCornerRadii mBorderRadii;
 
   // the colors for 'border-top-color' et. al.
   nscolor mBorderColors[4];
 
-  // the background color
-  nscolor mBackgroundColor;
-
   // calculated values
   bool mAllBordersSameStyle;
   bool mAllBordersSameWidth;
   bool mOneUnitBorder;
   bool mNoBorderRadius;
   bool mAvoidStroke;
   bool mBackfaceIsVisible;
   mozilla::Maybe<Rect> mLocalClip;
--- a/layout/reftests/table-bordercollapse/reftest.list
+++ b/layout/reftests/table-bordercollapse/reftest.list
@@ -105,18 +105,17 @@ fails-if(webrender) == frame_vsides_rule
 == bordercolor-3.html bordercolor-3-ref.html
 == bordercolor-4.html bordercolor-4-ref.html
 == empty-toprow.html empty-toprow-ref.html
 == double_borders.html double_borders_ref.html
 == border-collapse-rtl.html border-collapse-rtl-ref.html
 # Fuzzy because border-collapsed borders are not antialiased, since each segment is painted separately.
 # So get 40 pixels of fuzz, 20 at each beveled corner (because the border width
 # is 20px).
-# Bug 1382896 for webrender (since tables use Gecko border colors).
-fails-if(webrender) fuzzy(0-255,0-40) == border-style-outset-becomes-groove.html border-style-outset-becomes-groove-ref.html
+fuzzy(0-255,0-40) == border-style-outset-becomes-groove.html border-style-outset-becomes-groove-ref.html
 # Fuzzy because border-collapsed borders are not antialiased, since each segment is painted separately.
 # So get 40 pixels of fuzz, 20 at each beveled corner (because the border width
 # is 20px).
 # Bug 1382896 for webrender (since tables use Gecko border colors).
-fails-if(webrender) fuzzy(0-255,0-40) == border-style-inset-becomes-ridge.html border-style-inset-becomes-ridge-ref.html
+fuzzy(0-255,0-40) == border-style-inset-becomes-ridge.html border-style-inset-becomes-ridge-ref.html
 fuzzy(0-2,0-11000) == 1324524.html 1324524-ref.html
 == 1384602-1a.html 1384602-1-ref.html
 == 1384602-1b.html 1384602-1-ref.html
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -6492,17 +6492,16 @@ nsTableFrame::CalcBCBorders()
 }
 
 class BCPaintBorderIterator;
 
 struct BCBorderParameters
 {
   uint8_t mBorderStyle;
   nscolor mBorderColor;
-  nscolor mBGColor;
   nsRect mBorderRect;
   int32_t mAppUnitsPerDevPixel;
   mozilla::Side mStartBevelSide;
   nscoord mStartBevelOffset;
   mozilla::Side mEndBevelSide;
   nscoord mEndBevelOffset;
   bool mBackfaceIsVisible;
 
@@ -6712,17 +6711,16 @@ public:
   void StoreColumnWidth(int32_t aIndex);
   bool BlockDirSegmentOwnsCorner();
 
   nsTableFrame*         mTable;
   nsTableFrame*         mTableFirstInFlow;
   nsTableCellMap*       mTableCellMap;
   nsCellMap*            mCellMap;
   WritingMode           mTableWM;
-  nscolor               mTableBgColor;
   nsTableFrame::RowGroupArray mRowGroups;
 
   nsTableRowGroupFrame* mPrevRg;
   nsTableRowGroupFrame* mRg;
   bool                  mIsRepeatedHeader;
   bool                  mIsRepeatedFooter;
   nsTableRowGroupFrame* mStartRg; // first row group in the damagearea
   int32_t               mRgIndex; // current row group index in the
@@ -6852,20 +6850,16 @@ BCPaintBorderIterator::BCPaintBorderIter
     mTable->GetPrevInFlow() ? 0 : childAreaOffset.BStart(mTableWM);
   mNumTableRows  = mTable->GetRowCount();
   mNumTableCols  = mTable->GetColCount();
 
   // Get the ordered row groups
   mTable->OrderRowGroups(mRowGroups);
   // initialize to a non existing index
   mRepeatedHeaderRowIndex = -99;
-
-  nsIFrame* bgFrame =
-    nsCSSRendering::FindNonTransparentBackgroundFrame(aTable);
-  mTableBgColor = bgFrame->StyleBackground()->BackgroundColor(bgFrame);
 }
 
 bool
 BCPaintBorderIterator::SetDamageArea(const nsRect& aDirtyRect)
 {
   nsSize containerSize = mTable->GetSize();
   LogicalRect dirtyRect(mTableWM, aDirtyRect, containerSize);
   uint32_t startRowIndex, endRowIndex, startColIndex, endColIndex;
@@ -7379,17 +7373,16 @@ BCBlockDirSeg::BuildBorderParameters(BCP
   LogicalSide side =
     aIter.IsDamageAreaIEndMost() ? eLogicalSideIEnd : eLogicalSideIStart;
   int32_t relColIndex = aIter.GetRelativeColIndex();
   nsTableColFrame* col           = mCol; if (!col) ABORT1(Nothing());
   nsTableCellFrame* cell         = mFirstCell; // ???
   nsIFrame* owner = nullptr;
   result.mBorderStyle = NS_STYLE_BORDER_STYLE_SOLID;
   result.mBorderColor = 0xFFFFFFFF;
-  result.mBGColor = aIter.mTableBgColor;
   result.mBackfaceIsVisible = true;
 
   // All the tables frames have the same presContext, so we just use any one
   // that exists here:
   nsPresContext* presContext = aIter.mTable->PresContext();
   result.mAppUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
 
   switch (mOwner) {
@@ -7498,17 +7491,17 @@ BCBlockDirSeg::Paint(BCPaintBorderIterat
                      BCPixelSize            aInlineSegBSize)
 {
   Maybe<BCBorderParameters> param = BuildBorderParameters(aIter, aInlineSegBSize);
   if (param.isNothing()) {
     return;
   }
 
   nsCSSRendering::DrawTableBorderSegment(aDrawTarget, param->mBorderStyle, param->mBorderColor,
-                                         param->mBGColor, param->mBorderRect,
+                                         param->mBorderRect,
                                          param->mAppUnitsPerDevPixel,
                                          param->mStartBevelSide, param->mStartBevelOffset,
                                          param->mEndBevelSide, param->mEndBevelOffset);
 }
 
 // Pushes a border bevel triangle and substracts the relevant rectangle from
 // aRect, which, after all the bevels, will end up being a solid segment rect.
 static void
@@ -7611,17 +7604,16 @@ CreateWRCommandsForBeveledBorder(const B
                                  const nsPoint& aOffset)
 {
   MOZ_ASSERT(aBorderParams.NeedToBevel());
 
   AutoTArray<nsCSSRendering::SolidBeveledBorderSegment, 3> segments;
   nsCSSRendering::GetTableBorderSolidSegments(segments,
                                               aBorderParams.mBorderStyle,
                                               aBorderParams.mBorderColor,
-                                              aBorderParams.mBGColor,
                                               aBorderParams.mBorderRect,
                                               aBorderParams.mAppUnitsPerDevPixel,
                                               aBorderParams.mStartBevelSide,
                                               aBorderParams.mStartBevelOffset,
                                               aBorderParams.mEndBevelSide,
                                               aBorderParams.mEndBevelOffset);
 
   for (const auto& segment : segments) {
@@ -7830,17 +7822,16 @@ BCInlineDirSeg::BuildBorderParameters(BC
 
   // All the tables frames have the same presContext, so we just use any one
   // that exists here:
   nsPresContext* presContext = aIter.mTable->PresContext();
   result.mAppUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
 
   result.mBorderStyle = NS_STYLE_BORDER_STYLE_SOLID;
   result.mBorderColor = 0xFFFFFFFF;
-  result.mBGColor = aIter.mTableBgColor;
 
   switch (mOwner) {
     case eTableOwner:
       owner = aIter.mTable;
       break;
     case eAjaColGroupOwner:
       NS_ERROR("neighboring colgroups can never own an inline-dir border");
       MOZ_FALLTHROUGH;
@@ -7930,17 +7921,17 @@ void
 BCInlineDirSeg::Paint(BCPaintBorderIterator& aIter, DrawTarget& aDrawTarget)
 {
   Maybe<BCBorderParameters> param = BuildBorderParameters(aIter);
   if (param.isNothing()) {
     return;
   }
 
   nsCSSRendering::DrawTableBorderSegment(aDrawTarget, param->mBorderStyle, param->mBorderColor,
-                                         param->mBGColor, param->mBorderRect,
+                                         param->mBorderRect,
                                          param->mAppUnitsPerDevPixel,
                                          param->mStartBevelSide, param->mStartBevelOffset,
                                          param->mEndBevelSide, param->mEndBevelOffset);
 }
 
 void
 BCInlineDirSeg::CreateWebRenderCommands(BCPaintBorderIterator& aIter,
                                         wr::DisplayListBuilder& aBuilder,