* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "bench/Benchmark.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRRect.h"
#include "include/core/SkRect.h"
#include "include/effects/SkGradientShader.h"
#include "src/gpu/GrRenderTargetContext.h"
static sk_sp<SkShader> make_shader() {
static const SkPoint kPts[] = {{0, 0}, {10, 10}};
static const SkColor kColors[] = {SK_ColorBLUE, SK_ColorWHITE};
return SkGradientShader::MakeLinear(kPts, kColors, nullptr, 2, SkTileMode::kClamp);
}
class ClearBench : public Benchmark {
public:
enum ClearType {
kFull_ClearType,
kPartial_ClearType,
kComplex_ClearType
};
ClearBench(ClearType type) : fType(type) {}
protected:
const char* onGetName() override {
switch(fType) {
case kFull_ClearType:
return "Clear-Full";
case kPartial_ClearType:
return "Clear-Partial";
case kComplex_ClearType:
return "Clear-Complex";
}
SkASSERT(false);
return "Unreachable";
}
void onDraw(int loops, SkCanvas* canvas) override {
static const SkRect kPartialClip = SkRect::MakeLTRB(50, 50, 400, 400);
static const SkRRect kComplexClip = SkRRect::MakeRectXY(kPartialClip, 15, 15);
static const SkRect kInterruptRect = SkRect::MakeXYWH(200, 200, 3, 3);
SkPaint interruptPaint;
interruptPaint.setShader(make_shader());
GrRenderTargetContext* rtc = canvas->internal_private_accessTopLayerRenderTargetContext();
if (rtc) {
rtc->testingOnly_SetPreserveOpsOnFullClear();
}
for (int i = 0; i < loops; i++) {
canvas->save();
switch(fType) {
case kPartial_ClearType:
canvas->clipRect(kPartialClip);
break;
case kComplex_ClearType:
canvas->clipRRect(kComplexClip);
break;
case kFull_ClearType:
break;
}
canvas->clear(SK_ColorBLUE);
canvas->restore();
canvas->drawRect(kInterruptRect, interruptPaint);
}
}
private:
ClearType fType;
};
DEF_BENCH( return new ClearBench(ClearBench::kFull_ClearType); )
DEF_BENCH( return new ClearBench(ClearBench::kPartial_ClearType); )
DEF_BENCH( return new ClearBench(ClearBench::kComplex_ClearType); )