blob: 02f42037880ff83600879bddf5cb764c5564c076 [file] [log] [blame]
reed37a47362015-02-06 13:04:16 -08001/*
2 * Copyright 2015 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "bench/Benchmark.h"
9#include "include/core/SkCanvas.h"
10#include "include/core/SkPath.h"
11#include "tools/ToolUtils.h"
reed37a47362015-02-06 13:04:16 -080012
13enum Align {
14 kLeft_Align,
15 kMiddle_Align,
16 kRight_Align
17};
18
19const char* gAlignName[] = { "left", "middle", "right" };
20
21// Inspired by crbug.com/455429
22class BigPathBench : public Benchmark {
23 SkPath fPath;
24 SkString fName;
25 Align fAlign;
reed70a8ca82015-02-09 08:05:52 -080026 bool fRound;
reed37a47362015-02-06 13:04:16 -080027
28public:
reed70a8ca82015-02-09 08:05:52 -080029 BigPathBench(Align align, bool round) : fAlign(align), fRound(round) {
reed37a47362015-02-06 13:04:16 -080030 fName.printf("bigpath_%s", gAlignName[fAlign]);
reed70a8ca82015-02-09 08:05:52 -080031 if (round) {
32 fName.append("_round");
33 }
reed37a47362015-02-06 13:04:16 -080034 }
35
36protected:
mtklein36352bf2015-03-25 18:17:31 -070037 const char* onGetName() override {
reed37a47362015-02-06 13:04:16 -080038 return fName.c_str();
39 }
40
mtklein36352bf2015-03-25 18:17:31 -070041 SkIPoint onGetSize() override {
reed37a47362015-02-06 13:04:16 -080042 return SkIPoint::Make(640, 100);
43 }
44
Mike Kleinea3f0142019-03-20 11:12:10 -050045 void onDelayedSetup() override { ToolUtils::make_big_path(fPath); }
reed37a47362015-02-06 13:04:16 -080046
mtkleina1ebeb22015-10-01 09:43:39 -070047 void onDraw(int loops, SkCanvas* canvas) override {
reed37a47362015-02-06 13:04:16 -080048 SkPaint paint;
49 paint.setAntiAlias(true);
50 paint.setStyle(SkPaint::kStroke_Style);
51 paint.setStrokeWidth(2);
reed70a8ca82015-02-09 08:05:52 -080052 if (fRound) {
53 paint.setStrokeJoin(SkPaint::kRound_Join);
54 }
reed37a47362015-02-06 13:04:16 -080055 this->setupPaint(&paint);
56
57 const SkRect r = fPath.getBounds();
58 switch (fAlign) {
59 case kLeft_Align:
60 canvas->translate(-r.left(), 0);
61 break;
62 case kMiddle_Align:
63 break;
64 case kRight_Align:
65 canvas->translate(640 - r.right(), 0);
66 break;
67 }
68
69 for (int i = 0; i < loops; i++) {
70 canvas->drawPath(fPath, paint);
71 }
72 }
73
74private:
75 typedef Benchmark INHERITED;
76};
77
reed70a8ca82015-02-09 08:05:52 -080078DEF_BENCH( return new BigPathBench(kLeft_Align, false); )
79DEF_BENCH( return new BigPathBench(kMiddle_Align, false); )
80DEF_BENCH( return new BigPathBench(kRight_Align, false); )
81
82DEF_BENCH( return new BigPathBench(kLeft_Align, true); )
83DEF_BENCH( return new BigPathBench(kMiddle_Align, true); )
84DEF_BENCH( return new BigPathBench(kRight_Align, true); )