Bug 1230413 (part 5) - Pass a DrawTarget to Draw{Dashed,SolidBorder}Segment(). r=mattwoodrow.

Instead of an nsRenderingContext.

--HG--
extra : rebase_source : 1c6d8bba8af88f457d8310454daa4b40e09fc244
This commit is contained in:
Nicholas Nethercote 2015-12-06 14:13:58 -08:00
Родитель ac18a09064
Коммит ef7209c641
1 изменённых файлов: 53 добавлений и 37 удалений

Просмотреть файл

@ -3735,7 +3735,7 @@ static void SetPoly(const Rect& aRect, Point* poly)
}
static void
DrawDashedSegment(nsRenderingContext& aContext,
DrawDashedSegment(DrawTarget& aDrawTarget,
nsRect aRect,
nscoord aDashLength,
nscolor aColor,
@ -3743,8 +3743,6 @@ DrawDashedSegment(nsRenderingContext& aContext,
nscoord aTwipsPerPixel,
bool aHorizontal)
{
DrawTarget* drawTarget = aContext.GetDrawTarget();
ColorPattern color(ToDeviceColor(aColor));
DrawOptions drawOptions(1.f, CompositionOp::OP_OVER, AntialiasMode::NONE);
StrokeOptions strokeOptions;
@ -3761,20 +3759,20 @@ DrawDashedSegment(nsRenderingContext& aContext,
nsPoint right = (aRect.TopRight() + aRect.BottomRight()) / 2;
strokeOptions.mLineWidth = Float(aRect.height) / aAppUnitsPerDevPixel;
StrokeLineWithSnapping(left, right,
aAppUnitsPerDevPixel, *drawTarget,
aAppUnitsPerDevPixel, aDrawTarget,
color, strokeOptions, drawOptions);
} else {
nsPoint top = (aRect.TopLeft() + aRect.TopRight()) / 2;
nsPoint bottom = (aRect.BottomLeft() + aRect.BottomRight()) / 2;
strokeOptions.mLineWidth = Float(aRect.width) / aAppUnitsPerDevPixel;
StrokeLineWithSnapping(top, bottom,
aAppUnitsPerDevPixel, *drawTarget,
aAppUnitsPerDevPixel, aDrawTarget,
color, strokeOptions, drawOptions);
}
}
static void
DrawSolidBorderSegment(nsRenderingContext& aContext,
DrawSolidBorderSegment(DrawTarget& aDrawTarget,
nsRect aRect,
nscolor aColor,
int32_t aAppUnitsPerDevPixel,
@ -3784,8 +3782,6 @@ DrawSolidBorderSegment(nsRenderingContext& aContext,
uint8_t aEndBevelSide = 0,
nscoord aEndBevelOffset = 0)
{
DrawTarget* drawTarget = aContext.GetDrawTarget();
ColorPattern color(ToDeviceColor(aColor));
DrawOptions drawOptions(1.f, CompositionOp::OP_OVER, AntialiasMode::NONE);
@ -3793,14 +3789,14 @@ DrawSolidBorderSegment(nsRenderingContext& aContext,
if ((aRect.width == aTwipsPerPixel) || (aRect.height == aTwipsPerPixel) ||
((0 == aStartBevelOffset) && (0 == aEndBevelOffset))) {
// simple rectangle
drawTarget->FillRect(NSRectToSnappedRect(aRect, aAppUnitsPerDevPixel,
*drawTarget),
aDrawTarget.FillRect(NSRectToSnappedRect(aRect, aAppUnitsPerDevPixel,
aDrawTarget),
color, drawOptions);
}
else {
// polygon with beveling
Point poly[4];
SetPoly(NSRectToSnappedRect(aRect, aAppUnitsPerDevPixel, *drawTarget),
SetPoly(NSRectToSnappedRect(aRect, aAppUnitsPerDevPixel, aDrawTarget),
poly);
Float startBevelOffset =
@ -3835,14 +3831,14 @@ DrawSolidBorderSegment(nsRenderingContext& aContext,
poly[3].y -= endBevelOffset;
}
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
builder->MoveTo(poly[0]);
builder->LineTo(poly[1]);
builder->LineTo(poly[2]);
builder->LineTo(poly[3]);
builder->Close();
RefPtr<Path> path = builder->Finish();
drawTarget->Fill(path, color, drawOptions);
aDrawTarget.Fill(path, color, drawOptions);
}
}
@ -3900,6 +3896,8 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext,
ctx->SetColor(Color::FromABGR(aBorderColor));
DrawTarget& drawTarget = *aContext.GetDrawTarget();
switch (aBorderStyle) {
case NS_STYLE_BORDER_STYLE_NONE:
case NS_STYLE_BORDER_STYLE_HIDDEN:
@ -3922,36 +3920,36 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext,
GetDashInfo(aBorder.width, dashLength, twipsPerPixel, numDashSpaces,
startDashLength, endDashLength);
nsRect rect(aBorder.x, aBorder.y, startDashLength, aBorder.height);
DrawSolidBorderSegment(aContext, rect, aBorderColor,
DrawSolidBorderSegment(drawTarget, rect, aBorderColor,
aAppUnitsPerDevPixel, twipsPerPixel);
rect.x += startDashLength + dashLength;
rect.width = aBorder.width
- (startDashLength + endDashLength + dashLength);
DrawDashedSegment(aContext, rect, dashLength, aBorderColor,
DrawDashedSegment(drawTarget, rect, dashLength, aBorderColor,
aAppUnitsPerDevPixel, twipsPerPixel, horizontal);
rect.x += rect.width;
rect.width = endDashLength;
DrawSolidBorderSegment(aContext, rect, aBorderColor,
DrawSolidBorderSegment(drawTarget, rect, aBorderColor,
aAppUnitsPerDevPixel, twipsPerPixel);
}
else {
GetDashInfo(aBorder.height, dashLength, twipsPerPixel, numDashSpaces,
startDashLength, endDashLength);
nsRect rect(aBorder.x, aBorder.y, aBorder.width, startDashLength);
DrawSolidBorderSegment(aContext, rect, aBorderColor,
DrawSolidBorderSegment(drawTarget, rect, aBorderColor,
aAppUnitsPerDevPixel, twipsPerPixel);
rect.y += rect.height + dashLength;
rect.height = aBorder.height
- (startDashLength + endDashLength + dashLength);
DrawDashedSegment(aContext, rect, dashLength, aBorderColor,
DrawDashedSegment(drawTarget, rect, dashLength, aBorderColor,
aAppUnitsPerDevPixel, twipsPerPixel, horizontal);
rect.y += rect.height;
rect.height = endDashLength;
DrawSolidBorderSegment(aContext, rect, aBorderColor,
DrawSolidBorderSegment(drawTarget, rect, aBorderColor,
aAppUnitsPerDevPixel, twipsPerPixel);
}
}
@ -3962,7 +3960,8 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext,
if ((horizontal && (twipsPerPixel >= aBorder.height)) ||
(!horizontal && (twipsPerPixel >= aBorder.width))) {
// a one pixel border
DrawSolidBorderSegment(aContext, aBorder, aBorderColor, aAppUnitsPerDevPixel, twipsPerPixel,
DrawSolidBorderSegment(drawTarget, aBorder, aBorderColor,
aAppUnitsPerDevPixel, twipsPerPixel,
aStartBevelSide, aStartBevelOffset,
aEndBevelSide, aEndBevelOffset);
}
@ -3991,8 +3990,10 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext,
if (NS_SIDE_TOP == aEndBevelSide) {
rect.width -= endBevel;
}
DrawSolidBorderSegment(aContext, rect, bevelColor, aAppUnitsPerDevPixel, twipsPerPixel, aStartBevelSide,
startBevel, aEndBevelSide, endBevel);
DrawSolidBorderSegment(drawTarget, rect, bevelColor,
aAppUnitsPerDevPixel, twipsPerPixel,
aStartBevelSide, startBevel, aEndBevelSide,
endBevel);
}
else { // left, right
half = RoundFloatToPixel(0.5f * (float)aBorder.width, twipsPerPixel);
@ -4004,8 +4005,10 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext,
if (NS_SIDE_LEFT == aEndBevelSide) {
rect.height -= endBevel;
}
DrawSolidBorderSegment(aContext, rect, bevelColor, aAppUnitsPerDevPixel, twipsPerPixel, aStartBevelSide,
startBevel, aEndBevelSide, endBevel);
DrawSolidBorderSegment(drawTarget, rect, bevelColor,
aAppUnitsPerDevPixel, twipsPerPixel,
aStartBevelSide, startBevel, aEndBevelSide,
endBevel);
}
rect = aBorder;
@ -4026,8 +4029,10 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext,
if (NS_SIDE_BOTTOM == aEndBevelSide) {
rect.width -= endBevel;
}
DrawSolidBorderSegment(aContext, rect, bevelColor, aAppUnitsPerDevPixel, twipsPerPixel, aStartBevelSide,
startBevel, aEndBevelSide, endBevel);
DrawSolidBorderSegment(drawTarget, rect, bevelColor,
aAppUnitsPerDevPixel, twipsPerPixel,
aStartBevelSide, startBevel, aEndBevelSide,
endBevel);
}
else {
rect.x = rect.x + half;
@ -4039,8 +4044,10 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext,
if (NS_SIDE_RIGHT == aEndBevelSide) {
rect.height -= endBevel;
}
DrawSolidBorderSegment(aContext, rect, bevelColor, aAppUnitsPerDevPixel, twipsPerPixel, aStartBevelSide,
startBevel, aEndBevelSide, endBevel);
DrawSolidBorderSegment(drawTarget, rect, bevelColor,
aAppUnitsPerDevPixel, twipsPerPixel,
aStartBevelSide, startBevel, aEndBevelSide,
endBevel);
}
}
break;
@ -4066,8 +4073,10 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext,
if (NS_SIDE_TOP == aEndBevelSide) {
topRect.width -= aEndBevelOffset - endBevel;
}
DrawSolidBorderSegment(aContext, topRect, aBorderColor, aAppUnitsPerDevPixel, twipsPerPixel, aStartBevelSide,
startBevel, aEndBevelSide, endBevel);
DrawSolidBorderSegment(drawTarget, topRect, aBorderColor,
aAppUnitsPerDevPixel, twipsPerPixel,
aStartBevelSide, startBevel, aEndBevelSide,
endBevel);
// draw the botom line or rect
nscoord heightOffset = aBorder.height - thirdHeight;
@ -4079,8 +4088,10 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext,
if (NS_SIDE_BOTTOM == aEndBevelSide) {
bottomRect.width -= aEndBevelOffset - endBevel;
}
DrawSolidBorderSegment(aContext, bottomRect, aBorderColor, aAppUnitsPerDevPixel, twipsPerPixel, aStartBevelSide,
startBevel, aEndBevelSide, endBevel);
DrawSolidBorderSegment(drawTarget, bottomRect, aBorderColor,
aAppUnitsPerDevPixel, twipsPerPixel,
aStartBevelSide, startBevel, aEndBevelSide,
endBevel);
}
else { // left, right
nscoord thirdWidth = RoundFloatToPixel(0.333333f * (float)aBorder.width, twipsPerPixel);
@ -4093,8 +4104,10 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext,
if (NS_SIDE_LEFT == aEndBevelSide) {
leftRect.height -= aEndBevelOffset - endBevel;
}
DrawSolidBorderSegment(aContext, leftRect, aBorderColor, aAppUnitsPerDevPixel, twipsPerPixel, aStartBevelSide,
startBevel, aEndBevelSide, endBevel);
DrawSolidBorderSegment(drawTarget, leftRect, aBorderColor,
aAppUnitsPerDevPixel, twipsPerPixel,
aStartBevelSide, startBevel, aEndBevelSide,
endBevel);
nscoord widthOffset = aBorder.width - thirdWidth;
nsRect rightRect(aBorder.x + widthOffset, aBorder.y, aBorder.width - widthOffset, aBorder.height);
@ -4105,14 +4118,17 @@ nsCSSRendering::DrawTableBorderSegment(nsRenderingContext& aContext,
if (NS_SIDE_RIGHT == aEndBevelSide) {
rightRect.height -= aEndBevelOffset - endBevel;
}
DrawSolidBorderSegment(aContext, rightRect, aBorderColor, aAppUnitsPerDevPixel, twipsPerPixel, aStartBevelSide,
startBevel, aEndBevelSide, endBevel);
DrawSolidBorderSegment(drawTarget, rightRect, aBorderColor,
aAppUnitsPerDevPixel, twipsPerPixel,
aStartBevelSide, startBevel, aEndBevelSide,
endBevel);
}
break;
}
// else fall through to solid
case NS_STYLE_BORDER_STYLE_SOLID:
DrawSolidBorderSegment(aContext, aBorder, aBorderColor, aAppUnitsPerDevPixel, twipsPerPixel, aStartBevelSide,
DrawSolidBorderSegment(drawTarget, aBorder, aBorderColor,
aAppUnitsPerDevPixel, twipsPerPixel, aStartBevelSide,
aStartBevelOffset, aEndBevelSide, aEndBevelOffset);
break;
case NS_STYLE_BORDER_STYLE_OUTSET: