blob: 0ed8fc51e3660c60cfaaa110b6f298db7386ad33 [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
8#include "Benchmark.h"
9#include "SkCanvas.h"
10#include "SkPath.h"
11#include "SkString.h"
12
13static void make_path(SkPath& path) {
14 #include "BigPathBench.inc"
15}
16
17enum Align {
18 kLeft_Align,
19 kMiddle_Align,
20 kRight_Align
21};
22
23const char* gAlignName[] = { "left", "middle", "right" };
24
25// Inspired by crbug.com/455429
26class BigPathBench : public Benchmark {
27 SkPath fPath;
28 SkString fName;
29 Align fAlign;
reed70a8ca82015-02-09 08:05:52 -080030 bool fRound;
reed37a47362015-02-06 13:04:16 -080031
32public:
reed70a8ca82015-02-09 08:05:52 -080033 BigPathBench(Align align, bool round) : fAlign(align), fRound(round) {
reed37a47362015-02-06 13:04:16 -080034 fName.printf("bigpath_%s", gAlignName[fAlign]);
reed70a8ca82015-02-09 08:05:52 -080035 if (round) {
36 fName.append("_round");
37 }
reed37a47362015-02-06 13:04:16 -080038 }
39
40protected:
mtklein36352bf2015-03-25 18:17:31 -070041 const char* onGetName() override {
reed37a47362015-02-06 13:04:16 -080042 return fName.c_str();
43 }
44
mtklein36352bf2015-03-25 18:17:31 -070045 SkIPoint onGetSize() override {
reed37a47362015-02-06 13:04:16 -080046 return SkIPoint::Make(640, 100);
47 }
48
joshualitt8a6697a2015-09-30 12:11:07 -070049 void onDelayedSetup() override {
reed37a47362015-02-06 13:04:16 -080050 make_path(fPath);
51 }
52
mtkleina1ebeb22015-10-01 09:43:39 -070053 void onDraw(int loops, SkCanvas* canvas) override {
reed37a47362015-02-06 13:04:16 -080054 SkPaint paint;
55 paint.setAntiAlias(true);
56 paint.setStyle(SkPaint::kStroke_Style);
57 paint.setStrokeWidth(2);
reed70a8ca82015-02-09 08:05:52 -080058 if (fRound) {
59 paint.setStrokeJoin(SkPaint::kRound_Join);
60 }
reed37a47362015-02-06 13:04:16 -080061 this->setupPaint(&paint);
62
63 const SkRect r = fPath.getBounds();
64 switch (fAlign) {
65 case kLeft_Align:
66 canvas->translate(-r.left(), 0);
67 break;
68 case kMiddle_Align:
69 break;
70 case kRight_Align:
71 canvas->translate(640 - r.right(), 0);
72 break;
73 }
74
75 for (int i = 0; i < loops; i++) {
76 canvas->drawPath(fPath, paint);
77 }
78 }
79
80private:
81 typedef Benchmark INHERITED;
82};
83
reed70a8ca82015-02-09 08:05:52 -080084DEF_BENCH( return new BigPathBench(kLeft_Align, false); )
85DEF_BENCH( return new BigPathBench(kMiddle_Align, false); )
86DEF_BENCH( return new BigPathBench(kRight_Align, false); )
87
88DEF_BENCH( return new BigPathBench(kLeft_Align, true); )
89DEF_BENCH( return new BigPathBench(kMiddle_Align, true); )
90DEF_BENCH( return new BigPathBench(kRight_Align, true); )
reed37a47362015-02-06 13:04:16 -080091