2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
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"
16 * This bench measures the rendering time of SkCanvas::drawBitmap with different anti-aliasing /
17 * matrix combinations.
20 class DrawBitmapAABench : public Benchmark {
22 DrawBitmapAABench(bool doAA, const SkMatrix& matrix, const char name[])
24 , fName("draw_bitmap_") {
26 fPaint.setAntiAlias(doAA);
27 fName.appendf("%s_%s", doAA ? "aa" : "noaa", name);
31 const char* onGetName() override {
35 void onDelayedSetup() override {
36 auto surf = SkSurface::MakeRasterN32Premul(200, 200);
37 surf->getCanvas()->clear(0xFF00FF00);
38 fImage = surf->makeImageSnapshot();
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);
53 sk_sp<SkImage> fImage;
55 using INHERITED = Benchmark;
58 DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::I(), "ident"); )
60 DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Scale(1.17f, 1.17f), "scale"); )
62 DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Translate(17.5f, 17.5f), "translate"); )
68 return new DrawBitmapAABench(false, m, "rotate");
71 DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::I(), "ident"); )
73 DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Scale(1.17f, 1.17f), "scale"); )
75 DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Translate(17.5f, 17.5f), "translate"); )
81 return new DrawBitmapAABench(true, m, "rotate");