Pass sampling to surface.draw
Bug: skia:7650 Change-Id: I97941a44faa4176f94d57a9c1626ac36b0c0c4ea Reviewed-on: https://skia-review.googlesource.com/c/skia/+/350557 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
c294b82260
commit
b746b1f598
@ -27,7 +27,7 @@ void draw(SkCanvas* canvas) {
|
||||
? SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, &props)
|
||||
: SkSurface::MakeRaster(info, &props);
|
||||
test_draw(surface->getCanvas());
|
||||
surface->draw(canvas, 0, y, nullptr);
|
||||
surface->draw(canvas, 0, y);
|
||||
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
||||
SkAutoCanvasRestore acr(canvas, true);
|
||||
canvas->scale(8, 8);
|
||||
|
@ -8,7 +8,7 @@ void draw(SkCanvas* canvas) {
|
||||
sk_sp<SkSurface> lil(big->makeSurface(SkImageInfo::MakeN32(32, 32, kPremul_SkAlphaType)));
|
||||
big->getCanvas()->clear(SK_ColorRED);
|
||||
lil->getCanvas()->clear(SK_ColorBLACK);
|
||||
lil->draw(big->getCanvas(), 16, 16, nullptr);
|
||||
lil->draw(big->getCanvas(), 16, 16);
|
||||
SkPixmap pixmap;
|
||||
if (big->peekPixels(&pixmap)) {
|
||||
SkBitmap bigBits;
|
||||
|
@ -9,7 +9,7 @@ void draw(SkCanvas* canvas) {
|
||||
big->getCanvas()->clear(SK_ColorRED);
|
||||
lil->getCanvas()->clear(SK_ColorBLACK);
|
||||
sk_sp<SkImage> early(big->makeImageSnapshot());
|
||||
lil->draw(big->getCanvas(), 16, 16, nullptr);
|
||||
lil->draw(big->getCanvas(), 16, 16);
|
||||
sk_sp<SkImage> later(big->makeImageSnapshot());
|
||||
canvas->drawImage(early, 0, 0);
|
||||
canvas->drawImage(later, 128, 0);
|
||||
|
@ -9,7 +9,7 @@ void draw(SkCanvas* canvas) {
|
||||
big->getCanvas()->clear(SK_ColorRED);
|
||||
lil->getCanvas()->clear(SK_ColorBLACK);
|
||||
sk_sp<SkImage> early(big->makeImageSnapshot());
|
||||
lil->draw(big->getCanvas(), 16, 16, nullptr);
|
||||
lil->draw(big->getCanvas(), 16, 16);
|
||||
sk_sp<SkImage> later(big->makeImageSnapshot({0, 0, 16, 16}));
|
||||
canvas->drawImage(early, 0, 0);
|
||||
canvas->drawImage(later, 0, 0);
|
||||
|
@ -57,6 +57,6 @@ void draw(SkCanvas* canvas) {
|
||||
|
||||
SkPaint postPaint;
|
||||
postPaint.setDither(postDither);
|
||||
surf->draw(canvas, 0, 0, &postPaint);
|
||||
surf->draw(canvas, 0, 0, SkSamplingOptions(), &postPaint);
|
||||
}
|
||||
} // END FIDDLE
|
||||
|
@ -87,7 +87,7 @@ DEF_SIMPLE_GM(color4f, canvas, 1024, 260) {
|
||||
auto surface(SkSurface::MakeRaster(info));
|
||||
surface->getCanvas()->drawPaint(bg);
|
||||
draw_into_canvas(surface->getCanvas());
|
||||
surface->draw(canvas, 0, 0, nullptr);
|
||||
surface->draw(canvas, 0, 0);
|
||||
canvas->translate(0, 120);
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ protected:
|
||||
surface->getCanvas()->drawPaint(paint);
|
||||
break;
|
||||
}
|
||||
surface->draw(canvas, 10.f*x, 10.f*y, nullptr);
|
||||
surface->draw(canvas, 10.f*x, 10.f*y);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, const SkPath& pat
|
||||
|
||||
surface->getCanvas()->clear(SK_ColorTRANSPARENT);
|
||||
surface->getCanvas()->drawPath(path, paint);
|
||||
surface->draw(canvas, 0, 0, nullptr);
|
||||
surface->draw(canvas, 0, 0);
|
||||
|
||||
paint.setAntiAlias(true);
|
||||
paint.setColor(SK_ColorRED);
|
||||
|
@ -54,7 +54,7 @@ DEF_SIMPLE_GM(path_huge_aa, canvas, 200, 200) {
|
||||
canvas->save();
|
||||
canvas->clipRect(SkRect::MakeXYWH(4, 4, 64, 64));
|
||||
can->drawPath(path, paint);
|
||||
surf->draw(canvas, 64 - w, 0, nullptr);
|
||||
surf->draw(canvas, 64 - w, 0);
|
||||
canvas->restore();
|
||||
|
||||
canvas->translate(80, 0);
|
||||
@ -63,7 +63,7 @@ DEF_SIMPLE_GM(path_huge_aa, canvas, 200, 200) {
|
||||
can->clear(0);
|
||||
paint.setAntiAlias(true);
|
||||
can->drawPath(path, paint);
|
||||
surf->draw(canvas, 64 - w, 0, nullptr);
|
||||
surf->draw(canvas, 64 - w, 0);
|
||||
canvas->restore();
|
||||
};
|
||||
|
||||
|
@ -80,12 +80,10 @@ static void test_surface(SkCanvas* canvas, SkSurface* surf, bool usePaint) {
|
||||
drawContents(surf, SK_ColorBLUE);
|
||||
|
||||
SkPaint paint;
|
||||
// paint.setFilterBitmap(true);
|
||||
// paint.setAlpha(0x80);
|
||||
|
||||
canvas->drawImage(imgR, 0, 0, usePaint ? &paint : nullptr);
|
||||
canvas->drawImage(imgG, 0, 80, usePaint ? &paint : nullptr);
|
||||
surf->draw(canvas, 0, 160, usePaint ? &paint : nullptr);
|
||||
surf->draw(canvas, 0, 160, SkSamplingOptions(), usePaint ? &paint : nullptr);
|
||||
|
||||
SkRect src1, src2, src3;
|
||||
src1.setIWH(surf->width(), surf->height());
|
||||
|
@ -86,7 +86,7 @@ protected:
|
||||
|
||||
SkPaint surfPaint;
|
||||
surfPaint.setBlendMode(SkBlendMode::kSrcOver);
|
||||
surface->draw(canvas, 0, 0, &surfPaint);
|
||||
surface->draw(canvas, 0, 0, SkSamplingOptions(), &surfPaint);
|
||||
}
|
||||
|
||||
void drawColumn(SkCanvas* canvas, SkColor backgroundColor, SkColor textColor, bool useGrad) {
|
||||
|
@ -91,7 +91,7 @@ static void test_mac_fonts(SkCanvas* canvas, SkScalar size, SkScalar xpos) {
|
||||
CGContextSetShouldSmoothFonts(ctx, smooth);
|
||||
CGContextShowTextAtPoint(ctx, 2 + xpos, 2, "A", 1);
|
||||
|
||||
surf->draw(canvas, x, y, nullptr);
|
||||
surf->draw(canvas, x, y);
|
||||
x += pm.width();
|
||||
}
|
||||
y += pm.height();
|
||||
|
@ -663,7 +663,7 @@ DEF_SIMPLE_GM(path_stroke_clip_crbug1070835, canvas, 25, 50) {
|
||||
|
||||
canvas->drawPath(path, p);
|
||||
|
||||
surf->draw(orig, 0, 0, nullptr);
|
||||
surf->draw(orig, 0, 0);
|
||||
}
|
||||
|
||||
DEF_SIMPLE_GM(path_arcto_skbug_9077, canvas, 200, 200) {
|
||||
|
@ -133,7 +133,7 @@ class SrcModeGM : public skiagm::GM {
|
||||
auto surf(compat_surface(canvas, this->getISize()));
|
||||
surf->getCanvas()->drawColor(SK_ColorWHITE);
|
||||
this->drawContent(surf->getCanvas());
|
||||
surf->draw(canvas, 0, 0, nullptr);
|
||||
surf->draw(canvas, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -108,7 +108,7 @@ protected:
|
||||
continue;
|
||||
}
|
||||
test_draw(surface->getCanvas(), rec.fLabel);
|
||||
surface->draw(canvas, x, y, nullptr);
|
||||
surface->draw(canvas, x, y);
|
||||
y += H;
|
||||
}
|
||||
}
|
||||
@ -262,5 +262,5 @@ DEF_SIMPLE_GM(surface_underdraw, canvas, 256, 256) {
|
||||
}
|
||||
|
||||
// show it on screen
|
||||
surf->draw(canvas, 0, 0, nullptr);
|
||||
surf->draw(canvas, 0, 0);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ protected:
|
||||
// (i.e., unknown pixel geometry)
|
||||
c->clear(0x00ffffff);
|
||||
c->drawTextBlob(blob, 10, 150, SkPaint());
|
||||
surface->draw(canvas, 0, 0, nullptr);
|
||||
surface->draw(canvas, 0, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -146,7 +146,7 @@ protected:
|
||||
// Rotate in the surface canvas, not the final canvas, to avoid aliasing
|
||||
surfaceCanvas->rotate(-0.05f);
|
||||
surfaceCanvas->drawTextBlob(fBlob, 10, yOffset, paint);
|
||||
surface->draw(canvas, 0, 0, nullptr);
|
||||
surface->draw(canvas, 0, 0);
|
||||
yOffset += stride;
|
||||
|
||||
if (auto direct = context->asDirectContext()) {
|
||||
|
@ -74,6 +74,6 @@ DEF_SIMPLE_GM(transparency_check, canvas, 1792, 1080) {
|
||||
auto surface(SkSurface::MakeRasterN32Premul(256, 9));
|
||||
make_transparency(surface->getCanvas(), 256.0f, 9.0f);
|
||||
canvas->scale(7.0f, 120.0f);
|
||||
surface->draw(canvas, 0, 0, nullptr);
|
||||
surface->draw(canvas, 0, 0);
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ private:
|
||||
if (nullptr == surface) {
|
||||
canvas->restore();
|
||||
} else {
|
||||
surface->draw(canvas, 0, 0, nullptr);
|
||||
surface->draw(canvas, 0, 0);
|
||||
}
|
||||
|
||||
r.inset(-SK_ScalarHalf, -SK_ScalarHalf);
|
||||
|
@ -620,11 +620,19 @@ public:
|
||||
@param canvas SkCanvas drawn into
|
||||
@param x horizontal offset in SkCanvas
|
||||
@param y vertical offset in SkCanvas
|
||||
@param sampling what technique to use when sampling the surface pixels
|
||||
@param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
|
||||
and so on; or nullptr
|
||||
|
||||
example: https://fiddle.skia.org/c/@Surface_draw
|
||||
*/
|
||||
void draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkSamplingOptions& sampling,
|
||||
const SkPaint* paint);
|
||||
void draw(SkCanvas* canvas, SkScalar x, SkScalar y) {
|
||||
this->draw(canvas, x, y, SkSamplingOptions(), nullptr);
|
||||
}
|
||||
|
||||
// DEPRECATED -- use explicit sampling options
|
||||
void draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint);
|
||||
|
||||
/** Copies SkSurface pixel address, row bytes, and SkImageInfo to SkPixmap, if address
|
||||
|
@ -172,7 +172,7 @@ private:
|
||||
SkCanvas* canvas = fMaxSurface->getCanvas();
|
||||
canvas->save();
|
||||
canvas->concat(fMatrix);
|
||||
fMinSurface->draw(canvas, 0, 0, nullptr);
|
||||
fMinSurface->draw(canvas, 0, 0);
|
||||
canvas->restore();
|
||||
|
||||
SkPaint paint;
|
||||
@ -284,7 +284,7 @@ void FatBits::drawLine(SkCanvas* canvas, SkPoint pts[]) {
|
||||
fMatrix.mapPoints(pts, 2);
|
||||
this->drawLineSkeleton(max, pts);
|
||||
|
||||
fMaxSurface->draw(canvas, 0, 0, nullptr);
|
||||
fMaxSurface->draw(canvas, 0, 0);
|
||||
}
|
||||
|
||||
void FatBits::drawRect(SkCanvas* canvas, SkPoint pts[2]) {
|
||||
@ -314,7 +314,7 @@ void FatBits::drawRect(SkCanvas* canvas, SkPoint pts[2]) {
|
||||
r.setBounds(pts, 2);
|
||||
this->drawRectSkeleton(max, r);
|
||||
|
||||
fMaxSurface->draw(canvas, 0, 0, nullptr);
|
||||
fMaxSurface->draw(canvas, 0, 0);
|
||||
}
|
||||
|
||||
void FatBits::drawTriangleSkeleton(SkCanvas* max, const SkPoint pts[]) {
|
||||
@ -356,7 +356,7 @@ void FatBits::drawTriangle(SkCanvas* canvas, SkPoint pts[3]) {
|
||||
fMatrix.mapPoints(pts, 3);
|
||||
this->drawTriangleSkeleton(max, pts);
|
||||
|
||||
fMaxSurface->draw(canvas, 0, 0, nullptr);
|
||||
fMaxSurface->draw(canvas, 0, 0);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -252,7 +252,7 @@ protected:
|
||||
SkCanvas* canvas = fMaxSurface->getCanvas();
|
||||
canvas->save();
|
||||
canvas->concat(fMatrix);
|
||||
fMinSurface->draw(canvas, 0, 0, nullptr);
|
||||
fMinSurface->draw(canvas, 0, 0);
|
||||
canvas->restore();
|
||||
|
||||
SkPaint paint;
|
||||
@ -414,7 +414,7 @@ protected:
|
||||
if (drawText) {
|
||||
fMinSurface->getCanvas()->drawPath(path, paint);
|
||||
this->copyMinToMax();
|
||||
fMaxSurface->draw(canvas, 0, 0, nullptr);
|
||||
fMaxSurface->draw(canvas, 0, 0);
|
||||
}
|
||||
paint.setAntiAlias(true);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "src/core/SkAutoPixmapStorage.h"
|
||||
#include "src/core/SkImagePriv.h"
|
||||
#include "src/core/SkPaintPriv.h"
|
||||
#include "src/image/SkRescaleAndReadPixels.h"
|
||||
#include "src/image/SkSurface_Base.h"
|
||||
|
||||
@ -59,10 +60,11 @@ bool SkSurface_Base::onReplaceBackendTexture(const GrBackendTexture&,
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) {
|
||||
void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
|
||||
const SkSamplingOptions& sampling, const SkPaint* paint) {
|
||||
auto image = this->makeImageSnapshot();
|
||||
if (image) {
|
||||
canvas->drawImage(image, x, y, paint);
|
||||
canvas->drawImage(image.get(), x, y, sampling, paint);
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,9 +213,14 @@ sk_sp<SkSurface> SkSurface::makeSurface(int width, int height) {
|
||||
return this->makeSurface(this->imageInfo().makeWH(width, height));
|
||||
}
|
||||
|
||||
void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y,
|
||||
void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkSamplingOptions& sampling,
|
||||
const SkPaint* paint) {
|
||||
return asSB(this)->onDraw(canvas, x, y, paint);
|
||||
asSB(this)->onDraw(canvas, x, y, sampling, paint);
|
||||
}
|
||||
|
||||
void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) {
|
||||
SkSamplingOptions sampling(paint ? SkPaintPriv::GetFQ(*paint) : kNone_SkFilterQuality);
|
||||
this->draw(canvas, x, y, sampling, paint);
|
||||
}
|
||||
|
||||
bool SkSurface::peekPixels(SkPixmap* pmap) {
|
||||
@ -362,7 +369,7 @@ protected:
|
||||
}
|
||||
sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subsetOrNull) override { return nullptr; }
|
||||
void onWritePixels(const SkPixmap&, int x, int y) override {}
|
||||
void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) override {}
|
||||
void onDraw(SkCanvas*, SkScalar, SkScalar, const SkSamplingOptions&, const SkPaint*) override {}
|
||||
void onCopyOnWrite(ContentChangeMode) override {}
|
||||
};
|
||||
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
* image->unref();
|
||||
* }
|
||||
*/
|
||||
virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*);
|
||||
virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkSamplingOptions&,const SkPaint*);
|
||||
|
||||
/**
|
||||
* Called as a performance hint when the Surface is allowed to make it's contents
|
||||
|
@ -268,7 +268,8 @@ bool SkSurface_Gpu::onCharacterize(SkSurfaceCharacterization* characterization)
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) {
|
||||
void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
|
||||
const SkSamplingOptions& sampling, const SkPaint* paint) {
|
||||
// If the dst is also GPU we try to not force a new image snapshot (by calling the base class
|
||||
// onDraw) since that may not always perform the copy-on-write optimization.
|
||||
auto tryDraw = [&] {
|
||||
@ -296,11 +297,11 @@ void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPai
|
||||
image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(canvasContext), kNeedNewImageUniqueID,
|
||||
std::move(view), info.colorType(), info.alphaType(),
|
||||
info.refColorSpace());
|
||||
canvas->drawImage(image, x, y, paint);
|
||||
canvas->drawImage(image.get(), x, y, sampling, paint);
|
||||
return true;
|
||||
};
|
||||
if (!tryDraw()) {
|
||||
INHERITED::onDraw(canvas, x, y, paint);
|
||||
INHERITED::onDraw(canvas, x, y, sampling, paint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,8 @@ public:
|
||||
bool deleteSemaphoresAfterWait) override;
|
||||
bool onCharacterize(SkSurfaceCharacterization*) const override;
|
||||
bool onIsCompatible(const SkSurfaceCharacterization&) const override;
|
||||
void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) override;
|
||||
void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkSamplingOptions&,
|
||||
const SkPaint* paint) override;
|
||||
bool onDraw(sk_sp<const SkDeferredDisplayList>, SkIPoint offset) override;
|
||||
|
||||
SkGpuDevice* getDevice() { return fDevice.get(); }
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
sk_sp<SkSurface> onNewSurface(const SkImageInfo&) override;
|
||||
sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subset) override;
|
||||
void onWritePixels(const SkPixmap&, int x, int y) override;
|
||||
void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) override;
|
||||
void onDraw(SkCanvas*, SkScalar, SkScalar, const SkSamplingOptions&, const SkPaint*) override;
|
||||
void onCopyOnWrite(ContentChangeMode) override;
|
||||
void onRestoreBackingMutability() override;
|
||||
|
||||
@ -83,8 +83,8 @@ sk_sp<SkSurface> SkSurface_Raster::onNewSurface(const SkImageInfo& info) {
|
||||
}
|
||||
|
||||
void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
|
||||
const SkPaint* paint) {
|
||||
canvas->drawBitmap(fBitmap, x, y, paint);
|
||||
const SkSamplingOptions& sampling, const SkPaint* paint) {
|
||||
canvas->drawImage(fBitmap.asImage().get(), x, y, sampling, paint);
|
||||
}
|
||||
|
||||
sk_sp<SkImage> SkSurface_Raster::onNewImageSnapshot(const SkIRect* subset) {
|
||||
|
Loading…
Reference in New Issue
Block a user