Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Types | Public Member Functions | Protected Member Functions | List of all members
GameBench Class Reference
Inheritance diagram for GameBench:
Benchmark SkRefCnt SkRefCntBase

Public Types

enum  Type { kScale_Type , kTranslate_Type , kRotate_Type }
 
enum  Clear { kFull_Clear , kPartial_Clear }
 
- Public Types inherited from Benchmark
enum class  Backend {
  kNonRendering , kRaster , kGanesh , kGraphite ,
  kPDF , kHWUI
}
 

Public Member Functions

 GameBench (Type type, Clear clear, bool aligned=false, bool useAtlas=false, bool useDrawVertices=false)
 
- Public Member Functions inherited from Benchmark
 Benchmark ()
 
const char * getName ()
 
const char * getUniqueName ()
 
SkISize getSize ()
 
virtual bool isSuitableFor (Backend backend)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual bool shouldLoop () const
 
void delayedSetup ()
 
void perCanvasPreDraw (SkCanvas *)
 
void perCanvasPostDraw (SkCanvas *)
 
void preDraw (SkCanvas *)
 
void postDraw (SkCanvas *)
 
void draw (int loops, SkCanvas *)
 
virtual void getGpuStats (SkCanvas *, skia_private::TArray< SkString > *keys, skia_private::TArray< double > *values)
 
virtual bool getDMSAAStats (GrRecordingContext *)
 
int getUnits () const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

const char * onGetName () override
 
void onDelayedSetup () override
 
void onDraw (int loops, SkCanvas *canvas) override
 
- Protected Member Functions inherited from Benchmark
void setUnits (int units)
 
virtual void setupPaint (SkPaint *paint)
 
virtual const char * onGetName ()=0
 
virtual const char * onGetUniqueName ()
 
virtual void onDelayedSetup ()
 
virtual void onPerCanvasPreDraw (SkCanvas *)
 
virtual void onPerCanvasPostDraw (SkCanvas *)
 
virtual void onPreDraw (SkCanvas *)
 
virtual void onPostDraw (SkCanvas *)
 
virtual void onDraw (int loops, SkCanvas *)=0
 
virtual SkISize onGetSize ()
 

Detailed Description

Definition at line 21 of file GameBench.cpp.

Member Enumeration Documentation

◆ Clear

Enumerator
kFull_Clear 
kPartial_Clear 

Definition at line 29 of file GameBench.cpp.

29 {
32 };
@ kPartial_Clear
Definition: GameBench.cpp:31

◆ Type

Enumerator
kScale_Type 
kTranslate_Type 
kRotate_Type 

Definition at line 23 of file GameBench.cpp.

23 {
27 };
@ kTranslate_Type
Definition: GameBench.cpp:25
@ kRotate_Type
Definition: GameBench.cpp:26

Constructor & Destructor Documentation

◆ GameBench()

GameBench::GameBench ( Type  type,
Clear  clear,
bool  aligned = false,
bool  useAtlas = false,
bool  useDrawVertices = false 
)
inline

Definition at line 34 of file GameBench.cpp.

37 : fType(type)
38 , fClear(clear)
39 , fAligned(aligned)
40 , fUseAtlas(useAtlas)
41 , fUseDrawVertices(useDrawVertices)
42 , fName("game")
43 , fNumSaved(0)
44 , fInitialized(false) {
45
46 switch (fType) {
47 case kScale_Type:
48 fName.append("_scale");
49 break;
50 case kTranslate_Type:
51 fName.append("_trans");
52 break;
53 case kRotate_Type:
54 fName.append("_rot");
55 break;
56 }
57
58 if (aligned) {
59 fName.append("_aligned");
60 }
61
62 if (kPartial_Clear == clear) {
63 fName.append("_partial");
64 } else {
65 fName.append("_full");
66 }
67
68 if (useAtlas) {
69 fName.append("_atlas");
70 }
71
72 if (useDrawVertices) {
73 fName.append("_drawVerts");
74 }
75
76 // It's HTML 5 canvas, so always AA
77 fName.append("_aa");
78 }
GLenum type
void append(const char text[])
Definition: SkString.h:203

Member Function Documentation

◆ onDelayedSetup()

void GameBench::onDelayedSetup ( )
inlineoverrideprotectedvirtual

Reimplemented from Benchmark.

Definition at line 85 of file GameBench.cpp.

85 {
86 if (!fInitialized) {
87 this->makeCheckerboard();
88 this->makeAtlas();
89 fInitialized = true;
90 }
91 }

◆ onDraw()

void GameBench::onDraw ( int  loops,
SkCanvas canvas 
)
inlineoverrideprotectedvirtual

Implements Benchmark.

Definition at line 93 of file GameBench.cpp.

