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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2013-08-02 14:39:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() 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) {
|
2017-02-14 15:59:19 +00:00
|
|
|
fRects[i].fLeft = -kMinOffset - rand.nextUScalar1() * kOffsetRange;
|
|
|
|
fRects[i].fTop = -kMinOffset - rand.nextUScalar1() * kOffsetRange;
|
|
|
|
fRects[i].fRight = W + kMinOffset + rand.nextUScalar1() * kOffsetRange;
|
|
|
|
fRects[i].fBottom = H + kMinOffset + rand.nextUScalar1() * kOffsetRange;
|
2013-08-02 14:39:25 +00:00
|
|
|
fColors[i] = rand.nextU() | 0xFF000000;
|
|
|
|
}
|
|
|
|
fInit = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(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
|
|
|
};
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_BENCH(return new FSRectBench();)
|