Skip to content

Commit a9ea0ee

Browse files
MacDueawesomekling
authored andcommitted
LibWeb: Fix passing size/position to paint_radial_gradient()
This was wrong twice making it right... But let's fix that. The center was being passed as a DevicePixelPoint, but was in fact in CSS pixels, the size was passed as a Gfx::FloatSize but was in CSS pixels again. Then we were scaling from device pixels to CSS pixels when painting which does not need to be done if everything is passed which the correct scale factors already applied.
1 parent 6c27f2c commit a9ea0ee

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Userland/Libraries/LibWeb/CSS/StyleValue.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,9 @@ bool RadialGradientStyleValue::equals(StyleValue const& other) const
21782178
void RadialGradientStyleValue::paint(PaintContext& context, Gfx::IntRect const& dest_rect, CSS::ImageRendering) const
21792179
{
21802180
VERIFY(m_resolved.has_value());
2181-
Painting::paint_radial_gradient(context, dest_rect.to_type<DevicePixels>(), m_resolved->data, m_resolved->center.to_rounded<DevicePixels>(), m_resolved->gradient_size);
2181+
Painting::paint_radial_gradient(context, dest_rect.to_type<DevicePixels>(), m_resolved->data,
2182+
context.rounded_device_point(m_resolved->center.to_type<CSSPixels>()),
2183+
context.rounded_device_size(m_resolved->gradient_size.to_type<CSSPixels>()));
21822184
}
21832185

21842186
DeprecatedString ConicGradientStyleValue::to_deprecated_string() const

Userland/Libraries/LibWeb/Painting/GradientPainting.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,18 +304,18 @@ void paint_conic_gradient(PaintContext& context, DevicePixelRect const& gradient
304304
});
305305
}
306306

307-
void paint_radial_gradient(PaintContext& context, DevicePixelRect const& gradient_rect, RadialGradientData const& data, DevicePixelPoint center, Gfx::FloatSize size)
307+
void paint_radial_gradient(PaintContext& context, DevicePixelRect const& gradient_rect, RadialGradientData const& data, DevicePixelPoint center, DevicePixelSize size)
308308
{
309309
// A conservative guesstimate on how many colors we need to generate:
310310
auto max_dimension = max(gradient_rect.width(), gradient_rect.height());
311-
int max_visible_gradient = max(max_dimension.value() / 2, min(size.width(), max_dimension.value()));
311+
auto max_visible_gradient = max(max_dimension / 2, min(size.width(), max_dimension.value())).value();
312312
GradientLine gradient_line(max_visible_gradient, data.color_stops);
313313
auto center_point = Gfx::FloatPoint { center.to_type<int>() }.translated(0.5, 0.5);
314314
gradient_line.paint_into_rect(context.painter(), gradient_rect, [&](DevicePixels x, DevicePixels y) {
315315
// FIXME: See if there's a more efficient calculation we do there :^)
316-
auto point = context.scale_to_css_point({ x, y }).to_type<float>() - center_point;
317-
auto gradient_x = point.x() / size.width();
318-
auto gradient_y = point.y() / size.height();
316+
auto point = Gfx::FloatPoint(x.value(), y.value()) - center_point;
317+
auto gradient_x = point.x() / size.width().value();
318+
auto gradient_y = point.y() / size.height().value();
319319
return AK::sqrt(gradient_x * gradient_x + gradient_y * gradient_y) * max_visible_gradient;
320320
});
321321
}

Userland/Libraries/LibWeb/Painting/GradientPainting.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ RadialGradientData resolve_radial_gradient_data(Layout::Node const&, CSSPixelSiz
4747

4848
void paint_linear_gradient(PaintContext&, DevicePixelRect const&, LinearGradientData const&);
4949
void paint_conic_gradient(PaintContext&, DevicePixelRect const&, ConicGradientData const&, DevicePixelPoint position);
50-
void paint_radial_gradient(PaintContext&, DevicePixelRect const&, RadialGradientData const&, DevicePixelPoint position, Gfx::FloatSize size);
50+
void paint_radial_gradient(PaintContext&, DevicePixelRect const&, RadialGradientData const&, DevicePixelPoint position, DevicePixelSize size);
5151

5252
}

0 commit comments

Comments
 (0)