Pass sampling to drawimage
Change-Id: Ia1cd20bb4ea1afeb31a1e47da054c309bdaf15bd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/358216
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/gm/drawbitmaprect.cpp b/gm/drawbitmaprect.cpp
index c939507..d4a0a59 100644
--- a/gm/drawbitmaprect.cpp
+++ b/gm/drawbitmaprect.cpp
@@ -44,6 +44,7 @@
p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
}
}
+ bm.setImmutable();
return bm;
}
@@ -105,43 +106,48 @@
}
static void bitmapproc(SkCanvas* canvas, SkImage*, const SkBitmap& bm, const SkIRect& srcR,
- const SkRect& dstR, const SkPaint* paint) {
- canvas->drawBitmapRect(bm, srcR, dstR, paint);
+ const SkRect& dstR, const SkSamplingOptions& sampling,
+ const SkPaint* paint) {
+ canvas->drawImageRect(bm.asImage(), SkRect::Make(srcR), dstR, sampling, paint,
+ SkCanvas::kStrict_SrcRectConstraint);
}
static void bitmapsubsetproc(SkCanvas* canvas, SkImage*, const SkBitmap& bm, const SkIRect& srcR,
- const SkRect& dstR, const SkPaint* paint) {
+ const SkRect& dstR, const SkSamplingOptions& sampling,
+ const SkPaint* paint) {
if (!bm.bounds().contains(srcR)) {
- bitmapproc(canvas, nullptr, bm, srcR, dstR, paint);
+ bitmapproc(canvas, nullptr, bm, srcR, dstR, sampling, paint);
return;
}
SkBitmap subset;
if (bm.extractSubset(&subset, srcR)) {
- canvas->drawBitmapRect(subset, dstR, paint);
+ canvas->drawImageRect(subset.asImage(), dstR, sampling, paint);
}
}
static void imageproc(SkCanvas* canvas, SkImage* image, const SkBitmap&, const SkIRect& srcR,
- const SkRect& dstR, const SkPaint* paint) {
- canvas->drawImageRect(image, srcR, dstR, paint);
+ const SkRect& dstR, const SkSamplingOptions& sampling, const SkPaint* paint) {
+ canvas->drawImageRect(image, SkRect::Make(srcR), dstR, sampling, paint,
+ SkCanvas::kStrict_SrcRectConstraint);
}
static void imagesubsetproc(SkCanvas* canvas, SkImage* image, const SkBitmap& bm,
- const SkIRect& srcR, const SkRect& dstR, const SkPaint* paint) {
+ const SkIRect& srcR, const SkRect& dstR,
+ const SkSamplingOptions& sampling, const SkPaint* paint) {
if (!image->bounds().contains(srcR)) {
- imageproc(canvas, image, bm, srcR, dstR, paint);
+ imageproc(canvas, image, bm, srcR, dstR, sampling, paint);
return;
}
auto direct = GrAsDirectContext(canvas->recordingContext());
if (sk_sp<SkImage> subset = image->makeSubset(srcR, direct)) {
- canvas->drawImageRect(subset, dstR, paint);
+ canvas->drawImageRect(subset, dstR, sampling, paint);
}
}
typedef void DrawRectRectProc(SkCanvas*, SkImage*, const SkBitmap&, const SkIRect&, const SkRect&,
- const SkPaint*);
+ const SkSamplingOptions&, const SkPaint*);
constexpr int gSize = 1024;
constexpr int gBmpSize = 2048;
@@ -181,7 +187,7 @@
const int kPadY = 40;
SkPaint paint;
paint.setAlphaf(0.125f);
- canvas->drawImageRect(fImage, SkRect::MakeIWH(gSize, gSize), &paint);
+ canvas->drawImageRect(fImage, SkRect::MakeIWH(gSize, gSize), SkSamplingOptions(), &paint);
canvas->translate(SK_Scalar1 * kPadX / 2,
SK_Scalar1 * kPadY / 2);
SkPaint blackPaint;
@@ -202,7 +208,8 @@
for (int h = 1; h <= kMaxSrcRectSize; h *= 4) {
SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSize - h) / 2, w, h);
- fProc(canvas, fImage.get(), fLargeBitmap, srcRect, dstRect, nullptr);
+ fProc(canvas, fImage.get(), fLargeBitmap, srcRect, dstRect, SkSamplingOptions(),
+ nullptr);
SkString label;
label.appendf("%d x %d", w, h);
@@ -232,17 +239,15 @@
// SkGpuDevice::drawPath() -> SkGpuDevice::drawWithMaskFilter()
SkIRect srcRect;
SkPaint paint;
- SkBitmap bm;
-
- bm = make_chessbm(5, 5);
- paint.setFilterQuality(kLow_SkFilterQuality);
+ SkBitmap bm = make_chessbm(5, 5);
srcRect.setXYWH(1, 1, 3, 3);
paint.setMaskFilter(SkMaskFilter::MakeBlur(
kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5))));
- fProc(canvas, bm.asImage().get(), bm, srcRect, dstRect, &paint);
+ fProc(canvas, bm.asImage().get(), bm, srcRect, dstRect,
+ SkSamplingOptions(SkFilterMode::kLinear), &paint);
}
}