blob: 7c68143623b821fb9fcd42116856c9d57ca83de1 [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 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "bench/Benchmark.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkCanvas.h"
Mike Reed839eef32020-12-23 11:18:24 -05009#include "include/core/SkImage.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkMatrix.h"
11#include "include/core/SkPaint.h"
12#include "include/core/SkString.h"
Mike Reed839eef32020-12-23 11:18:24 -050013#include "include/core/SkSurface.h"
fmalitaf0ebdd72015-07-06 05:25:17 -070014
15/**
16 * This bench measures the rendering time of SkCanvas::drawBitmap with different anti-aliasing /
17 * matrix combinations.
18 */
19
20class DrawBitmapAABench : public Benchmark {
21public:
22 DrawBitmapAABench(bool doAA, const SkMatrix& matrix, const char name[])
23 : fMatrix(matrix)
24 , fName("draw_bitmap_") {
25
26 fPaint.setAntiAlias(doAA);
fmalitaf0ebdd72015-07-06 05:25:17 -070027 fName.appendf("%s_%s", doAA ? "aa" : "noaa", name);
28 }
29
30protected:
31 const char* onGetName() override {
32 return fName.c_str();
33 }
34
joshualitt8a6697a2015-09-30 12:11:07 -070035 void onDelayedSetup() override {
Mike Reed839eef32020-12-23 11:18:24 -050036 auto surf = SkSurface::MakeRasterN32Premul(200, 200);
37 surf->getCanvas()->clear(0xFF00FF00);
38 fImage = surf->makeImageSnapshot();
fmalitaf0ebdd72015-07-06 05:25:17 -070039 }
40
mtkleina1ebeb22015-10-01 09:43:39 -070041 void onDraw(int loops, SkCanvas* canvas) override {
Mike Reed5ec22382021-01-14 21:59:01 -050042 SkSamplingOptions sampling(SkFilterMode::kLinear);
fmalitaf0ebdd72015-07-06 05:25:17 -070043 canvas->concat(fMatrix);
44 for (int i = 0; i < loops; i++) {
Mike Reed839eef32020-12-23 11:18:24 -050045 canvas->drawImage(fImage.get(), 0, 0, sampling, &fPaint);
fmalitaf0ebdd72015-07-06 05:25:17 -070046 }
47 }
48
49private:
50 SkPaint fPaint;
51 SkMatrix fMatrix;
52 SkString fName;
Mike Reed839eef32020-12-23 11:18:24 -050053 sk_sp<SkImage> fImage;
fmalitaf0ebdd72015-07-06 05:25:17 -070054
John Stiles7571f9e2020-09-02 22:42:33 -040055 using INHERITED = Benchmark;
fmalitaf0ebdd72015-07-06 05:25:17 -070056};
57
Mike Reed1f607332020-05-21 12:11:27 -040058DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::I(), "ident"); )
fmalitaf0ebdd72015-07-06 05:25:17 -070059
Mike Reed1f607332020-05-21 12:11:27 -040060DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Scale(1.17f, 1.17f), "scale"); )
fmalitaf0ebdd72015-07-06 05:25:17 -070061
Mike Reed1f607332020-05-21 12:11:27 -040062DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Translate(17.5f, 17.5f), "translate"); )
fmalitaf0ebdd72015-07-06 05:25:17 -070063
64DEF_BENCH(
65 SkMatrix m;
66 m.reset();
67 m.preRotate(15);
68 return new DrawBitmapAABench(false, m, "rotate");
69)
70
Mike Reed1f607332020-05-21 12:11:27 -040071DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::I(), "ident"); )
fmalitaf0ebdd72015-07-06 05:25:17 -070072
Mike Reed1f607332020-05-21 12:11:27 -040073DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Scale(1.17f, 1.17f), "scale"); )
fmalitaf0ebdd72015-07-06 05:25:17 -070074
Mike Reed1f607332020-05-21 12:11:27 -040075DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Translate(17.5f, 17.5f), "translate"); )
fmalitaf0ebdd72015-07-06 05:25:17 -070076
77DEF_BENCH(
78 SkMatrix m;
79 m.reset();
80 m.preRotate(15);
81 return new DrawBitmapAABench(true, m, "rotate");
82)