Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::UberSDFParameters Struct Reference

Parameters for rendering shapes using the UberSDF shader. More...

#include <uber_sdf_parameters.h>

Public Types

enum class  Type {
  kCircle ,
  kRect ,
  kOval ,
  kRoundedRect ,
  kRoundedSuperellipseSymmetric
}
 The type of primitive shape. More...
 

Static Public Member Functions

static UberSDFParameters MakeRect (Color color, const Rect &rect, std::optional< StrokeParameters > stroke)
 Creates UberSDFParameters for a rectangle.
 
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.
 
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.
 

Public Attributes

Type type
 The type of shape to render.
 
Color color
 The color used for filling or stroking the shape.
 
Point center
 The center point of the shape in local coordinates.
 
Point size
 
std::optional< StrokeParametersstroke
 The stroke parameters. If std::nullopt, the shape is filled.
 
Point superellipse_degree
 The degree (n) of the superellipse curve for the top and right octants.
 
Point superellipse_semi_axis
 
Point angle_span
 The angular span of the circular cap for the top and right octants.
 
float octant_offset_c
 The geometric offset 'c' used to connect the two octants of each quadrant.
 
Point circle_center_top
 
Point circle_center_right
 
Point superellipse_scale
 
Vector4 radii
 

Static Public Attributes

static constexpr Scalar kAntialiasPixels = 1.0f
 

Detailed Description

Parameters for rendering shapes using the UberSDF shader.

Definition at line 21 of file uber_sdf_parameters.h.

Member Enumeration Documentation

◆ Type

The type of primitive shape.

Enumerator
kCircle 
kRect 
kOval 
kRoundedRect 
kRoundedSuperellipseSymmetric 

Definition at line 27 of file uber_sdf_parameters.h.

Member Function Documentation

◆ MakeCircle()

UberSDFParameters impeller::UberSDFParameters::MakeCircle ( Color  color,
const Point center,
Scalar  radius,
std::optional< StrokeParameters stroke 
)
static

Creates UberSDFParameters for a circle.

Definition at line 31 of file uber_sdf_parameters.cc.

35 {
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
41 return UberSDFParameters{.type = Type::kCircle,
42 .color = color,
43 .center = center,
44 .size = size,
45 .stroke = stroke};
46}
TPoint< Scalar > Point
Definition point.h:426
Color color
The color used for filling or stroking the shape.
Point center
The center point of the shape in local coordinates.
std::optional< StrokeParameters > stroke
The stroke parameters. If std::nullopt, the shape is filled.

References center, color, kCircle, size, stroke, and type.

Referenced by impeller::Canvas::DrawCircle(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), and impeller::testing::TEST().

◆ MakeOval()

UberSDFParameters impeller::UberSDFParameters::MakeOval ( Color  color,
const Rect bounds,
std::optional< StrokeParameters stroke 
)
static

Creates UberSDFParameters for an Oval.

Definition at line 48 of file uber_sdf_parameters.cc.

51 {
52 Point size = Point(bounds.GetSize() * 0.5f);
53 return UberSDFParameters{.type = Type::kOval,
54 .color = color,
55 .center = bounds.GetCenter(),
56 .size = size,
57 .stroke = stroke};
58}

References color, impeller::TRect< T >::GetCenter(), impeller::TRect< T >::GetSize(), kOval, size, stroke, and type.

Referenced by impeller::Canvas::DrawOval(), impeller::testing::TEST(), and impeller::testing::TEST().

◆ MakeRect()

UberSDFParameters impeller::UberSDFParameters::MakeRect ( Color  color,
const Rect rect,
std::optional< StrokeParameters stroke 
)
static

Creates UberSDFParameters for a rectangle.

Definition at line 9 of file uber_sdf_parameters.cc.

12 {
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
24 return UberSDFParameters{.type = Type::kRect,
25 .color = color,
26 .center = rect.GetCenter(),
27 .size = size,
28 .stroke = adjusted_stroke};
29}
constexpr float kSqrt2
Definition constants.h:47

References color, impeller::TRect< T >::GetCenter(), impeller::TRect< T >::GetSize(), impeller::kBevel, impeller::kMiter, kRect, impeller::kSqrt2, size, stroke, and type.

Referenced by impeller::Canvas::DrawRect(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), and impeller::testing::TEST().

◆ MakeRoundedRect()

UberSDFParameters impeller::UberSDFParameters::MakeRoundedRect ( Color  color,
const Rect rect,
const RoundingRadii radii,
std::optional< StrokeParameters stroke 
)
static

Creates UberSDFParameters for a rounded rectangle.

Definition at line 60 of file uber_sdf_parameters.cc.

