Chromium Code Reviews| 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..9fb775f7ee3666ff8a59624f494d0a8d19a7ae12 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,18 @@ 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 destOffset, |
|
fs
2016/12/19 16:49:22
Maybe structure this as an interval containment ch
f(malita)
2016/12/19 17:34:56
Done.
|
| + float destSize, |
| + float tileOffset, |
| + float tileSize) { |
| + return destOffset >= tileOffset && |
| + destOffset + destSize <= tileOffset + tileSize |
| + ? SkShader::kClamp_TileMode |
| + : SkShader::kRepeat_TileMode; |
| } |
| } // anonymous namespace |
| @@ -286,6 +296,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.width(), adjustedX, |
| + tileSize.width()); |
| + const auto tmy = computeTileMode(destRect.y(), destRect.height(), adjustedY, |
| + tileSize.height()); |
| + |
| { |
| SkPaint paint = context.fillPaint(); |
| paint.setColor(SK_ColorBLACK); |
| @@ -293,10 +311,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); |
| } |