2015-02-06 21:04:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Benchmark.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPath.h"
|
2015-10-05 14:23:30 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2015-02-06 21:04:16 +00:00
|
|
|
|
|
|
|
enum Align {
|
|
|
|
kLeft_Align,
|
|
|
|
kMiddle_Align,
|
|
|
|
kRight_Align
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* gAlignName[] = { "left", "middle", "right" };
|
|
|
|
|
|
|
|
// Inspired by crbug.com/455429
|
|
|
|
class BigPathBench : public Benchmark {
|
|
|
|
SkPath fPath;
|
|
|
|
SkString fName;
|
|
|
|
Align fAlign;
|
2015-02-09 16:05:52 +00:00
|
|
|
bool fRound;
|
2015-02-06 21:04:16 +00:00
|
|
|
|
|
|
|
public:
|
2015-02-09 16:05:52 +00:00
|
|
|
BigPathBench(Align align, bool round) : fAlign(align), fRound(round) {
|
2015-02-06 21:04:16 +00:00
|
|
|
fName.printf("bigpath_%s", gAlignName[fAlign]);
|
2015-02-09 16:05:52 +00:00
|
|
|
if (round) {
|
|
|
|
fName.append("_round");
|
|
|
|
}
|
2015-02-06 21:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2015-02-06 21:04:16 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkIPoint onGetSize() override {
|
2015-02-06 21:04:16 +00:00
|
|
|
return SkIPoint::Make(640, 100);
|
|
|
|
}
|
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2015-10-05 14:23:30 +00:00
|
|
|
sk_tool_utils::make_big_path(fPath);
|
2015-02-06 21:04:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2015-02-06 21:04:16 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(2);
|
2015-02-09 16:05:52 +00:00
|
|
|
if (fRound) {
|
|
|
|
paint.setStrokeJoin(SkPaint::kRound_Join);
|
|
|
|
}
|
2015-02-06 21:04:16 +00:00
|
|
|
this->setupPaint(&paint);
|
|
|
|
|
|
|
|
const SkRect r = fPath.getBounds();
|
|
|
|
switch (fAlign) {
|
|
|
|
case kLeft_Align:
|
|
|
|
canvas->translate(-r.left(), 0);
|
|
|
|
break;
|
|
|
|
case kMiddle_Align:
|
|
|
|
break;
|
|
|
|
case kRight_Align:
|
|
|
|
canvas->translate(640 - r.right(), 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
canvas->drawPath(fPath, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-02-09 16:05:52 +00:00
|
|
|
DEF_BENCH( return new BigPathBench(kLeft_Align, false); )
|
|
|
|
DEF_BENCH( return new BigPathBench(kMiddle_Align, false); )
|
|
|
|
DEF_BENCH( return new BigPathBench(kRight_Align, false); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new BigPathBench(kLeft_Align, true); )
|
|
|
|
DEF_BENCH( return new BigPathBench(kMiddle_Align, true); )
|
|
|
|
DEF_BENCH( return new BigPathBench(kRight_Align, true); )
|