blob: 1738ce71d57d8e41866d790852136ed78c44f544 [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);
25 fName.appendf("%s_%s", doAA ? "aa" : "noaa", name);
26 }
27
28protected:
29 const char* onGetName() override {
30 return fName.c_str();
31 }
32
33 void onPreDraw() override {
34 fBitmap.allocN32Pixels(200, 200);
35 fBitmap.eraseARGB(255, 0, 255, 0);
36 }
37
38 void onDraw(const int loops, SkCanvas* canvas) override {
39 canvas->concat(fMatrix);
40 for (int i = 0; i < loops; i++) {
41 canvas->drawBitmap(fBitmap, 0, 0, &fPaint);
42 }
43 }
44
45private:
46 SkPaint fPaint;
47 SkMatrix fMatrix;
48 SkString fName;
49 SkBitmap fBitmap;
50
51 typedef Benchmark INHERITED;
52};
53
54DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeScale(1), "ident"); )
55
56DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeScale(1.17f), "scale"); )
57
58DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeTrans(17.5f, 17.5f), "translate"); )
59
60DEF_BENCH(
61 SkMatrix m;
62 m.reset();
63 m.preRotate(15);
64 return new DrawBitmapAABench(false, m, "rotate");
65)
66
67DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeScale(1), "ident"); )
68
69DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeScale(1.17f), "scale"); )
70
71DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeTrans(17.5f, 17.5f), "translate"); )
72
73DEF_BENCH(
74 SkMatrix m;
75 m.reset();
76 m.preRotate(15);
77 return new DrawBitmapAABench(true, m, "rotate");
78)