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