2012-10-03 13:25:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkRect.h"
|
2012-10-03 13:25:13 +00:00
|
|
|
|
|
|
|
static const SkScalar kCellWidth = SkIntToScalar(20);
|
|
|
|
static const SkScalar kCellHeight = SkIntToScalar(10);
|
|
|
|
|
|
|
|
// This bench draws a table in the manner of Google spreadsheet and sahadan.com.
|
|
|
|
// ____________ ___
|
|
|
|
// | 1 | 2 |
|
|
|
|
// |____________|___|
|
|
|
|
// | 3 | 4 |
|
|
|
|
// |____________|___|
|
|
|
|
//
|
|
|
|
// Areas 1-4 are first all draw white. Areas 3&4 are then drawn grey. Areas
|
|
|
|
// 2&4 are then drawn grey. Areas 2&3 are thus double drawn while area 4 is
|
|
|
|
// triple drawn.
|
|
|
|
// This trio of drawRects is then repeat for the next cell.
|
2014-06-19 19:32:29 +00:00
|
|
|
class TableBench : public Benchmark {
|
2012-10-03 13:25:13 +00:00
|
|
|
public:
|
|
|
|
static const int kNumRows = 48;
|
|
|
|
static const int kNumCols = 32;
|
|
|
|
|
|
|
|
protected:
|
2020-07-21 21:03:56 +00:00
|
|
|
const char* onGetName() override {
|
2012-10-04 02:01:34 +00:00
|
|
|
return "tablebench";
|
2012-10-03 13:25:13 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 21:03:56 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2012-10-03 13:25:13 +00:00
|
|
|
SkPaint cellPaint;
|
|
|
|
cellPaint.setColor(0xFFFFFFF);
|
|
|
|
|
|
|
|
SkPaint borderPaint;
|
|
|
|
borderPaint.setColor(0xFFCCCCCC);
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-10-03 13:25:13 +00:00
|
|
|
for (int row = 0; row < kNumRows; ++row) {
|
|
|
|
for (int col = 0; col < kNumCols; ++col) {
|
2012-10-04 02:01:34 +00:00
|
|
|
SkRect cell = SkRect::MakeLTRB(col * kCellWidth,
|
|
|
|
row * kCellHeight,
|
|
|
|
(col+1) * kCellWidth,
|
2012-10-03 13:25:13 +00:00
|
|
|
(row+1) * kCellHeight);
|
|
|
|
canvas->drawRect(cell, cellPaint);
|
|
|
|
|
2012-10-04 02:01:34 +00:00
|
|
|
SkRect bottom = SkRect::MakeLTRB(col * kCellWidth,
|
|
|
|
row * kCellHeight + (kCellHeight-SK_Scalar1),
|
|
|
|
(col+1) * kCellWidth,
|
2012-10-03 13:25:13 +00:00
|
|
|
(row+1) * kCellHeight);
|
|
|
|
canvas->drawRect(bottom, borderPaint);
|
|
|
|
|
2012-10-04 02:01:34 +00:00
|
|
|
SkRect right = SkRect::MakeLTRB(col * kCellWidth + (kCellWidth-SK_Scalar1),
|
|
|
|
row * kCellHeight,
|
|
|
|
(col+1) * kCellWidth,
|
2012-10-03 13:25:13 +00:00
|
|
|
(row+1) * kCellHeight);
|
|
|
|
canvas->drawRect(right, borderPaint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-10-03 13:25:13 +00:00
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new TableBench(); )
|