22#define ENABLE_COMMAND_LINE_SHAPES_BENCH 0
24#if ENABLE_COMMAND_LINE_SHAPES_BENCH
26 "Type of shape to use in ShapesBench. Must be one of: "
27 "rect, oval, rrect, mixed.");
29 "Type of inner shape to use in ShapesBench. Must be one of: "
30 "none, rect, oval, rrect, mixed.");
31static DEFINE_int(numShapes, 10000,
"Number of shapes to draw in ShapesBench.");
32static DEFINE_string(shapesSize,
"32x32",
"Size of shapes to draw in ShapesBench.");
33static DEFINE_bool(shapesPersp,
false,
"Use slight perspective tilt in ShapesBench?");
53 int numShapes,
const SkISize& shapesSize,
bool perspective)
54 : fShapesType(shapesType)
55 , fInnerShapesType(innerShapesType)
56 , fNumShapes(numShapes)
57 , fShapesSize(shapesSize)
58 , fPerspective(perspective) {
62#if ENABLE_COMMAND_LINE_SHAPES_BENCH
64 if (!strcmp(FLAGS_shapesType[0],
"rect")) {
66 }
else if (!strcmp(FLAGS_shapesType[0],
"oval")) {
68 }
else if (!strcmp(FLAGS_shapesType[0],
"rrect")) {
70 }
else if (!strcmp(FLAGS_shapesType[0],
"mixed")) {
73 SkDebugf(
"Invalid shapesType \"%s\". Must be one of: rect, oval, rrect, mixed.",
77 if (!strcmp(FLAGS_innerShapesType[0],
"none")) {
79 }
else if (!strcmp(FLAGS_innerShapesType[0],
"rect")) {
81 }
else if (!strcmp(FLAGS_innerShapesType[0],
"oval")) {
83 }
else if (!strcmp(FLAGS_innerShapesType[0],
"rrect")) {
85 }
else if (!strcmp(FLAGS_innerShapesType[0],
"mixed")) {
88 SkDebugf(
"Invalid innerShapesType \"%s\". Must be one of: "
89 "none, rect, oval, rrect, mixed.", FLAGS_innerShapesType[0]);
92 if (2 != sscanf(FLAGS_shapesSize[0],
"%ix%i", &fShapesSize.
fWidth, &fShapesSize.
fHeight)) {
93 SkDebugf(
"Could not parse shapesSize from \"%s\". Expected \"%%ix%%i\"\n",
98 fNumShapes = FLAGS_numShapes;
99 fPerspective = FLAGS_shapesPersp;
106 void clampShapeSize() {
107 float maxDiagonal =
static_cast<float>(
std::min(kBenchWidth, kBenchHeight));
108 float diagonal = sqrtf(
static_cast<float>(fShapesSize.
width() * fShapesSize.
width()) +
109 static_cast<float>(fShapesSize.
height() * fShapesSize.
height()));
110 if (diagonal > maxDiagonal) {
111 fShapesSize.
fWidth =
static_cast<int>(fShapesSize.
width() * maxDiagonal / diagonal);
112 fShapesSize.
fHeight =
static_cast<int>(fShapesSize.
height() * maxDiagonal / diagonal);
116 const char* onGetName()
override {
117 const char* shapeTypeNames[] = {
118 "none",
"rect",
"oval",
"rrect",
"mixed"
121 fName.
printf(
"shapes_%s", shapeTypeNames[fShapesType]);
124 fName.
appendf(
"_inner_%s", shapeTypeNames[fInnerShapesType]);
133 return fName.
c_str();
137 void onDelayedSetup()
override {
146 fRect.
inset(
w / 7,
h / 11, &fInnerRect);
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);
161 fShapes[
i].fMatrix.setPerspX(0.00015f);
162 fShapes[
i].fMatrix.setPerspY(-0.00015f);
164 fShapes[
i].fColor = rand.
nextU() | 0xff808080;
166 for (
int i = 0;
i < fNumShapes;
i++) {
169 int shapeType = fShapesType;
173 int innerShapeType = fInnerShapesType;
180 using namespace std::placeholders;
192 const SkRRect* outer =
nullptr;
198 const SkRRect* inner =
nullptr;
199 switch (innerShapeType) {
205 std::cref(*outer), std::cref(*inner),
206 std::placeholders::_2);
211 void onDraw(
int loops,
SkCanvas* canvas)
override {
214 for (
int j = 0; j < loops; j++) {
215 for (
int i = 0;
i < fNumShapes;
i++) {
218 paint.setColor(fShapes[
i].fColor);
219 fShapes[
i].fDraw(canvas,
paint);
225 static constexpr int kBenchWidth = 1000;
226 static constexpr int kBenchHeight = 1000;
252#if ENABLE_COMMAND_LINE_SHAPES_BENCH
#define DEFINE_string(name, defaultValue, helpString)
DEFINE_int(gpuThreads, 2, "Create this many extra threads to assist with GPU work, " "including software path rendering. Defaults to two.")
DEFINE_bool(verboseFontMgr, false, "FontMgr will be very verbose.")
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
virtual void setupPaint(SkPaint *paint)
ShapesBench(ShapesType shapesType, ShapesType innerShapesType, int numShapes, const SkISize &shapesSize, bool perspective)
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 setMatrix(const SkM44 &matrix)
void drawDRRect(const SkRRect &outer, const SkRRect &inner, const SkPaint &paint)
const SkRect & rect() const
void inset(SkScalar dx, SkScalar dy, SkRRect *dst) const
void setOval(const SkRect &oval)
void offset(SkScalar dx, SkScalar dy)
void setRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
void setNinePatch(const SkRect &rect, SkScalar leftRad, SkScalar topRad, SkScalar rightRad, SkScalar bottomRad)
void setRect(const SkRect &rect)
uint32_t nextRangeU(uint32_t min, uint32_t max)
void printf(const char format[],...) SK_PRINTF_LIKE(2
void append(const char text[])
const char * c_str() const
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Dart_NativeFunction function
static float min(float r, float g, float b)
static constexpr SkISize Make(int32_t w, int32_t h)
constexpr int32_t width() const
constexpr int32_t height() const
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)