aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/FSRectBench.cpp
blob: 64c1c3d35f95027950773aecc6832b0e2e4c904b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkBenchmark.h"
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkRandom.h"

/**
 * Draws full screen opaque rectangles. It is designed to test any optimizations in the GPU backend
 * to turn such draws into clears.
 */
class FSRectBench : public SkBenchmark {
public:
    FSRectBench(void* param)
        : INHERITED(param)
        , fInit(false) {
    }

protected:
    virtual const char* onGetName() SK_OVERRIDE { return "fullscreen_rects"; }

    virtual void onPreDraw() SK_OVERRIDE {
        if (!fInit) {
            SkMWCRandom rand;
            static const SkScalar kMinOffset = 0;
            static const SkScalar kMaxOffset = 100 * SK_Scalar1;
            static const SkScalar kOffsetRange = kMaxOffset - kMinOffset;
            for (int i = 0; i < N; ++i) {
                fRects[i].fLeft = -kMinOffset - SkScalarMul(rand.nextUScalar1(), kOffsetRange);
                fRects[i].fTop = -kMinOffset - SkScalarMul(rand.nextUScalar1(), kOffsetRange);
                fRects[i].fRight = W + kMinOffset + SkScalarMul(rand.nextUScalar1(), kOffsetRange);
                fRects[i].fBottom = H + kMinOffset + SkScalarMul(rand.nextUScalar1(), kOffsetRange);
                fColors[i] = rand.nextU() | 0xFF000000;
            }
            fInit = true;
        }
    }

    virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
        SkPaint paint;
        for (int i = 0; i < N; ++i) {
            paint.setColor(fColors[i]);
            canvas->drawRect(fRects[i], paint);
        }
    }

private:
    enum {
        W = 640,
        H = 480,
        N = SkBENCHLOOP(300)
    };
    SkRect  fRects[N];
    SkColor fColors[N];
    bool fInit;

    typedef SkBenchmark INHERITED;
};

DEF_BENCH( return SkNEW_ARGS(FSRectBench, (p)); )