Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1097)

Unified Diff: third_party/WebKit/Source/platform/graphics/ImagePattern.cpp

Issue 2130063002: Correct color bleeding of no-repeat pattern in canvas2d (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-no-repeat-with-transformations-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/graphics/ImagePattern.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/ImagePattern.cpp b/third_party/WebKit/Source/platform/graphics/ImagePattern.cpp
index 7decc3076d51b8801bba501abae5f31b8111bb41..257a80eb9fa25b3920fe0102b147ab11d297eaaf 100644
--- a/third_party/WebKit/Source/platform/graphics/ImagePattern.cpp
+++ b/third_party/WebKit/Source/platform/graphics/ImagePattern.cpp
@@ -49,22 +49,25 @@ sk_sp<SkShader> ImagePattern::createShader(const SkMatrix& localMatrix) const
? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode;
SkShader::TileMode tileModeY = isRepeatY()
? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode;
- int expandW = isRepeatX() ? 0 : 1;
- int expandH = isRepeatY() ? 0 : 1;
+ int borderPixelX = isRepeatX() ? 0 : 1;
+ int borderPixelY = isRepeatY() ? 0 : 1;
- // Create a transparent image 1 pixel wider and/or taller than the
- // original, then copy the orignal into it.
+ // Create a transparent image 2 pixels wider and/or taller than the
+ // original, then copy the orignal into the middle of it.
// FIXME: Is there a better way to pad (not scale) an image in skia?
sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(
- m_tileImage->width() + expandW, m_tileImage->height() + expandH);
+ m_tileImage->width() + 2 * borderPixelX, m_tileImage->height() + 2 * borderPixelY);
if (!surface)
return SkShader::MakeColorShader(SK_ColorTRANSPARENT);
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
- surface->getCanvas()->drawImage(m_tileImage, 0, 0, &paint);
+ surface->getCanvas()->drawImage(m_tileImage, borderPixelX, borderPixelY, &paint);
- return surface->makeImageSnapshot()->makeShader(tileModeX, tileModeY, &localMatrix);
+ SkMatrix newLocalMatrix(localMatrix);
+ newLocalMatrix.postTranslate(-borderPixelX, -borderPixelY);
+
+ return surface->makeImageSnapshot()->makeShader(tileModeX, tileModeY, &newLocalMatrix);
}
bool ImagePattern::isTextureBacked() const
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-no-repeat-with-transformations-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698