blob: 0646d26be5558ae81b9ac12f5c1a943d7fe82b5a [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
robertphillips@google.com92435262012-10-03 13:25:13 +000031protected:
skia.committer@gmail.com7cc7f492012-10-04 02:01:34 +000032 virtual const char* onGetName() {
33 return "tablebench";
robertphillips@google.com92435262012-10-03 13:25:13 +000034 }
35
36 virtual void onDraw(SkCanvas* canvas) {
robertphillips@google.com92435262012-10-03 13:25:13 +000037 SkPaint cellPaint;
38 cellPaint.setColor(0xFFFFFFF);
39
40 SkPaint borderPaint;
41 borderPaint.setColor(0xFFCCCCCC);
42
mtklein@google.comc2897432013-09-10 19:23:38 +000043 for (int i = 0; i < this->getLoops(); ++i) {
robertphillips@google.com92435262012-10-03 13:25:13 +000044 for (int row = 0; row < kNumRows; ++row) {
45 for (int col = 0; col < kNumCols; ++col) {
skia.committer@gmail.com7cc7f492012-10-04 02:01:34 +000046 SkRect cell = SkRect::MakeLTRB(col * kCellWidth,
47 row * kCellHeight,
48 (col+1) * kCellWidth,
robertphillips@google.com92435262012-10-03 13:25:13 +000049 (row+1) * kCellHeight);
50 canvas->drawRect(cell, cellPaint);
51
skia.committer@gmail.com7cc7f492012-10-04 02:01:34 +000052 SkRect bottom = SkRect::MakeLTRB(col * kCellWidth,
53 row * kCellHeight + (kCellHeight-SK_Scalar1),
54 (col+1) * kCellWidth,
robertphillips@google.com92435262012-10-03 13:25:13 +000055 (row+1) * kCellHeight);
56 canvas->drawRect(bottom, borderPaint);
57
skia.committer@gmail.com7cc7f492012-10-04 02:01:34 +000058 SkRect right = SkRect::MakeLTRB(col * kCellWidth + (kCellWidth-SK_Scalar1),
59 row * kCellHeight,
60 (col+1) * kCellWidth,
robertphillips@google.com92435262012-10-03 13:25:13 +000061 (row+1) * kCellHeight);
62 canvas->drawRect(right, borderPaint);
63 }
64 }
65 }
66 }
67
68private:
69 typedef SkBenchmark INHERITED;
70};
71
mtklein@google.com410e6e82013-09-13 19:52:27 +000072DEF_BENCH( return new TableBench(); )