| 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 "bench/Benchmark.h" |
| 8 |
#include "include/core/SkCanvas.h" |
| 9 |
#include "include/core/SkImage.h" |
| 10 |
#include "include/core/SkMatrix.h" |
| 11 |
#include "include/core/SkPaint.h" |
| 12 |
#include "include/core/SkString.h" |
| 13 |
#include "include/core/SkSurface.h" |
| 14 |
|
| 15 |
/** |
| 16 |
* This bench measures the rendering time of SkCanvas::drawBitmap with different anti-aliasing / |
| 17 |
* matrix combinations. |
| 18 |
*/ |
| 19 |
|
| 20 |
class DrawBitmapAABench : public Benchmark { |
| 21 |
public: |
| 22 |
DrawBitmapAABench(bool doAA, const SkMatrix& matrix, const char name[]) |
| 23 |
: fMatrix(matrix) |
| 24 |
, fName("draw_bitmap_") { |
| 25 |
|
| 26 |
fPaint.setAntiAlias(doAA); |
| 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 |
|
| 35 |
void onDelayedSetup() override { |
| 36 |
auto surf = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(200, 200)); |
| 37 |
surf->getCanvas()->clear(0xFF00FF00); |
| 38 |
fImage = surf->makeImageSnapshot(); |
| 39 |
} |
| 40 |
|
| 41 |
void onDraw(int loops, SkCanvas* canvas) override { |
| 42 |
SkSamplingOptions sampling(SkFilterMode::kLinear); |
| 43 |
canvas->concat(fMatrix); |
| 44 |
for (int i = 0; i < loops; i++) { |
| 45 |
canvas->drawImage(fImage.get(), 0, 0, sampling, &fPaint); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
private: |
| 50 |
SkPaint fPaint; |
| 51 |
SkMatrix fMatrix; |
| 52 |
SkString fName; |
| 53 |
sk_sp<SkImage> fImage; |
| 54 |
|
| 55 |
using INHERITED = Benchmark; |
| 56 |
}; |
| 57 |
|
| 58 |
DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::I(), "ident"); ) |
| 59 |
|
| 60 |
DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Scale(1.17f, 1.17f), "scale"); ) |
| 61 |
|
| 62 |
DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Translate(17.5f, 17.5f), "translate"); ) |
| 63 |
|
| 64 |
DEF_BENCH( |
| 65 |
SkMatrix m; |
| 66 |
m.reset(); |
| 67 |
m.preRotate(15); |
| 68 |
return new DrawBitmapAABench(false, m, "rotate"); |
| 69 |
) |
| 70 |
|
| 71 |
DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::I(), "ident"); ) |
| 72 |
|
| 73 |
DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Scale(1.17f, 1.17f), "scale"); ) |
| 74 |
|
| 75 |
DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Translate(17.5f, 17.5f), "translate"); ) |
| 76 |
|
| 77 |
DEF_BENCH( |
| 78 |
SkMatrix m; |
| 79 |
m.reset(); |
| 80 |
m.preRotate(15); |
| 81 |
return new DrawBitmapAABench(true, m, "rotate"); |
| 82 |
) |