blob: 4207a34cb423246d2b5e962772b879cd949a3f0f [file] [log] [blame]
Michael Ludwig076238f2018-10-08 16:37:17 -04001/*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8// This benchmark attempts to measure the time to do a fullscreen clear, an axis-aligned partial
9// clear, and a clear restricted to an axis-aligned rounded rect. The fullscreen and axis-aligned
10// partial clears on the GPU should follow a fast path that maps to backend-specialized clear
11// operations, whereas the rounded-rect clear cannot be.
12
13#include "Benchmark.h"
14#include "SkCanvas.h"
15#include "SkPaint.h"
16#include "SkRect.h"
17#include "SkRRect.h"
18
19class ClearBench : public Benchmark {
20public:
21 enum ClearType {
22 kFull_ClearType,
23 kPartial_ClearType,
24 kComplex_ClearType
25 };
26
27 ClearBench(ClearType type) : fType(type) {}
28
29protected:
30 const char* onGetName() override {
31 switch(fType) {
32 case kFull_ClearType:
33 return "Clear-Full";
34 case kPartial_ClearType:
35 return "Clear-Partial";
36 case kComplex_ClearType:
37 return "Clear-Complex";
38 }
39 SkASSERT(false);
40 return "Unreachable";
41 }
42
43 void onDraw(int loops, SkCanvas* canvas) override {
44 const SkColor color = SK_ColorBLUE;
45 const SkRect partialClip = SkRect::MakeLTRB(50, 50, 400, 400);
46 const SkRRect complexClip = SkRRect::MakeRectXY(partialClip, 15, 15);
47
48 // TODO (michaelludwig): Any benefit to changing the clip geometry?
49 for (int i = 0; i < loops; i++) {
50 canvas->save();
51 switch(fType) {
52 case kPartial_ClearType:
53 canvas->clipRect(partialClip);
54 break;
55 case kComplex_ClearType:
56 canvas->clipRRect(complexClip);
57 break;
58 case kFull_ClearType:
59 // Don't add any extra clipping, since it defaults to the entire "device"
60 break;
61 }
62
63 canvas->clear(color);
64 canvas->restore();
65 }
66 }
67
68private:
69 ClearType fType;
70};
71
72DEF_BENCH( return new ClearBench(ClearBench::kFull_ClearType); )
73DEF_BENCH( return new ClearBench(ClearBench::kPartial_ClearType); )
74DEF_BENCH( return new ClearBench(ClearBench::kComplex_ClearType); )