• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 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 "SkBenchmark.h"
9 #include "SkBitmap.h"
10 #include "SkCanvas.h"
11 #include "SkColorPriv.h"
12 #include "SkPaint.h"
13 #include "SkRandom.h"
14 #include "SkShader.h"
15 #include "SkString.h"
16 #include "SkTArray.h"
17 
18 
19 class LineBench : public SkBenchmark {
20     SkScalar    fStrokeWidth;
21     bool        fDoAA;
22     SkString    fName;
23     enum {
24         PTS = 500,
25         N = SkBENCHLOOP(10)
26     };
27     SkPoint fPts[PTS];
28 
29 public:
LineBench(void * param,SkScalar width,bool doAA)30     LineBench(void* param, SkScalar width, bool doAA) : INHERITED(param) {
31         fStrokeWidth = width;
32         fDoAA = doAA;
33         fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW");
34 
35         SkRandom rand;
36         for (int i = 0; i < PTS; ++i) {
37             fPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
38         }
39     }
40 
41 protected:
onGetName()42     virtual const char* onGetName() SK_OVERRIDE {
43         return fName.c_str();
44     }
45 
onDraw(SkCanvas * canvas)46     virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
47         SkPaint paint;
48         this->setupPaint(&paint);
49 
50         paint.setStyle(SkPaint::kStroke_Style);
51         paint.setAntiAlias(fDoAA);
52         paint.setStrokeWidth(fStrokeWidth);
53 
54         for (int i = 0; i < N; i++) {
55             canvas->drawPoints(SkCanvas::kLines_PointMode, PTS, fPts, paint);
56         }
57     }
58 
59 private:
60     typedef SkBenchmark INHERITED;
61 };
62 
63 DEF_BENCH(return new LineBench(p, 0,            false);)
64 DEF_BENCH(return new LineBench(p, SK_Scalar1,   false);)
65 DEF_BENCH(return new LineBench(p, 0,            true);)
66 DEF_BENCH(return new LineBench(p, SK_Scalar1/2, true);)
67 DEF_BENCH(return new LineBench(p, SK_Scalar1,   true);)
68