64 {
65 Point size = Point(rect.GetSize() * 0.5f);
66 return UberSDFParameters{
67 .type = Type::kRoundedRect,
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}

References color, impeller::TRect< T >::GetCenter(), impeller::TRect< T >::GetSize(), kRoundedRect, radii, size, stroke, and type.

Referenced by impeller::Canvas::DrawRoundRect(), and impeller::testing::TEST().

◆ MakeRoundedSuperellipse()

UberSDFParameters impeller::UberSDFParameters::MakeRoundedSuperellipse ( Color  color,
const Rect bounds,
const RoundSuperellipseParam round_superellipse_params,
std::optional< StrokeParameters stroke 
)
static

Creates UberSDFParameters for an asymmetric round superellipse.

Definition at line 76 of file uber_sdf_parameters.cc.

80 {
81 FML_DCHECK(round_superellipse_params.all_corners_same);
82 Point center = bounds.GetCenter();
83
84 RoundSuperellipseParam::Quadrant top_right =
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}
#define FML_DCHECK(condition)
Definition logging.h:122
constexpr TPoint Abs() const
Definition point.h:294

References impeller::TPoint< T >::Abs(), impeller::RoundSuperellipseParam::all_corners_same, center, impeller::RoundSuperellipseParam::Octant::circle_center, impeller::RoundSuperellipseParam::Octant::circle_max_angle, impeller::RoundSuperellipseParam::Octant::circle_radius, color, FML_DCHECK, impeller::TRect< T >::GetCenter(), impeller::TRect< T >::GetSize(), kRoundedSuperellipseSymmetric, impeller::Radians::radians, impeller::RoundSuperellipseParam::Quadrant::right, impeller::RoundSuperellipseParam::Octant::se_a, impeller::RoundSuperellipseParam::Octant::se_n, impeller::RoundSuperellipseParam::Quadrant::signed_scale, size, stroke, impeller::RoundSuperellipseParam::Quadrant::top, impeller::RoundSuperellipseParam::top_right, and type.

Referenced by impeller::Canvas::DrawRoundSuperellipse(), and impeller::testing::TEST().

Member Data Documentation

◆ angle_span

Point impeller::UberSDFParameters::angle_span

The angular span of the circular cap for the top and right octants.

Definition at line 90 of file uber_sdf_parameters.h.

Referenced by impeller::UberSDFContents::Render().

◆ center

Point impeller::UberSDFParameters::center

The center point of the shape in local coordinates.

Definition at line 72 of file uber_sdf_parameters.h.

Referenced by impeller::UberSDFGeometry::CoversArea(), MakeCircle(), MakeRoundedSuperellipse(), and impeller::UberSDFContents::Render().

◆ circle_center_right

Point impeller::UberSDFParameters::circle_center_right

The circular cap center for the right octant of each quadrant.

Definition at line 101 of file uber_sdf_parameters.h.

Referenced by impeller::UberSDFContents::Render().

◆ circle_center_top

Point impeller::UberSDFParameters::circle_center_top

The circular cap center for the top octant of each quadrant.

Definition at line 97 of file uber_sdf_parameters.h.

Referenced by impeller::UberSDFContents::Render().

◆ color

Color impeller::UberSDFParameters::color

◆ kAntialiasPixels

constexpr Scalar impeller::UberSDFParameters::kAntialiasPixels = 1.0f
staticconstexpr

The amount by which the UberSDF shader fades the edge of the drawn shapes, in pixels.

Definition at line 24 of file uber_sdf_parameters.h.

Referenced by impeller::UberSDFGeometry::CoversArea(), and impeller::UberSDFContents::Render().

◆ octant_offset_c

float impeller::UberSDFParameters::octant_offset_c

The geometric offset 'c' used to connect the two octants of each quadrant.

Definition at line 93 of file uber_sdf_parameters.h.

Referenced by impeller::UberSDFContents::Render().

◆ radii

Vector4 impeller::UberSDFParameters::radii

Rounding radii for standard rounded rects and corner radii for circular caps of superellipses for top and right octants.

Definition at line 109 of file uber_sdf_parameters.h.

Referenced by MakeRoundedRect(), and impeller::UberSDFContents::Render().

◆ size

Point impeller::UberSDFParameters::size

For a rectangle, this is half the width and height. For a circle, this is the radius in both dimensions. For an oval, this is half the width and height of the bounds.

Definition at line 77 of file uber_sdf_parameters.h.

Referenced by impeller::UberSDFGeometry::CoversArea(), MakeCircle(), MakeOval(), MakeRect(), MakeRoundedRect(), MakeRoundedSuperellipse(), and impeller::UberSDFContents::Render().

◆ stroke

std::optional<StrokeParameters> impeller::UberSDFParameters::stroke

◆ superellipse_degree

Point impeller::UberSDFParameters::superellipse_degree

The degree (n) of the superellipse curve for the top and right octants.

Definition at line 83 of file uber_sdf_parameters.h.

Referenced by impeller::UberSDFContents::Render().

◆ superellipse_scale

Point impeller::UberSDFParameters::superellipse_scale

The scaling factors used to transform normalized superellipses to their true size.

Definition at line 105 of file uber_sdf_parameters.h.

Referenced by impeller::UberSDFContents::Render().

◆ superellipse_semi_axis

Point impeller::UberSDFParameters::superellipse_semi_axis

The semi-axis length of the superellipse curve for the top and right octants.

Definition at line 87 of file uber_sdf_parameters.h.

Referenced by impeller::UberSDFContents::Render().

◆ type


The documentation for this struct was generated from the following files: