diff options
author | Mike Reed <reed@google.com> | 2017-03-07 09:37:29 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-07 15:43:03 +0000 |
commit | a1361364e64138adda3dc5f71d50d7503838bb6d (patch) | |
tree | 13dd723a62883d7bf3e8d280a0a454fae02081a2 /gm/surface.cpp | |
parent | 467921e5e6479fe9cebba125657d8e33d89004ae (diff) |
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>
Diffstat (limited to 'gm/surface.cpp')
-rw-r--r-- | gm/surface.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/gm/surface.cpp b/gm/surface.cpp index 9c47b4badc..baa84ebdc0 100644 --- a/gm/surface.cpp +++ b/gm/surface.cpp @@ -169,3 +169,28 @@ DEF_SIMPLE_GM(copy_on_write_retain, canvas, 256, 256) { // 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); +} |