2013-11-07 16:06:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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"
|
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColorPriv.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
|
|
|
#include "src/core/SkDraw.h"
|
2020-06-12 19:46:06 +00:00
|
|
|
#include "src/core/SkMatrixProvider.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkRasterClip.h"
|
2013-11-07 16:06:53 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class DrawPathBench : public Benchmark {
|
2013-11-07 16:06:53 +00:00
|
|
|
SkPaint fPaint;
|
|
|
|
SkString fName;
|
|
|
|
SkPath fPath;
|
|
|
|
SkRasterClip fRC;
|
2015-06-09 19:16:53 +00:00
|
|
|
SkAutoPixmapStorage fPixmap;
|
2021-12-09 17:55:27 +00:00
|
|
|
SkMatrixProvider fIdentityMatrixProvider;
|
2013-11-07 16:06:53 +00:00
|
|
|
SkDraw fDraw;
|
|
|
|
bool fDrawCoverage;
|
|
|
|
public:
|
2020-05-08 18:54:37 +00:00
|
|
|
DrawPathBench(bool drawCoverage)
|
|
|
|
: fIdentityMatrixProvider(SkMatrix::I()), fDrawCoverage(drawCoverage) {
|
2013-11-07 16:06:53 +00:00
|
|
|
fPaint.setAntiAlias(true);
|
|
|
|
fName.printf("draw_coverage_%s", drawCoverage ? "true" : "false");
|
|
|
|
|
|
|
|
fPath.moveTo(0, 0);
|
|
|
|
fPath.quadTo(500, 0, 500, 500);
|
|
|
|
fPath.quadTo(250, 0, 0, 500);
|
|
|
|
|
2015-06-09 19:16:53 +00:00
|
|
|
fPixmap.alloc(SkImageInfo::MakeA8(500, 500));
|
2017-01-13 12:59:23 +00:00
|
|
|
if (!drawCoverage) {
|
|
|
|
// drawPathCoverage() goes out of its way to work fine with an uninitialized
|
|
|
|
// dst buffer, even in "SrcOver" mode, but ordinary drawing sure doesn't.
|
|
|
|
fPixmap.erase(0);
|
|
|
|
}
|
2013-11-07 16:06:53 +00:00
|
|
|
|
|
|
|
fRC.setRect(fPath.getBounds().round());
|
|
|
|
|
2020-05-08 18:54:37 +00:00
|
|
|
fDraw.fDst = fPixmap;
|
|
|
|
fDraw.fMatrixProvider = &fIdentityMatrixProvider;
|
|
|
|
fDraw.fRC = &fRC;
|
2013-11-07 16:06:53 +00:00
|
|
|
}
|
2013-11-08 07:01:56 +00:00
|
|
|
|
2013-11-07 16:06:53 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-11-07 16:06:53 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
2013-11-08 07:01:56 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2013-11-07 16:06:53 +00:00
|
|
|
if (fDrawCoverage) {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-11-07 16:06:53 +00:00
|
|
|
fDraw.drawPathCoverage(fPath, fPaint);
|
|
|
|
}
|
|
|
|
} else {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-11-07 16:06:53 +00:00
|
|
|
fDraw.drawPath(fPath, fPaint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-08 07:01:56 +00:00
|
|
|
|
2013-11-07 16:06:53 +00:00
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2013-11-07 16:06:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_BENCH( return new DrawPathBench(false) )
|
|
|
|
DEF_BENCH( return new DrawPathBench(true) )
|