blob: 128ae6c351460fc3827fddce1cb7651f3c8180b8 [file] [log] [blame]
Jim Van Verthe549a052017-02-21 17:55:13 -05001/*
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
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/SkColor.h"
11#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkRRect.h"
13#include "include/core/SkRect.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#include "include/core/SkScalar.h"
15#include "include/core/SkSize.h"
16#include "include/core/SkString.h"
Kevin Lubick0d4d1142023-02-13 09:13:10 -050017#include "src/base/SkRandom.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "tools/ToolUtils.h"
Jim Van Verthe549a052017-02-21 17:55:13 -050019
20namespace skiagm {
21
22static SkColor gen_color(SkRandom* rand) {
23 SkScalar hsv[3];
24 hsv[0] = rand->nextRangeF(0.0f, 360.0f);
25 hsv[1] = rand->nextRangeF(0.5f, 1.0f);
26 hsv[2] = rand->nextRangeF(0.5f, 1.0f);
27
Mike Kleinea3f0142019-03-20 11:12:10 -050028 return ToolUtils::color_to_565(SkHSVToColor(hsv));
Jim Van Verthe549a052017-02-21 17:55:13 -050029}
30
31class ManyCirclesGM : public GM {
32 // This GM attempts to flood Ganesh with more circles than will fit in a single index buffer
33 // Stresses crbug.com/688582.
34public:
35 ManyCirclesGM() {
36 this->setBGColor(0xFFFFFFFF);
37 }
38
39protected:
40 static const int kWidth = 800;
41 static const int kHeight = 600;
42
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000043 SkString getName() const override { return SkString("manycircles"); }
Jim Van Verthe549a052017-02-21 17:55:13 -050044
Leandro Lovisolo8f023882023-08-15 21:13:52 +000045 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
Jim Van Verthe549a052017-02-21 17:55:13 -050046
47 void onDraw(SkCanvas* canvas) override {
48 SkRandom rand(1);
49 SkPaint paint;
50 paint.setAntiAlias(true);
51 int total = 10000;
52 while (total--) {
53 SkScalar x = rand.nextF() * kWidth - 100;
54 SkScalar y = rand.nextF() * kHeight - 100;
55 SkScalar w = rand.nextF() * 200;
56 SkRect circle = SkRect::MakeXYWH(x, y, w, w);
57 paint.setColor(gen_color(&rand));
58 canvas->drawOval(circle, paint);
59 }
60 }
61
62private:
John Stiles7571f9e2020-09-02 22:42:33 -040063 using INHERITED = GM;
Jim Van Verthe549a052017-02-21 17:55:13 -050064};
65
66//////////////////////////////////////////////////////////////////////////////
67
68class ManyRRectsGM : public GM {
69 // This GM attempts to flood Ganesh with more rrects than will fit in a single index buffer
70 // Stresses crbug.com/684112
71public:
72 ManyRRectsGM() {
73 this->setBGColor(0xFFFFFFFF);
74 }
75
76protected:
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000077 SkString getName() const override { return SkString("manyrrects"); }
Jim Van Verthe549a052017-02-21 17:55:13 -050078
Leandro Lovisolo8f023882023-08-15 21:13:52 +000079 SkISize getISize() override { return SkISize::Make(800, 300); }
Jim Van Verthe549a052017-02-21 17:55:13 -050080
81 void onDraw(SkCanvas* canvas) override {
82 SkRandom rand(1);
83 SkPaint paint;
84 paint.setAntiAlias(true);
85 paint.setColor(SK_ColorBLUE);
86 int total = 7000;
87
88 // Rectangle positioning variables
89 int x = 0;
90 int y = 0;
91 const int kXLimit = 700;
92 const int kYIncrement = 5;
93 const int kXIncrement = 5;
94
95 SkRect rect = SkRect::MakeLTRB(0, 0, 4, 4);
96 SkRRect rrect = SkRRect::MakeRectXY(rect, 1, 1);
97 while (total--) {
98 canvas->save();
99 canvas->translate(x, y);
100 canvas->drawRRect(rrect, paint);
101 x += kXIncrement;
102 if (x > kXLimit) {
103 x = 0;
104 y += kYIncrement;
105 }
106 canvas->restore();
107 }
108 }
109
110private:
John Stiles7571f9e2020-09-02 22:42:33 -0400111 using INHERITED = GM;
Jim Van Verthe549a052017-02-21 17:55:13 -0500112};
113
114//////////////////////////////////////////////////////////////////////////////
115
116DEF_GM( return new ManyCirclesGM; )
117DEF_GM( return new ManyRRectsGM; )
118
John Stilesa6841be2020-08-06 14:11:56 -0400119} // namespace skiagm