Migrate to drawImage w/ sampling
Bug: skia:7650 Change-Id: Icb99ee9f7142fe1ca22f9fa66b1467486ce576a6 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/357598 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
d6b6f3ec84
commit
34c56a5c3d
@ -1282,18 +1282,8 @@ static void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 9) {
|
||||
if (usePaint) {
|
||||
fuzz_paint(fuzz, &paint, depth - 1);
|
||||
}
|
||||
canvas->drawImage(img.get(), left, top, usePaint ? &paint : nullptr);
|
||||
break;
|
||||
}
|
||||
case 34: {
|
||||
auto img = make_fuzz_image(fuzz);
|
||||
SkRect src, dst;
|
||||
bool usePaint;
|
||||
fuzz->next(&src, &dst, &usePaint);
|
||||
if (usePaint) {
|
||||
fuzz_paint(fuzz, &paint, depth - 1);
|
||||
}
|
||||
canvas->drawImageRect(img, src, dst, usePaint ? &paint : nullptr);
|
||||
canvas->drawImage(img.get(), left, top, SkSamplingOptions(),
|
||||
usePaint ? &paint : nullptr);
|
||||
break;
|
||||
}
|
||||
case 35: {
|
||||
@ -1308,18 +1298,8 @@ static void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 9) {
|
||||
SkCanvas::SrcRectConstraint constraint =
|
||||
make_fuzz_t<bool>(fuzz) ? SkCanvas::kStrict_SrcRectConstraint
|
||||
: SkCanvas::kFast_SrcRectConstraint;
|
||||
canvas->drawImageRect(img, src, dst, usePaint ? &paint : nullptr, constraint);
|
||||
break;
|
||||
}
|
||||
case 36: {
|
||||
bool usePaint;
|
||||
auto img = make_fuzz_image(fuzz);
|
||||
SkRect dst;
|
||||
fuzz->next(&dst, &usePaint);
|
||||
if (usePaint) {
|
||||
fuzz_paint(fuzz, &paint, depth - 1);
|
||||
}
|
||||
canvas->drawImageRect(img, dst, usePaint ? &paint : nullptr);
|
||||
canvas->drawImageRect(img.get(), SkRect::Make(src), dst, SkSamplingOptions(),
|
||||
usePaint ? &paint : nullptr, constraint);
|
||||
break;
|
||||
}
|
||||
case 37: {
|
||||
|
@ -65,8 +65,7 @@ protected:
|
||||
void draw(SkCanvas* canvas, int x, int y, int xSize, int ySize) {
|
||||
SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
|
||||
SkIntToScalar(xSize), SkIntToScalar(ySize));
|
||||
canvas->drawImageRect(fImage.get(), r, fSampling, nullptr,
|
||||
SkCanvas::kStrict_SrcRectConstraint);
|
||||
canvas->drawImageRect(fImage, r, fSampling);
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
|
@ -1666,7 +1666,16 @@ public:
|
||||
void drawImageRect(const SkImage*, const SkRect& src, const SkRect& dst,
|
||||
const SkSamplingOptions&, const SkPaint*, SrcRectConstraint);
|
||||
void drawImageRect(const SkImage*, const SkRect& dst, const SkSamplingOptions&,
|
||||
const SkPaint*, SrcRectConstraint);
|
||||
const SkPaint* = nullptr);
|
||||
void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst,
|
||||
const SkSamplingOptions& sampling, const SkPaint* paint,
|
||||
SrcRectConstraint constraint) {
|
||||
this->drawImageRect(image.get(), src, dst, sampling, paint, constraint);
|
||||
}
|
||||
void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst,
|
||||
const SkSamplingOptions& sampling, const SkPaint* paint = nullptr) {
|
||||
this->drawImageRect(image.get(), dst, sampling, paint);
|
||||
}
|
||||
|
||||
/** Draws SkImage image stretched proportionally to fit into SkRect dst.
|
||||
SkIRect center divides the image into nine sections: four sides, four corners, and
|
||||
|
@ -16,25 +16,27 @@
|
||||
#include "src/core/SkPaintPriv.h"
|
||||
|
||||
typedef void (*DrawAtlasProc)(SkCanvas*, SkImage*, const SkRSXform[], const SkRect[],
|
||||
const SkColor[], int, const SkRect*, const SkPaint*);
|
||||
const SkColor[], int, const SkRect*, const SkSamplingOptions&,
|
||||
const SkPaint*);
|
||||
|
||||
static void draw_atlas(SkCanvas* canvas, SkImage* atlas, const SkRSXform xform[],
|
||||
const SkRect tex[], const SkColor colors[], int count, const SkRect* cull,
|
||||
const SkPaint* paint) {
|
||||
canvas->drawAtlas(atlas, xform, tex, colors, count, SkBlendMode::kModulate, cull, paint);
|
||||
const SkSamplingOptions& sampling, const SkPaint* paint) {
|
||||
canvas->drawAtlas(atlas, xform, tex, colors, count, SkBlendMode::kModulate,
|
||||
sampling, cull, paint);
|
||||
}
|
||||
|
||||
static void draw_atlas_sim(SkCanvas* canvas, SkImage* atlas, const SkRSXform xform[],
|
||||
const SkRect tex[], const SkColor colors[], int count, const SkRect* cull,
|
||||
const SkPaint* paint) {
|
||||
const SkSamplingOptions& sampling, const SkPaint* paint) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkMatrix matrix;
|
||||
matrix.setRSXform(xform[i]);
|
||||
|
||||
canvas->save();
|
||||
canvas->concat(matrix);
|
||||
canvas->drawImageRect(atlas, tex[i], tex[i].makeOffset(-tex[i].x(), -tex[i].y()), paint,
|
||||
SkCanvas::kFast_SrcRectConstraint);
|
||||
canvas->drawImageRect(atlas, tex[i], tex[i].makeOffset(-tex[i].x(), -tex[i].y()),
|
||||
sampling, paint, SkCanvas::kFast_SrcRectConstraint);
|
||||
canvas->restore();
|
||||
}
|
||||
}
|
||||
@ -184,12 +186,11 @@ protected:
|
||||
}
|
||||
}
|
||||
SkPaint paint;
|
||||
// TODO: add sampling options to drawAtlas
|
||||
SkPaintPriv::SetFQ(&paint, kLow_SkFilterQuality);
|
||||
SkSamplingOptions sampling(SkFilterMode::kLinear);
|
||||
|
||||
const SkRect cull = this->getBounds();
|
||||
const SkColor* colorsPtr = fUseColors ? colors : nullptr;
|
||||
fProc(canvas, fAtlas.get(), xform, fTex, colorsPtr, N, &cull, &paint);
|
||||
fProc(canvas, fAtlas.get(), xform, fTex, colorsPtr, N, &cull, sampling, &paint);
|
||||
}
|
||||
|
||||
SkRect onGetBounds() override {
|
||||
|
@ -142,19 +142,23 @@ class ChineseZoomView : public Sample {
|
||||
sk_sp<SkImage> image = direct->priv().testingOnly_getFontAtlasImage(
|
||||
GrMaskFormat::kA8_GrMaskFormat, 0);
|
||||
canvas->drawImageRect(image,
|
||||
SkRect::MakeXYWH(10.0f, 10.0f, 512.0f, 512.0), &paint);
|
||||
SkRect::MakeXYWH(10.0f, 10.0f, 512.0f, 512.0),
|
||||
SkSamplingOptions(), &paint);
|
||||
image = direct->priv().testingOnly_getFontAtlasImage(
|
||||
GrMaskFormat::kA8_GrMaskFormat, 1);
|
||||
canvas->drawImageRect(image,
|
||||
SkRect::MakeXYWH(522.0f, 10.0f, 512.f, 512.0f), &paint);
|
||||
SkRect::MakeXYWH(522.0f, 10.0f, 512.f, 512.0f),
|
||||
SkSamplingOptions(), &paint);
|
||||
image = direct->priv().testingOnly_getFontAtlasImage(
|
||||
GrMaskFormat::kA8_GrMaskFormat, 2);
|
||||
canvas->drawImageRect(image,
|
||||
SkRect::MakeXYWH(10.0f, 522.0f, 512.0f, 512.0f), &paint);
|
||||
SkRect::MakeXYWH(10.0f, 522.0f, 512.0f, 512.0f),
|
||||
SkSamplingOptions(), &paint);
|
||||
image = direct->priv().testingOnly_getFontAtlasImage(
|
||||
GrMaskFormat::kA8_GrMaskFormat, 3);
|
||||
canvas->drawImageRect(image,
|
||||
SkRect::MakeXYWH(522.0f, 522.0f, 512.0f, 512.0f), &paint);
|
||||
SkRect::MakeXYWH(522.0f, 522.0f, 512.0f, 512.0f),
|
||||
SkSamplingOptions(), &paint);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ static sk_sp<SkImage> zoom_up(SkSurface* origSurf, SkImage* orig) {
|
||||
canvas->scale(S, S);
|
||||
canvas->translate(-SkScalarHalf(orig->width()) * (S - D) / S,
|
||||
-SkScalarHalf(orig->height()) * (S - D) / S);
|
||||
canvas->drawImage(orig, 0, 0, nullptr);
|
||||
canvas->drawImage(orig, 0, 0);
|
||||
|
||||
if (S > 3) {
|
||||
SkPaint paint;
|
||||
|
@ -190,7 +190,7 @@ protected:
|
||||
SkString name() override { return SkString("Backdrop"); }
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
canvas->drawImage(fImage.get(), 0, 0, nullptr);
|
||||
canvas->drawImage(fImage.get(), 0, 0);
|
||||
|
||||
const SkScalar w = 250;
|
||||
const SkScalar h = 150;
|
||||
|
@ -40,13 +40,14 @@ protected:
|
||||
void dodraw(SkCanvas* canvas, sk_sp<SkColorFilter> cf0, sk_sp<SkColorFilter> cf1, float gap) {
|
||||
SkPaint paint;
|
||||
paint.setColorFilter(cf0);
|
||||
canvas->drawImage(fImg, 0, 0, &paint);
|
||||
canvas->drawImage(fImg, 0, 0, SkSamplingOptions(), &paint);
|
||||
|
||||
paint.setColorFilter(SkColorFilters::Lerp(fWeight, cf0, cf1));
|
||||
canvas->drawImage(fImg, fImg->width() + gap * fWeight, 0, &paint);
|
||||
canvas->drawImage(fImg, fImg->width() + gap * fWeight, 0,
|
||||
SkSamplingOptions(), &paint);
|
||||
|
||||
paint.setColorFilter(cf1);
|
||||
canvas->drawImage(fImg, 2*fImg->width() + gap, 0, &paint);
|
||||
canvas->drawImage(fImg, 2*fImg->width() + gap, 0, SkSamplingOptions(), &paint);
|
||||
}
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
|
@ -107,8 +107,6 @@ class TextureUploadSample : public Sample {
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
#if SK_SUPPORT_GPU
|
||||
SkPaint paint;
|
||||
|
||||
auto direct = GrAsDirectContext(canvas->recordingContext());
|
||||
if (direct) {
|
||||
// One-time context-specific setup.
|
||||
@ -133,7 +131,7 @@ class TextureUploadSample : public Sample {
|
||||
for (int x = 0; x < fTileCols; x++) {
|
||||
int currentIndex = y * fTileCols + x;
|
||||
canvas->drawImage(fTextures[currentIndex]->getImage(),
|
||||
x * fTileSize, y * fTileSize, &paint);
|
||||
x * fTileSize, y * fTileSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,9 +72,12 @@ struct TimingSample : public Sample {
|
||||
for (int y = 0; y < H; y++)
|
||||
for (int x = 0; x < W; x++) {
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
offscreen->getCanvas()->drawImageRect(fImg, SkRect::MakeXYWH(x,y,1,1)
|
||||
, SkRect::MakeXYWH(0,0,1024,1024)
|
||||
, /*paint=*/nullptr);
|
||||
offscreen->getCanvas()->drawImageRect(fImg,
|
||||
SkRect::MakeXYWH(x,y,1,1),
|
||||
SkRect::MakeXYWH(0,0,1024,1024),
|
||||
SkSamplingOptions(),
|
||||
/*paint=*/nullptr,
|
||||
SkCanvas::kStrict_SrcRectConstraint);
|
||||
auto elapsed = std::chrono::steady_clock::now() - start;
|
||||
|
||||
cost[y][x] = elapsed.count();
|
||||
|
@ -350,7 +350,7 @@ void sk_canvas_draw_image_rect(sk_canvas_t* ccanvas, const sk_image_t* cimage,
|
||||
canvas->drawImageRect(image, AsRect(*csrcR), dst, sampling, paint,
|
||||
SkCanvas::kStrict_SrcRectConstraint);
|
||||
} else {
|
||||
canvas->drawImageRect(image, dst, sampling, paint, SkCanvas::kStrict_SrcRectConstraint);
|
||||
canvas->drawImageRect(image, dst, sampling, paint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1852,6 +1852,7 @@ 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);
|
||||
}
|
||||
@ -1880,6 +1881,7 @@ void SkCanvas::drawImageRect(const SkImage* image, const SkRect& dst, const SkPa
|
||||
this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst, paint,
|
||||
kFast_SrcRectConstraint);
|
||||
}
|
||||
#endif
|
||||
|
||||
static SkPaint clean_paint_for_lattice(const SkPaint* paint) {
|
||||
SkPaint cleaned;
|
||||
@ -2362,11 +2364,10 @@ void SkCanvas::drawImageRect(const SkImage* image, const SkRect& src, const SkRe
|
||||
}
|
||||
|
||||
void SkCanvas::drawImageRect(const SkImage* image, const SkRect& dst,
|
||||
const SkSamplingOptions& sampling, const SkPaint* paint,
|
||||
SrcRectConstraint constraint) {
|
||||
const SkSamplingOptions& sampling, const SkPaint* paint) {
|
||||
RETURN_ON_NULL(image);
|
||||
this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst, sampling,
|
||||
paint, constraint);
|
||||
paint, kFast_SrcRectConstraint);
|
||||
}
|
||||
|
||||
void SkCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
|
||||
|
@ -357,7 +357,10 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
|
||||
reader->readPoint(&loc);
|
||||
BREAK_ON_READ_ERROR(reader);
|
||||
|
||||
canvas->drawImage(image, loc.fX, loc.fY, paint);
|
||||
canvas->drawImage(image, loc.fX, loc.fY,
|
||||
SkSamplingOptions(paint ? paint->getFilterQuality()
|
||||
: kNone_SkFilterQuality),
|
||||
paint);
|
||||
} break;
|
||||
case DRAW_IMAGE2: {
|
||||
const SkPaint* paint = fPictureData->optionalPaint(reader);
|
||||
@ -422,7 +425,7 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
|
||||
if (src) {
|
||||
canvas->drawImageRect(image, *src, dst, sampling, paint, constraint);
|
||||
} else {
|
||||
canvas->drawImageRect(image, dst, sampling, paint, constraint);
|
||||
canvas->drawImageRect(image, dst, sampling, paint);
|
||||
}
|
||||
} break;
|
||||
case DRAW_IMAGE_RECT2: {
|
||||
|
@ -569,7 +569,7 @@ static bool draw_orientation(const SkPixmap& dst, const SkPixmap& src, SkEncoded
|
||||
SkPaint p;
|
||||
p.setBlendMode(SkBlendMode::kSrc);
|
||||
surf->getCanvas()->concat(m);
|
||||
surf->getCanvas()->drawImage(SkImage::MakeFromBitmap(bm), 0, 0, &p);
|
||||
surf->getCanvas()->drawImage(SkImage::MakeFromBitmap(bm), 0, 0, SkSamplingOptions(), &p);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1419,7 +1419,7 @@ static sk_sp<SkImage> color_filter(const SkImage* image,
|
||||
canvas->clear(SK_ColorTRANSPARENT);
|
||||
SkPaint paint;
|
||||
paint.setColorFilter(sk_ref_sp(colorFilter));
|
||||
canvas->drawImage(image, 0, 0, &paint);
|
||||
canvas->drawImage(image, 0, 0, SkSamplingOptions(), &paint);
|
||||
return surface->makeImageSnapshot();
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ static void draw_bitmap_matrix(SkCanvas* canvas, const SkBitmap& bm,
|
||||
SkAutoCanvasRestore acr(canvas, true);
|
||||
canvas->concat(matrix);
|
||||
SkPaint paint(paintColor);
|
||||
canvas->drawImage(SkImage::MakeFromBitmap(bm), 0, 0, &paint);
|
||||
canvas->drawImage(bm.asImage(), 0, 0, SkSamplingOptions(), &paint);
|
||||
}
|
||||
|
||||
static void fill_color_from_bitmap(SkCanvas* canvas,
|
||||
|
@ -91,7 +91,7 @@ sk_sp<SkImage> SkAnimCodecPlayer::getFrameAt(int index) {
|
||||
SkAssertResult(originMatrix.invert(&inverse));
|
||||
canvas->concat(inverse);
|
||||
}
|
||||
canvas->drawImage(requiredImage, 0, 0, &paint);
|
||||
canvas->drawImage(requiredImage, 0, 0, SkSamplingOptions(), &paint);
|
||||
opts.fPriorFrame = requiredFrame;
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ sk_sp<SkImage> SkAnimCodecPlayer::getFrameAt(int index) {
|
||||
data = SkData::MakeUninitialized(size);
|
||||
auto canvas = SkCanvas::MakeRasterDirect(imageInfo, data->writable_data(), rb);
|
||||
canvas->concat(originMatrix);
|
||||
canvas->drawImage(image, 0, 0, &paint);
|
||||
canvas->drawImage(image, 0, 0, SkSamplingOptions(), &paint);
|
||||
image = SkImage::MakeRasterData(imageInfo, std::move(data), rb);
|
||||
}
|
||||
return fImages[index] = image;
|
||||
|
@ -1682,7 +1682,7 @@ DEF_TEST(Codec_ossfuzz6274, r) {
|
||||
bm.eraseColor(SK_ColorTRANSPARENT);
|
||||
|
||||
SkCanvas canvas(bm);
|
||||
canvas.drawImage(image, 0, 0, nullptr);
|
||||
canvas.drawImage(image, 0, 0);
|
||||
|
||||
for (int i = 0; i < image->width(); ++i)
|
||||
for (int j = 0; j < image->height(); ++j) {
|
||||
@ -1772,7 +1772,7 @@ DEF_TEST(Codec_crbug807324, r) {
|
||||
bm.eraseColor(SK_ColorTRANSPARENT);
|
||||
|
||||
SkCanvas canvas(bm);
|
||||
canvas.drawImage(image, 0, 0, nullptr);
|
||||
canvas.drawImage(image, 0, 0);
|
||||
|
||||
for (int i = 0; i < kWidth; ++i)
|
||||
for (int j = 0; j < kHeight; ++j) {
|
||||
|
@ -73,6 +73,8 @@ static void check_compressed_mipmaps(GrRecordingContext* rContext, sk_sp<SkImage
|
||||
|
||||
SkCanvas* canvas = surf->getCanvas();
|
||||
|
||||
const SkSamplingOptions sampling(SkFilterMode::kLinear,
|
||||
SkMipmapMode::kLinear);
|
||||
SkPaint p;
|
||||
SkPaintPriv::SetFQ(&p, kMedium_SkFilterQuality); // to force mipMapping
|
||||
p.setBlendMode(SkBlendMode::kSrc);
|
||||
@ -88,7 +90,7 @@ static void check_compressed_mipmaps(GrRecordingContext* rContext, sk_sp<SkImage
|
||||
canvas->clear(SK_ColorTRANSPARENT);
|
||||
|
||||
SkRect r = SkRect::MakeWH(rectSize, rectSize);
|
||||
canvas->drawImageRect(img, r, &p);
|
||||
canvas->drawImageRect(img, r, sampling, &p);
|
||||
|
||||
SkImageInfo readbackII = SkImageInfo::Make(rectSize, rectSize,
|
||||
kRGBA_8888_SkColorType,
|
||||
|
Loading…
Reference in New Issue
Block a user