blob: b6238f67365681f239b66e211eceb489df04eca3 [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
Ben Wagner7fde8e12019-05-01 17:28:53 -040018class AnimTimer;
19
reed5e0d9272016-08-18 15:01:10 -070020class SimpleRectGM : public skiagm::GM {
21public:
22 SimpleRectGM() {}
23
24protected:
25 SkString onShortName() override {
26 SkString name;
27 name.printf("simplerect");
28 return name;
29 }
30
31 SkISize onISize() override {
reedc1fb8e82016-08-18 19:35:52 -070032 return SkISize::Make(800, 800);
reed5e0d9272016-08-18 15:01:10 -070033 }
34
35 void onDraw(SkCanvas* canvas) override {
reed577e0122016-08-21 15:03:47 -070036 canvas->translate(1, 1); // want to exercise non-identity ctm performance
37
reed5e0d9272016-08-18 15:01:10 -070038 const SkScalar min = -20;
39 const SkScalar max = 800;
40 const SkScalar size = 20;
41
42 SkRandom rand;
43 SkPaint paint;
44 for (int i = 0; i < 10000; i++) {
Mike Kleinea3f0142019-03-20 11:12:10 -050045 paint.setColor(ToolUtils::color_to_565(rand.nextU() | (0xFF << 24)));
reedc1fb8e82016-08-18 19:35:52 -070046 SkScalar x = rand.nextRangeScalar(min, max);
47 SkScalar y = rand.nextRangeScalar(min, max);
48 SkScalar w = rand.nextRangeScalar(0, size);
49 SkScalar h = rand.nextRangeScalar(0, size);
50 canvas->drawRect(SkRect::MakeXYWH(x, y, w, h), paint);
reed5e0d9272016-08-18 15:01:10 -070051 }
52 }
53
Mike Kleincd5104e2019-03-20 11:55:08 -050054 bool onAnimate(const AnimTimer& timer) override { return true; }
reed5e0d9272016-08-18 15:01:10 -070055
56private:
57
58 typedef GM INHERITED;
59};
60DEF_GM(return new SimpleRectGM;)