Flutter Engine
The Flutter Engine
DrawBitmapAABench.cpp
Go to the documentation of this file.
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"
14
15/**
16 * This bench measures the rendering time of SkCanvas::drawBitmap with different anti-aliasing /
17 * matrix combinations.
18 */
19
21public:
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
30protected:
31 const char* onGetName() override {
32 return fName.c_str();
33 }
34
35 void onDelayedSetup() override {
37 surf->getCanvas()->clear(0xFF00FF00);
38 fImage = surf->makeImageSnapshot();
39 }
40
41 void onDraw(int loops, SkCanvas* canvas) override {
43 canvas->concat(fMatrix);
44 for (int i = 0; i < loops; i++) {
45 canvas->drawImage(fImage.get(), 0, 0, sampling, &fPaint);
46 }
47 }
48
49private:
50 SkPaint fPaint;
51 SkMatrix fMatrix;
52 SkString fName;
53 sk_sp<SkImage> fImage;
54
55 using INHERITED = Benchmark;
56};
57
58DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::I(), "ident"); )
59
60DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Scale(1.17f, 1.17f), "scale"); )
61
62DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::Translate(17.5f, 17.5f), "translate"); )
63
65 SkMatrix m;
66 m.reset();
67 m.preRotate(15);
68 return new DrawBitmapAABench(false, m, "rotate");
69)
70
71DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::I(), "ident"); )
72
73DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Scale(1.17f, 1.17f), "scale"); )
74
75DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::Translate(17.5f, 17.5f), "translate"); )
76
78 SkMatrix m;
79 m.reset();
80 m.preRotate(15);
81 return new DrawBitmapAABench(true, m, "rotate");
82)
DEF_BENCH(return new DrawBitmapAABench(false, SkMatrix::I(), "ident");) DEF_BENCH(return new DrawBitmapAABench(false
return new DrawBitmapAABench(false, m, "rotate")
DrawBitmapAABench(bool doAA, const SkMatrix &matrix, const char name[])
void onDelayedSetup() override
const char * onGetName() override
void onDraw(int loops, SkCanvas *canvas) override
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
const char * c_str() const
Definition: SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
T * get() const
Definition: SkRefCnt.h:303
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
SkSamplingOptions sampling
Definition: SkRecords.h:337
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
static SkImageInfo MakeN32Premul(int width, int height)