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 | |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 18 | class AnimTimer; |
| 19 | |
reed | 5e0d927 | 2016-08-18 15:01:10 -0700 | [diff] [blame] | 20 | class SimpleRectGM : public skiagm::GM { |
| 21 | public: |
| 22 | SimpleRectGM() {} |
| 23 | |
| 24 | protected: |
| 25 | SkString onShortName() override { |
| 26 | SkString name; |
| 27 | name.printf("simplerect"); |
| 28 | return name; |
| 29 | } |
| 30 | |
| 31 | SkISize onISize() override { |
reed | c1fb8e8 | 2016-08-18 19:35:52 -0700 | [diff] [blame] | 32 | return SkISize::Make(800, 800); |
reed | 5e0d927 | 2016-08-18 15:01:10 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void onDraw(SkCanvas* canvas) override { |
reed | 577e012 | 2016-08-21 15:03:47 -0700 | [diff] [blame] | 36 | canvas->translate(1, 1); // want to exercise non-identity ctm performance |
| 37 | |
reed | 5e0d927 | 2016-08-18 15:01:10 -0700 | [diff] [blame] | 38 | 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 Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 45 | paint.setColor(ToolUtils::color_to_565(rand.nextU() | (0xFF << 24))); |
reed | c1fb8e8 | 2016-08-18 19:35:52 -0700 | [diff] [blame] | 46 | 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); |
reed | 5e0d927 | 2016-08-18 15:01:10 -0700 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | |
Mike Klein | cd5104e | 2019-03-20 11:55:08 -0500 | [diff] [blame] | 54 | bool onAnimate(const AnimTimer& timer) override { return true; } |
reed | 5e0d927 | 2016-08-18 15:01:10 -0700 | [diff] [blame] | 55 | |
| 56 | private: |
| 57 | |
| 58 | typedef GM INHERITED; |
| 59 | }; |
| 60 | DEF_GM(return new SimpleRectGM;) |