bsalomon@google.com | aade2e1 | 2013-08-02 14:39:25 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2013 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 9 | #include "Benchmark.h" |
bsalomon@google.com | aade2e1 | 2013-08-02 14:39:25 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkPaint.h" |
| 12 | #include "SkRandom.h" |
| 13 | |
| 14 | /** |
| 15 | * Draws full screen opaque rectangles. It is designed to test any optimizations in the GPU backend |
| 16 | * to turn such draws into clears. |
| 17 | */ |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 18 | class FSRectBench : public Benchmark { |
bsalomon@google.com | aade2e1 | 2013-08-02 14:39:25 +0000 | [diff] [blame] | 19 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 20 | FSRectBench() : fInit(false) { } |
bsalomon@google.com | aade2e1 | 2013-08-02 14:39:25 +0000 | [diff] [blame] | 21 | |
| 22 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 23 | const char* onGetName() override { return "fullscreen_rects"; } |
bsalomon@google.com | aade2e1 | 2013-08-02 14:39:25 +0000 | [diff] [blame] | 24 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 25 | void onDelayedSetup() override { |
bsalomon@google.com | aade2e1 | 2013-08-02 14:39:25 +0000 | [diff] [blame] | 26 | if (!fInit) { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 27 | SkRandom rand; |
bsalomon@google.com | aade2e1 | 2013-08-02 14:39:25 +0000 | [diff] [blame] | 28 | static const SkScalar kMinOffset = 0; |
| 29 | static const SkScalar kMaxOffset = 100 * SK_Scalar1; |
| 30 | static const SkScalar kOffsetRange = kMaxOffset - kMinOffset; |
| 31 | for (int i = 0; i < N; ++i) { |
| 32 | fRects[i].fLeft = -kMinOffset - SkScalarMul(rand.nextUScalar1(), kOffsetRange); |
| 33 | fRects[i].fTop = -kMinOffset - SkScalarMul(rand.nextUScalar1(), kOffsetRange); |
| 34 | fRects[i].fRight = W + kMinOffset + SkScalarMul(rand.nextUScalar1(), kOffsetRange); |
| 35 | fRects[i].fBottom = H + kMinOffset + SkScalarMul(rand.nextUScalar1(), kOffsetRange); |
| 36 | fColors[i] = rand.nextU() | 0xFF000000; |
| 37 | } |
| 38 | fInit = true; |
| 39 | } |
| 40 | } |
| 41 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 42 | void onDraw(int loops, SkCanvas* canvas) override { |
bsalomon@google.com | aade2e1 | 2013-08-02 14:39:25 +0000 | [diff] [blame] | 43 | SkPaint paint; |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 44 | for (int i = 0; i < loops; ++i) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 45 | paint.setColor(fColors[i % N]); |
| 46 | canvas->drawRect(fRects[i % N], paint); |
bsalomon@google.com | aade2e1 | 2013-08-02 14:39:25 +0000 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
| 50 | private: |
| 51 | enum { |
| 52 | W = 640, |
| 53 | H = 480, |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 54 | N = 300, |
bsalomon@google.com | aade2e1 | 2013-08-02 14:39:25 +0000 | [diff] [blame] | 55 | }; |
| 56 | SkRect fRects[N]; |
| 57 | SkColor fColors[N]; |
| 58 | bool fInit; |
| 59 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 60 | typedef Benchmark INHERITED; |
bsalomon@google.com | aade2e1 | 2013-08-02 14:39:25 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 63 | DEF_BENCH(return new FSRectBench();) |