blob: 92a7b6deef7069f56b8637128a715fc83c070495 [file] [log] [blame]
reed5e0d9272016-08-18 15:01:10 -07001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkCanvas.h"
10#include "include/core/SkPaint.h"
11#include "include/core/SkRect.h"
12#include "include/core/SkScalar.h"
13#include "include/core/SkSize.h"
14#include "include/core/SkString.h"
15#include "include/utils/SkRandom.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "tools/ToolUtils.h"
reed5e0d9272016-08-18 15:01:10 -070017
18class SimpleRectGM : public skiagm::GM {
19public:
20 SimpleRectGM() {}
21
22protected:
23 SkString onShortName() override {
24 SkString name;
25 name.printf("simplerect");
26 return name;
27 }
28
29 SkISize onISize() override {
reedc1fb8e82016-08-18 19:35:52 -070030 return SkISize::Make(800, 800);
reed5e0d9272016-08-18 15:01:10 -070031 }
32
33 void onDraw(SkCanvas* canvas) override {
reed577e0122016-08-21 15:03:47 -070034 canvas->translate(1, 1); // want to exercise non-identity ctm performance
35
reed5e0d9272016-08-18 15:01:10 -070036 const SkScalar min = -20;
37 const SkScalar max = 800;
38 const SkScalar size = 20;
39
40 SkRandom rand;
41 SkPaint paint;
42 for (int i = 0; i < 10000; i++) {
Mike Kleinea3f0142019-03-20 11:12:10 -050043 paint.setColor(ToolUtils::color_to_565(rand.nextU() | (0xFF << 24)));
reedc1fb8e82016-08-18 19:35:52 -070044 SkScalar x = rand.nextRangeScalar(min, max);
45 SkScalar y = rand.nextRangeScalar(min, max);
46 SkScalar w = rand.nextRangeScalar(0, size);
47 SkScalar h = rand.nextRangeScalar(0, size);
48 canvas->drawRect(SkRect::MakeXYWH(x, y, w, h), paint);
reed5e0d9272016-08-18 15:01:10 -070049 }
50 }
51
Hal Canary41248072019-07-11 16:32:53 -040052 bool onAnimate(double nanos) override { return true; }
reed5e0d9272016-08-18 15:01:10 -070053
54private:
55
56 typedef GM INHERITED;
57};
58DEF_GM(return new SimpleRectGM;)