Flutter Engine
The Flutter Engine
QuickRejectBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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
8#include "bench/Benchmark.h"
10#include "src/base/SkRandom.h"
11
13 enum { N = 1000000 };
14 float fFloats[N];
15 int fInts [N];
16
17 const char* onGetName() override { return "quick_reject"; }
18 bool isSuitableFor(Backend backend) override { return backend != Backend::kNonRendering; }
19
20 void onDelayedSetup() override {
21 SkRandom rand;
22 for (int i = 0; i < N; ++i) {
23 fFloats[i] = 300.0f * (rand.nextSScalar1() + 0.5f);
24 }
25 }
26
27 void onDraw(int loops, SkCanvas* canvas) override {
28 while (loops --> 0) {
29 for (int i = 0; i < N - 4; i++) {
30 if (canvas->quickReject(*(SkRect*)(fFloats+i))) {
31 fInts[i] = 11;
32 } else {
33 fInts[i] = 24;
34 }
35 }
36 }
37 }
38};
39DEF_BENCH( return new QuickRejectBench; )
40
41class ConcatBench : public Benchmark {
43
44 const char* onGetName() override { return "concat"; }
45 bool isSuitableFor(Backend backend) override { return backend != Backend::kNonRendering; }
46
47 void onDelayedSetup() override {
48 SkRandom r;
49 fMatrix.setScale(5.0f, 5.0f);
52 }
53
54 void onDraw(int loops, SkCanvas* canvas) override {
55 while (loops --> 0) {
56 canvas->setMatrix(SkMatrix::Scale(3, 3));
57 canvas->concat(fMatrix);
58 }
59 }
60};
61DEF_BENCH( return new ConcatBench; )
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * backend
SkMatrix fMatrix
Definition: FillRRectOp.cpp:74
void setMatrix(const SkM44 &matrix)
Definition: SkCanvas.cpp:1349
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
bool quickReject(const SkRect &rect) const
Definition: SkCanvas.cpp:1557
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
SkMatrix & setTranslateY(SkScalar v)
Definition: SkMatrix.h:530
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:296
SkMatrix & setTranslateX(SkScalar v)
Definition: SkMatrix.h:524
SkScalar nextSScalar1()
Definition: SkRandom.h:113