Flutter Engine
The Flutter Engine
RectanizerBench.cpp
Go to the documentation of this file.
1/*
2* Copyright 2014 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 <memory>
9
10#include "bench/Benchmark.h"
11#include "include/core/SkSize.h"
13#include "src/base/SkRandom.h"
14
17
18using namespace skgpu;
19
20/**
21 * This bench exercises the GPU backend's Rectanizer classes. It exercises the following
22 * rectanizers:
23 * Pow2 Rectanizer
24 * Skyline Rectanizer
25 * in the following cases:
26 * random rects (e.g., pull-save-layers forward use case)
27 * random power of two rects
28 * small constant sized power of 2 rects (e.g., glyph cache use case)
29 */
30class RectanizerBench : public Benchmark {
31public:
32 inline static constexpr int kWidth = 1024;
33 inline static constexpr int kHeight = 1024;
34
38 };
39
40 enum RectType {
44 };
45
46 RectanizerBench(RectanizerType rectanizerType, RectType rectType)
47 : fName("rectanizer_")
48 , fRectanizerType(rectanizerType)
49 , fRectType(rectType) {
50
51 if (kPow2_RectanizerType == fRectanizerType) {
52 fName.append("pow2_");
53 } else {
54 SkASSERT(kSkyline_RectanizerType == fRectanizerType);
55 fName.append("skyline_");
56 }
57
58 if (kRand_RectType == fRectType) {
59 fName.append("rand");
60 } else if (kRandPow2_RectType == fRectType) {
61 fName.append("rand2");
62 } else {
63 SkASSERT(kSmallPow2_RectType == fRectType);
64 fName.append("sm2");
65 }
66 }
67
68protected:
69 bool isSuitableFor(Backend backend) override {
71 }
72
73 const char* onGetName() override {
74 return fName.c_str();
75 }
76
77 void onDelayedSetup() override {
78 SkASSERT(nullptr == fRectanizer.get());
79
80 if (kPow2_RectanizerType == fRectanizerType) {
81 fRectanizer = std::make_unique<RectanizerPow2>(kWidth, kHeight);
82 } else {
83 SkASSERT(kSkyline_RectanizerType == fRectanizerType);
84 fRectanizer = std::make_unique<RectanizerSkyline>(kWidth, kHeight);
85 }
86 }
87
88 void onDraw(int loops, SkCanvas* canvas) override {
89 SkRandom rand;
90 SkIPoint16 loc;
92
93 for (int i = 0; i < loops; ++i) {
94 if (kRand_RectType == fRectType) {
95 size = SkISize::Make(rand.nextRangeU(1, kWidth / 2),
96 rand.nextRangeU(1, kHeight / 2));
97 } else if (kRandPow2_RectType == fRectType) {
99 GrNextPow2(rand.nextRangeU(1, kHeight / 2)));
100 } else {
101 SkASSERT(kSmallPow2_RectType == fRectType);
102 size = SkISize::Make(128, 128);
103 }
104
105 if (!fRectanizer->addRect(size.fWidth, size.fHeight, &loc)) {
106 // insert failed so clear out the rectanizer and give the
107 // current rect another try
108 fRectanizer->reset();
109 i--;
110 }
111 }
112
113 fRectanizer->reset();
114 }
115
116private:
117 SkString fName;
118 RectanizerType fRectanizerType;
119 RectType fRectType;
120 std::unique_ptr<Rectanizer> fRectanizer;
121
122 using INHERITED = Benchmark;
123};
124
125//////////////////////////////////////////////////////////////////////////////
126
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * backend
#define SkASSERT(cond)
Definition: SkAssert.h:116
static uint32_t GrNextPow2(uint32_t n)
Definition: SkMathPriv.h:302
RectanizerBench(RectanizerType rectanizerType, RectType rectType)
void onDraw(int loops, SkCanvas *canvas) override
static constexpr int kHeight
static constexpr int kWidth
const char * onGetName() override
void onDelayedSetup() override
bool isSuitableFor(Backend backend) override
uint32_t nextRangeU(uint32_t min, uint32_t max)
Definition: SkRandom.h:80
void append(const char text[])
Definition: SkString.h:203
const char * c_str() const
Definition: SkString.h:133
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: GpuTools.h:21
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20