blob: 0083dd4e256a7efe32e4c825efe5dabc08375eea [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
9#include "SkBenchmark.h"
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 */
18class FSRectBench : public SkBenchmark {
19public:
20 FSRectBench(void* param)
21 : INHERITED(param)
22 , fInit(false) {
23 }
24
25protected:
26 virtual const char* onGetName() SK_OVERRIDE { return "fullscreen_rects"; }
27
28 virtual void onPreDraw() SK_OVERRIDE {
29 if (!fInit) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000030 SkRandom rand;
bsalomon@google.comaade2e12013-08-02 14:39:25 +000031 static const SkScalar kMinOffset = 0;
32 static const SkScalar kMaxOffset = 100 * SK_Scalar1;
33 static const SkScalar kOffsetRange = kMaxOffset - kMinOffset;
34 for (int i = 0; i < N; ++i) {
35 fRects[i].fLeft = -kMinOffset - SkScalarMul(rand.nextUScalar1(), kOffsetRange);
36 fRects[i].fTop = -kMinOffset - SkScalarMul(rand.nextUScalar1(), kOffsetRange);
37 fRects[i].fRight = W + kMinOffset + SkScalarMul(rand.nextUScalar1(), kOffsetRange);
38 fRects[i].fBottom = H + kMinOffset + SkScalarMul(rand.nextUScalar1(), kOffsetRange);
39 fColors[i] = rand.nextU() | 0xFF000000;
40 }
41 fInit = true;
42 }
43 }
44
45 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
46 SkPaint paint;
mtklein@google.comc2897432013-09-10 19:23:38 +000047 for (int i = 0; i < this->getLoops(); ++i) {
48 paint.setColor(fColors[i % N]);
49 canvas->drawRect(fRects[i % N], paint);
bsalomon@google.comaade2e12013-08-02 14:39:25 +000050 }
51 }
52
53private:
54 enum {
55 W = 640,
56 H = 480,
mtklein@google.comc2897432013-09-10 19:23:38 +000057 N = 300,
bsalomon@google.comaade2e12013-08-02 14:39:25 +000058 };
59 SkRect fRects[N];
60 SkColor fColors[N];
61 bool fInit;
62
63 typedef SkBenchmark INHERITED;
64};
65
66DEF_BENCH( return SkNEW_ARGS(FSRectBench, (p)); )