Flutter Impeller
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 
7 namespace 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);
66  return UberSDFParameters{
68  .color = color,
69  .center = rect.GetCenter(),
70  .size = size,
71  .stroke = stroke,
72  .radii = Vector4(radii.bottom_right.width, radii.top_right.width,
73  radii.bottom_left.width, radii.top_left.width)};
74 }
75 
77  Color color,
78  const Rect& bounds,
79  const RoundSuperellipseParam& round_superellipse_params,
80  std::optional<StrokeParameters> stroke) {
81  FML_DCHECK(round_superellipse_params.all_corners_same);
82  Point center = bounds.GetCenter();
83 
85  round_superellipse_params.top_right;
86 
87  Point size = Point(bounds.GetSize() * 0.5f);
88 
89  return UberSDFParameters{
91  .color = color,
92  .center = center,
93  .size = size,
94  .stroke = stroke,
95  .superellipse_degree = Point(top_right.top.se_n, top_right.right.se_n),
96  .superellipse_semi_axis = Point(top_right.top.se_a, top_right.right.se_a),
97  .angle_span = Point(top_right.top.circle_max_angle.radians,
98  top_right.right.circle_max_angle.radians),
99  .octant_offset_c = top_right.top.se_a - top_right.right.se_a,
100  .circle_center_top = top_right.top.circle_center,
101  .circle_center_right = top_right.right.circle_center,
102  .superellipse_scale = top_right.signed_scale.Abs(),
103  .radii = Vector4(top_right.top.circle_radius,
104  top_right.right.circle_radius, 0.0f, 0.0f)};
105 }
106 
107 } // namespace impeller
float Scalar
Definition: scalar.h:19
TPoint< Scalar > Point
Definition: point.h:426
constexpr float kSqrt2
Definition: constants.h:47
Scalar radians
Definition: scalar.h:45
A structure to store all of the parameters related to stroking a path or basic geometry object.
constexpr TPoint Abs() const
Definition: point.h:294
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.
Color color
The color used for filling or stroking the shape.
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.
static UberSDFParameters MakeRoundedSuperellipse(Color color, const Rect &bounds, const RoundSuperellipseParam &round_superellipse_params, std::optional< StrokeParameters > stroke)
Creates UberSDFParameters for an asymmetric round superellipse.
std::optional< StrokeParameters > stroke
The stroke parameters. If std::nullopt, the shape is filled.
static UberSDFParameters MakeRect(Color color, const Rect &rect, std::optional< StrokeParameters > stroke)
Creates UberSDFParameters for a rectangle.