diff options
author | Robert Phillips <robertphillips@google.com> | 2017-01-17 10:48:52 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-18 18:35:11 +0000 |
commit | 42f3094c9071c62b5e42c84a3d1b7b8bcd34e6ed (patch) | |
tree | c53930d7d3f69e9f197c721df323a6f8678e0645 /gm | |
parent | ccfd1083a7b9d546735ddd1037f3240635cce72d (diff) |
saveLayer experiments
Change-Id: Ic4f916cf3483244d5a79e32dc287a01dac41a650
Reviewed-on: https://skia-review.googlesource.com/7106
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'gm')
-rw-r--r-- | gm/savelayer.cpp | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/gm/savelayer.cpp b/gm/savelayer.cpp index 9b4db3530b..8f2d5c8299 100644 --- a/gm/savelayer.cpp +++ b/gm/savelayer.cpp @@ -7,17 +7,20 @@ #include "gm.h" -static void saveLayer(SkCanvas* canvas, SkScalar l, SkScalar t, SkScalar r, SkScalar b) { - uint32_t flag = 1U << 31; +// This GM tests out the deprecated Android-specific unclipped saveLayer "feature". +// In particular, it attempts to compare the performance of unclipped saveLayers with alternatives. + +static void save_layer_unclipped(SkCanvas* canvas, + SkScalar l, SkScalar t, SkScalar r, SkScalar b) { + static const uint32_t kSecretDeprecated_DontClipToLayerFlag = 1U << 31; SkRect rect = SkRect::MakeLTRB(l, t, r, b); - canvas->saveLayer({ &rect, nullptr, nullptr, flag }); + canvas->saveLayer({ &rect, nullptr, nullptr, kSecretDeprecated_DontClipToLayerFlag }); } static void do_draw(SkCanvas* canvas) { SkPaint paint; SkRandom rand; - SkAutoCanvasRestore acr(canvas, true); for (int i = 0; i < 20; ++i) { paint.setColor(rand.nextU() | (0xFF << 24)); canvas->drawRect({ 15, 15, 290, 40 }, paint); @@ -25,18 +28,60 @@ static void do_draw(SkCanvas* canvas) { } } -DEF_SIMPLE_GM(savelayer_unclipped, canvas, 320, 640) { - const SkScalar L = 10; - const SkScalar T = 10; - const SkScalar R = 310; - const SkScalar B = 630; +class UnclippedSaveLayerGM : public skiagm::GM { +public: + enum class Mode { + kClipped, + kUnclipped + }; + + UnclippedSaveLayerGM(Mode mode) : fMode(mode) { this->setBGColor(SK_ColorWHITE); } - canvas->clipRect({ L, T, R, B }); +protected: + bool runAsBench() const override { return true; } - for (int i = 0; i < 100; ++i) { - SkAutoCanvasRestore acr(canvas, true); - saveLayer(canvas, L, T, R, T + 20); - saveLayer(canvas, L, B - 20, R, B); - do_draw(canvas); + SkString onShortName() override { + if (Mode::kClipped == fMode) { + return SkString("savelayer_unclipped"); + } else { + SkASSERT(Mode::kUnclipped == fMode); + return SkString("savelayer_clipped"); + } } -} + + SkISize onISize() override { return SkISize::Make(320, 640); } + + void onDraw(SkCanvas* canvas) override { + const SkScalar L = 10; + const SkScalar T = 10; + const SkScalar R = 310; + const SkScalar B = 630; + + canvas->clipRect({ L, T, R, B }); + + for (int i = 0; i < 100; ++i) { + SkAutoCanvasRestore acr(canvas, true); + if (Mode::kClipped == fMode) { + save_layer_unclipped(canvas, L, T, R, T + 20); + save_layer_unclipped(canvas, L, B - 20, R, B); + } else { + SkASSERT(Mode::kUnclipped == fMode); + canvas->saveLayer({ L, T, R, B }, nullptr); + } + + do_draw(canvas); + } + } + +private: + Mode fMode; + + typedef skiagm::GM INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +DEF_GM(return new UnclippedSaveLayerGM(UnclippedSaveLayerGM::Mode::kClipped);) +DEF_GM(return new UnclippedSaveLayerGM(UnclippedSaveLayerGM::Mode::kUnclipped);) + + |