3 * Copyright 2013 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
15 * Draws full screen opaque rectangles. It is designed to test any optimizations in the GPU backend
16 * to turn such draws into clears.
18 class FSRectBench : public Benchmark {
20 FSRectBench() : fInit(false) { }
23 const char* onGetName() override { return "fullscreen_rects"; }
25 void onPreDraw() override {
28 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;
42 void onDraw(const int loops, SkCanvas* canvas) override {
44 for (int i = 0; i < loops; ++i) {
45 paint.setColor(fColors[i % N]);
46 canvas->drawRect(fRects[i % N], paint);
60 typedef Benchmark INHERITED;
63 DEF_BENCH( return SkNEW_ARGS(FSRectBench, ()); )