From 2c8267babf412be16928f5e9feb5551c7fc052a2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 11 Jul 2024 15:51:41 +0300 Subject: [PATCH] LibWeb: Add basic conic gradient support in Skia painter For now it doesn't account for start angle and repeat length but it's better than not painting conic gradients at all. --- .../LibWeb/Painting/DisplayListPlayerSkia.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Userland/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp b/Userland/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp index aca291230e2..0711617a6e5 100644 --- a/Userland/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp +++ b/Userland/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp @@ -1098,6 +1098,28 @@ CommandResult DisplayListPlayerSkia::paint_radial_gradient(PaintRadialGradient c CommandResult DisplayListPlayerSkia::paint_conic_gradient(PaintConicGradient const& command) { APPLY_PATH_CLIP_IF_NEEDED + + auto const& conic_gradient_data = command.conic_gradient_data; + + auto const& color_stop_list = conic_gradient_data.color_stops.list; + VERIFY(!color_stop_list.is_empty()); + + Vector colors; + Vector positions; + for (auto const& stop : color_stop_list) { + colors.append(to_skia_color(stop.color)); + positions.append(stop.position); + } + + auto const& rect = command.rect; + auto center = command.position.translated(rect.location()); + // FIXME: Account for repeat length and start angle + auto shader = SkGradientShader::MakeSweep(center.x(), center.y(), colors.data(), positions.data(), positions.size()); + + SkPaint paint; + paint.setShader(shader); + surface().canvas().drawRect(to_skia_rect(rect), paint); + return CommandResult::Continue; }