• 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 "Benchmark.h"
9 #include "SkCanvas.h"
10 #include "SkPath.h"
11 #include "SkString.h"
12 
make_path(SkPath & path)13 static void make_path(SkPath& path) {
14     #include "BigPathBench.inc"
15 }
16 
17 enum Align {
18     kLeft_Align,
19     kMiddle_Align,
20     kRight_Align
21 };
22 
23 const char* gAlignName[] = { "left", "middle", "right" };
24 
25 // Inspired by crbug.com/455429
26 class BigPathBench : public Benchmark {
27     SkPath      fPath;
28     SkString    fName;
29     Align       fAlign;
30     bool        fRound;
31 
32 public:
BigPathBench(Align align,bool round)33     BigPathBench(Align align, bool round) : fAlign(align), fRound(round) {
34         fName.printf("bigpath_%s", gAlignName[fAlign]);
35         if (round) {
36             fName.append("_round");
37         }
38     }
39 
40 protected:
onGetName()41     const char* onGetName() override {
42         return fName.c_str();
43     }
44 
onGetSize()45     SkIPoint onGetSize() override {
46         return SkIPoint::Make(640, 100);
47     }
48 
onPreDraw()49     void onPreDraw() override {
50         make_path(fPath);
51     }
52 
onDraw(const int loops,SkCanvas * canvas)53     void onDraw(const int loops, SkCanvas* canvas) override {
54         SkPaint paint;
55         paint.setAntiAlias(true);
56         paint.setStyle(SkPaint::kStroke_Style);
57         paint.setStrokeWidth(2);
58         if (fRound) {
59             paint.setStrokeJoin(SkPaint::kRound_Join);
60         }
61         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 
80 private:
81     typedef Benchmark INHERITED;
82 };
83 
84 DEF_BENCH( return new BigPathBench(kLeft_Align,     false); )
85 DEF_BENCH( return new BigPathBench(kMiddle_Align,   false); )
86 DEF_BENCH( return new BigPathBench(kRight_Align,    false); )
87 
88 DEF_BENCH( return new BigPathBench(kLeft_Align,     true); )
89 DEF_BENCH( return new BigPathBench(kMiddle_Align,   true); )
90 DEF_BENCH( return new BigPathBench(kRight_Align,    true); )
91 
92