Jim Van Verth | e549a05 | 2017-02-21 17:55:13 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
| 8 | #include "gm.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
Jim Van Verth | e549a05 | 2017-02-21 17:55:13 -0500 | [diff] [blame] | 10 | #include "SkRandom.h" |
| 11 | #include "SkRect.h" |
| 12 | #include "SkRRect.h" |
| 13 | |
| 14 | namespace skiagm { |
| 15 | |
| 16 | static SkColor gen_color(SkRandom* rand) { |
| 17 | SkScalar hsv[3]; |
| 18 | hsv[0] = rand->nextRangeF(0.0f, 360.0f); |
| 19 | hsv[1] = rand->nextRangeF(0.5f, 1.0f); |
| 20 | hsv[2] = rand->nextRangeF(0.5f, 1.0f); |
| 21 | |
| 22 | return sk_tool_utils::color_to_565(SkHSVToColor(hsv)); |
| 23 | } |
| 24 | |
| 25 | class ManyCirclesGM : public GM { |
| 26 | // This GM attempts to flood Ganesh with more circles than will fit in a single index buffer |
| 27 | // Stresses crbug.com/688582. |
| 28 | public: |
| 29 | ManyCirclesGM() { |
| 30 | this->setBGColor(0xFFFFFFFF); |
| 31 | } |
| 32 | |
| 33 | protected: |
| 34 | static const int kWidth = 800; |
| 35 | static const int kHeight = 600; |
| 36 | |
| 37 | SkString onShortName() override { |
| 38 | return SkString("manycircles"); |
| 39 | } |
| 40 | |
| 41 | SkISize onISize() override { |
| 42 | return SkISize::Make(kWidth, kHeight); |
| 43 | } |
| 44 | |
| 45 | void onDraw(SkCanvas* canvas) override { |
| 46 | SkRandom rand(1); |
| 47 | SkPaint paint; |
| 48 | paint.setAntiAlias(true); |
| 49 | int total = 10000; |
| 50 | while (total--) { |
| 51 | SkScalar x = rand.nextF() * kWidth - 100; |
| 52 | SkScalar y = rand.nextF() * kHeight - 100; |
| 53 | SkScalar w = rand.nextF() * 200; |
| 54 | SkRect circle = SkRect::MakeXYWH(x, y, w, w); |
| 55 | paint.setColor(gen_color(&rand)); |
| 56 | canvas->drawOval(circle, paint); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | private: |
| 61 | typedef GM INHERITED; |
| 62 | }; |
| 63 | |
| 64 | ////////////////////////////////////////////////////////////////////////////// |
| 65 | |
| 66 | class ManyRRectsGM : public GM { |
| 67 | // This GM attempts to flood Ganesh with more rrects than will fit in a single index buffer |
| 68 | // Stresses crbug.com/684112 |
| 69 | public: |
| 70 | ManyRRectsGM() { |
| 71 | this->setBGColor(0xFFFFFFFF); |
| 72 | } |
| 73 | |
| 74 | protected: |
| 75 | |
| 76 | SkString onShortName() override { |
| 77 | return SkString("manyrrects"); |
| 78 | } |
| 79 | |
| 80 | SkISize onISize() override { |
| 81 | return SkISize::Make(800, 300); |
| 82 | } |
| 83 | |
| 84 | void onDraw(SkCanvas* canvas) override { |
| 85 | SkRandom rand(1); |
| 86 | SkPaint paint; |
| 87 | paint.setAntiAlias(true); |
| 88 | paint.setColor(SK_ColorBLUE); |
| 89 | int total = 7000; |
| 90 | |
| 91 | // Rectangle positioning variables |
| 92 | int x = 0; |
| 93 | int y = 0; |
| 94 | const int kXLimit = 700; |
| 95 | const int kYIncrement = 5; |
| 96 | const int kXIncrement = 5; |
| 97 | |
| 98 | SkRect rect = SkRect::MakeLTRB(0, 0, 4, 4); |
| 99 | SkRRect rrect = SkRRect::MakeRectXY(rect, 1, 1); |
| 100 | while (total--) { |
| 101 | canvas->save(); |
| 102 | canvas->translate(x, y); |
| 103 | canvas->drawRRect(rrect, paint); |
| 104 | x += kXIncrement; |
| 105 | if (x > kXLimit) { |
| 106 | x = 0; |
| 107 | y += kYIncrement; |
| 108 | } |
| 109 | canvas->restore(); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | private: |
| 114 | typedef GM INHERITED; |
| 115 | }; |
| 116 | |
| 117 | ////////////////////////////////////////////////////////////////////////////// |
| 118 | |
| 119 | DEF_GM( return new ManyCirclesGM; ) |
| 120 | DEF_GM( return new ManyRRectsGM; ) |
| 121 | |
| 122 | } |