Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
manypaths.cpp
Go to the documentation of this file.
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/gm.h"
13#include "include/core/SkRect.h"
15#include "include/core/SkSize.h"
17#include "src/base/SkRandom.h"
18#include "tools/ToolUtils.h"
19
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
29}
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:
36 this->setBGColor(0xFFFFFFFF);
37 }
38
39protected:
40 static const int kWidth = 800;
41 static const int kHeight = 600;
42
43 SkString getName() const override { return SkString("manycircles"); }
44
45 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
46
47 void onDraw(SkCanvas* canvas) override {
48 SkRandom rand(1);
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:
63 using INHERITED = GM;
64};
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:
73 this->setBGColor(0xFFFFFFFF);
74 }
75
76protected:
77 SkString getName() const override { return SkString("manyrrects"); }
78
79 SkISize getISize() override { return SkISize::Make(800, 300); }
80
81 void onDraw(SkCanvas* canvas) override {
82 SkRandom rand(1);
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:
111 using INHERITED = GM;
112};
113
114//////////////////////////////////////////////////////////////////////////////
115
116DEF_GM( return new ManyCirclesGM; )
117DEF_GM( return new ManyRRectsGM; )
118
119} // namespace skiagm
uint32_t SkColor
Definition SkColor.h:37
SK_API SkColor SkHSVToColor(U8CPU alpha, const SkScalar hsv[3])
Definition SkColor.cpp:78
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
void drawOval(const SkRect &oval, const SkPaint &paint)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
int save()
Definition SkCanvas.cpp:451
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition SkRRect.h:180
float nextF()
Definition SkRandom.h:55
float nextRangeF(float min, float max)
Definition SkRandom.h:64
void setBGColor(SkColor)
Definition gm.cpp:159
static const int kWidth
Definition manypaths.cpp:40
SkISize getISize() override
Definition manypaths.cpp:45
SkString getName() const override
Definition manypaths.cpp:43
void onDraw(SkCanvas *canvas) override
Definition manypaths.cpp:47
static const int kHeight
Definition manypaths.cpp:41
void onDraw(SkCanvas *canvas) override
Definition manypaths.cpp:81
SkString getName() const override
Definition manypaths.cpp:77
SkISize getISize() override
Definition manypaths.cpp:79
const Paint & paint
float SkScalar
Definition extension.cpp:12
#define DEF_GM(CODE)
Definition gm.h:40
double y
double x
SkColor color_to_565(SkColor color)
static SkColor gen_color(SkRandom *rand)
Definition manypaths.cpp:22
SkScalar w
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646