Revert "add rect-parameter to makeImageSnapshot"

This reverts commit e195d1c22e.

Reason for revert: broke android subclass (illegal)

Original change's description:
> add rect-parameter to makeImageSnapshot
> 
> Bug: skia:
> Change-Id: I56044fb1f21b959993d69fc587f95e3dbf30c371
> Reviewed-on: https://skia-review.googlesource.com/c/171905
> Commit-Queue: Mike Reed <reed@google.com>
> Auto-Submit: Mike Reed <reed@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>

TBR=djsollen@google.com,egdaniel@google.com,jvanverth@google.com,bsalomon@google.com,reed@google.com

Change-Id: Ied294732b332192e251a845a5cb6349a670c25b0
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/c/172301
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2018-11-21 13:13:29 +00:00 committed by Skia Commit-Bot
parent 302809f47e
commit 1e28e5d79e
7 changed files with 10 additions and 110 deletions

View File

@ -185,62 +185,3 @@ DEF_SIMPLE_GM(copy_on_write_savelayer, canvas, 256, 256) {
// expect to see two rects: blue blended on red
canvas->drawImage(surf->makeImageSnapshot(), 0, 0, nullptr);
}
DEF_SIMPLE_GM(surface_underdraw, canvas, 256, 256) {
SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256, nullptr);
auto surf = sk_tool_utils::makeSurface(canvas, info);
const SkIRect subset = SkIRect::MakeLTRB(180, 0, 256, 256);
// noisy background
{
SkPoint pts[] = {{0, 0}, {40, 50}};
SkColor colors[] = {SK_ColorRED, SK_ColorBLUE};
auto sh = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kRepeat_TileMode);
SkPaint paint;
paint.setShader(sh);
surf->getCanvas()->drawPaint(paint);
}
// save away the right-hand strip, then clear it
sk_sp<SkImage> saveImg = surf->makeImageSnapshot(subset);
{
SkPaint paint;
paint.setBlendMode(SkBlendMode::kClear);
surf->getCanvas()->drawRect(SkRect::Make(subset), paint);
}
// draw the "foreground"
{
SkPaint paint;
paint.setColor(SK_ColorGREEN);
SkRect r = { 0, 10, 256, 35 };
while (r.fBottom < 256) {
surf->getCanvas()->drawRect(r, paint);
r.offset(0, r.height() * 2);
}
}
// apply the "fade"
{
SkPoint pts[] = {{SkIntToScalar(subset.left()), 0}, {SkIntToScalar(subset.right()), 0}};
SkColor colors[] = {0xFF000000, 0};
auto sh = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
SkPaint paint;
paint.setShader(sh);
paint.setBlendMode(SkBlendMode::kDstIn);
surf->getCanvas()->drawRect(SkRect::Make(subset), paint);
}
// restore the original strip, drawing it "under" the current foreground
{
SkPaint paint;
paint.setBlendMode(SkBlendMode::kDstOver);
surf->getCanvas()->drawImage(saveImg,
SkIntToScalar(subset.left()), SkIntToScalar(subset.top()),
&paint);
}
// show it on screen
surf->draw(canvas, 0, 0, nullptr);
}

View File

