• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "bench/Benchmark.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkPath.h"
11 #include "tools/ToolUtils.h"
12 
13 enum Align {
14     kLeft_Align,
15     kMiddle_Align,
16     kRight_Align
17 };
18 
19 const char* gAlignName[] = { "left", "middle", "right" };
20 
21 // Inspired by crbug.com/455429
22 class BigPathBench : public Benchmark {
23     SkPath      fPath;
24     SkString    fName;
25     Align       fAlign;
26     bool        fRound;
27 
28 public:
BigPathBench(Align align,bool round)29     BigPathBench(Align align, bool round) : fAlign(align), fRound(round) {
30         fName.printf("bigpath_%s", gAlignName[fAlign]);
31         if (round) {
32             fName.append("_round");
33         }
34     }
35 
36 protected:
onGetName()37     const char* onGetName() override {
38         return fName.c_str();
39     }
40 
onGetSize()41     SkIPoint onGetSize() override {
42         return SkIPoint::Make(640, 100);
43     }
44 
onDelayedSetup()45     void onDelayedSetup() override { ToolUtils::make_big_path(fPath); }
46 
onDraw(int loops,SkCanvas * canvas)47     void onDraw(int loops, SkCanvas* canvas) override {
48         SkPaint paint;
49         paint.setAntiAlias(true);
50         paint.setStyle(SkPaint::kStroke_Style);
51         paint.setStrokeWidth(2);
52         if (fRound) {
53             paint.setStrokeJoin(SkPaint::kRound_Join);
54         }
55         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 
74 private:
75     typedef Benchmark INHERITED;
76 };
77 
78 DEF_BENCH( return new BigPathBench(kLeft_Align,     false); )
79 DEF_BENCH( return new BigPathBench(kMiddle_Align,   false); )
80 DEF_BENCH( return new BigPathBench(kRight_Align,    false); )
81 
82 DEF_BENCH( return new BigPathBench(kLeft_Align,     true); )
83 DEF_BENCH( return new BigPathBench(kMiddle_Align,   true); )
84 DEF_BENCH( return new BigPathBench(kRight_Align,    true); )
85