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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
2021-10-13 20:02:56 +00:00
|
|
|
#include "bench/BigPath.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "tools/ToolUtils.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);
|
|
|
|
}
|
|
|
|
|
2021-10-13 20:02:56 +00:00
|
|
|
void onDelayedSetup() override { fPath = BenchUtils::make_big_path(); }
|
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:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2015-02-06 21:04:16 +00:00
|
|
|
};
|
|
|
|
|
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); )
|