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