Skip to content

Truly independent web browser

LibGfx+LibCompositing+Compositor: Move cap and join styles out of Path

Aliaksandr Kalenikff32f0f2220b
diff --git a/Libraries/LibCompositing/DisplayList/RustFFIAssertions.cpp b/Libraries/LibCompositing/DisplayList/RustFFIAssertions.cpp
index 23bb18f877c..3a0983110c4 100644
--- a/Libraries/LibCompositing/DisplayList/RustFFIAssertions.cpp
+++ b/Libraries/LibCompositing/DisplayList/RustFFIAssertions.cpp
@@ -145,14 +145,14 @@ static_assert(to_underlying(Compositing::RustFFI::HueInterpolationMethod::Decrea
static_assert(sizeof(Compositing::RustFFI::GradientInterpolationType) == sizeof(Gfx::GradientInterpolationMethod::Type));
static_assert(to_underlying(Compositing::RustFFI::GradientInterpolationType::Rectangular) == to_underlying(Gfx::GradientInterpolationMethod::Type::Rectangular));
static_assert(to_underlying(Compositing::RustFFI::GradientInterpolationType::Polar) == to_underlying(Gfx::GradientInterpolationMethod::Type::Polar));
-static_assert(sizeof(Compositing::RustFFI::CapStyle) == sizeof(Gfx::Path::CapStyle));
-static_assert(to_underlying(Compositing::RustFFI::CapStyle::Butt) == to_underlying(Gfx::Path::CapStyle::Butt));
-static_assert(to_underlying(Compositing::RustFFI::CapStyle::Round) == to_underlying(Gfx::Path::CapStyle::Round));
-static_assert(to_underlying(Compositing::RustFFI::CapStyle::Square) == to_underlying(Gfx::Path::CapStyle::Square));
-static_assert(sizeof(Compositing::RustFFI::JoinStyle) == sizeof(Gfx::Path::JoinStyle));
-static_assert(to_underlying(Compositing::RustFFI::JoinStyle::Miter) == to_underlying(Gfx::Path::JoinStyle::Miter));
-static_assert(to_underlying(Compositing::RustFFI::JoinStyle::Round) == to_underlying(Gfx::Path::JoinStyle::Round));
-static_assert(to_underlying(Compositing::RustFFI::JoinStyle::Bevel) == to_underlying(Gfx::Path::JoinStyle::Bevel));
+static_assert(sizeof(Compositing::RustFFI::CapStyle) == sizeof(Gfx::CapStyle));
+static_assert(to_underlying(Compositing::RustFFI::CapStyle::Butt) == to_underlying(Gfx::CapStyle::Butt));
+static_assert(to_underlying(Compositing::RustFFI::CapStyle::Round) == to_underlying(Gfx::CapStyle::Round));
+static_assert(to_underlying(Compositing::RustFFI::CapStyle::Square) == to_underlying(Gfx::CapStyle::Square));
+static_assert(sizeof(Compositing::RustFFI::JoinStyle) == sizeof(Gfx::JoinStyle));
+static_assert(to_underlying(Compositing::RustFFI::JoinStyle::Miter) == to_underlying(Gfx::JoinStyle::Miter));
+static_assert(to_underlying(Compositing::RustFFI::JoinStyle::Round) == to_underlying(Gfx::JoinStyle::Round));
+static_assert(to_underlying(Compositing::RustFFI::JoinStyle::Bevel) == to_underlying(Gfx::JoinStyle::Bevel));
static_assert(sizeof(Compositing::RustFFI::ColorFilterType) == sizeof(Gfx::ColorFilterType));
static_assert(to_underlying(Compositing::RustFFI::ColorFilterType::Brightness) == to_underlying(Gfx::ColorFilterType::Brightness));
static_assert(to_underlying(Compositing::RustFFI::ColorFilterType::Contrast) == to_underlying(Gfx::ColorFilterType::Contrast));
diff --git a/Libraries/LibCompositing/Rust/build.rs b/Libraries/LibCompositing/Rust/build.rs
index 2c72d9505fe..495adda2b82 100644
--- a/Libraries/LibCompositing/Rust/build.rs
+++ b/Libraries/LibCompositing/Rust/build.rs
@@ -158,8 +158,8 @@ fn expose_shared_abi_types_as_cpp_types(config: &mut cbindgen::Config) {
("VideoSinkResourceId", "Compositing::VideoSinkResourceId"),
("Canvas2DPaintKind", "Compositing::Canvas2DPaintKind"),
("Canvas2DPatternRepetition", "Compositing::Canvas2DPatternRepetition"),
- ("CapStyle", "Gfx::Path::CapStyle"),
- ("JoinStyle", "Gfx::Path::JoinStyle"),
+ ("CapStyle", "Gfx::CapStyle"),
+ ("JoinStyle", "Gfx::JoinStyle"),
("PathGeometryData", "Gfx::FFI::PathGeometryData"),
] {
config.export.rename.insert(rust_name.to_string(), cpp_name.to_string());
@@ -181,6 +181,7 @@ fn expose_shared_abi_types_as_cpp_types(config: &mut cbindgen::Config) {
"LibGfx/Rect.h",
"LibGfx/ScalingMode.h",
"LibGfx/Size.h",
+ "LibGfx/StrokeStyle.h",
"LibGfx/Vector3.h",
"LibGfx/WindingRule.h",
"LibCompositing/DisplayList/AccumulatedVisualContext.h",
@@ -421,8 +422,8 @@ fn main() -> Result<(), Box<dyn Error>> {
("InterpolationColorSpace", "Gfx::InterpolationColorSpace"),
("WindingRule", "Gfx::WindingRule"),
("LineStyle", "Gfx::LineStyle"),
- ("CapStyle", "Gfx::Path::CapStyle"),
- ("JoinStyle", "Gfx::Path::JoinStyle"),
+ ("CapStyle", "Gfx::CapStyle"),
+ ("JoinStyle", "Gfx::JoinStyle"),
("ScalingMode", "Gfx::ScalingMode"),
("CompositingAndBlendingOperator", "Gfx::CompositingAndBlendingOperator"),
("ColorFilterType", "Gfx::ColorFilterType"),
@@ -460,11 +461,11 @@ fn main() -> Result<(), Box<dyn Error>> {
"LibGfx/InterpolationColorSpace.h",
"LibGfx/LineStyle.h",
"LibGfx/Orientation.h",
- "LibGfx/Path.h",
"LibGfx/Point.h",
"LibGfx/Rect.h",
"LibGfx/ScalingMode.h",
"LibGfx/Size.h",
+ "LibGfx/StrokeStyle.h",
"LibGfx/WindingRule.h",
"LibCompositing/DisplayList/ContextRef.h",
"LibCompositing/DisplayList/DisplayListResourceIds.h",
diff --git a/Libraries/LibGfx/Path.h b/Libraries/LibGfx/Path.h
index e1bee8133f3..3586276ab36 100644
--- a/Libraries/LibGfx/Path.h
+++ b/Libraries/LibGfx/Path.h
@@ -64,18 +64,6 @@ public:
void line_to(Gfx::FloatPoint const&);
void close();
- enum class CapStyle {
- Butt,
- Round,
- Square,
- };
-
- enum class JoinStyle {
- Miter,
- Round,
- Bevel,
- };
-
Gfx::Path clone() const { return *this; }
PathData data() const;
diff --git a/Libraries/LibGfx/StrokeStyle.h b/Libraries/LibGfx/StrokeStyle.h
new file mode 100644
index 00000000000..7778ab880ad
--- /dev/null
+++ b/Libraries/LibGfx/StrokeStyle.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+namespace Gfx {
+
+enum class CapStyle {
+ Butt,
+ Round,
+ Square,
+};
+
+enum class JoinStyle {
+ Miter,
+ Round,
+ Bevel,
+};
+
+}
diff --git a/Services/Compositor/PainterSkia.cpp b/Services/Compositor/PainterSkia.cpp
index d2ad5eab48f..c0046dc07ba 100644
--- a/Services/Compositor/PainterSkia.cpp
+++ b/Services/Compositor/PainterSkia.cpp
@@ -353,7 +353,7 @@ void PainterSkia::set_transform(Gfx::AffineTransform const& transform)
canvas.setMatrix(matrix);
}
-void PainterSkia::stroke_path(Gfx::Path const& path, Gfx::PaintStyle const& paint_style, sk_sp<SkImageFilter> image_filter, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const& cap_style, Gfx::Path::JoinStyle const& join_style, float miter_limit, Vector<float> const& dash_array, float dash_offset, Optional<CanvasShadow> const& shadow)
+void PainterSkia::stroke_path(Gfx::Path const& path, Gfx::PaintStyle const& paint_style, sk_sp<SkImageFilter> image_filter, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::CapStyle const& cap_style, Gfx::JoinStyle const& join_style, float miter_limit, Vector<float> const& dash_array, float dash_offset, Optional<CanvasShadow> const& shadow)
{
// Skia treats zero thickness as a special case and will draw a hairline, while we want to draw nothing.
if (thickness <= 0)
diff --git a/Services/Compositor/PainterSkia.h b/Services/Compositor/PainterSkia.h
index 9964a3c7bba..032c1b5c8b2 100644
--- a/Services/Compositor/PainterSkia.h
+++ b/Services/Compositor/PainterSkia.h
@@ -17,6 +17,7 @@
#include <LibGfx/Path.h>
#include <LibGfx/Point.h>
#include <LibGfx/ScalingMode.h>
+#include <LibGfx/StrokeStyle.h>
#include <LibGfx/WindingRule.h>
class SkColorSpace;
@@ -56,7 +57,7 @@ public:
void fill_rect(Gfx::FloatRect const&, Color);
void draw_bitmap(Gfx::FloatRect const& dst_rect, Gfx::DecodedImageFrame const& source, Gfx::FloatRect const& src_rect, Gfx::ScalingMode, sk_sp<SkImageFilter>, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Optional<CanvasShadow> const&);
void draw_image(SkImage const&, Gfx::FloatRect const& dst_rect, Gfx::FloatRect const& src_rect, Gfx::ScalingMode, sk_sp<SkImageFilter>, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Optional<CanvasShadow> const&);
- void stroke_path(Gfx::Path const&, Gfx::PaintStyle const&, sk_sp<SkImageFilter>, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const&, Gfx::Path::JoinStyle const&, float miter_limit, Vector<float> const&, float dash_offset, Optional<CanvasShadow> const&);
+ void stroke_path(Gfx::Path const&, Gfx::PaintStyle const&, sk_sp<SkImageFilter>, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::CapStyle const&, Gfx::JoinStyle const&, float miter_limit, Vector<float> const&, float dash_offset, Optional<CanvasShadow> const&);
void fill_path(Gfx::Path const&, Gfx::PaintStyle const&, sk_sp<SkImageFilter>, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::WindingRule, Optional<CanvasShadow> const&);
void draw_glyph_runs(ReadonlySpan<CanvasGlyphRun>, FloatPoint translation, float horizontal_scale, PaintStyle const&, sk_sp<SkImageFilter>, float global_alpha, CompositingAndBlendingOperator, Optional<CanvasShadow> const&);
void set_transform(Gfx::AffineTransform const&);
diff --git a/Services/Compositor/SkiaUtils.h b/Services/Compositor/SkiaUtils.h
index be3b0774d9d..65db9a33fa6 100644
--- a/Services/Compositor/SkiaUtils.h
+++ b/Services/Compositor/SkiaUtils.h
@@ -16,6 +16,7 @@
#include <LibGfx/PaintStyle.h>
#include <LibGfx/Path.h>
#include <LibGfx/ScalingMode.h>
+#include <LibGfx/StrokeStyle.h>
#include <LibGfx/WindingRule.h>
#include <core/SkBlender.h>
#include <core/SkColor.h>
@@ -72,27 +73,27 @@ constexpr SkColor to_skia_color(Gfx::Color const& color)
return SkColorSetARGB(color.alpha(), color.red(), color.green(), color.blue());
}
-constexpr SkPaint::Join to_skia_join(Gfx::Path::JoinStyle const& join_style)
+constexpr SkPaint::Join to_skia_join(Gfx::JoinStyle const& join_style)
{
switch (join_style) {
- case Gfx::Path::JoinStyle::Round:
+ case Gfx::JoinStyle::Round:
return SkPaint::kRound_Join;
- case Gfx::Path::JoinStyle::Bevel:
+ case Gfx::JoinStyle::Bevel:
return SkPaint::kBevel_Join;
- case Gfx::Path::JoinStyle::Miter:
+ case Gfx::JoinStyle::Miter:
return SkPaint::kMiter_Join;
}
VERIFY_NOT_REACHED();
}
-constexpr SkPaint::Cap to_skia_cap(Gfx::Path::CapStyle const& cap_style)
+constexpr SkPaint::Cap to_skia_cap(Gfx::CapStyle const& cap_style)
{
switch (cap_style) {
- case Gfx::Path::CapStyle::Butt:
+ case Gfx::CapStyle::Butt:
return SkPaint::kButt_Cap;
- case Gfx::Path::CapStyle::Round:
+ case Gfx::CapStyle::Round:
return SkPaint::kRound_Cap;
- case Gfx::Path::CapStyle::Square:
+ case Gfx::CapStyle::Square:
return SkPaint::kSquare_Cap;
}
VERIFY_NOT_REACHED();