blob: 3c5304294d1830f757205a9a64572e933635240c [file] [log] [blame]
bsalomon@google.comaade2e12013-08-02 14:39:25 +00001
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
tfarinaf168b862014-06-19 12:32:29 -07009#include "Benchmark.h"
bsalomon@google.comaade2e12013-08-02 14:39:25 +000010#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 */
tfarinaf168b862014-06-19 12:32:29 -070018class FSRectBench : public Benchmark {
bsalomon@google.comaade2e12013-08-02 14:39:25 +000019public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000020 FSRectBench() : fInit(false) { }
bsalomon@google.comaade2e12013-08-02 14:39:25 +000021
22protected:
23 virtual const char* onGetName() SK_OVERRIDE { return "fullscreen_rects"; }
24
25 virtual void onPreDraw() SK_OVERRIDE {
26 if (!fInit) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000027 SkRandom rand;
bsalomon@google.comaade2e12013-08-02 14:39:25 +000028 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
commit-bot@chromium.org33614712013-12-03 18:17:16 +000042 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
bsalomon@google.comaade2e12013-08-02 14:39:25 +000043 SkPaint paint;
commit-bot@chromium.org33614712013-12-03 18:17:16 +000044 for (int i = 0; i < loops; ++i) {
mtklein@google.comc2897432013-09-10 19:23:38 +000045 paint.setColor(fColors[i % N]);
46 canvas->drawRect(fRects[i % N], paint);
bsalomon@google.comaade2e12013-08-02 14:39:25 +000047 }
48 }
49
50private:
51 enum {
52 W = 640,
53 H = 480,
mtklein@google.comc2897432013-09-10 19:23:38 +000054 N = 300,
bsalomon@google.comaade2e12013-08-02 14:39:25 +000055 };
56 SkRect fRects[N];
57 SkColor fColors[N];
58 bool fInit;
59
tfarinaf168b862014-06-19 12:32:29 -070060 typedef Benchmark INHERITED;
bsalomon@google.comaade2e12013-08-02 14:39:25 +000061};
62
mtklein@google.com410e6e82013-09-13 19:52:27 +000063DEF_BENCH( return SkNEW_ARGS(FSRectBench, ()); )