blob: 346aba8367fa2aac1cbc3599fd167fe3e7a7b5d0 [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
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
robertphillips@google.com92435262012-10-03 13:25:13 +00009#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.
tfarinaf168b862014-06-19 12:32:29 -070026class TableBench : public Benchmark {
robertphillips@google.com92435262012-10-03 13:25:13 +000027public:
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
mtkleina1ebeb22015-10-01 09:43:39 -070036 virtual void onDraw(int loops, 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
commit-bot@chromium.org33614712013-12-03 18:17:16 +000043 for (int i = 0; i < loops; ++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:
tfarinaf168b862014-06-19 12:32:29 -070069 typedef Benchmark INHERITED;
robertphillips@google.com92435262012-10-03 13:25:13 +000070};
71
mtklein@google.com410e6e82013-09-13 19:52:27 +000072DEF_BENCH( return new TableBench(); )