2017-01-14 18:45:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
|
2017-01-17 15:48:52 +00:00
|
|
|
// 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;
|
2017-01-14 18:45:02 +00:00
|
|
|
SkRect rect = SkRect::MakeLTRB(l, t, r, b);
|
2017-01-17 15:48:52 +00:00
|
|
|
canvas->saveLayer({ &rect, nullptr, nullptr, kSecretDeprecated_DontClipToLayerFlag });
|
2017-01-14 18:45:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
SkRandom rand;
|
|
|
|
|
|
|
|
for (int i = 0; i < 20; ++i) {
|
|
|
|
paint.setColor(rand.nextU() | (0xFF << 24));
|
|
|
|
canvas->drawRect({ 15, 15, 290, 40 }, paint);
|
|
|
|
canvas->translate(0, 30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-17 15:48:52 +00:00
|
|
|
class UnclippedSaveLayerGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
enum class Mode {
|
|
|
|
kClipped,
|
|
|
|
kUnclipped
|
|
|
|
};
|
|
|
|
|
|
|
|
UnclippedSaveLayerGM(Mode mode) : fMode(mode) { this->setBGColor(SK_ColorWHITE); }
|
2017-01-14 18:45:02 +00:00
|
|
|
|
2017-01-17 15:48:52 +00:00
|
|
|
protected:
|
|
|
|
bool runAsBench() const override { return true; }
|
2017-01-14 18:45:02 +00:00
|
|
|
|
2017-01-17 15:48:52 +00:00
|
|
|
SkString onShortName() override {
|
|
|
|
if (Mode::kClipped == fMode) {
|
|
|
|
return SkString("savelayer_unclipped");
|
|
|
|
} else {
|
|
|
|
SkASSERT(Mode::kUnclipped == fMode);
|
|
|
|
return SkString("savelayer_clipped");
|
|
|
|
}
|
2017-01-14 18:45:02 +00:00
|
|
|
}
|
2017-01-17 15:48:52 +00:00
|
|
|
|
|
|
|
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);)
|
|
|
|
|
|
|
|
|