blob: 52a92f7a528115a20acae586b7c44c4f5bc8740e [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
57DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeScale(1), "ident"); )
58
59DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeScale(1.17f), "scale"); )
60
61DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeTrans(17.5f, 17.5f), "translate"); )
62
63DEF_BENCH(
64 SkMatrix m;
65 m.reset();
66 m.preRotate(15);
67 return new DrawBitmapAABench(false, m, "rotate");
68)
69
70DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeScale(1), "ident"); )
71
72DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeScale(1.17f), "scale"); )
73
74DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeTrans(17.5f, 17.5f), "translate"); )
75
76DEF_BENCH(
77 SkMatrix m;
78 m.reset();
79 m.preRotate(15);
80 return new DrawBitmapAABench(true, m, "rotate");
81)