diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-25 17:32:10 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-25 17:32:10 +0000 |
commit | 1ca015bd5911987ab10fa81f168a5cf3b582f2dd (patch) | |
tree | fcac962a4acdaa90518b2d0f2b776a43b11a559e /bench/LineBench.cpp | |
parent | 49a5b1967ac5bbc6699bee9a2c66088c42aef6fd (diff) |
add bench for hairlines
git-svn-id: http://skia.googlecode.com/svn/trunk@6118 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench/LineBench.cpp')
-rw-r--r-- | bench/LineBench.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/bench/LineBench.cpp b/bench/LineBench.cpp new file mode 100644 index 0000000000..feaae2b267 --- /dev/null +++ b/bench/LineBench.cpp @@ -0,0 +1,67 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkBenchmark.h" +#include "SkBitmap.h" +#include "SkCanvas.h" +#include "SkColorPriv.h" +#include "SkPaint.h" +#include "SkRandom.h" +#include "SkShader.h" +#include "SkString.h" +#include "SkTArray.h" + + +class LineBench : public SkBenchmark { + SkScalar fStrokeWidth; + bool fDoAA; + SkString fName; + enum { + PTS = 500, + N = SkBENCHLOOP(10) + }; + SkPoint fPts[PTS]; + +public: + LineBench(void* param, SkScalar width, bool doAA) : INHERITED(param) { + fStrokeWidth = width; + fDoAA = doAA; + fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW"); + + SkRandom rand; + for (int i = 0; i < PTS; ++i) { + fPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); + } + } + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return fName.c_str(); + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + SkPaint paint; + this->setupPaint(&paint); + + paint.setStyle(SkPaint::kStroke_Style); + paint.setAntiAlias(fDoAA); + paint.setStrokeWidth(fStrokeWidth); + + for (int i = 0; i < N; i++) { + canvas->drawPoints(SkCanvas::kLines_PointMode, PTS, fPts, paint); + } + } + +private: + typedef SkBenchmark INHERITED; +}; + +DEF_BENCH(return new LineBench(p, 0, false);) +DEF_BENCH(return new LineBench(p, SK_Scalar1, false);) +DEF_BENCH(return new LineBench(p, 0, true);) +DEF_BENCH(return new LineBench(p, SK_Scalar1/2, true);) +DEF_BENCH(return new LineBench(p, SK_Scalar1, true);) |