SkXPS: use correct drawBitmapRect logic for !bitmap.bounds().contains(*src)
authorHal Canary <halcanary@google.com>
Fri, 17 Mar 2017 19:16:21 +0000 (15:16 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Fri, 17 Mar 2017 19:56:34 +0000 (19:56 +0000)
Change-Id: I768b01d1a9afce99f09a0aaa793ba8ebfdefb41e
Reviewed-on: https://skia-review.googlesource.com/9867
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>

src/xps/SkXPSDevice.cpp

index 75f4119..ec74e49 100644 (file)
@@ -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)