SkPDF: Do draw{Image,Bitmap}Rect with maskfilter.

https://fiddle.skia.org/c/@skbug_237_drawImageRect

BUG=skia:237
Change-Id: I4d6d683fcbfd6dc86a27998e3d03534458952db0
Reviewed-on: https://skia-review.googlesource.com/19023
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
This commit is contained in:
Hal Canary 2017-06-07 11:47:51 -04:00 committed by Skia Commit-Bot
parent a924dd3b7e
commit fa2a26a026

View File

@ -54,13 +54,47 @@ void SkPDFCanvas::onDrawImageNine(const SkImage* image,
}
}
static bool is_integer(SkScalar x) {
return x == SkScalarTruncToScalar(x);
}
static bool is_integral(const SkRect& r) {
return is_integer(r.left()) &&
is_integer(r.top()) &&
is_integer(r.right()) &&
is_integer(r.bottom());
}
void SkPDFCanvas::onDrawImageRect(const SkImage* image,
const SkRect* src,
const SkRect& dst,
const SkPaint* paint,
SkCanvas::SrcRectConstraint constraint) {
SkAutoCanvasRestore autoCanvasRestore(this, true);
SkASSERT(src);
SkASSERT(image);
if (paint && paint->getMaskFilter()) {
SkPaint paintCopy(*paint);
paintCopy.setAntiAlias(true);
SkRect srcRect = src ? *src : SkRect::Make(image->bounds());
SkMatrix m = SkMatrix::MakeRectToRect(srcRect, dst, SkMatrix::kFill_ScaleToFit);
if (!src || *src == SkRect::Make(image->bounds()) ||
SkCanvas::kFast_SrcRectConstraint == constraint) {
paintCopy.setShader(image->makeShader(&m));
} else {
SkIRect subset = src->roundOut();
m.preTranslate(subset.x(), subset.y());
auto si = image->makeSubset(subset);
if (!si) { return; }
paintCopy.setShader(si->makeShader(&m));
}
this->drawRect(dst, paintCopy);
return;
}
SkAutoCanvasRestore autoCanvasRestore(this, false);
if (src && !is_integral(*src)) {
this->save();
this->clipRect(dst);
}
this->SkCanvas::onDrawImageRect(image, src, dst, paint, constraint);
}
@ -69,8 +103,18 @@ void SkPDFCanvas::onDrawBitmapRect(const SkBitmap& bitmap,
const SkRect& dst,
const SkPaint* paint,
SkCanvas::SrcRectConstraint constraint) {
SkAutoCanvasRestore autoCanvasRestore(this, true);
SkASSERT(src);
if (paint && paint->getMaskFilter()) {
if (sk_sp<SkImage> img = SkImage::MakeFromBitmap(bitmap)) {
this->onDrawImageRect(img.get(), src, dst, paint, constraint);
}
return;
}
SkAutoCanvasRestore autoCanvasRestore(this, false);
if (src && !is_integral(*src)) {
this->save();
this->clipRect(dst);
}
this->SkCanvas::onDrawBitmapRect(bitmap, src, dst, paint, constraint);
}