Flutter Engine
The Flutter Engine
FSRectBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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"
11#include "src/base/SkRandom.h"
12
13/**
14 * Draws full screen opaque rectangles. It is designed to test any optimizations in the GPU backend
15 * to turn such draws into clears.
16 */
17class FSRectBench : public Benchmark {
18public:
19 FSRectBench() : fInit(false) { }
20
21protected:
22 const char* onGetName() override { return "fullscreen_rects"; }
23
24 void onDelayedSetup() override {
25 if (!fInit) {
26 SkRandom rand;
27 static const SkScalar kMinOffset = 0;
28 static const SkScalar kMaxOffset = 100 * SK_Scalar1;
29 static const SkScalar kOffsetRange = kMaxOffset - kMinOffset;
30 for (int i = 0; i < N; ++i) {
31 fRects[i].fLeft = -kMinOffset - rand.nextUScalar1() * kOffsetRange;
32 fRects[i].fTop = -kMinOffset - rand.nextUScalar1() * kOffsetRange;
33 fRects[i].fRight = W + kMinOffset + rand.nextUScalar1() * kOffsetRange;
34 fRects[i].fBottom = H + kMinOffset + rand.nextUScalar1() * kOffsetRange;
35 fColors[i] = rand.nextU() | 0xFF000000;
36 }
37 fInit = true;
38 }
39 }
40
41 void onDraw(int loops, SkCanvas* canvas) override {
43 for (int i = 0; i < loops; ++i) {
44 paint.setColor(fColors[i % N]);
45 canvas->drawRect(fRects[i % N], paint);
46 }
47 }
48
49private:
50 static constexpr int W = 640;
51 static constexpr int H = 480;
52 static constexpr int N = 300;
53
54 SkRect fRects[N];
55 SkColor fColors[N];
56 bool fInit;
57
58 using INHERITED = Benchmark;
59};
60
61DEF_BENCH(return new FSRectBench();)
#define DEF_BENCH(code)
Definition: Benchmark.h:20
uint32_t SkColor
Definition: SkColor.h:37
#define SK_Scalar1
Definition: SkScalar.h:18
#define N
Definition: beziers.cpp:19
const char * onGetName() override
Definition: FSRectBench.cpp:22
void onDelayedSetup() override
Definition: FSRectBench.cpp:24
void onDraw(int loops, SkCanvas *canvas) override
Definition: FSRectBench.cpp:41
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
uint32_t nextU()
Definition: SkRandom.h:42
SkScalar nextUScalar1()
Definition: SkRandom.h:101
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
Definition: SkMD5.cpp:130
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15