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
This commit is contained in:
Emilio Cobos Álvarez 2018-09-22 07:18:34 +02:00
parent 2afc706839
commit 0cf08372ac
9 changed files with 33 additions and 167 deletions

View File

@ -214,11 +214,9 @@ impl BorderSideHelpers for BorderSide {
// 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)

View File

@ -19,86 +19,27 @@
#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)
{
const float kDarkerScale = 2.0 / 3.0;
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 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);
// 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);
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)
@ -242,19 +183,3 @@ void NS_HSV2RGB(nscolor &aColor, uint16_t aHue, uint16_t aSat, uint16_t aValue,
#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

View File

@ -19,10 +19,8 @@
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);

View File

@ -433,13 +433,6 @@ protected:
}
};
/* 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.
@ -464,7 +457,6 @@ nsCSSRendering::Shutdown()
static nscolor
MakeBevelColor(mozilla::Side whichSide,
uint8_t style,
nscolor aBackgroundColor,
nscolor aBorderColor)
{
@ -473,7 +465,7 @@ MakeBevelColor(mozilla::Side whichSide,
// 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)) {
@ -855,15 +847,6 @@ ConstructBorderRenderer(nsPresContext* aPresContext,
{
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(
@ -943,7 +926,6 @@ ConstructBorderRenderer(nsPresContext* aPresContext,
borderWidths,
bgRadii,
borderColors,
bgColor,
!aForFrame->BackfaceIsHidden(),
*aNeedsClip ? Some(NSRectToRect(aBorderArea, oneDevPixel)) : Nothing());
}
@ -1126,12 +1108,6 @@ nsCSSRendering::CreateBorderRendererForOutline(nsPresContext* aPresContext,
return Nothing();
}
nsIFrame* bgFrame =
nsCSSRendering::FindNonTransparentBackgroundFrame(aForFrame, false);
ComputedStyle* bgContext = bgFrame->Style();
nscolor bgColor =
bgContext->GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor);
nsRect innerRect;
if (
#ifdef MOZ_XUL
@ -1235,7 +1211,6 @@ nsCSSRendering::CreateBorderRendererForOutline(nsPresContext* aPresContext,
outlineWidths,
outlineRadii,
outlineColors,
bgColor,
!aForFrame->BackfaceIsHidden(),
Nothing());
@ -1312,7 +1287,6 @@ nsCSSRendering::PaintFocus(nsPresContext* aPresContext,
focusWidths,
focusRadii,
focusColors,
NS_RGB(255, 0, 0),
true,
Nothing());
br.DrawBorders();
@ -3787,7 +3761,6 @@ void
nsCSSRendering::DrawTableBorderSegment(DrawTarget& aDrawTarget,
uint8_t aBorderStyle,
nscolor aBorderColor,
nscolor aBGColor,
const nsRect& aBorder,
int32_t aAppUnitsPerDevPixel,
mozilla::Side aStartBevelSide,
@ -3886,7 +3859,6 @@ nsCSSRendering::DrawTableBorderSegment(DrawTarget& aDrawTarget,
GetTableBorderSolidSegments(segments,
aBorderStyle,
aBorderColor,
aBGColor,
aBorder,
aAppUnitsPerDevPixel,
aStartBevelSide,
@ -3912,7 +3884,6 @@ nsCSSRendering::GetTableBorderSolidSegments(
nsTArray<SolidBeveledBorderSegment>& aSegments,
uint8_t aBorderStyle,
nscolor aBorderColor,
nscolor aBGColor,
const nsRect& aBorder,
int32_t aAppUnitsPerDevPixel,
mozilla::Side aStartBevelSide,
@ -3952,7 +3923,7 @@ nsCSSRendering::GetTableBorderSolidSegments(
// 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
@ -3996,7 +3967,7 @@ nsCSSRendering::GetTableBorderSolidSegments(
// 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;

View File

@ -597,7 +597,6 @@ struct nsCSSRendering
DrawTarget& aDrawTarget,
uint8_t aBorderStyle,
nscolor aBorderColor,
nscolor aBGColor,
const nsRect& aBorderRect,
int32_t aAppUnitsPerDevPixel,
mozilla::Side aStartBevelSide,
@ -627,7 +626,6 @@ struct nsCSSRendering
nsTArray<SolidBeveledBorderSegment>& aSegments,
uint8_t aBorderStyle,
nscolor aBorderColor,
nscolor aBGColor,
const nsRect& aBorderRect,
int32_t aAppUnitsPerDevPixel,
mozilla::Side aStartBevelSide,

View File

@ -83,7 +83,6 @@ ComputeBorderCornerDimensions(const Float* aBorderWidths,
// 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
@ -93,8 +92,7 @@ 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
@ -180,7 +178,6 @@ nsCSSBorderRenderer::nsCSSBorderRenderer(nsPresContext* aPresContext,
const Float* aBorderWidths,
RectCornerRadii& aBorderRadii,
const nscolor* aBorderColors,
nscolor aBackgroundColor,
bool aBackfaceIsVisible,
const Maybe<Rect>& aClipRect)
: mPresContext(aPresContext)
@ -189,7 +186,6 @@ nsCSSBorderRenderer::nsCSSBorderRenderer(nsPresContext* aPresContext,
, mDirtyRect(aDirtyRect)
, mOuterRect(aOuterRect)
, mBorderRadii(aBorderRadii)
, mBackgroundColor(aBackgroundColor)
, mBackfaceIsVisible(aBackfaceIsVisible)
, mLocalClip(aClipRect)
{
@ -1253,9 +1249,7 @@ nsCSSBorderRenderer::FillSolidBorder(const Rect& aOuterRect,
}
Color
MakeBorderColor(nscolor aColor,
nscolor aBackgroundColor,
BorderColorStyle aBorderColorStyle)
MakeBorderColor(nscolor aColor, BorderColorStyle aBorderColorStyle)
{
nscolor colors[2];
int k = 0;
@ -1268,7 +1262,7 @@ MakeBorderColor(nscolor aColor,
k = 1;
MOZ_FALLTHROUGH;
case BorderColorStyleDark:
NS_GetSpecial3DColors(colors, aBackgroundColor, aColor);
NS_GetSpecial3DColors(colors, aColor);
return Color::FromABGR(colors[k]);
case BorderColorStyleSolid:
@ -1281,13 +1275,11 @@ 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
@ -1568,8 +1560,7 @@ nsCSSBorderRenderer::DrawBorderSides(int aSides)
Color c = ComputeColorForLine(i,
borderColorStyle,
borderColorStyleCount,
borderRenderColor,
mBackgroundColor);
borderRenderColor);
ColorPattern color(ToDeviceColor(c));
FillSolidBorder(soRect, siRect, radii, borderWidths[i], aSides, color);
@ -3412,7 +3403,6 @@ nsCSSBorderRenderer::DrawBorders()
IsSolidCornerStyle(mBorderStyles[sides[0]], corner)) {
Color color = MakeBorderColor(
mBorderColors[sides[0]],
mBackgroundColor,
BorderColorStyleForSolidCorner(mBorderStyles[sides[0]], corner));
mDrawTarget->FillRect(GetCornerRect(corner),
ColorPattern(ToDeviceColor(color)));

View File

@ -96,7 +96,6 @@ public:
const Float* aBorderWidths,
RectCornerRadii& aBorderRadii,
const nscolor* aBorderColors,
nscolor aBackgroundColor,
bool aBackfaceIsVisible,
const mozilla::Maybe<Rect>& aClipRect);
@ -147,9 +146,6 @@ private:
// the colors for 'border-top-color' et. al.
nscolor mBorderColors[4];
// the background color
nscolor mBackgroundColor;
// calculated values
bool mAllBordersSameStyle;
bool mAllBordersSameWidth;

View File

@ -110,13 +110,12 @@ fails-if(webrender) == frame_vsides_rules_none.html frame_vsides_rules_none_ref.
# 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

View File

@ -6497,7 +6497,6 @@ struct BCBorderParameters
{
uint8_t mBorderStyle;
nscolor mBorderColor;
nscolor mBGColor;
nsRect mBorderRect;
int32_t mAppUnitsPerDevPixel;
mozilla::Side mStartBevelSide;
@ -6717,7 +6716,6 @@ public:
nsTableCellMap* mTableCellMap;
nsCellMap* mCellMap;
WritingMode mTableWM;
nscolor mTableBgColor;
nsTableFrame::RowGroupArray mRowGroups;
nsTableRowGroupFrame* mPrevRg;
@ -6857,10 +6855,6 @@ BCPaintBorderIterator::BCPaintBorderIterator(nsTableFrame* aTable)
mTable->OrderRowGroups(mRowGroups);
// initialize to a non existing index
mRepeatedHeaderRowIndex = -99;
nsIFrame* bgFrame =
nsCSSRendering::FindNonTransparentBackgroundFrame(aTable);
mTableBgColor = bgFrame->StyleBackground()->BackgroundColor(bgFrame);
}
bool
@ -7384,7 +7378,6 @@ BCBlockDirSeg::BuildBorderParameters(BCPaintBorderIterator& aIter,
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
@ -7503,7 +7496,7 @@ BCBlockDirSeg::Paint(BCPaintBorderIterator& aIter,
}
nsCSSRendering::DrawTableBorderSegment(aDrawTarget, param->mBorderStyle, param->mBorderColor,
param->mBGColor, param->mBorderRect,
param->mBorderRect,
param->mAppUnitsPerDevPixel,
param->mStartBevelSide, param->mStartBevelOffset,
param->mEndBevelSide, param->mEndBevelOffset);
@ -7616,7 +7609,6 @@ CreateWRCommandsForBeveledBorder(const BCBorderParameters& aBorderParams,
nsCSSRendering::GetTableBorderSolidSegments(segments,
aBorderParams.mBorderStyle,
aBorderParams.mBorderColor,
aBorderParams.mBGColor,
aBorderParams.mBorderRect,
aBorderParams.mAppUnitsPerDevPixel,
aBorderParams.mStartBevelSide,
@ -7835,7 +7827,6 @@ BCInlineDirSeg::BuildBorderParameters(BCPaintBorderIterator& aIter)
result.mBorderStyle = NS_STYLE_BORDER_STYLE_SOLID;
result.mBorderColor = 0xFFFFFFFF;
result.mBGColor = aIter.mTableBgColor;
switch (mOwner) {
case eTableOwner:
@ -7935,7 +7926,7 @@ BCInlineDirSeg::Paint(BCPaintBorderIterator& aIter, DrawTarget& aDrawTarget)
}
nsCSSRendering::DrawTableBorderSegment(aDrawTarget, param->mBorderStyle, param->mBorderColor,
param->mBGColor, param->mBorderRect,
param->mBorderRect,
param->mAppUnitsPerDevPixel,
param->mStartBevelSide, param->mStartBevelOffset,
param->mEndBevelSide, param->mEndBevelOffset);