reed | 5e0d927 | 2016-08-18 15:01:10 -0700 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "tools/ToolUtils.h" |
reed | 5e0d927 | 2016-08-18 15:01:10 -0700 | [diff] [blame] | 17 | |
| 18 | class SimpleRectGM : public skiagm::GM { |
| 19 | public: |
| 20 | SimpleRectGM() {} |
| 21 | |
| 22 | protected: |
| 23 | SkString onShortName() override { |
| 24 | SkString name; |
| 25 | name.printf("simplerect"); |
| 26 | return name; |
| 27 | } |
| 28 | |
| 29 | SkISize onISize() override { |
reed | c1fb8e8 | 2016-08-18 19:35:52 -0700 | [diff] [blame] | 30 | return SkISize::Make(800, 800); |
reed | 5e0d927 | 2016-08-18 15:01:10 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | void onDraw(SkCanvas* canvas) override { |
reed | 577e012 | 2016-08-21 15:03:47 -0700 | [diff] [blame] | 34 | canvas->translate(1, 1); // want to exercise non-identity ctm performance |
| 35 | |
reed | 5e0d927 | 2016-08-18 15:01:10 -0700 | [diff] [blame] | 36 | 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 Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 43 | paint.setColor(ToolUtils::color_to_565(rand.nextU() | (0xFF << 24))); |
reed | c1fb8e8 | 2016-08-18 19:35:52 -0700 | [diff] [blame] | 44 | 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); |
reed | 5e0d927 | 2016-08-18 15:01:10 -0700 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
Hal Canary | 4124807 | 2019-07-11 16:32:53 -0400 | [diff] [blame] | 52 | bool onAnimate(double nanos) override { return true; } |
reed | 5e0d927 | 2016-08-18 15:01:10 -0700 | [diff] [blame] | 53 | |
| 54 | private: |
| 55 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame^] | 56 | using INHERITED = GM; |
reed | 5e0d927 | 2016-08-18 15:01:10 -0700 | [diff] [blame] | 57 | }; |
| 58 | DEF_GM(return new SimpleRectGM;) |