diff --git a/gm/animated_gif.cpp b/gm/animated_gif.cpp index 4a5cd1a307..5a5ba51429 100644 --- a/gm/animated_gif.cpp +++ b/gm/animated_gif.cpp @@ -213,7 +213,7 @@ private: void onDraw(SkCanvas* canvas) override { canvas->scale(0.25f, 0.25f); for (auto& p : fPlayers) { - canvas->drawImage(p->getFrame(), 0, 0, nullptr); + canvas->drawImage(p->getFrame(), 0, 0); canvas->translate(p->dimensions().width(), 0); } } @@ -285,7 +285,7 @@ class AnimCodecPlayerExifGM : public skiagm::GM { auto image = fPlayer->getFrame(); - canvas->drawImage(image, 0, 0, nullptr); + canvas->drawImage(image, 0, 0); duration += fFrameInfos[frame].fDuration; fPlayer->seek(duration); } diff --git a/gm/animated_image_orientation.cpp b/gm/animated_image_orientation.cpp index e969d7f13d..efb0d0cd56 100644 --- a/gm/animated_image_orientation.cpp +++ b/gm/animated_image_orientation.cpp @@ -93,7 +93,7 @@ public: canvas->drawPicture(pic); } else { auto image = animatedImage->getCurrentFrame(); - canvas->drawImage(image, 0, 0, nullptr); + canvas->drawImage(image, 0, 0); } }; for (float scale : { 1.25f, 1.0f, .75f, .5f }) { diff --git a/gm/asyncrescaleandread.cpp b/gm/asyncrescaleandread.cpp index c9f91bcf99..89bfb575b6 100644 --- a/gm/asyncrescaleandread.cpp +++ b/gm/asyncrescaleandread.cpp @@ -209,7 +209,7 @@ static skiagm::DrawResult do_rescale_image_grid(SkCanvas* canvas, } SkPaint paint; paint.setBlendMode(SkBlendMode::kSrc); - surface->getCanvas()->drawImage(image, 0, 0, &paint); + surface->getCanvas()->drawImage(image, 0, 0, SkSamplingOptions(), &paint); return do_rescale_grid(canvas, surface.get(), dContext, srcRect, newSize, doYUV420, errorMsg); } else if (dContext) { diff --git a/gm/bleed.cpp b/gm/bleed.cpp index 656f58aef0..6a2506fa23 100644 --- a/gm/bleed.cpp +++ b/gm/bleed.cpp @@ -34,7 +34,7 @@ /** Creates an image with two one-pixel wide borders around a checkerboard. The checkerboard is 2x2 checks where each check has as many pixels as is necessary to fill the interior. It returns the image and a src rect that bounds the checkerboard portion. */ -std::tuple, SkIRect> make_ringed_image(int width, int height) { +std::tuple, SkRect> make_ringed_image(int width, int height) { // These are kRGBA_8888_SkColorType values. static constexpr uint32_t kOuterRingColor = 0xFFFF0000, @@ -102,7 +102,7 @@ std::tuple, SkIRect> make_ringed_image(int width, int height) { scanline[x] = kOuterRingColor; } bitmap.setImmutable(); - return {bitmap.asImage(), {2, 2, width - 2, height - 2}}; + return {bitmap.asImage(), SkRect::Make({2, 2, width - 2, height - 2})}; } /** @@ -121,95 +121,95 @@ protected: SkString onShortName() override { return fShortName; } SkISize onISize() override { return SkISize::Make(800, 1000); } - void drawImage(SkCanvas* canvas, sk_sp image, - SkIRect srcRect, SkRect dstRect, SkPaint* paint) { + void drawImage(SkCanvas* canvas, sk_sp image, SkRect srcRect, SkRect dstRect, + const SkSamplingOptions& sampling, SkPaint* paint) { if (fBatch) { SkCanvas::ImageSetEntry imageSetEntry[1]; imageSetEntry[0].fImage = image; - imageSetEntry[0].fSrcRect = SkRect::Make(srcRect); + imageSetEntry[0].fSrcRect = srcRect; imageSetEntry[0].fDstRect = dstRect; imageSetEntry[0].fAAFlags = paint->isAntiAlias() ? SkCanvas::kAll_QuadAAFlags : SkCanvas::kNone_QuadAAFlags; canvas->experimental_DrawEdgeAAImageSet(imageSetEntry, SK_ARRAY_COUNT(imageSetEntry), /*dstClips=*/nullptr, /*preViewMatrices=*/nullptr, - paint, fConstraint); + sampling, paint, fConstraint); } else { - canvas->drawImageRect(image.get(), srcRect, dstRect, paint, fConstraint); + canvas->drawImageRect(image.get(), srcRect, dstRect, sampling, paint, fConstraint); } } // Draw the area of interest of the small image - void drawCase1(SkCanvas* canvas, int transX, int transY, bool aa, SkFilterQuality filter) { + void drawCase1(SkCanvas* canvas, int transX, int transY, bool aa, + const SkSamplingOptions& sampling) { SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY), SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize)); SkPaint paint; - paint.setFilterQuality(filter); paint.setColor(SK_ColorBLUE); paint.setAntiAlias(aa); - drawImage(canvas, fSmallImage, fSmallSrcRect, dst, &paint); + drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint); } // Draw the area of interest of the large image - void drawCase2(SkCanvas* canvas, int transX, int transY, bool aa, SkFilterQuality filter) { + void drawCase2(SkCanvas* canvas, int transX, int transY, bool aa, + const SkSamplingOptions& sampling) { SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY), SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize)); SkPaint paint; - paint.setFilterQuality(filter); paint.setColor(SK_ColorBLUE); paint.setAntiAlias(aa); - drawImage(canvas, fBigImage, fBigSrcRect, dst, &paint); + drawImage(canvas, fBigImage, fBigSrcRect, dst, sampling, &paint); } // Draw upper-left 1/4 of the area of interest of the large image - void drawCase3(SkCanvas* canvas, int transX, int transY, bool aa, SkFilterQuality filter) { - SkIRect src = SkIRect::MakeXYWH(fBigSrcRect.fLeft, - fBigSrcRect.fTop, - fBigSrcRect.width()/2, - fBigSrcRect.height()/2); + void drawCase3(SkCanvas* canvas, int transX, int transY, bool aa, + const SkSamplingOptions& sampling) { + SkRect src = SkRect::MakeXYWH(fBigSrcRect.fLeft, + fBigSrcRect.fTop, + fBigSrcRect.width()/2, + fBigSrcRect.height()/2); SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY), SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize)); SkPaint paint; - paint.setFilterQuality(filter); paint.setColor(SK_ColorBLUE); paint.setAntiAlias(aa); - drawImage(canvas, fBigImage, src, dst, &paint); + drawImage(canvas, fBigImage, src, dst, sampling, &paint); } // Draw the area of interest of the small image with a normal blur - void drawCase4(SkCanvas* canvas, int transX, int transY, bool aa, SkFilterQuality filter) { + void drawCase4(SkCanvas* canvas, int transX, int transY, bool aa, + const SkSamplingOptions& sampling) { SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY), SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize)); SkPaint paint; - paint.setFilterQuality(filter); paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, SkBlurMask::ConvertRadiusToSigma(3))); paint.setColor(SK_ColorBLUE); paint.setAntiAlias(aa); - drawImage(canvas, fSmallImage, fSmallSrcRect, dst, &paint); + drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint); } // Draw the area of interest of the small image with a outer blur - void drawCase5(SkCanvas* canvas, int transX, int transY, bool aa, SkFilterQuality filter) { + void drawCase5(SkCanvas* canvas, int transX, int transY, bool aa, + const SkSamplingOptions& sampling) { SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY), SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize)); SkPaint paint; - paint.setFilterQuality(filter); paint.setMaskFilter(SkMaskFilter::MakeBlur(kOuter_SkBlurStyle, SkBlurMask::ConvertRadiusToSigma(7))); paint.setColor(SK_ColorBLUE); paint.setAntiAlias(aa); - drawImage(canvas, fSmallImage, fSmallSrcRect, dst, &paint); + drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint); } void onOnceBeforeDraw() override { @@ -240,6 +240,10 @@ protected: m.preScale(0.2f, 0.2f); matrices.push_back(m); + const SkSamplingOptions none(SkFilterMode::kNearest); + const SkSamplingOptions low(SkFilterMode::kLinear); + const SkSamplingOptions high({1.0f/3, 1.0f/3}); + SkScalar maxX = 0; for (bool antiAlias : {false, true}) { canvas->save(); @@ -249,18 +253,18 @@ protected: canvas->concat(matrix); // First draw a column with no filtering - this->drawCase1(canvas, kCol0X, kRow0Y, antiAlias, kNone_SkFilterQuality); - this->drawCase2(canvas, kCol0X, kRow1Y, antiAlias, kNone_SkFilterQuality); - this->drawCase3(canvas, kCol0X, kRow2Y, antiAlias, kNone_SkFilterQuality); - this->drawCase4(canvas, kCol0X, kRow3Y, antiAlias, kNone_SkFilterQuality); - this->drawCase5(canvas, kCol0X, kRow4Y, antiAlias, kNone_SkFilterQuality); + this->drawCase1(canvas, kCol0X, kRow0Y, antiAlias, none); + this->drawCase2(canvas, kCol0X, kRow1Y, antiAlias, none); + this->drawCase3(canvas, kCol0X, kRow2Y, antiAlias, none); + this->drawCase4(canvas, kCol0X, kRow3Y, antiAlias, none); + this->drawCase5(canvas, kCol0X, kRow4Y, antiAlias, none); // Then draw a column with low filtering - this->drawCase1(canvas, kCol1X, kRow0Y, antiAlias, kLow_SkFilterQuality); - this->drawCase2(canvas, kCol1X, kRow1Y, antiAlias, kLow_SkFilterQuality); - this->drawCase3(canvas, kCol1X, kRow2Y, antiAlias, kLow_SkFilterQuality); - this->drawCase4(canvas, kCol1X, kRow3Y, antiAlias, kLow_SkFilterQuality); - this->drawCase5(canvas, kCol1X, kRow4Y, antiAlias, kLow_SkFilterQuality); + this->drawCase1(canvas, kCol1X, kRow0Y, antiAlias, low); + this->drawCase2(canvas, kCol1X, kRow1Y, antiAlias, low); + this->drawCase3(canvas, kCol1X, kRow2Y, antiAlias, low); + this->drawCase4(canvas, kCol1X, kRow3Y, antiAlias, low); + this->drawCase5(canvas, kCol1X, kRow4Y, antiAlias, low); // Then draw a column with high filtering. Skip it if in kStrict mode and MIP // mapping will be used. On GPU we allow bleeding at non-base levels because @@ -268,11 +272,11 @@ protected: SkScalar scales[2]; SkAssertResult(matrix.getMinMaxScales(scales)); if (fConstraint != SkCanvas::kStrict_SrcRectConstraint || scales[0] >= 1.f) { - this->drawCase1(canvas, kCol2X, kRow0Y, antiAlias, kHigh_SkFilterQuality); - this->drawCase2(canvas, kCol2X, kRow1Y, antiAlias, kHigh_SkFilterQuality); - this->drawCase3(canvas, kCol2X, kRow2Y, antiAlias, kHigh_SkFilterQuality); - this->drawCase4(canvas, kCol2X, kRow3Y, antiAlias, kHigh_SkFilterQuality); - this->drawCase5(canvas, kCol2X, kRow4Y, antiAlias, kHigh_SkFilterQuality); + this->drawCase1(canvas, kCol2X, kRow0Y, antiAlias, high); + this->drawCase2(canvas, kCol2X, kRow1Y, antiAlias, high); + this->drawCase3(canvas, kCol2X, kRow2Y, antiAlias, high); + this->drawCase4(canvas, kCol2X, kRow3Y, antiAlias, high); + this->drawCase5(canvas, kCol2X, kRow4Y, antiAlias, high); } SkPoint innerCorners[] = {{0, 0}, {0, kBottom}, {kWidth, kBottom}, {kWidth, 0}}; @@ -311,8 +315,8 @@ private: SkString fShortName; sk_sp fBigImage; sk_sp fSmallImage; - SkIRect fBigSrcRect; - SkIRect fSmallSrcRect; + SkRect fBigSrcRect; + SkRect fSmallSrcRect; SkCanvas::SrcRectConstraint fConstraint; bool fBatch = false; using INHERITED = GM; diff --git a/gm/blurs.cpp b/gm/blurs.cpp index 8ca356f115..e0ddb571db 100644 --- a/gm/blurs.cpp +++ b/gm/blurs.cpp @@ -127,7 +127,7 @@ DEF_SIMPLE_GM(BlurDrawImage, canvas, 256, 256) { canvas->clear(0xFF88FF88); if (auto image = GetResourceAsImage("images/mandrill_512_q075.jpg")) { canvas->scale(0.25, 0.25); - canvas->drawImage(image, 256, 256, &paint); + canvas->drawImage(image, 256, 256, SkSamplingOptions(), &paint); } } diff --git a/gm/complexclip.cpp b/gm/complexclip.cpp index c8a5220d69..84bebe89ad 100644 --- a/gm/complexclip.cpp +++ b/gm/complexclip.cpp @@ -217,7 +217,7 @@ DEF_SIMPLE_GM(clip_shader, canvas, 840, 650) { SkPaint p; canvas->translate(10, 10); - canvas->drawImage(img, 0, 0, nullptr); + canvas->drawImage(img, 0, 0); canvas->save(); canvas->translate(img->width() + 10, 0); @@ -240,7 +240,7 @@ DEF_SIMPLE_GM(clip_shader, canvas, 840, 650) { SkMatrix lm = SkMatrix::Scale(1.0f/5, 1.0f/5); canvas->clipShader(img->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, SkSamplingOptions(), lm)); - canvas->drawImage(img, 0, 0, nullptr); + canvas->drawImage(img, 0, 0); canvas->restore(); canvas->restore(); diff --git a/gm/crosscontextimage.cpp b/gm/crosscontextimage.cpp index e3c60d0402..1490fefe3b 100644 --- a/gm/crosscontextimage.cpp +++ b/gm/crosscontextimage.cpp @@ -60,9 +60,9 @@ DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, canvas, errorMsg, 0, 0); canvas->translate(128, 0); - SkPaint paint; - paint.setFilterQuality(kMedium_SkFilterQuality); - canvas->drawImageRect(images[i], SkRect::MakeWH(128, 128), &paint); + canvas->drawImageRect(images[i], SkRect::MakeWH(128, 128), + SkSamplingOptions(SkFilterMode::kLinear, + SkMipmapMode::kLinear)); canvas->restore(); canvas->translate(256 + 10, 0); diff --git a/gm/hsl.cpp b/gm/hsl.cpp index 0a6441e28f..7bd52ca804 100644 --- a/gm/hsl.cpp +++ b/gm/hsl.cpp @@ -247,7 +247,7 @@ DEF_SIMPLE_GM(HSL_duck, canvas, 1110, 620) { p.setShader(nullptr); p.setBlendMode(mode); p.setAlphaf(src_a); - canvas->drawImageRect(src, r, &p); + canvas->drawImageRect(src, r, SkSamplingOptions(), &p); canvas->translate(r.width() + 10, 0); } diff --git a/gm/imageblurrepeatmode.cpp b/gm/imageblurrepeatmode.cpp index 7373c88534..1376efc535 100644 --- a/gm/imageblurrepeatmode.cpp +++ b/gm/imageblurrepeatmode.cpp @@ -155,14 +155,14 @@ DEF_SIMPLE_GM(imageblurrepeatunclipped, canvas, 256, 128) { // Draw the blurred image once canvas->translate(0, 50); - canvas->drawImage(img, 0, 0, &paint); + canvas->drawImage(img, 0, 0, SkSamplingOptions(), &paint); // Draw the blurred image with a clip positioned such that the draw would be excluded except // that the image filter causes it to intersect with the clip. Ideally should look like the // left image, but clipped to the debug-black rectangle (Narrator: it does not look like that). canvas->translate(110, 0); canvas->clipRect(SkRect::MakeXYWH(0, -30, 100, 10)); - canvas->drawImage(img, 0, 0, &paint); + canvas->drawImage(img, 0, 0, SkSamplingOptions(), &paint); // Visualize the clip SkPaint line; diff --git a/gm/imagefilterstransformed.cpp b/gm/imagefilterstransformed.cpp index 83fca2a302..75566aac63 100644 --- a/gm/imagefilterstransformed.cpp +++ b/gm/imagefilterstransformed.cpp @@ -207,7 +207,7 @@ protected: SkPaint p; p.setImageFilter(filter); - canvas->drawImage(fImage.get(), 128, 128, &p); + canvas->drawImage(fImage.get(), 128, 128, SkSamplingOptions(), &p); } private: @@ -264,7 +264,7 @@ private: canvas->clipRect(SkRect::MakeIWH(256, 256)); canvas->scale(0.5f, 0.5f); canvas->translate(128, 128); - canvas->drawImage(fImage, 0, 0, &p); + canvas->drawImage(fImage, 0, 0, SkSamplingOptions(), &p); canvas->restore(); } diff --git a/gm/imagemakewithfilter.cpp b/gm/imagemakewithfilter.cpp index 03b214f95f..f561e2137c 100644 --- a/gm/imagemakewithfilter.cpp +++ b/gm/imagemakewithfilter.cpp @@ -216,7 +216,8 @@ protected: // Resize to 100x100 surface->getCanvas()->drawImageRect( colorImage, SkRect::MakeWH(colorImage->width(), colorImage->height()), - SkRect::MakeWH(info.width(), info.height()), nullptr); + SkRect::MakeWH(info.width(), info.height()), SkSamplingOptions(), nullptr, + SkCanvas::kStrict_SrcRectConstraint); fMainImage = surface->makeImageSnapshot(); ToolUtils::draw_checkerboard(surface->getCanvas()); @@ -319,7 +320,7 @@ protected: // filtered result. SkPaint alpha; alpha.setAlphaf(0.3f); - canvas->drawImage(mainImage, 0, 0, &alpha); + canvas->drawImage(mainImage, 0, 0, SkSamplingOptions(), &alpha); this->drawImageWithFilter(canvas, mainImage, auxImage, filters[i], clipBound, subset, &outSubset); @@ -368,7 +369,9 @@ private: canvas->saveLayer(nullptr, &paint); // Draw the original subset of the image - canvas->drawImageRect(mainImage, subset, SkRect::Make(subset), nullptr); + SkRect r = SkRect::Make(subset); + canvas->drawImageRect(mainImage, r, r, SkSamplingOptions(), + nullptr, SkCanvas::kStrict_SrcRectConstraint); *dstRect = subset; } else { @@ -385,7 +388,9 @@ private: *dstRect = SkIRect::MakeXYWH(offset.x(), offset.y(), outSubset.width(), outSubset.height()); - canvas->drawImageRect(result, outSubset, SkRect::Make(*dstRect), nullptr); + canvas->drawImageRect(result, SkRect::Make(outSubset), SkRect::Make(*dstRect), + SkSamplingOptions(), nullptr, + SkCanvas::kStrict_SrcRectConstraint); } } diff --git a/gm/lattice.cpp b/gm/lattice.cpp index 21d3d8b69d..75f733bb10 100644 --- a/gm/lattice.cpp +++ b/gm/lattice.cpp @@ -125,7 +125,7 @@ protected: { 200, 200, }, }; - canvas->drawImage(image, 10, 10, nullptr); + canvas->drawImage(image, 10, 10); SkScalar x = SkIntToScalar(100); SkScalar y = SkIntToScalar(100); @@ -299,7 +299,7 @@ public: sk_sp image = makeImage(canvas, padLeft, padTop, padRight, padBottom); - canvas->drawImage(image, 10, 10, nullptr); + canvas->drawImage(image, 10, 10); SkCanvas::Lattice lattice; lattice.fXCount = 2; diff --git a/gm/overdrawcanvas.cpp b/gm/overdrawcanvas.cpp index b24d0b6243..a6951017ed 100644 --- a/gm/overdrawcanvas.cpp +++ b/gm/overdrawcanvas.cpp @@ -52,7 +52,7 @@ DEF_SIMPLE_GM_BG(overdraw_canvas, canvas, WIDTH, HEIGHT, SK_ColorWHITE) { // Draw overdraw colors to the canvas. The color filter will convert counts to colors. SkPaint paint; paint.setColorFilter(SkOverdrawColorFilter::MakeWithSkColors(kOverdrawColors)); - canvas->drawImage(counts.get(), 0.0f, 0.0f, &paint); + canvas->drawImage(counts.get(), 0.0f, 0.0f, SkSamplingOptions(), &paint); canvas->drawString("This is some text:", 180, 300, SkFont(), SkPaint()); } diff --git a/gm/perspshaders.cpp b/gm/perspshaders.cpp index bcc953166e..96d24337cd 100644 --- a/gm/perspshaders.cpp +++ b/gm/perspshaders.cpp @@ -56,9 +56,8 @@ protected: } void onOnceBeforeDraw() override { - fBitmap = ToolUtils::create_checkerboard_bitmap( + fBitmapImage = ToolUtils::create_checkerboard_image( kCellSize, kCellSize, SK_ColorBLUE, SK_ColorYELLOW, kCellSize / 10); - fBitmap.setImmutable(); SkPoint pts1[] = { { 0, 0 }, @@ -89,13 +88,12 @@ protected: fPath.close(); } - void drawRow(SkCanvas* canvas, SkFilterQuality filterQ) { + void drawRow(SkCanvas* canvas, const SkSamplingOptions& sampling) { SkPaint filterPaint; - filterPaint.setFilterQuality(filterQ); filterPaint.setAntiAlias(fDoAA); SkPaint pathPaint; - pathPaint.setShader(fBitmap.makeShader(SkSamplingOptions(filterQ))); + pathPaint.setShader(fBitmapImage->makeShader(sampling)); pathPaint.setAntiAlias(fDoAA); SkPaint gradPaint1; @@ -111,13 +109,13 @@ protected: canvas->save(); canvas->concat(fPerspMatrix); - canvas->drawBitmapRect(fBitmap, r, &filterPaint); + canvas->drawImageRect(fBitmapImage, r, sampling, &filterPaint); canvas->restore(); canvas->translate(SkIntToScalar(kCellSize), 0); canvas->save(); canvas->concat(fPerspMatrix); - canvas->drawImage(fImage.get(), 0, 0, &filterPaint); + canvas->drawImage(fImage.get(), 0, 0, sampling, &filterPaint); canvas->restore(); canvas->translate(SkIntToScalar(kCellSize), 0); @@ -152,13 +150,14 @@ protected: fImage = make_image(canvas, kCellSize, kCellSize); } - this->drawRow(canvas, kNone_SkFilterQuality); + this->drawRow(canvas, SkSamplingOptions(SkFilterMode::kNearest)); canvas->translate(0, SkIntToScalar(kCellSize)); - this->drawRow(canvas, kLow_SkFilterQuality); + this->drawRow(canvas, SkSamplingOptions(SkFilterMode::kLinear)); canvas->translate(0, SkIntToScalar(kCellSize)); - this->drawRow(canvas, kMedium_SkFilterQuality); + this->drawRow(canvas, SkSamplingOptions(SkFilterMode::kLinear, + SkMipmapMode::kNearest)); canvas->translate(0, SkIntToScalar(kCellSize)); - this->drawRow(canvas, kHigh_SkFilterQuality); + this->drawRow(canvas, SkSamplingOptions({1.0f/3, 1.0f/3})); canvas->translate(0, SkIntToScalar(kCellSize)); } private: @@ -172,7 +171,7 @@ private: sk_sp fLinearGrad2; SkMatrix fPerspMatrix; sk_sp fImage; - SkBitmap fBitmap; + sk_sp fBitmapImage; using INHERITED = GM; }; diff --git a/gm/readpixels.cpp b/gm/readpixels.cpp index f238cdffc2..fcc52a21b0 100644 --- a/gm/readpixels.cpp +++ b/gm/readpixels.cpp @@ -124,7 +124,7 @@ static void draw_image(GrDirectContext* dContext, SkCanvas* canvas, SkImage* ima // Now that we have called readPixels(), dump the raw pixels into an srgb image. sk_sp srgb = SkColorSpace::MakeSRGB(); sk_sp raw = SkImage::MakeRasterData(dstInfo.makeColorSpace(srgb), data, rowBytes); - canvas->drawImage(raw.get(), 0.0f, 0.0f, nullptr); + canvas->drawImage(raw.get(), 0.0f, 0.0f); } class ReadPixelsGM : public skiagm::GM { diff --git a/gm/runtimecolorfilter.cpp b/gm/runtimecolorfilter.cpp index 58577020a1..091d1afc05 100644 --- a/gm/runtimecolorfilter.cpp +++ b/gm/runtimecolorfilter.cpp @@ -109,7 +109,7 @@ DEF_SIMPLE_GM(runtimecolorfilter, canvas, 256 * 3, 256 * 2) { SkPaint p; sk_sp input = nullptr; p.setColorFilter(effect->makeColorFilter(nullptr, &input, 1)); - canvas->drawImage(img, 0, 0, &p); + canvas->drawImage(img, 0, 0, SkSamplingOptions(), &p); canvas->translate(256, 0); }; diff --git a/gm/savelayer.cpp b/gm/savelayer.cpp index 3d9bd50700..dbb667699a 100644 --- a/gm/savelayer.cpp +++ b/gm/savelayer.cpp @@ -47,7 +47,7 @@ // restore with kPlus mode, which should show the mandrill super-bright on the outside, but // normal where we punched the hole. DEF_SIMPLE_GM(savelayer_initfromprev, canvas, 256, 256) { - canvas->drawImage(GetResourceAsImage("images/mandrill_256.png"), 0, 0, nullptr); + canvas->drawImage(GetResourceAsImage("images/mandrill_256.png"), 0, 0); SkCanvas::SaveLayerRec rec; SkPaint paint; @@ -88,7 +88,7 @@ DEF_SIMPLE_GM(savelayer_coverage, canvas, 500, 500) { canvas->translate(x * 200.f, y * 200.f); SkCanvas::SaveLayerRec rec(&r, &layerPaint, yflags[y] | xflags[x]); - canvas->drawImageRect(image, r, nullptr); + canvas->drawImageRect(image, r, SkSamplingOptions(), nullptr); proc(canvas, rec); canvas->restore(); diff --git a/gm/surface.cpp b/gm/surface.cpp index 9af76d9cc1..a0d96afd6a 100644 --- a/gm/surface.cpp +++ b/gm/surface.cpp @@ -148,7 +148,7 @@ protected: drawInto(surf->getCanvas()); sk_sp image(surf->makeImageSnapshot()); - canvas->drawImage(image, 10, 10, nullptr); + canvas->drawImage(image, 10, 10); auto surf2(surf->makeSurface(info)); drawInto(surf2->getCanvas()); @@ -157,7 +157,7 @@ protected: SkASSERT(equal(surf->props(), surf2->props())); sk_sp image2(surf2->makeImageSnapshot()); - canvas->drawImage(image2.get(), 10 + SkIntToScalar(image->width()) + 10, 10, nullptr); + canvas->drawImage(image2.get(), 10 + SkIntToScalar(image->width()) + 10, 10); } private: @@ -182,7 +182,7 @@ DEF_SIMPLE_GM(copy_on_write_retain, canvas, 256, 256) { surf->getCanvas()->clear(SK_ColorBLUE); // expect to see two rects: blue | red - canvas->drawImage(surf->makeImageSnapshot(), 0, 0, nullptr); + canvas->drawImage(surf->makeImageSnapshot(), 0, 0); } DEF_SIMPLE_GM(copy_on_write_savelayer, canvas, 256, 256) { @@ -203,7 +203,7 @@ DEF_SIMPLE_GM(copy_on_write_savelayer, canvas, 256, 256) { surf->getCanvas()->restore(); // expect to see two rects: blue blended on red - canvas->drawImage(surf->makeImageSnapshot(), 0, 0, nullptr); + canvas->drawImage(surf->makeImageSnapshot(), 0, 0); } DEF_SIMPLE_GM(surface_underdraw, canvas, 256, 256) { @@ -258,7 +258,7 @@ DEF_SIMPLE_GM(surface_underdraw, canvas, 256, 256) { paint.setBlendMode(SkBlendMode::kDstOver); surf->getCanvas()->drawImage(saveImg, SkIntToScalar(subset.left()), SkIntToScalar(subset.top()), - &paint); + SkSamplingOptions(), &paint); } // show it on screen diff --git a/gm/textblobmixedsizes.cpp b/gm/textblobmixedsizes.cpp index edba3b839a..4354607e85 100644 --- a/gm/textblobmixedsizes.cpp +++ b/gm/textblobmixedsizes.cpp @@ -176,7 +176,7 @@ protected: SkAutoCanvasRestore acr(inputCanvas, true); // since we prepended this matrix already, we blit using identity inputCanvas->resetMatrix(); - inputCanvas->drawImage(surface->makeImageSnapshot().get(), 0, 0, nullptr); + inputCanvas->drawImage(surface->makeImageSnapshot().get(), 0, 0); } } diff --git a/gm/verylargebitmap.cpp b/gm/verylargebitmap.cpp index c5b8e10307..2cade42d9c 100644 --- a/gm/verylargebitmap.cpp +++ b/gm/verylargebitmap.cpp @@ -64,19 +64,20 @@ static void show_image(SkCanvas* canvas, int width, int height, SkColor colors[2 canvas->save(); canvas->clipRect(dstRect); - canvas->drawImage(image, 0, 0, nullptr); + canvas->drawImage(image, 0, 0); canvas->restore(); canvas->drawRect(dstRect, borderPaint); dstRect.offset(SkIntToScalar(150), 0); int hw = width / 2; int hh = height / 2; - SkIRect subset = SkIRect::MakeLTRB(hw - 64, hh - 32, hw + 64, hh + 32); - canvas->drawImageRect(image, subset, dstRect, nullptr); + SkRect subset = SkRect::MakeLTRB(hw - 64, hh - 32, hw + 64, hh + 32); + canvas->drawImageRect(image, subset, dstRect, SkSamplingOptions(), nullptr, + SkCanvas::kStrict_SrcRectConstraint); canvas->drawRect(dstRect, borderPaint); dstRect.offset(SkIntToScalar(150), 0); - canvas->drawImageRect(image, dstRect, nullptr); + canvas->drawImageRect(image, dstRect, SkSamplingOptions(), nullptr); canvas->drawRect(dstRect, borderPaint); } diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index ccee75d1d9..59b0a6c4a1 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -1852,11 +1852,6 @@ void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { this->onDrawPath(path, paint); } -#ifdef SK_SUPPORT_LEGACY_DRAWIMAGE_NOSAMPLING -void SkCanvas::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) { - this->drawImage(image, x, y, paint_to_sampling(paint, this->recordingContext()), paint); -} - // Returns true if the rect can be "filled" : non-empty and finite static bool fillable(const SkRect& r) { SkScalar w = r.width(); @@ -1864,6 +1859,11 @@ static bool fillable(const SkRect& r) { return SkScalarIsFinite(w) && w > 0 && SkScalarIsFinite(h) && h > 0; } +#ifdef SK_SUPPORT_LEGACY_DRAWIMAGE_NOSAMPLING +void SkCanvas::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) { + this->drawImage(image, x, y, paint_to_sampling(paint, this->recordingContext()), paint); +} + void SkCanvas::drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst, const SkPaint* paint, SrcRectConstraint constraint) { this->drawImageRect(image, src, dst, paint_to_sampling(paint, this->recordingContext()), diff --git a/src/effects/imagefilters/SkImageSource.cpp b/src/effects/imagefilters/SkImageSource.cpp index 202db9e5e8..63f170c23b 100644 --- a/src/effects/imagefilters/SkImageSource.cpp +++ b/src/effects/imagefilters/SkImageSource.cpp @@ -139,12 +139,17 @@ sk_sp SkImageSourceImpl::onFilterImage(const Context& ctx, // Subtract off the integer component of the translation (will be applied in offset, below). dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop)); paint.setBlendMode(SkBlendMode::kSrc); + + // TODO: take sampling explicitly, rather than filter-quality + SkSamplingOptions sampling(fFilterQuality, canvas->recordingContext() ? + SkSamplingOptions::kMedium_asMipmapLinear : + SkSamplingOptions::kMedium_asMipmapNearest); // FIXME: this probably shouldn't be necessary, but drawImageRect asserts // None filtering when it's translate-only - paint.setFilterQuality( - fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.height() ? - kNone_SkFilterQuality : fFilterQuality); - canvas->drawImageRect(fImage.get(), fSrcRect, dstRect, &paint, + if (fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.height()) { + sampling = SkSamplingOptions(); + } + canvas->drawImageRect(fImage.get(), fSrcRect, dstRect, sampling, &paint, SkCanvas::kStrict_SrcRectConstraint); offset->fX = dstIRect.fLeft;