93 {
94 SkRandom scaleRand;
95 SkRandom transRand;
96 SkRandom rotRand;
97
98 int width, height;
99 if (fUseAtlas) {
100 width = kAtlasCellWidth;
101 height = kAtlasCellHeight;
102 } else {
103 width = kCheckerboardWidth;
104 height = kCheckerboardHeight;
105 }
106
107 SkPaint clearPaint;
108 clearPaint.setColor(0xFF000000);
109 clearPaint.setAntiAlias(true);
110
111 SkISize size = canvas->getBaseLayerSize();
112
113 SkScalar maxTransX, maxTransY;
114
115 if (kScale_Type == fType) {
116 maxTransX = size.fWidth - (1.5f * width);
117 maxTransY = size.fHeight - (1.5f * height);
118 } else if (kTranslate_Type == fType) {
119 maxTransX = SkIntToScalar(size.fWidth - width);
120 maxTransY = SkIntToScalar(size.fHeight - height);
121 } else {
122 SkASSERT(kRotate_Type == fType);
123 // Yes, some rotations will be off the top and left sides
124 maxTransX = size.fWidth - SK_ScalarSqrt2 * height;
125 maxTransY = size.fHeight - SK_ScalarSqrt2 * height;
126 }
127
128 SkMatrix mat;
130 SkRect clearRect = { -1.0f, -1.0f, width+1.0f, height+1.0f };
131 SkPoint verts[4] = { // for drawVertices path
132 { 0, 0 },
133 { 0, SkIntToScalar(height) },
135 { SkIntToScalar(width), 0 }
136 };
137 uint16_t indices[6] = { 0, 1, 2, 0, 2, 3 };
138
139 SkPaint p;
140 p.setColor(0xFF000000);
141
142 SkPaint p2; // for drawVertices path
143 p2.setColor(0xFF000000);
145
146 for (int i = 0; i < loops; ++i, ++fNumSaved) {
147 if (0 == i % kNumBeforeClear) {
148 if (kPartial_Clear == fClear) {
149 for (int j = 0; j < fNumSaved; ++j) {
150 canvas->setMatrix(SkMatrix::I());
151 mat.setTranslate(fSaved[j][0], fSaved[j][1]);
152
153 if (kScale_Type == fType) {
154 mat.preScale(fSaved[j][2], fSaved[j][2]);
155 } else if (kRotate_Type == fType) {
156 mat.preRotate(fSaved[j][2]);
157 }
158
159 canvas->concat(mat);
160 canvas->drawRect(clearRect, clearPaint);
161 }
162 } else {
163 canvas->clear(0xFF000000);
164 }
165
166 fNumSaved = 0;
167 }
168
169 SkASSERT(fNumSaved < kNumBeforeClear);
170
171 canvas->setMatrix(SkMatrix::I());
172
173 fSaved[fNumSaved][0] = transRand.nextRangeScalar(0.0f, maxTransX);
174 fSaved[fNumSaved][1] = transRand.nextRangeScalar(0.0f, maxTransY);
175 if (fAligned) {
176 // make the translations integer aligned
177 fSaved[fNumSaved][0] = SkScalarFloorToScalar(fSaved[fNumSaved][0]);
178 fSaved[fNumSaved][1] = SkScalarFloorToScalar(fSaved[fNumSaved][1]);
179 }
180
181 mat.setTranslate(fSaved[fNumSaved][0], fSaved[fNumSaved][1]);
182
183 if (kScale_Type == fType) {
184 fSaved[fNumSaved][2] = scaleRand.nextRangeScalar(0.5f, 1.5f);
185 mat.preScale(fSaved[fNumSaved][2], fSaved[fNumSaved][2]);
186 } else if (kRotate_Type == fType) {
187 fSaved[fNumSaved][2] = rotRand.nextRangeScalar(0.0f, 360.0f);
188 mat.preRotate(fSaved[fNumSaved][2]);
189 }
190
191 canvas->concat(mat);
192 if (fUseAtlas) {
193 const int curCell = i % (kNumAtlasedX * kNumAtlasedY);
195 fAtlasRects[curCell % (kNumAtlasedX)][curCell / (kNumAtlasedX)]);
196
197 if (fUseDrawVertices) {
198 SkPoint uvs[4] = {
199 { SkIntToScalar(src.fLeft), SkIntToScalar(src.fBottom) },
200 { SkIntToScalar(src.fLeft), SkIntToScalar(src.fTop) },
201 { SkIntToScalar(src.fRight), SkIntToScalar(src.fTop) },
202 { SkIntToScalar(src.fRight), SkIntToScalar(src.fBottom) },
203 };
205 4, verts, uvs, nullptr, 6, indices),
207 } else {
208 canvas->drawImageRect(fAtlas, src, dst, SkSamplingOptions(), &p,
210 }
211 } else {
212 canvas->drawImageRect(fCheckerboard, dst, SkSamplingOptions(), &p);
213 }
214 }
215 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kModulate
r = s*d
#define SkScalarFloorToScalar(x)
Definition: SkScalar.h:30
#define SkIntToScalar(x)
Definition: SkScalar.h:57
#define SK_ScalarSqrt2
Definition: SkScalar.h:20
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
virtual SkISize getBaseLayerSize() const
Definition: SkCanvas.cpp:369
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition: SkCanvas.h:1543
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
void setMatrix(const SkM44 &matrix)
Definition: SkCanvas.cpp:1349
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
void drawVertices(const SkVertices *vertices, SkBlendMode mode, const SkPaint &paint)
Definition: SkCanvas.cpp:1720
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
SkMatrix & setTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:254
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
SkMatrix & preRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:462
SkMatrix & preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:315
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setShader(sk_sp< SkShader > shader)
SkScalar nextRangeScalar(SkScalar min, SkScalar max)
Definition: SkRandom.h:106
static sk_sp< SkVertices > MakeCopy(VertexMode mode, int vertexCount, const SkPoint positions[], const SkPoint texs[], const SkColor colors[], int indexCount, const uint16_t indices[])
Definition: SkVertices.cpp:200
@ kTriangles_VertexMode
Definition: SkVertices.h:31
float SkScalar
Definition: extension.cpp:12
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
dst
Definition: cp.py:12
SkSamplingOptions(SkFilterMode::kLinear))
int32_t height
int32_t width
Definition: SkSize.h:16
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669

◆ onGetName()

const char * GameBench::onGetName ( )
inlineoverrideprotectedvirtual

Implements Benchmark.

Definition at line 81 of file GameBench.cpp.

81 {
82 return fName.c_str();
83 }
const char * c_str() const
Definition: SkString.h:133

The documentation for this class was generated from the following file: