2013-08-02 14:39:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2013-08-02 14:39:25 +00:00
|
|
|
#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.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
class FSRectBench : public Benchmark {
|
2013-08-02 14:39:25 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
FSRectBench() : fInit(false) { }
|
2013-08-02 14:39:25 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override { return "fullscreen_rects"; }
|
2013-08-02 14:39:25 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onPreDraw() override {
|
2013-08-02 14:39:25 +00:00
|
|
|
if (!fInit) {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-08-02 14:39:25 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2013-08-02 14:39:25 +00:00
|
|
|
SkPaint paint;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-09-10 19:23:38 +00:00
|
|
|
paint.setColor(fColors[i % N]);
|
|
|
|
canvas->drawRect(fRects[i % N], paint);
|
2013-08-02 14:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum {
|
|
|
|
W = 640,
|
|
|
|
H = 480,
|
2013-09-10 19:23:38 +00:00
|
|
|
N = 300,
|
2013-08-02 14:39:25 +00:00
|
|
|
};
|
|
|
|
SkRect fRects[N];
|
|
|
|
SkColor fColors[N];
|
|
|
|
bool fInit;
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-08-02 14:39:25 +00:00
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return SkNEW_ARGS(FSRectBench, ()); )
|