Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c337a59

Browse files
[Impeller] Remove the use of a subpixel minimum stroke size for MSAA (#56223)
Based on #55230 Fixes flutter/flutter#156438
1 parent 3f5ce70 commit c337a59

File tree

6 files changed

+17
-38
lines changed

6 files changed

+17
-38
lines changed

impeller/entity/geometry/circle_geometry.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ GeometryResult CircleGeometry::GetPositionBuffer(const ContentContext& renderer,
4242
RenderPass& pass) const {
4343
auto& transform = entity.GetTransform();
4444

45-
Scalar half_width = stroke_width_ < 0
46-
? 0.0
47-
: LineGeometry::ComputePixelHalfWidth(
48-
transform, stroke_width_,
49-
pass.GetSampleCount() == SampleCount::kCount4);
45+
Scalar half_width = stroke_width_ < 0 ? 0.0
46+
: LineGeometry::ComputePixelHalfWidth(
47+
transform, stroke_width_);
5048

5149
const std::shared_ptr<Tessellator>& tessellator = renderer.GetTessellator();
5250

impeller/entity/geometry/geometry.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ bool Geometry::CanApplyMaskFilter() const {
133133
Scalar Geometry::ComputeStrokeAlphaCoverage(const Matrix& transform,
134134
Scalar stroke_width) {
135135
Scalar scaled_stroke_width = transform.GetMaxBasisLengthXY() * stroke_width;
136-
// If the stroke width is 0 or greater than kMinStrokeSizeMSAA, don't apply
137-
// any additional alpha. This is intended to match Skia behavior.
138-
if (scaled_stroke_width == 0.0 || scaled_stroke_width >= kMinStrokeSizeMSAA) {
136+
if (scaled_stroke_width == 0.0 || scaled_stroke_width >= kMinStrokeSize) {
139137
return 1.0;
140138
}
141139
// This scalling is eyeballed from Skia.

impeller/entity/geometry/geometry.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ namespace impeller {
1616

1717
class Tessellator;
1818

19-
/// @brief The minimum stroke size can be less than one physical pixel because
20-
/// of MSAA, but no less that half a physical pixel otherwise we might
21-
/// not hit one of the sample positions.
22-
static constexpr Scalar kMinStrokeSizeMSAA = 0.5f;
23-
2419
static constexpr Scalar kMinStrokeSize = 1.0f;
2520

2621
struct GeometryResult {

impeller/entity/geometry/line_geometry.cc

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,19 @@ LineGeometry::LineGeometry(Point p0, Point p1, Scalar width, Cap cap)
1515
LineGeometry::~LineGeometry() = default;
1616

1717
Scalar LineGeometry::ComputePixelHalfWidth(const Matrix& transform,
18-
Scalar width,
19-
bool msaa) {
18+
Scalar width) {
2019
Scalar max_basis = transform.GetMaxBasisLengthXY();
2120
if (max_basis == 0) {
2221
return {};
2322
}
2423

25-
Scalar min_size = (msaa ? kMinStrokeSize : kMinStrokeSizeMSAA) / max_basis;
24+
Scalar min_size = kMinStrokeSize / max_basis;
2625
return std::max(width, min_size) * 0.5f;
2726
}
2827

2928
Vector2 LineGeometry::ComputeAlongVector(const Matrix& transform,
30-
bool allow_zero_length,
31-
bool msaa) const {
32-
Scalar stroke_half_width = ComputePixelHalfWidth(transform, width_, msaa);
29+
bool allow_zero_length) const {
30+
Scalar stroke_half_width = ComputePixelHalfWidth(transform, width_);
3331
if (stroke_half_width < kEhCloseEnough) {
3432
return {};
3533
}
@@ -49,9 +47,8 @@ Vector2 LineGeometry::ComputeAlongVector(const Matrix& transform,
4947

5048
bool LineGeometry::ComputeCorners(Point corners[4],
5149
const Matrix& transform,
52-
bool extend_endpoints,
53-
bool msaa) const {
54-
auto along = ComputeAlongVector(transform, extend_endpoints, msaa);
50+
bool extend_endpoints) const {
51+
auto along = ComputeAlongVector(transform, extend_endpoints);
5552
if (along.IsZero()) {
5653
return false;
5754
}
@@ -80,8 +77,7 @@ GeometryResult LineGeometry::GetPositionBuffer(const ContentContext& renderer,
8077
using VT = SolidFillVertexShader::PerVertexData;
8178

8279
auto& transform = entity.GetTransform();
83-
auto radius = ComputePixelHalfWidth(
84-
transform, width_, pass.GetSampleCount() == SampleCount::kCount4);
80+
auto radius = ComputePixelHalfWidth(transform, width_);
8581

8682
if (cap_ == Cap::kRound) {
8783
std::shared_ptr<Tessellator> tessellator = renderer.GetTessellator();
@@ -90,8 +86,7 @@ GeometryResult LineGeometry::GetPositionBuffer(const ContentContext& renderer,
9086
}
9187

9288
Point corners[4];
93-
if (!ComputeCorners(corners, transform, cap_ == Cap::kSquare,
94-
pass.GetSampleCount() == SampleCount::kCount4)) {
89+
if (!ComputeCorners(corners, transform, cap_ == Cap::kSquare)) {
9590
return kEmptyResult;
9691
}
9792

@@ -123,7 +118,7 @@ GeometryResult LineGeometry::GetPositionBuffer(const ContentContext& renderer,
123118
std::optional<Rect> LineGeometry::GetCoverage(const Matrix& transform) const {
124119
Point corners[4];
125120
// Note: MSAA boolean doesn't matter for coverage computation.
126-
if (!ComputeCorners(corners, transform, cap_ != Cap::kButt, /*msaa=*/false)) {
121+
if (!ComputeCorners(corners, transform, cap_ != Cap::kButt)) {
127122
return {};
128123
}
129124

impeller/entity/geometry/line_geometry.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class LineGeometry final : public Geometry {
1515

1616
~LineGeometry() override;
1717

18-
static Scalar ComputePixelHalfWidth(const Matrix& transform,
19-
Scalar width,
20-
bool msaa);
18+
static Scalar ComputePixelHalfWidth(const Matrix& transform, Scalar width);
2119

2220
// |Geometry|
2321
bool CoversArea(const Matrix& transform, const Rect& rect) const override;
@@ -44,12 +42,10 @@ class LineGeometry final : public Geometry {
4442
// @return true if the transform and width were not degenerate
4543
bool ComputeCorners(Point corners[4],
4644
const Matrix& transform,
47-
bool extend_endpoints,
48-
bool msaa) const;
45+
bool extend_endpoints) const;
4946

5047
Vector2 ComputeAlongVector(const Matrix& transform,
51-
bool allow_zero_length,
52-
bool msaa) const;
48+
bool allow_zero_length) const;
5349

5450
// |Geometry|
5551
GeometryResult GetPositionBuffer(const ContentContext& renderer,

impeller/entity/geometry/stroke_path_geometry.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,7 @@ GeometryResult StrokePathGeometry::GetPositionBuffer(
574574
return {};
575575
}
576576

577-
Scalar min_size =
578-
(pass.GetSampleCount() == SampleCount::kCount4 ? kMinStrokeSizeMSAA
579-
: kMinStrokeSize) /
580-
max_basis;
577+
Scalar min_size = kMinStrokeSize / max_basis;
581578
Scalar stroke_width = std::max(stroke_width_, min_size);
582579

583580
auto& host_buffer = renderer.GetTransientsBuffer();

0 commit comments

Comments
 (0)