Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Member Functions | List of all members
ShapesBench Class Reference
Inheritance diagram for ShapesBench:
Benchmark SkRefCnt SkRefCntBase

Public Types

enum  ShapesType {
  kNone_ShapesType , kRect_ShapesType , kOval_ShapesType , kRRect_ShapesType ,
  kMixed_ShapesType
}
 
- Public Types inherited from Benchmark
enum class  Backend {
  kNonRendering , kRaster , kGanesh , kGraphite ,
  kPDF , kHWUI
}
 

Public Member Functions

 ShapesBench (ShapesType shapesType, ShapesType innerShapesType, int numShapes, const SkISize &shapesSize, bool perspective)
 
- 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
 

Private Member Functions

const char * onGetName () override
 
SkISize onGetSize () override
 
void onDelayedSetup () override
 
void onDraw (int loops, SkCanvas *canvas) override
 

Additional Inherited Members

- Protected Member Functions inherited from Benchmark
void setUnits (int units)
 
virtual void setupPaint (SkPaint *paint)
 
virtual const char * onGetUniqueName ()
 
virtual void onPerCanvasPreDraw (SkCanvas *)
 
virtual void onPerCanvasPostDraw (SkCanvas *)
 
virtual void onPreDraw (SkCanvas *)
 
virtual void onPostDraw (SkCanvas *)
 

Detailed Description

Definition at line 42 of file ShapesBench.cpp.

Member Enumeration Documentation

◆ ShapesType

Enumerator
kNone_ShapesType 
kRect_ShapesType 
kOval_ShapesType 
kRRect_ShapesType 
kMixed_ShapesType 

Definition at line 44 of file ShapesBench.cpp.

Constructor & Destructor Documentation

◆ ShapesBench()

ShapesBench::ShapesBench ( ShapesType  shapesType,
ShapesType  innerShapesType,
int  numShapes,
const SkISize shapesSize,
bool  perspective 
)
inline

Definition at line 52 of file ShapesBench.cpp.

54 : fShapesType(shapesType)
55 , fInnerShapesType(innerShapesType)
56 , fNumShapes(numShapes)
57 , fShapesSize(shapesSize)
58 , fPerspective(perspective) {
59 clampShapeSize();
60 }

Member Function Documentation

◆ onDelayedSetup()

void ShapesBench::onDelayedSetup ( )
inlineoverrideprivatevirtual

Reimplemented from Benchmark.

Definition at line 137 of file ShapesBench.cpp.

