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

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

Issue 2582383002: Clamp background tiles when possible (Closed)
Patch Set: relax asserts Created 4 years 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/Source/platform/graphics/Image.h ('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/Image.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/Image.cpp b/third_party/WebKit/Source/platform/graphics/Image.cpp
index 5e5a23663f39473dc0a82d4a0e44d2fa30ea5874..0531c45046d1f4940384235fd0c1237144772312 100644
--- a/third_party/WebKit/Source/platform/graphics/Image.cpp
+++ b/third_party/WebKit/Source/platform/graphics/Image.cpp
@@ -225,10 +225,11 @@ namespace {
sk_sp<SkShader> createPatternShader(const SkImage* image,
const SkMatrix& shaderMatrix,
const SkPaint& paint,
- const FloatSize& spacing) {
+ const FloatSize& spacing,
+ SkShader::TileMode tmx,
+ SkShader::TileMode tmy) {
if (spacing.isZero())
- return image->makeShader(SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode, &shaderMatrix);
+ return image->makeShader(tmx, tmy, &shaderMatrix);
// Arbitrary tiling is currently only supported for SkPictureShader, so we use
// that instead of a plain bitmap shader to implement spacing.
@@ -239,9 +240,17 @@ sk_sp<SkShader> createPatternShader(const SkImage* image,
SkCanvas* canvas = recorder.beginRecording(tileRect);
canvas->drawImage(image, 0, 0, &paint);
- return SkShader::MakePictureShader(
- recorder.finishRecordingAsPicture(), SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode, &shaderMatrix, nullptr);
+ return SkShader::MakePictureShader(recorder.finishRecordingAsPicture(), tmx,
+ tmy, &shaderMatrix, nullptr);
+}
+
+SkShader::TileMode computeTileMode(float left,
+ float right,
+ float min,
+ float max) {
+ DCHECK(left < right);
+ return left >= min && right <= max ? SkShader::kClamp_TileMode
+ : SkShader::kRepeat_TileMode;
}
} // anonymous namespace
@@ -286,6 +295,14 @@ void Image::drawPattern(GraphicsContext& context,
if (!image)
return;
+ const FloatSize tileSize(
+ image->width() * scale.width() + repeatSpacing.width(),
+ image->height() * scale.height() + repeatSpacing.height());
+ const auto tmx = computeTileMode(destRect.x(), destRect.maxX(), adjustedX,
+ adjustedX + tileSize.width());
+ const auto tmy = computeTileMode(destRect.y(), destRect.maxY(), adjustedY,
+ adjustedY + tileSize.height());
+
{
SkPaint paint = context.fillPaint();
paint.setColor(SK_ColorBLACK);
@@ -293,10 +310,11 @@ void Image::drawPattern(GraphicsContext& context,
paint.setFilterQuality(
context.computeFilterQuality(this, destRect, normSrcRect));
paint.setAntiAlias(context.shouldAntialias());
- paint.setShader(createPatternShader(
- image.get(), localMatrix, paint,
- FloatSize(repeatSpacing.width() / scale.width(),
- repeatSpacing.height() / scale.height())));
+ paint.setShader(
+ createPatternShader(image.get(), localMatrix, paint,
+ FloatSize(repeatSpacing.width() / scale.width(),
+ repeatSpacing.height() / scale.height()),
+ tmx, tmy));
context.drawRect(destRect, paint);
}
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/Image.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698