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