35 bool aligned =
false,
bool useAtlas =
false,
36 bool useDrawVertices =
false)
41 , fUseDrawVertices(useDrawVertices)
44 , fInitialized(
false) {
72 if (useDrawVertices) {
73 fName.
append(
"_drawVerts");
87 this->makeCheckerboard();
100 width = kAtlasCellWidth;
101 height = kAtlasCellHeight;
103 width = kCheckerboardWidth;
104 height = kCheckerboardHeight;
116 maxTransX =
size.fWidth - (1.5f *
width);
137 uint16_t indices[6] = { 0, 1, 2, 0, 2, 3 };
140 p.setColor(0xFF000000);
146 for (
int i = 0;
i < loops; ++
i, ++fNumSaved) {
147 if (0 ==
i % kNumBeforeClear) {
149 for (
int j = 0; j < fNumSaved; ++j) {
154 mat.
preScale(fSaved[j][2], fSaved[j][2]);
160 canvas->
drawRect(clearRect, clearPaint);
163 canvas->
clear(0xFF000000);
169 SkASSERT(fNumSaved < kNumBeforeClear);
181 mat.
setTranslate(fSaved[fNumSaved][0], fSaved[fNumSaved][1]);
185 mat.
preScale(fSaved[fNumSaved][2], fSaved[fNumSaved][2]);
193 const int curCell =
i % (kNumAtlasedX * kNumAtlasedY);
195 fAtlasRects[curCell % (kNumAtlasedX)][curCell / (kNumAtlasedX)]);
197 if (fUseDrawVertices) {
205 4, verts, uvs,
nullptr, 6, indices),
218 static const int kCheckerboardWidth = 64;
219 static const int kCheckerboardHeight = 128;
221 static const int kAtlasCellWidth = 48;
222 static const int kAtlasCellHeight = 36;
223 static const int kNumAtlasedX = 5;
224 static const int kNumAtlasedY = 5;
225 static const int kAtlasSpacer = 2;
226 static const int kTotAtlasWidth = kNumAtlasedX * kAtlasCellWidth +
227 (kNumAtlasedX+1) * kAtlasSpacer;
228 static const int kTotAtlasHeight = kNumAtlasedY * kAtlasCellHeight +
229 (kNumAtlasedY+1) * kAtlasSpacer;
230 static const int kNumBeforeClear = 100;
236 bool fUseDrawVertices;
242 SkScalar fSaved[kNumBeforeClear][3];
245 SkIRect fAtlasRects[kNumAtlasedX][kNumAtlasedY];
248 void makeCheckerboard() {
249 static int kCheckSize = 16;
253 for (
int y = 0;
y < kCheckerboardHeight; ++
y) {
254 int even = (
y / kCheckSize) % 2;
258 for (
int x = 0;
x < kCheckerboardWidth; ++
x) {
259 if (even == (
x / kCheckSize) % 2) {
260 *scanline++ = 0xFFFF0000;
262 *scanline++ = 0x00000000;
275 for (
int y = 0;
y < kNumAtlasedY; ++
y) {
276 for (
int x = 0;
x < kNumAtlasedX; ++
x) {
279 kAtlasSpacer +
y * (kAtlasCellHeight + kAtlasSpacer),
288 for (
int y = 0;
y < kTotAtlasHeight; ++
y) {
289 int colorY =
y / (kAtlasCellHeight + kAtlasSpacer);
290 bool inColorY = (
y % (kAtlasCellHeight + kAtlasSpacer)) >= kAtlasSpacer;
294 for (
int x = 0;
x < kTotAtlasWidth; ++
x, ++scanline) {
295 int colorX =
x / (kAtlasCellWidth + kAtlasSpacer);
296 bool inColorX = (
x % (kAtlasCellWidth + kAtlasSpacer)) >= kAtlasSpacer;
298 if (inColorX && inColorY) {
299 SkASSERT(colorX < kNumAtlasedX && colorY < kNumAtlasedY);
300 *scanline =
colors[colorX][colorY];
302 *scanline = 0x00000000;
330class CanvasMatrixBench :
public Benchmark {
342 CanvasMatrixBench(
Type t) : fType(t) {
343 fName.set(
"canvas_matrix");
345 case kTranslate_Type:
fName.append(
"_trans");
break;
346 case kScale_Type:
fName.append(
"_scale");
break;
347 case k2x3_Type:
fName.append(
"_2x3");
break;
348 case k3x3_Type:
fName.append(
"_3x3");
break;
349 case k4x4_Type:
fName.append(
"_4x4");
break;
354 const char* onGetName()
override {
355 return fName.c_str();
358 void onDraw(
int loops,
SkCanvas* canvas)
override {
361 if (fType == k3x3_Type) {
366 for (
int i = 0;
i < loops; ++
i) {
368 for (
int j = 0; j < 10000; ++j) {
370 case kTranslate_Type: canvas->
translate(0.0001f, 0.0001f);
break;
371 case kScale_Type: canvas->
scale(1.0001f, 0.9999f);
break;
372 case k2x3_Type: canvas->
concat(
m);
break;
373 case k3x3_Type: canvas->
concat(
m);
break;
374 case k4x4_Type: canvas->
concat(m4);
break;
385DEF_BENCH(
return new CanvasMatrixBench(CanvasMatrixBench::kTranslate_Type));
386DEF_BENCH(
return new CanvasMatrixBench(CanvasMatrixBench::kScale_Type));
387DEF_BENCH(
return new CanvasMatrixBench(CanvasMatrixBench::k2x3_Type));
388DEF_BENCH(
return new CanvasMatrixBench(CanvasMatrixBench::k3x3_Type));
389DEF_BENCH(
return new CanvasMatrixBench(CanvasMatrixBench::k4x4_Type));
DEF_BENCH(return new GameBench(GameBench::kTranslate_Type, GameBench::kFull_Clear, false, true, true);) class CanvasMatrixBench DEF_BENCH(return new CanvasMatrixBench(CanvasMatrixBench::kTranslate_Type))
#define INHERITED(method,...)
#define SkScalarFloorToScalar(x)
GameBench(Type type, Clear clear, bool aligned=false, bool useAtlas=false, bool useDrawVertices=false)
const char * onGetName() override
void onDraw(int loops, SkCanvas *canvas) override
void onDelayedSetup() override
sk_sp< SkImage > asImage() const
void allocN32Pixels(int width, int height, bool isOpaque=false)
uint32_t * getAddr32(int x, int y) const
void drawRect(const SkRect &rect, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
virtual SkISize getBaseLayerSize() const
@ kFast_SrcRectConstraint
sample outside bounds; faster
void clear(SkColor color)
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
void setMatrix(const SkM44 &matrix)
void scale(SkScalar sx, SkScalar sy)
void concat(const SkMatrix &matrix)
void drawVertices(const SkVertices *vertices, SkBlendMode mode, const SkPaint &paint)
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
SkMatrix & setTranslate(SkScalar dx, SkScalar dy)
static const SkMatrix & I()
SkMatrix & preRotate(SkScalar degrees, SkScalar px, SkScalar py)
SkMatrix & preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
void setColor(SkColor color)
void setAntiAlias(bool aa)
void setShader(sk_sp< SkShader > shader)
SkScalar nextRangeScalar(SkScalar min, SkScalar max)
void append(const char text[])
const char * c_str() const
static sk_sp< SkVertices > MakeCopy(VertexMode mode, int vertexCount, const SkPoint positions[], const SkPoint texs[], const SkColor colors[], int indexCount, const uint16_t indices[])
PODArray< SkColor > colors
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
SkSamplingOptions(SkFilterMode::kLinear))
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
static SkRect Make(const SkISize &size)