blob: a2f3ae01338f2c78f2ff34de568d12a1cf656d87 [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"
joshualitt98d2e2f2015-10-05 07:23:30 -070011#include "sk_tool_utils.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
joshualitt8a6697a2015-09-30 12:11:07 -070045 void onDelayedSetup() override {
joshualitt98d2e2f2015-10-05 07:23:30 -070046 sk_tool_utils::make_big_path(fPath);
reed37a47362015-02-06 13:04:16 -080047 }
48
mtkleina1ebeb22015-10-01 09:43:39 -070049 void onDraw(int loops, SkCanvas* canvas) override {
reed37a47362015-02-06 13:04:16 -080050 SkPaint paint;
51 paint.setAntiAlias(true);
52 paint.setStyle(SkPaint::kStroke_Style);
53 paint.setStrokeWidth(2);
reed70a8ca82015-02-09 08:05:52 -080054 if (fRound) {
55 paint.setStrokeJoin(SkPaint::kRound_Join);
56 }
reed37a47362015-02-06 13:04:16 -080057 this->setupPaint(&paint);
58
59 const SkRect r = fPath.getBounds();
60 switch (fAlign) {
61 case kLeft_Align:
62 canvas->translate(-r.left(), 0);
63 break;
64 case kMiddle_Align:
65 break;
66 case kRight_Align:
67 canvas->translate(640 - r.right(), 0);
68 break;
69 }
70
71 for (int i = 0; i < loops; i++) {
72 canvas->drawPath(fPath, paint);
73 }
74 }
75
76private:
77 typedef Benchmark INHERITED;
78};
79
reed70a8ca82015-02-09 08:05:52 -080080DEF_BENCH( return new BigPathBench(kLeft_Align, false); )
81DEF_BENCH( return new BigPathBench(kMiddle_Align, false); )
82DEF_BENCH( return new BigPathBench(kRight_Align, false); )
83
84DEF_BENCH( return new BigPathBench(kLeft_Align, true); )
85DEF_BENCH( return new BigPathBench(kMiddle_Align, true); )
86DEF_BENCH( return new BigPathBench(kRight_Align, true); )