blob: 24fc263993c6acc0ba568cca70f44c5f456fee08 [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "include/utils/SkRandom.h"
18#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
43 SkString onShortName() override {
44 return SkString("manycircles");
45 }
46
47 SkISize onISize() override {
48 return SkISize::Make(kWidth, kHeight);
49 }
50
51 void onDraw(SkCanvas* canvas) override {
52 SkRandom rand(1);
53 SkPaint paint;
54 paint.setAntiAlias(true);
55 int total = 10000;
56 while (total--) {
57 SkScalar x = rand.nextF() * kWidth - 100;
58 SkScalar y = rand.nextF() * kHeight - 100;
59 SkScalar w = rand.nextF() * 200;
60 SkRect circle = SkRect::MakeXYWH(x, y, w, w);
61 paint.setColor(gen_color(&rand));
62 canvas->drawOval(circle, paint);
63 }
64 }
65
66private:
John Stiles7571f9e2020-09-02 22:42:33 -040067 using INHERITED = GM;
Jim Van Verthe549a052017-02-21 17:55:13 -050068};
69
70//////////////////////////////////////////////////////////////////////////////
71
72class ManyRRectsGM : public GM {
73 // This GM attempts to flood Ganesh with more rrects than will fit in a single index buffer
74 // Stresses crbug.com/684112
75public:
76 ManyRRectsGM() {
77 this->setBGColor(0xFFFFFFFF);
78 }
79
80protected:
81
82 SkString onShortName() override {
83 return SkString("manyrrects");
84 }
85
86 SkISize onISize() override {
87 return SkISize::Make(800, 300);
88 }
89
90 void onDraw(SkCanvas* canvas) override {
91 SkRandom rand(1);
92 SkPaint paint;
93 paint.setAntiAlias(true);
94 paint.setColor(SK_ColorBLUE);
95 int total = 7000;
96
97 // Rectangle positioning variables
98 int x = 0;
99 int y = 0;
100 const int kXLimit = 700;
101 const int kYIncrement = 5;
102 const int kXIncrement = 5;
103
104 SkRect rect = SkRect::MakeLTRB(0, 0, 4, 4);
105 SkRRect rrect = SkRRect::MakeRectXY(rect, 1, 1);
106 while (total--) {
107 canvas->save();
108 canvas->translate(x, y);
109 canvas->drawRRect(rrect, paint);
110 x += kXIncrement;
111 if (x > kXLimit) {
112 x = 0;
113 y += kYIncrement;
114 }
115 canvas->restore();
116 }
117 }
118
119private:
John Stiles7571f9e2020-09-02 22:42:33 -0400120 using INHERITED = GM;
Jim Van Verthe549a052017-02-21 17:55:13 -0500121};
122
123//////////////////////////////////////////////////////////////////////////////
124
125DEF_GM( return new ManyCirclesGM; )
126DEF_GM( return new ManyRRectsGM; )
127
John Stilesa6841be2020-08-06 14:11:56 -0400128} // namespace skiagm