2015-07-06 12:25:17 +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"
|
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkString.h"
|
2015-07-06 12:25:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This bench measures the rendering time of SkCanvas::drawBitmap with different anti-aliasing /
|
|
|
|
* matrix combinations.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DrawBitmapAABench : public Benchmark {
|
|
|
|
public:
|
|
|
|
DrawBitmapAABench(bool doAA, const SkMatrix& matrix, const char name[])
|
|
|
|
: fMatrix(matrix)
|
|
|
|
, fName("draw_bitmap_") {
|
|
|
|
|
|
|
|
fPaint.setAntiAlias(doAA);
|
2015-07-06 15:20:15 +00:00
|
|
|
// Most clients use filtering, so let's focus on this for now.
|
|
|
|
fPaint.setFilterQuality(kLow_SkFilterQuality);
|
2015-07-06 12:25:17 +00:00
|
|
|
fName.appendf("%s_%s", doAA ? "aa" : "noaa", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2015-07-06 12:25:17 +00:00
|
|
|
fBitmap.allocN32Pixels(200, 200);
|
|
|
|
fBitmap.eraseARGB(255, 0, 255, 0);
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2015-07-06 12:25:17 +00:00
|
|
|
canvas->concat(fMatrix);
|
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
canvas->drawBitmap(fBitmap, 0, 0, &fPaint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkPaint fPaint;
|
|
|
|
SkMatrix fMatrix;
|
|
|
|
SkString fName;
|
|
|
|
SkBitmap fBitmap;
|
|
|
|
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2020-05-21 16:11:27 +00:00
|
|
|
DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::I(), "ident"); )
|
2015-07-06 12:25:17 +00:00
|
|
|
|
2020-05-21 16:11:27 +00:00
|
|
|
DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Scale(1.17f, 1.17f), "scale"); )
|
2015-07-06 12:25:17 +00:00
|
|
|
|
2020-05-21 16:11:27 +00:00
|
|
|
DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Translate(17.5f, 17.5f), "translate"); )
|
2015-07-06 12:25:17 +00:00
|
|
|
|
|
|
|
DEF_BENCH(
|
|
|
|
SkMatrix m;
|
|
|
|
m.reset();
|
|
|
|
m.preRotate(15);
|
|
|
|
return new DrawBitmapAABench(false, m, "rotate");
|
|
|
|
)
|
|
|
|
|
2020-05-21 16:11:27 +00:00
|
|
|
DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::I(), "ident"); )
|
2015-07-06 12:25:17 +00:00
|
|
|
|
2020-05-21 16:11:27 +00:00
|
|
|
DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Scale(1.17f, 1.17f), "scale"); )
|
2015-07-06 12:25:17 +00:00
|
|
|
|
2020-05-21 16:11:27 +00:00
|
|
|
DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Translate(17.5f, 17.5f), "translate"); )
|
2015-07-06 12:25:17 +00:00
|
|
|
|
|
|
|
DEF_BENCH(
|
|
|
|
SkMatrix m;
|
|
|
|
m.reset();
|
|
|
|
m.preRotate(15);
|
|
|
|
return new DrawBitmapAABench(true, m, "rotate");
|
|
|
|
)
|