blob: 8dcefbed5f63b2b98ab86cb2ea0aa1fc5b285a5f [file] [log] [blame]
robertphillips@google.com92435262012-10-03 13:25:13 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkBenchmark.h"
9#include "SkCanvas.h"
10#include "SkRect.h"
11
12static const SkScalar kCellWidth = SkIntToScalar(20);
13static const SkScalar kCellHeight = SkIntToScalar(10);
14
15// This bench draws a table in the manner of Google spreadsheet and sahadan.com.
16// ____________ ___
17// | 1 | 2 |
18// |____________|___|
19// | 3 | 4 |
20// |____________|___|
21//
22// Areas 1-4 are first all draw white. Areas 3&4 are then drawn grey. Areas
23// 2&4 are then drawn grey. Areas 2&3 are thus double drawn while area 4 is
24// triple drawn.
25// This trio of drawRects is then repeat for the next cell.
26class TableBench : public SkBenchmark {
27public:
robertphillips@google.com92435262012-10-03 13:25:13 +000028 static const int kNumRows = 48;
29 static const int kNumCols = 32;
30
skia.committer@gmail.com7cc7f492012-10-04 02:01:34 +000031 TableBench(void* param)
32 : INHERITED(param) {
robertphillips@google.com92435262012-10-03 13:25:13 +000033 }
34
35protected:
skia.committer@gmail.com7cc7f492012-10-04 02:01:34 +000036 virtual const char* onGetName() {
37 return "tablebench";
robertphillips@google.com92435262012-10-03 13:25:13 +000038 }
39
40 virtual void onDraw(SkCanvas* canvas) {
robertphillips@google.com92435262012-10-03 13:25:13 +000041 SkPaint cellPaint;
42 cellPaint.setColor(0xFFFFFFF);
43
44 SkPaint borderPaint;
45 borderPaint.setColor(0xFFCCCCCC);
46
mtklein@google.comc2897432013-09-10 19:23:38 +000047 for (int i = 0; i < this->getLoops(); ++i) {
robertphillips@google.com92435262012-10-03 13:25:13 +000048 for (int row = 0; row < kNumRows; ++row) {
49 for (int col = 0; col < kNumCols; ++col) {
skia.committer@gmail.com7cc7f492012-10-04 02:01:34 +000050 SkRect cell = SkRect::MakeLTRB(col * kCellWidth,
51 row * kCellHeight,
52 (col+1) * kCellWidth,
robertphillips@google.com92435262012-10-03 13:25:13 +000053 (row+1) * kCellHeight);
54 canvas->drawRect(cell, cellPaint);
55
skia.committer@gmail.com7cc7f492012-10-04 02:01:34 +000056 SkRect bottom = SkRect::MakeLTRB(col * kCellWidth,
57 row * kCellHeight + (kCellHeight-SK_Scalar1),
58 (col+1) * kCellWidth,
robertphillips@google.com92435262012-10-03 13:25:13 +000059 (row+1) * kCellHeight);
60 canvas->drawRect(bottom, borderPaint);
61
skia.committer@gmail.com7cc7f492012-10-04 02:01:34 +000062 SkRect right = SkRect::MakeLTRB(col * kCellWidth + (kCellWidth-SK_Scalar1),
63 row * kCellHeight,
64 (col+1) * kCellWidth,
robertphillips@google.com92435262012-10-03 13:25:13 +000065 (row+1) * kCellHeight);
66 canvas->drawRect(right, borderPaint);
67 }
68 }
69 }
70 }
71
72private:
73 typedef SkBenchmark INHERITED;
74};
75
76static SkBenchmark* gFactory(void* p) { return new TableBench(p); }
77
78static BenchRegistry gRegistry(gFactory);