2011-10-28 18:57:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2011-10-28 18:57:32 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkShader.h"
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "SkString.h"
|
2011-10-28 18:57:32 +00:00
|
|
|
|
|
|
|
enum VertFlags {
|
|
|
|
kColors_VertFlag,
|
|
|
|
kTexture_VertFlag,
|
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class VertBench : public Benchmark {
|
2011-10-28 18:57:32 +00:00
|
|
|
SkString fName;
|
|
|
|
enum {
|
|
|
|
W = 640,
|
|
|
|
H = 480,
|
|
|
|
ROW = 20,
|
|
|
|
COL = 20,
|
|
|
|
PTS = (ROW + 1) * (COL + 1),
|
|
|
|
IDX = ROW * COL * 6,
|
|
|
|
};
|
|
|
|
|
|
|
|
SkPoint fPts[PTS];
|
|
|
|
SkColor fColors[PTS];
|
|
|
|
uint16_t fIdx[IDX];
|
|
|
|
|
|
|
|
static void load_2_tris(uint16_t idx[], int x, int y, int rb) {
|
|
|
|
int n = y * rb + x;
|
|
|
|
idx[0] = n; idx[1] = n + 1; idx[2] = rb + n + 1;
|
|
|
|
idx[3] = n; idx[4] = rb + n + 1; idx[5] = n + rb;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-10-28 18:57:32 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
VertBench() {
|
2011-10-28 18:57:32 +00:00
|
|
|
const SkScalar dx = SkIntToScalar(W) / COL;
|
|
|
|
const SkScalar dy = SkIntToScalar(H) / COL;
|
|
|
|
|
|
|
|
SkPoint* pts = fPts;
|
|
|
|
uint16_t* idx = fIdx;
|
|
|
|
|
|
|
|
SkScalar yy = 0;
|
|
|
|
for (int y = 0; y <= ROW; y++) {
|
|
|
|
SkScalar xx = 0;
|
|
|
|
for (int x = 0; x <= COL; ++x) {
|
|
|
|
pts->set(xx, yy);
|
|
|
|
pts += 1;
|
|
|
|
xx += dx;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-10-28 18:57:32 +00:00
|
|
|
if (x < COL && y < ROW) {
|
|
|
|
load_2_tris(idx, x, y, COL + 1);
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
SkASSERT(idx[i] < PTS);
|
|
|
|
}
|
|
|
|
idx += 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yy += dy;
|
|
|
|
}
|
|
|
|
SkASSERT(PTS == pts - fPts);
|
|
|
|
SkASSERT(IDX == idx - fIdx);
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2011-10-28 18:57:32 +00:00
|
|
|
for (int i = 0; i < PTS; ++i) {
|
|
|
|
fColors[i] = rand.nextU() | (0xFF << 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
fName.set("verts");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() { return fName.c_str(); }
|
2015-10-01 16:43:39 +00:00
|
|
|
virtual void onDraw(int loops, SkCanvas* canvas) {
|
2011-10-28 18:57:32 +00:00
|
|
|
SkPaint paint;
|
|
|
|
this->setupPaint(&paint);
|
2011-10-28 19:50:21 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2011-10-28 18:57:32 +00:00
|
|
|
canvas->drawVertices(SkCanvas::kTriangles_VertexMode, PTS,
|
2016-10-28 19:42:34 +00:00
|
|
|
fPts, nullptr, fColors, fIdx, IDX, paint);
|
2011-10-28 18:57:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2011-10-28 18:57:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_BENCH(return new VertBench();)
|