From 7da8d646a2114b252e79a0c93a4aeb153d2e1390 Mon Sep 17 00:00:00 2001 From: Hal Canary Date: Fri, 17 Mar 2017 15:16:21 -0400 Subject: [PATCH] SkXPS: use correct drawBitmapRect logic for !bitmap.bounds().contains(*src) Change-Id: I768b01d1a9afce99f09a0aaa793ba8ebfdefb41e Reviewed-on: https://skia-review.googlesource.com/9867 Reviewed-by: Ben Wagner Commit-Queue: Hal Canary --- src/xps/SkXPSDevice.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp index 75f4119..ec74e49 100644 --- a/src/xps/SkXPSDevice.cpp +++ b/src/xps/SkXPSDevice.cpp @@ -2256,10 +2256,18 @@ void SkXPSDevice::drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { - // TODO(halcanary): more closely use correct logic for src > bitmap.bounds(). - SkRect srcBounds = src ? *src : SkRect::Make(bitmap.bounds()); + SkRect bitmapBounds = SkRect::Make(bitmap.bounds()); + SkRect srcBounds = src ? *src : bitmapBounds; SkMatrix matrix = SkMatrix::MakeRectToRect(srcBounds, dst, SkMatrix::kFill_ScaleToFit); - + SkRect actualDst; + if (!src || bitmapBounds.contains(*src)) { + actualDst = dst; + } else { + if (!srcBounds.intersect(bitmapBounds)) { + return; + } + matrix.mapRect(&actualDst, srcBounds); + } auto bitmapShader = SkMakeBitmapShader(bitmap, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix, kNever_SkCopyPixelsMode); @@ -2268,6 +2276,6 @@ void SkXPSDevice::drawBitmapRect(const SkBitmap& bitmap, SkPaint paintWithShader(paint); paintWithShader.setStyle(SkPaint::kFill_Style); paintWithShader.setShader(std::move(bitmapShader)); - this->drawRect(dst, paintWithShader); + this->drawRect(actualDst, paintWithShader); } #endif//defined(SK_BUILD_FOR_WIN32) -- 2.7.4