blob: e57ecd9c66457cb47f71d1f832ee6edc03410076 [file] [log] [blame]
fmalitaf0ebdd72015-07-06 05:25:17 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "bench/Benchmark.h"
8#include "include/core/SkBitmap.h"
9#include "include/core/SkCanvas.h"
10#include "include/core/SkMatrix.h"
11#include "include/core/SkPaint.h"
12#include "include/core/SkString.h"
fmalitaf0ebdd72015-07-06 05:25:17 -070013
14/**
15 * This bench measures the rendering time of SkCanvas::drawBitmap with different anti-aliasing /
16 * matrix combinations.
17 */
18
19class DrawBitmapAABench : public Benchmark {
20public:
21 DrawBitmapAABench(bool doAA, const SkMatrix& matrix, const char name[])
22 : fMatrix(matrix)
23 , fName("draw_bitmap_") {
24
25 fPaint.setAntiAlias(doAA);
fmalitad3901102015-07-06 08:20:15 -070026 // Most clients use filtering, so let's focus on this for now.
27 fPaint.setFilterQuality(kLow_SkFilterQuality);
fmalitaf0ebdd72015-07-06 05:25:17 -070028 fName.appendf("%s_%s", doAA ? "aa" : "noaa", name);
29 }
30
31protected:
32 const char* onGetName() override {
33 return fName.c_str();
34 }
35
joshualitt8a6697a2015-09-30 12:11:07 -070036 void onDelayedSetup() override {
fmalitaf0ebdd72015-07-06 05:25:17 -070037 fBitmap.allocN32Pixels(200, 200);
38 fBitmap.eraseARGB(255, 0, 255, 0);
39 }
40
mtkleina1ebeb22015-10-01 09:43:39 -070041 void onDraw(int loops, SkCanvas* canvas) override {
fmalitaf0ebdd72015-07-06 05:25:17 -070042 canvas->concat(fMatrix);
43 for (int i = 0; i < loops; i++) {
44 canvas->drawBitmap(fBitmap, 0, 0, &fPaint);
45 }
46 }
47
48private:
49 SkPaint fPaint;
50 SkMatrix fMatrix;
51 SkString fName;
52 SkBitmap fBitmap;
53
54 typedef Benchmark INHERITED;
55};
56
Mike Reed1f607332020-05-21 12:11:27 -040057DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::I(), "ident"); )
fmalitaf0ebdd72015-07-06 05:25:17 -070058
Mike Reed1f607332020-05-21 12:11:27 -040059DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Scale(1.17f, 1.17f), "scale"); )
fmalitaf0ebdd72015-07-06 05:25:17 -070060
Mike Reed1f607332020-05-21 12:11:27 -040061DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Translate(17.5f, 17.5f), "translate"); )
fmalitaf0ebdd72015-07-06 05:25:17 -070062
63DEF_BENCH(
64 SkMatrix m;
65 m.reset();
66 m.preRotate(15);
67 return new DrawBitmapAABench(false, m, "rotate");
68)
69
Mike Reed1f607332020-05-21 12:11:27 -040070DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::I(), "ident"); )
fmalitaf0ebdd72015-07-06 05:25:17 -070071
Mike Reed1f607332020-05-21 12:11:27 -040072DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Scale(1.17f, 1.17f), "scale"); )
fmalitaf0ebdd72015-07-06 05:25:17 -070073
Mike Reed1f607332020-05-21 12:11:27 -040074DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Translate(17.5f, 17.5f), "translate"); )
fmalitaf0ebdd72015-07-06 05:25:17 -070075
76DEF_BENCH(
77 SkMatrix m;
78 m.reset();
79 m.preRotate(15);
80 return new DrawBitmapAABench(true, m, "rotate");
81)