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