@ -495,17 +495,6 @@ public:
*/
sk_sp<SkImage> makeImageSnapshot();
/**
* Like the no-parameter version, this returns an image of the current surface contents.
* This variant takes a rectangle specifying the subset of the surface that is of interest.
* These bounds will be sanitized before being used.
* - If bounds extends beyond the surface, it will be trimmed to just the intersection of
* it and the surface.
* - If bounds does not intersect the surface, then this returns nullptr.
* - If bounds == the surface, then this is the same as calling the no-parameter variant.
*/
sk_sp<SkImage> makeImageSnapshot(const SkIRect& bounds);
/** Draws SkSurface contents to canvas, with its top-left corner at (x, y).
If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter,

View File

@ -167,20 +167,6 @@ sk_sp<SkImage> SkSurface::makeImageSnapshot() {
return asSB(this)->refCachedImage();
}
sk_sp<SkImage> SkSurface::makeImageSnapshot(const SkIRect& srcBounds) {
const SkIRect surfBounds = { 0, 0, fWidth, fHeight };
SkIRect bounds = srcBounds;
if (!bounds.intersect(surfBounds)) {
return nullptr;
}
SkASSERT(!bounds.isEmpty());
if (bounds == surfBounds) {
return this->makeImageSnapshot();
} else {
return asSB(this)->onNewImageSnapshot(&bounds);
}
}
sk_sp<SkSurface> SkSurface::makeSurface(const SkImageInfo& info) {
return asSB(this)->onNewSurface(info);
}
@ -279,7 +265,7 @@ protected:
sk_sp<SkSurface> onNewSurface(const SkImageInfo& info) override {
return MakeNull(info.width(), info.height());
}
sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subsetOrNull) override { return nullptr; }
sk_sp<SkImage> onNewImageSnapshot() override { return nullptr; }
void onWritePixels(const SkPixmap&, int x, int y) override {}
void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) override {}
void onCopyOnWrite(ContentChangeMode) override {}

View File

@ -37,11 +37,8 @@ public:
* This needs to be able to outlive the surface itself (if need be), and
* must faithfully represent the current contents, even if the surface
* is changed after this called (e.g. it is drawn to via its canvas).
*
* If a subset is specified, the the impl must make a copy, rather than try to wait
* on copy-on-write.
*/
virtual sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subset = nullptr) = 0;
virtual sk_sp<SkImage> onNewImageSnapshot() = 0;
virtual void onWritePixels(const SkPixmap&, int x, int y) = 0;

View File

@ -83,7 +83,7 @@ sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
origin, &this->props());
}
sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(const SkIRect* subset) {
sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot() {
GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext();
if (!rtc) {
return nullptr;
@ -98,14 +98,10 @@ sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(const SkIRect* subset) {
SkBudgeted budgeted = rtc->asSurfaceProxy()->isBudgeted();
sk_sp<GrTextureProxy> srcProxy = rtc->asTextureProxyRef();
if (subset) {
srcProxy = GrSurfaceProxy::Copy(ctx, rtc->asSurfaceProxy(), rtc->mipMapped(), *subset,
budgeted);
} else if (!srcProxy || rtc->priv().refsWrappedObjects()) {
// If the original render target is a buffer originally created by the client, then we don't
// want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid
// copy-on-write.
// If the original render target is a buffer originally created by the client, then we don't
// want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid
// copy-on-write.
if (!srcProxy || rtc->priv().refsWrappedObjects()) {
SkASSERT(rtc->origin() == rtc->asSurfaceProxy()->origin());
srcProxy = GrSurfaceProxy::Copy(ctx, rtc->asSurfaceProxy(), rtc->mipMapped(), budgeted);

View File

@ -28,7 +28,7 @@ public:
SkCanvas* onNewCanvas() override;
sk_sp<SkSurface> onNewSurface(const SkImageInfo&) override;
sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subset) override;
sk_sp<SkImage> onNewImageSnapshot() override;
void onWritePixels(const SkPixmap&, int x, int y) override;
void onCopyOnWrite(ContentChangeMode) override;
void onDiscard() override;

View File

@ -21,7 +21,7 @@ public:
SkCanvas* onNewCanvas() override;
sk_sp<SkSurface> onNewSurface(const SkImageInfo&) override;
sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subset) override;
sk_sp<SkImage> onNewImageSnapshot() override;
void onWritePixels(const SkPixmap&, int x, int y) override;
void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) override;
void onCopyOnWrite(ContentChangeMode) override;
@ -98,16 +98,7 @@ void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
canvas->drawBitmap(fBitmap, x, y, paint);
}
sk_sp<SkImage> SkSurface_Raster::onNewImageSnapshot(const SkIRect* subset) {
if (subset) {
SkASSERT(SkIRect::MakeWH(fBitmap.width(), fBitmap.height()).contains(*subset));
SkBitmap dst;
dst.allocPixels(fBitmap.info().makeWH(subset->width(), subset->height()));
SkAssertResult(fBitmap.readPixels(dst.pixmap(), subset->left(), subset->top()));
dst.setImmutable(); // key, so MakeFromBitmap doesn't make a copy of the buffer
return SkImage::MakeFromBitmap(dst);
}
sk_sp<SkImage> SkSurface_Raster::onNewImageSnapshot() {
SkCopyPixelsMode cpm = kIfMutable_SkCopyPixelsMode;
if (fWeOwnThePixels) {
// SkImage_raster requires these pixels are immutable for its full lifetime.