Revert[6] "Remove SkDraw from device-draw methods, and enable device-centric clipping.""""""
Previous failure was failure to detect that the clip wasn't wide-open when
optimizing for retain-vs-discard in copy-on-write. gm:copy_on_write_retain
detected this. Now fixed by adding new method to SkBaseDevice.h
This reverts commit 27d07f0acb85eea4062075dfbe9148ce12d92c66.
BUG=skia:6214
Change-Id: I532d16ec075a4525c2a550b1157bcec695dd8efd
Reviewed-on: https://skia-review.googlesource.com/9341
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/gm/surface.cpp b/gm/surface.cpp
index 9c47b4b..baa84eb 100644
--- a/gm/surface.cpp
+++ b/gm/surface.cpp
@@ -169,3 +169,28 @@
// expect to see two rects: blue | red
canvas->drawImage(surf->makeImageSnapshot(), 0, 0, nullptr);
}
+
+DEF_SIMPLE_GM(copy_on_write_savelayer, canvas, 256, 256) {
+ const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256);
+ sk_sp<SkSurface> surf = canvas->makeSurface(info, nullptr);
+ if (!surf) {
+ surf = SkSurface::MakeRaster(info, nullptr);
+ }
+
+ surf->getCanvas()->clear(SK_ColorRED);
+ // its important that image survives longer than the next draw, so the surface will see
+ // an outstanding image, and have to decide if it should retain or discard those pixels
+ sk_sp<SkImage> image = surf->makeImageSnapshot();
+
+ // now draw into a full-screen layer. This should (a) trigger a copy-on-write, but it should
+ // not trigger discard, even tho its alpha (SK_ColorBLUE) is opaque, since it is in a layer
+ // with a non-opaque paint.
+ SkPaint paint;
+ paint.setAlpha(0x40);
+ surf->getCanvas()->saveLayer({0, 0, 256, 256}, &paint);
+ surf->getCanvas()->clear(SK_ColorBLUE);
+ surf->getCanvas()->restore();
+
+ // expect to see two rects: blue blended on red
+ canvas->drawImage(surf->makeImageSnapshot(), 0, 0, nullptr);
+}