137 {
138 SkScalar w = SkIntToScalar(fShapesSize.width());
139 SkScalar h = SkIntToScalar(fShapesSize.height());
140
141 fRect.setRect(SkRect::MakeXYWH(-w / 2, -h / 2, w, h));
142 fOval.setOval(fRect.rect());
143 fRRect.setNinePatch(fRect.rect(), w / 8, h / 13, w / 11, h / 7);
144
145 if (kNone_ShapesType != fInnerShapesType) {
146 fRect.inset(w / 7, h / 11, &fInnerRect);
147 fInnerRect.offset(w / 28, h / 44);
148 fInnerOval.setOval(fInnerRect.rect());
149 fInnerRRect.setRectXY(fInnerRect.rect(), w / 13, w / 7);
150 }
151
152 SkRandom rand;
153 fShapes.push_back_n(fNumShapes);
154 for (int i = 0; i < fNumShapes; i++) {
155 float pad = sqrtf(static_cast<float>(fShapesSize.width() * fShapesSize.width()) +
156 static_cast<float>(fShapesSize.height() * fShapesSize.height()));
157 fShapes[i].fMatrix.setTranslate(0.5f * pad + rand.nextF() * (kBenchWidth - pad),
158 0.5f * pad + rand.nextF() * (kBenchHeight - pad));
159 fShapes[i].fMatrix.preRotate(rand.nextF() * 360.0f);
160 if (fPerspective) {
161 fShapes[i].fMatrix.setPerspX(0.00015f);
162 fShapes[i].fMatrix.setPerspY(-0.00015f);
163 }
164 fShapes[i].fColor = rand.nextU() | 0xff808080;
165 }
166 for (int i = 0; i < fNumShapes; i++) {
167 // Do this in a separate loop so mixed shapes get the same random numbers during
168 // placement as non-mixed do.
169 int shapeType = fShapesType;
170 if (kMixed_ShapesType == shapeType) {
172 }
173 int innerShapeType = fInnerShapesType;
174 if (kMixed_ShapesType == innerShapeType) {
175 innerShapeType = rand.nextRangeU(kRect_ShapesType, kRRect_ShapesType);
176 }
177 if (kNone_ShapesType == innerShapeType) {
178 switch (shapeType) {
179 using namespace std;
180 using namespace std::placeholders;
181 case kRect_ShapesType:
182 fShapes[i].fDraw = bind(&SkCanvas::drawRect, _1, cref(fRect.rect()), _2);
183 break;
184 case kOval_ShapesType:
185 fShapes[i].fDraw = bind(&SkCanvas::drawOval, _1, cref(fOval.rect()), _2);
186 break;
188 fShapes[i].fDraw = bind(&SkCanvas::drawRRect, _1, cref(fRRect), _2);
189 break;
190 }
191 } else {
192 const SkRRect* outer = nullptr;
193 switch (shapeType) {
194 case kRect_ShapesType: outer = &fRect; break;
195 case kOval_ShapesType: outer = &fOval; break;
196 case kRRect_ShapesType: outer = &fRRect; break;
197 }
198 const SkRRect* inner = nullptr;
199 switch (innerShapeType) {
200 case kRect_ShapesType: inner = &fInnerRect; break;
201 case kOval_ShapesType: inner = &fInnerOval; break;
202 case kRRect_ShapesType: inner = &fInnerRRect; break;
203 }
204 fShapes[i].fDraw = std::bind(&SkCanvas::drawDRRect, std::placeholders::_1,
205 std::cref(*outer), std::cref(*inner),
206 std::placeholders::_2);
207 }
208 }
209 }
#define SkIntToScalar(x)
Definition SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawOval(const SkRect &oval, const SkPaint &paint)
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
void drawDRRect(const SkRRect &outer, const SkRRect &inner, const SkPaint &paint)
const SkRect & rect() const
Definition SkRRect.h:264
void inset(SkScalar dx, SkScalar dy, SkRRect *dst) const
Definition SkRRect.cpp:562
void setOval(const SkRect &oval)
Definition SkRRect.cpp:30
void offset(SkScalar dx, SkScalar dy)
Definition SkRRect.h:387
void setRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition SkRRect.cpp:52
void setNinePatch(const SkRect &rect, SkScalar leftRad, SkScalar topRad, SkScalar rightRad, SkScalar bottomRad)
Definition SkRRect.cpp:115
void setRect(const SkRect &rect)
Definition SkRRect.h:126
uint32_t nextU()
Definition SkRandom.h:42
float nextF()
Definition SkRandom.h:55
uint32_t nextRangeU(uint32_t min, uint32_t max)
Definition SkRandom.h:80
T * push_back_n(int n)
Definition SkTArray.h:262
float SkScalar
Definition extension.cpp:12
Definition ref_ptr.h:256
SkScalar w
SkScalar h
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

◆ onDraw()

void ShapesBench::onDraw ( int  loops,
SkCanvas canvas 
)
inlineoverrideprivatevirtual

Implements Benchmark.

Definition at line 211 of file ShapesBench.cpp.

211 {
213 this->setupPaint(&paint);
214 for (int j = 0; j < loops; j++) {
215 for (int i = 0; i < fNumShapes; i++) {
216 canvas->save();
217 canvas->setMatrix(fShapes[i].fMatrix);
218 paint.setColor(fShapes[i].fColor);
219 fShapes[i].fDraw(canvas, paint);
220 canvas->restore();
221 }
222 }
223 }
virtual void setupPaint(SkPaint *paint)
Definition Benchmark.cpp:55
void restore()
Definition SkCanvas.cpp:465
int save()
Definition SkCanvas.cpp:451
void setMatrix(const SkM44 &matrix)
const Paint & paint

◆ onGetName()

const char * ShapesBench::onGetName ( )
inlineoverrideprivatevirtual

Implements Benchmark.

Definition at line 116 of file ShapesBench.cpp.

116 {
117 const char* shapeTypeNames[] = {
118 "none", "rect", "oval", "rrect", "mixed"
119 };
120
121 fName.printf("shapes_%s", shapeTypeNames[fShapesType]);
122
123 if (kNone_ShapesType != fInnerShapesType) {
124 fName.appendf("_inner_%s", shapeTypeNames[fInnerShapesType]);
125 }
126
127 fName.appendf("_%i_%ix%i", fNumShapes, fShapesSize.width(), fShapesSize.height());
128
129 if (fPerspective) {
130 fName.append("_persp");
131 }
132
133 return fName.c_str();
134 }
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
void append(const char text[])
Definition SkString.h:203
const char * c_str() const
Definition SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:550

◆ onGetSize()

SkISize ShapesBench::onGetSize ( )
inlineoverrideprivatevirtual

Reimplemented from Benchmark.

Definition at line 135 of file ShapesBench.cpp.

135{ return SkISize::Make(kBenchWidth, kBenchHeight); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20

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