Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
uber_sdf_parameters.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7namespace impeller {
8
10 Color color,
11 const Rect& rect,
12 std::optional<StrokeParameters> stroke) {
13 // Size is the x and y extents from the center of the rect.
14 Point size = Point(rect.GetSize() * 0.5f);
15
16 // Stroke may be changed from miter to bevel joins depending on the miter
17 // limit.
18 std::optional<StrokeParameters> adjusted_stroke =
19 stroke && stroke->join == Join::kMiter && stroke->miter_limit < kSqrt2
20 ? std::make_optional(StrokeParameters(
21 {.width = stroke->width, .join = Join::kBevel}))
22 : stroke;
23
25 .color = color,
26 .center = rect.GetCenter(),
27 .size = size,
28 .stroke = adjusted_stroke};
29}
30
32 Color color,
33 const Point& center,
34 Scalar radius,
35 std::optional<StrokeParameters> stroke) {
36 // Both size parameters are the same, but this allows us to treat this
37 // case as if it were an oval to share code down the line. We can also
38 // share bounds calculations without having to test for circle vs rect.
39 Point size = Point(radius, radius);
40
42 .color = color,
43 .center = center,
44 .size = size,
45 .stroke = stroke};
46}
47
49 Color color,
50 const Rect& bounds,
51 std::optional<StrokeParameters> stroke) {
52 Point size = Point(bounds.GetSize() * 0.5f);
54 .color = color,
55 .center = bounds.GetCenter(),
56 .size = size,
57 .stroke = stroke};
58}
59
61 Color color,
62 const Rect& rect,
63 const RoundingRadii& radii,
64 std::optional<StrokeParameters> stroke) {
65 Point size = Point(rect.GetSize() * 0.5f);
67 .color = color,
68 .center = rect.GetCenter(),
69 .size = size,
70 .stroke = stroke,
71 .radii = radii};
72}
73
75 Color color,
76 Rect rect,
77 Point superellipse_degree,
78 Point superellipse_a,
79 RoundingRadii radii,
80 Point corner_angle_span,
81 Point corner_circle_center_top,
82 Point corner_circle_center_right,
83 Scalar superellipse_c,
84 Point superellipse_scale,
85 std::optional<StrokeParameters> stroke) {
86 Point size = Point(rect.GetSize() * 0.5f);
87 return UberSDFParameters{
89 .color = color,
90 .center = rect.GetCenter(),
91 .size = size,
92 .stroke = stroke,
93 .radii = radii,
94 .superellipse_degree = superellipse_degree,
95 .superellipse_a = superellipse_a,
96 .corner_angle_span = corner_angle_span,
97 .corner_circle_center_top = corner_circle_center_top,
98 .corner_circle_center_right = corner_circle_center_right,
99 .superellipse_c = superellipse_c,
100 .superellipse_scale = superellipse_scale};
101}
102
103} // namespace impeller
float Scalar
Definition scalar.h:19
TPoint< Scalar > Point
Definition point.h:426
constexpr float kSqrt2
Definition constants.h:47
A structure to store all of the parameters related to stroking a path or basic geometry object.
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
Definition rect.h:361
constexpr Point GetCenter() const
Get the center point as a |Point|.
Definition rect.h:416
Parameters for rendering shapes using the UberSDF shader.
Point superellipse_a
The semi-axes of the top (.x) and right (.y) superellipse segments.
Color color
The color used for filling or stroking the shape.
Point corner_circle_center_right
The center of the right circular arc in a RoundSuperellipse.
Point superellipse_degree
The degrees of the top (.x) and right (.y) octants of a RoundSuperellipse.
static UberSDFParameters MakeCircle(Color color, const Point &center, Scalar radius, std::optional< StrokeParameters > stroke)
Creates UberSDFParameters for a circle.
static UberSDFParameters MakeOval(Color color, const Rect &bounds, std::optional< StrokeParameters > stroke)
Creates UberSDFParameters for an Oval.
Type type
The type of shape to render.
Point center
The center point of the shape in local coordinates.
static UberSDFParameters MakeRoundedRect(Color color, const Rect &rect, const RoundingRadii &radii, std::optional< StrokeParameters > stroke)
Creates UberSDFParameters for a rounded rectangle.
Point corner_angle_span
The spans of the top (.x) and right (.y) circular arcs.
Point superellipse_scale
The scale of the superellipse.
std::optional< StrokeParameters > stroke
The stroke parameters. If std::nullopt, the shape is filled.
Point corner_circle_center_top
The center of the top circular arc in a RoundSuperellipse.
static UberSDFParameters MakeRect(Color color, const Rect &rect, std::optional< StrokeParameters > stroke)
Creates UberSDFParameters for a rectangle.
static UberSDFParameters MakeRoundedSuperellipse(Color color, Rect bounds, Point superellipse_degree, Point superellipse_a, RoundingRadii radii, Point corner_angle_span, Point corner_circle_center_top, Point corner_circle_center_right, Scalar superellipse_c, Point superellipse_scale, std::optional< StrokeParameters > stroke)
Creates UberSDFParameters for a symmetric round superellipse.
Scalar superellipse_c
The offset of the octants in a RoundSuperellipse.