Bug 768775. For linear gradients where the gradient line is parallel to an axis and runs from one edge of a background tile to the other, we can repeat the background by just repeating the gradient instead of drawing individual tiles. r=jrmuizel

--HG--
extra : rebase_source : 81b9a7951ce78f60aa8eaeca4f66f62561133254
This commit is contained in:
Robert O'Callahan 2012-07-02 11:46:32 +12:00
Родитель b1e87e032b
Коммит 7abd565f63
2 изменённых файлов: 18 добавлений и 5 удалений

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

@ -2099,4 +2099,4 @@ gfxContext::ChangeTransform(const Matrix &aNewMatrix)
}
mDT->SetTransform(aNewMatrix);
}
}

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

@ -1997,6 +1997,7 @@ nsCSSRendering::PaintGradient(nsPresContext* aPresContext,
// Create the gradient pattern.
nsRefPtr<gfxPattern> gradientPattern;
bool forceRepeatToCoverTiles = false;
if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_LINEAR) {
// Compute the actual gradient line ends we need to pass to cairo after
// stops have been normalized.
@ -2015,6 +2016,16 @@ nsCSSRendering::PaintGradient(nsPresContext* aPresContext,
gradientPattern = new gfxPattern(gradientStart.x, gradientStart.y,
gradientEnd.x, gradientEnd.y);
// When the gradient line is parallel to the x axis from the left edge
// to the right edge of a tile, then we can repeat by just repeating the
// gradient.
if ((gradientStart.y == gradientEnd.y && gradientStart.x == 0 &&
gradientEnd.x == oneCellArea.width) ||
(gradientStart.x == gradientEnd.x && gradientStart.y == 0 &&
gradientEnd.y == oneCellArea.height)) {
forceRepeatToCoverTiles = true;
}
} else {
NS_ASSERTION(firstStop >= 0.0,
"Negative stops not allowed for radial gradients");
@ -2065,7 +2076,7 @@ nsCSSRendering::PaintGradient(nsPresContext* aPresContext,
}
// Set repeat mode. Default cairo extend mode is PAD.
if (aGradient->mRepeating) {
if (aGradient->mRepeating || forceRepeatToCoverTiles) {
gradientPattern->SetExtend(gfxPattern::EXTEND_REPEAT);
}
@ -2084,8 +2095,9 @@ nsCSSRendering::PaintGradient(nsPresContext* aPresContext,
// xStart/yStart are the top-left corner of the top-left tile.
nscoord xStart = FindTileStart(dirty.x, aOneCellArea.x, aOneCellArea.width);
nscoord yStart = FindTileStart(dirty.y, aOneCellArea.y, aOneCellArea.height);
nscoord xEnd = dirty.XMost();
nscoord yEnd = dirty.YMost();
nscoord xEnd = forceRepeatToCoverTiles ? xStart + aOneCellArea.width : dirty.XMost();
nscoord yEnd = forceRepeatToCoverTiles ? yStart + aOneCellArea.height : dirty.YMost();
// x and y are the top-left corner of the tile to draw
for (nscoord y = yStart; y < yEnd; y += aOneCellArea.height) {
for (nscoord x = xStart; x < xEnd; x += aOneCellArea.width) {
@ -2095,7 +2107,8 @@ nsCSSRendering::PaintGradient(nsPresContext* aPresContext,
appUnitsPerPixel);
// The actual area to fill with this tile is the intersection of this
// tile with the overall area we're supposed to be filling
gfxRect fillRect = tileRect.Intersect(areaToFill);
gfxRect fillRect =
forceRepeatToCoverTiles ? areaToFill : tileRect.Intersect(areaToFill);
ctx->NewPath();
ctx->Translate(tileRect.TopLeft());
ctx->SetPattern(gradientPattern);