Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 enum {
51 W = 640,
52 H = 480,
53 N = 300,
54 };
55 SkRect fRects[N];
56 SkColor fColors[N];
57 bool fInit;
58
59 using INHERITED = Benchmark;
60};
61
62DEF_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
void onDelayedSetup() override
void onDraw(int loops, SkCanvas *canvas) override
void drawRect(const SkRect &rect, const SkPaint &paint)
uint32_t nextU()
Definition SkRandom.h:42
SkScalar nextUScalar1()
Definition SkRandom.h:101
const Paint & paint
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