blob: 2d5abc21cdebfdc88f766abc58aff49cdd609f86 [file] [log] [blame]
bsalomon@google.comaade2e12013-08-02 14:39:25 +00001/*
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
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
bsalomon@google.comaade2e12013-08-02 14:39:25 +00009#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 */
tfarinaf168b862014-06-19 12:32:29 -070017class FSRectBench : public Benchmark {
bsalomon@google.comaade2e12013-08-02 14:39:25 +000018public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000019 FSRectBench() : fInit(false) { }
bsalomon@google.comaade2e12013-08-02 14:39:25 +000020
21protected:
mtklein36352bf2015-03-25 18:17:31 -070022 const char* onGetName() override { return "fullscreen_rects"; }
bsalomon@google.comaade2e12013-08-02 14:39:25 +000023
joshualitt8a6697a2015-09-30 12:11:07 -070024 void onDelayedSetup() override {
bsalomon@google.comaade2e12013-08-02 14:39:25 +000025 if (!fInit) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000026 SkRandom rand;
bsalomon@google.comaade2e12013-08-02 14:39:25 +000027 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
mtkleina1ebeb22015-10-01 09:43:39 -070041 void onDraw(int loops, SkCanvas* canvas) override {
bsalomon@google.comaade2e12013-08-02 14:39:25 +000042 SkPaint paint;
commit-bot@chromium.org33614712013-12-03 18:17:16 +000043 for (int i = 0; i < loops; ++i) {
mtklein@google.comc2897432013-09-10 19:23:38 +000044 paint.setColor(fColors[i % N]);
45 canvas->drawRect(fRects[i % N], paint);
bsalomon@google.comaade2e12013-08-02 14:39:25 +000046 }
47 }
48
49private:
50 enum {
51 W = 640,
52 H = 480,
mtklein@google.comc2897432013-09-10 19:23:38 +000053 N = 300,
bsalomon@google.comaade2e12013-08-02 14:39:25 +000054 };
55 SkRect fRects[N];
56 SkColor fColors[N];
57 bool fInit;
58
tfarinaf168b862014-06-19 12:32:29 -070059 typedef Benchmark INHERITED;
bsalomon@google.comaade2e12013-08-02 14:39:25 +000060};
61
halcanary385fe4d2015-08-26 13:07:48 -070062DEF_BENCH(return new FSRectBench();)