blob: 011c30a1006ecb07c18d0a7384df4334e74da67f [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 */
7#include "Benchmark.h"
8#include "SkCanvas.h"
9#include "SkMatrix.h"
10#include "SkPaint.h"
11#include "SkString.h"
12
13/**
14 * This bench measures the rendering time of SkCanvas::drawBitmap with different anti-aliasing /
15 * matrix combinations.
16 */
17
18class DrawBitmapAABench : public Benchmark {
19public:
20 DrawBitmapAABench(bool doAA, const SkMatrix& matrix, const char name[])
21 : fMatrix(matrix)
22 , fName("draw_bitmap_") {
23
24 fPaint.setAntiAlias(doAA);
fmalitad3901102015-07-06 08:20:15 -070025 // Most clients use filtering, so let's focus on this for now.
26 fPaint.setFilterQuality(kLow_SkFilterQuality);
fmalitaf0ebdd72015-07-06 05:25:17 -070027 fName.appendf("%s_%s", doAA ? "aa" : "noaa", name);
28 }
29
30protected:
31 const char* onGetName() override {
32 return fName.c_str();
33 }
34
joshualitt8a6697a2015-09-30 12:11:07 -070035 void onDelayedSetup() override {
fmalitaf0ebdd72015-07-06 05:25:17 -070036 fBitmap.allocN32Pixels(200, 200);
37 fBitmap.eraseARGB(255, 0, 255, 0);
38 }
39
mtkleina1ebeb22015-10-01 09:43:39 -070040 void onDraw(int loops, SkCanvas* canvas) override {
fmalitaf0ebdd72015-07-06 05:25:17 -070041 canvas->concat(fMatrix);
42 for (int i = 0; i < loops; i++) {
43 canvas->drawBitmap(fBitmap, 0, 0, &fPaint);
44 }
45 }
46
47private:
48 SkPaint fPaint;
49 SkMatrix fMatrix;
50 SkString fName;
51 SkBitmap fBitmap;
52
53 typedef Benchmark INHERITED;
54};
55
56DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeScale(1), "ident"); )
57
58DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeScale(1.17f), "scale"); )
59
60DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeTrans(17.5f, 17.5f), "translate"); )
61
62DEF_BENCH(
63 SkMatrix m;
64 m.reset();
65 m.preRotate(15);
66 return new DrawBitmapAABench(false, m, "rotate");
67)
68
69DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeScale(1), "ident"); )
70
71DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeScale(1.17f), "scale"); )
72
73DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeTrans(17.5f, 17.5f), "translate"); )
74
75DEF_BENCH(
76 SkMatrix m;
77 m.reset();
78 m.preRotate(15);
79 return new DrawBitmapAABench(true, m, "rotate");
80)