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>
This commit is contained in:
Robert Phillips 2017-01-17 10:48:52 -05:00 committed by Skia Commit-Bot
parent ccfd1083a7
commit 42f3094c90

View File

@ -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
};
canvas->clipRect({ L, T, R, B });
UnclippedSaveLayerGM(Mode mode) : fMode(mode) { this->setBGColor(SK_ColorWHITE); }
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);
protected:
bool runAsBench() const override { return true; }
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);)