Flutter Engine
The Flutter Engine
GrQuadBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
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"
9#include "src/base/SkRandom.h"
12
14public:
15 GrQuadBoundsBench(bool perspective)
16 : fPerspective(perspective) {
17 fName.printf("grquad_bounds_%s", perspective ? "3d" : "2d");
18 }
19
20 bool isSuitableFor(Backend backend) override {
22 }
23
24protected:
25 inline static constexpr int kQuadCount = 1000;
26
27 const char* onGetName() override {
28 return fName.c_str();
29 }
30
31 void onDelayedSetup() override {
32 SkRandom r;
33 for (int i = 0; i < kQuadCount; ++i) {
34 for (int j = 0; j < 4; ++j) {
35 fQuads[i].xs()[j] = r.nextRangeF(-100.f, 100.f);
36 fQuads[i].ys()[j] = r.nextRangeF(-100.f, 100.f);
37 if (fPerspective) {
38 // Biased towards in front of the viewpoint, but do include some that require
39 // the vertices to be clipped against w = 0.
40 fQuads[i].ws()[j] = r.nextRangeF(-1.f, 10.f);
41 } else {
42 fQuads[i].ws()[j] = 1.f;
43 }
44 }
47 }
48 }
49
50 void onDraw(int loops, SkCanvas*) override {
51 SkScalar area = 0.f;
52 for (int i = 0; i < loops; ++i) {
53 for (int j = 0; j < kQuadCount; ++j) {
54 SkRect qb = fQuads[j].bounds();
55 area += qb.width() + qb.height();
56 }
57 }
58 // Must persist this calculation in order to prevent the compiler from optimizing the
59 // loops away.
60 fArea = area;
61 }
62
67
69};
70
71///////////////////////////////////////////////////////////////////////////////////////////////////
72
73DEF_BENCH( return new GrQuadBoundsBench(/* persp */ false); )
74DEF_BENCH( return new GrQuadBoundsBench(/* persp */ true); )
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * backend
bool isSuitableFor(Backend backend) override
Definition: GrQuadBench.cpp:20
void onDraw(int loops, SkCanvas *) override
Definition: GrQuadBench.cpp:50
const char * onGetName() override
Definition: GrQuadBench.cpp:27
static constexpr int kQuadCount
Definition: GrQuadBench.cpp:25
GrQuad fQuads[kQuadCount]
Definition: GrQuadBench.cpp:65
GrQuadBoundsBench(bool perspective)
Definition: GrQuadBench.cpp:15
void onDelayedSetup() override
Definition: GrQuadBench.cpp:31
Definition: GrQuad.h:30
const float * xs() const
Definition: GrQuad.h:132
const float * ys() const
Definition: GrQuad.h:134
void setQuadType(Type newType)
Definition: GrQuad.h:140
SkRect bounds() const
Definition: GrQuad.h:81
const float * ws() const
Definition: GrQuad.h:136
float nextRangeF(float min, float max)
Definition: SkRandom.h:64
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
const char * c_str() const
Definition: SkString.h:133
float SkScalar
Definition: extension.cpp:12
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762