From d94abc5330a9332ca7bdb98f20d3d3b085bf623b Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Mon, 6 Mar 2017 16:37:07 -0500 Subject: [PATCH] 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 Commit-Queue: Mike Reed --- gm/surface.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gm/surface.cpp b/gm/surface.cpp index 6323c70..9c47b4b 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 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 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); +} -- 2.7.4