aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/surface.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-03-06 16:37:07 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-06 22:15:36 +0000
commitd94abc5330a9332ca7bdb98f20d3d3b085bf623b (patch)
tree558cff9e0fede4dd57f1a7c9d15ef92f44d6f4a0 /gm/surface.cpp
parente9c99b8baac224d7329fe6c0d9c69e3a4dac714f (diff)
add test for copy-on-write optimization
exercises a bug in the device-clip CL (hopefully to land soon) BUG=skia: Change-Id: I5a740280e1a3d6a4634338d04d9f1a1f9dc84dbb Reviewed-on: https://skia-review.googlesource.com/9325 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.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/gm/surface.cpp b/gm/surface.cpp
index 6323c7047b..9c47b4badc 100644
--- a/gm/surface.cpp
+++ b/gm/surface.cpp
@@ -146,3 +146,26 @@ private:
typedef GM INHERITED;
};
DEF_GM( return new NewSurfaceGM )
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+DEF_SIMPLE_GM(copy_on_write_retain, 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();
+
+ // normally a clear+opaque should trigger the discard optimization, but since we have a clip
+ // it should not (we need the previous red pixels).
+ surf->getCanvas()->clipRect(SkRect::MakeWH(128, 256));
+ surf->getCanvas()->clear(SK_ColorBLUE);
+
+ // expect to see two rects: blue | red
+ canvas->drawImage(surf->makeImageSnapshot(), 0, 0, nullptr);
+}