Flutter Engine
The Flutter Engine
third_party
skia
gm
beziers.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2014 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
"
9
#include "
include/core/SkCanvas.h
"
10
#include "
include/core/SkPaint.h
"
11
#include "
include/core/SkPathBuilder.h
"
12
#include "
include/core/SkScalar.h
"
13
#include "
include/core/SkSize.h
"
14
#include "
include/core/SkString.h
"
15
#include "
src/base/SkRandom.h
"
16
17
#define W 400
18
#define H 400
19
#define N 10
20
21
constexpr
SkScalar
SH
=
SkIntToScalar
(
H
);
22
23
static
SkPath
rnd_quad
(
SkPaint
*
paint
,
SkRandom
& rand) {
24
auto
a
= rand.
nextRangeScalar
(0,
W
),
25
b
= rand.
nextRangeScalar
(0,
H
);
26
27
SkPathBuilder
builder
;
28
builder
.moveTo(
a
,
b
);
29
for
(
int
x
= 0;
x
< 2; ++
x
) {
30
auto
c = rand.
nextRangeScalar
(
W
/4,
W
),
31
d
= rand.
nextRangeScalar
( 0,
H
),
32
e
= rand.
nextRangeScalar
( 0,
W
),
33
f
= rand.
nextRangeScalar
(
H
/4,
H
);
34
builder
.quadTo(c,
d
,
e
,
f
);
35
}
36
paint
->setColor(rand.
nextU
());
37
SkScalar
width
= rand.
nextRangeScalar
(1, 5);
38
width
*=
width
;
39
paint
->setStrokeWidth(
width
);
40
paint
->setAlphaf(1.0f);
41
return
builder
.detach();
42
}
43
44
static
SkPath
rnd_cubic
(
SkPaint
*
paint
,
SkRandom
& rand) {
45
auto
a
= rand.
nextRangeScalar
(0,
W
),
46
b
= rand.
nextRangeScalar
(0,
H
);
47
48
SkPathBuilder
builder
;
49
builder
.moveTo(
a
,
b
);
50
for
(
int
x
= 0;
x
< 2; ++
x
) {
51
auto
c = rand.
nextRangeScalar
(
W
/4,
W
),
52
d
= rand.
nextRangeScalar
( 0,
H
),
53
e
= rand.
nextRangeScalar
( 0,
W
),
54
f
= rand.
nextRangeScalar
(
H
/4,
H
),
55
g = rand.
nextRangeScalar
(
W
/4,
W
),
56
h
= rand.
nextRangeScalar
(
H
/4,
H
);
57
builder
.cubicTo(c,
d
,
e
,
f
,g,
h
);
58
}
59
paint
->setColor(rand.
nextU
());
60
SkScalar
width
= rand.
nextRangeScalar
(1, 5);
61
width
*=
width
;
62
paint
->setStrokeWidth(
width
);
63
paint
->setAlphaf(1.0f);
64
return
builder
.detach();
65
}
66
67
class
BeziersGM
:
public
skiagm::GM
{
68
public
:
69
BeziersGM
() {}
70
71
protected
:
72
SkString
getName
()
const override
{
return
SkString
(
"beziers"
); }
73
74
SkISize
getISize
()
override
{
return
SkISize::Make
(
W
,
H
* 2); }
75
76
void
onDraw
(
SkCanvas
* canvas)
override
{
77
SkPaint
paint
;
78
paint
.setStyle(
SkPaint::kStroke_Style
);
79
paint
.setStrokeWidth(
SkIntToScalar
(9)/2);
80
paint
.setAntiAlias(
true
);
81
82
SkRandom
rand;
83
for
(
int
i
= 0;
i
<
N
;
i
++) {
84
canvas->
drawPath
(
rnd_quad
(&
paint
, rand),
paint
);
85
}
86
canvas->
translate
(0,
SH
);
87
for
(
int
i
= 0;
i
<
N
;
i
++) {
88
canvas->
drawPath
(
rnd_cubic
(&
paint
, rand),
paint
);
89
}
90
}
91
92
private
:
93
using
INHERITED =
skiagm::GM
;
94
};
95
96
DEF_GM
(
return
new
BeziersGM
; )
SkCanvas.h
SkPaint.h
SkPathBuilder.h
SkRandom.h
SkScalar.h
SkIntToScalar
#define SkIntToScalar(x)
Definition:
SkScalar.h:57
SkSize.h
SkString.h
N
#define N
Definition:
beziers.cpp:19
rnd_cubic
static SkPath rnd_cubic(SkPaint *paint, SkRandom &rand)
Definition:
beziers.cpp:44
SH
constexpr SkScalar SH
Definition:
beziers.cpp:21
W
#define W
Definition:
beziers.cpp:17
rnd_quad
static SkPath rnd_quad(SkPaint *paint, SkRandom &rand)
Definition:
beziers.cpp:23
BeziersGM
Definition:
beziers.cpp:67
BeziersGM::BeziersGM
BeziersGM()
Definition:
beziers.cpp:69
BeziersGM::onDraw
void onDraw(SkCanvas *canvas) override
Definition:
beziers.cpp:76
BeziersGM::getISize
SkISize getISize() override
Definition:
beziers.cpp:74
BeziersGM::getName
SkString getName() const override
Definition:
beziers.cpp:72
SkCanvas
Definition:
SkCanvas.h:106
SkCanvas::translate
void translate(SkScalar dx, SkScalar dy)
Definition:
SkCanvas.cpp:1278
SkCanvas::drawPath
void drawPath(const SkPath &path, const SkPaint &paint)
Definition:
SkCanvas.cpp:1747
SkPaint
Definition:
SkPaint.h:44
SkPaint::kStroke_Style
@ kStroke_Style
set to stroke geometry
Definition:
SkPaint.h:194
SkPathBuilder
Definition:
SkPathBuilder.h:25
SkPath
Definition:
SkPath.h:59
SkRandom
Definition:
SkRandom.h:27
SkRandom::nextU
uint32_t nextU()
Definition:
SkRandom.h:42
SkRandom::nextRangeScalar
SkScalar nextRangeScalar(SkScalar min, SkScalar max)
Definition:
SkRandom.h:106
SkString
Definition:
SkString.h:118
skiagm::GM
Definition:
gm.h:110
paint
const Paint & paint
Definition:
color_source.cc:38
d
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition:
main.cc:19
SkScalar
float SkScalar
Definition:
extension.cpp:12
b
static bool b
Definition:
ffi_native_test_module.c:74
a
struct MyStruct a[10]
i
int i
Definition:
fl_socket_accessible.cc:18
gm.h
DEF_GM
#define DEF_GM(CODE)
Definition:
gm.h:40
x
double x
Definition:
mouse-input-test.cc:82
dependency.builder
builder
Definition:
dependency.py:1
protoc_wrapper.e
e
Definition:
protoc_wrapper.py:226
skcms_private::f
float f
Definition:
skcms_Transform.h:121
h
SkScalar h
Definition:
pictureshadertile.cpp:30
width
int32_t width
Definition:
serialization_callbacks.cc:0
H
Definition:
SkMD5.cpp:130
SkISize
Definition:
SkSize.h:16
SkISize::Make
static constexpr SkISize Make(int32_t w, int32_t h)
Definition:
SkSize.h:20
Generated on Sun Jun 23 2024 21:55:57 for Flutter Engine by
1.9.4