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);
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)