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 | |
| 8 | #include "SkBenchmark.h" |
| 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. |
| 26 | class TableBench : public SkBenchmark { |
| 27 | public: |
| 28 | |
| 29 | static const int kNumIterations = SkBENCHLOOP(10); |
| 30 | static const int kNumRows = 48; |
| 31 | static const int kNumCols = 32; |
| 32 | |
skia.committer@gmail.com | 7cc7f49 | 2012-10-04 02:01:34 +0000 | [diff] [blame] | 33 | TableBench(void* param) |
| 34 | : INHERITED(param) { |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | protected: |
skia.committer@gmail.com | 7cc7f49 | 2012-10-04 02:01:34 +0000 | [diff] [blame] | 38 | virtual const char* onGetName() { |
| 39 | return "tablebench"; |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | virtual void onDraw(SkCanvas* canvas) { |
| 43 | |
| 44 | SkPaint cellPaint; |
| 45 | cellPaint.setColor(0xFFFFFFF); |
| 46 | |
| 47 | SkPaint borderPaint; |
| 48 | borderPaint.setColor(0xFFCCCCCC); |
| 49 | |
| 50 | for (int i = 0; i < kNumIterations; ++i) { |
| 51 | for (int row = 0; row < kNumRows; ++row) { |
| 52 | for (int col = 0; col < kNumCols; ++col) { |
skia.committer@gmail.com | 7cc7f49 | 2012-10-04 02:01:34 +0000 | [diff] [blame] | 53 | SkRect cell = SkRect::MakeLTRB(col * kCellWidth, |
| 54 | row * kCellHeight, |
| 55 | (col+1) * kCellWidth, |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 56 | (row+1) * kCellHeight); |
| 57 | canvas->drawRect(cell, cellPaint); |
| 58 | |
skia.committer@gmail.com | 7cc7f49 | 2012-10-04 02:01:34 +0000 | [diff] [blame] | 59 | SkRect bottom = SkRect::MakeLTRB(col * kCellWidth, |
| 60 | row * kCellHeight + (kCellHeight-SK_Scalar1), |
| 61 | (col+1) * kCellWidth, |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 62 | (row+1) * kCellHeight); |
| 63 | canvas->drawRect(bottom, borderPaint); |
| 64 | |
skia.committer@gmail.com | 7cc7f49 | 2012-10-04 02:01:34 +0000 | [diff] [blame] | 65 | SkRect right = SkRect::MakeLTRB(col * kCellWidth + (kCellWidth-SK_Scalar1), |
| 66 | row * kCellHeight, |
| 67 | (col+1) * kCellWidth, |
robertphillips@google.com | 9243526 | 2012-10-03 13:25:13 +0000 | [diff] [blame] | 68 | (row+1) * kCellHeight); |
| 69 | canvas->drawRect(right, borderPaint); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | private: |
| 76 | typedef SkBenchmark INHERITED; |
| 77 | }; |
| 78 | |
| 79 | static SkBenchmark* gFactory(void* p) { return new TableBench(p); } |
| 80 | |
| 81 | static BenchRegistry gRegistry(gFactory); |