robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
| 10 | #include "SkRect.h" |
| 11 | |
| 12 | static const SkScalar kCellWidth = SkIntToScalar(20); |
| 13 | static 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. |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 26 | class TableBench : public Benchmark { |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 27 | public: |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 28 | static const int kNumRows = 48; |
| 29 | static const int kNumCols = 32; |
| 30 | |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 31 | protected: |
skia.committer@gmail.com | 7cc7f49 | 2012-10-04 02:01:34 +0000 | [diff] [blame] | 32 | virtual const char* onGetName() { |
| 33 | return "tablebench"; |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 34 | } |
| 35 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 36 | virtual void onDraw(int loops, SkCanvas* canvas) { |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 37 | SkPaint cellPaint; |
| 38 | cellPaint.setColor(0xFFFFFFF); |
| 39 | |
| 40 | SkPaint borderPaint; |
| 41 | borderPaint.setColor(0xFFCCCCCC); |
| 42 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 43 | for (int i = 0; i < loops; ++i) { |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 44 | for (int row = 0; row < kNumRows; ++row) { |
| 45 | for (int col = 0; col < kNumCols; ++col) { |
skia.committer@gmail.com | 7cc7f49 | 2012-10-04 02:01:34 +0000 | [diff] [blame] | 46 | SkRect cell = SkRect::MakeLTRB(col * kCellWidth, |
| 47 | row * kCellHeight, |
| 48 | (col+1) * kCellWidth, |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 49 | (row+1) * kCellHeight); |
| 50 | canvas->drawRect(cell, cellPaint); |
| 51 | |
skia.committer@gmail.com | 7cc7f49 | 2012-10-04 02:01:34 +0000 | [diff] [blame] | 52 | SkRect bottom = SkRect::MakeLTRB(col * kCellWidth, |
| 53 | row * kCellHeight + (kCellHeight-SK_Scalar1), |
| 54 | (col+1) * kCellWidth, |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 55 | (row+1) * kCellHeight); |
| 56 | canvas->drawRect(bottom, borderPaint); |
| 57 | |
skia.committer@gmail.com | 7cc7f49 | 2012-10-04 02:01:34 +0000 | [diff] [blame] | 58 | SkRect right = SkRect::MakeLTRB(col * kCellWidth + (kCellWidth-SK_Scalar1), |
| 59 | row * kCellHeight, |
| 60 | (col+1) * kCellWidth, |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 61 | (row+1) * kCellHeight); |
| 62 | canvas->drawRect(right, borderPaint); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 69 | typedef Benchmark INHERITED; |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 72 | DEF_BENCH( return new TableBench(); ) |