Skip to content

Truly independent web browser

LibGfx+Compositor: Replace Gfx::Path with SkPath

Aliaksandr Kalenikea12f660f616
diff --git a/Libraries/LibCompositing/Rust/build.rs b/Libraries/LibCompositing/Rust/build.rs
index 495adda2b82..ef2a47dfbe7 100644
--- a/Libraries/LibCompositing/Rust/build.rs
+++ b/Libraries/LibCompositing/Rust/build.rs
@@ -176,7 +176,7 @@ fn expose_shared_abi_types_as_cpp_types(config: &mut cbindgen::Config) {
"LibGfx/GradientInterpolation.h",
"LibGfx/InterpolationColorSpace.h",
"LibGfx/Matrix4x4.h",
- "LibGfx/Path.h",
+ "LibGfx/PathData.h",
"LibGfx/Point.h",
"LibGfx/Rect.h",
"LibGfx/ScalingMode.h",
diff --git a/Libraries/LibCompositing/Rust/src/display_list/canvas_2d.rs b/Libraries/LibCompositing/Rust/src/display_list/canvas_2d.rs
index 3b98d13bcee..0ea8605bc01 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/canvas_2d.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/canvas_2d.rs
@@ -225,7 +225,7 @@ impl TapeWriter {
append_record(&mut self.bytes, command, &[]);
}
- /// `path` is a serialized Gfx::Path.
+ /// `path` is a serialized `libgfx_rust::path::Path`.
pub fn fill_path(&mut self, path: &[u8], paint: &Paint, winding_rule: WindingRule, compositing: &Compositing) {
let mut inline_data = InlineData::new::<Canvas2DFillPath>();
let command = Canvas2DFillPath {
@@ -237,7 +237,7 @@ impl TapeWriter {
self.append(&command, &inline_data);
}
- /// `path` is a serialized Gfx::Path.
+ /// `path` is a serialized `libgfx_rust::path::Path`.
pub fn stroke_path(&mut self, path: &[u8], paint: &Paint, stroke: &Stroke, compositing: &Compositing) {
let mut inline_data = InlineData::new::<Canvas2DStrokePath>();
let command = Canvas2DStrokePath {
@@ -350,7 +350,7 @@ impl TapeWriter {
self.append_plain(&Canvas2DRestore::default());
}
- /// `path` is a serialized Gfx::Path.
+ /// `path` is a serialized `libgfx_rust::path::Path`.
pub fn clip_path(&mut self, path: &[u8], winding_rule: WindingRule) {
let mut inline_data = InlineData::new::<Canvas2DClipPath>();
let command = Canvas2DClipPath {
diff --git a/Libraries/LibCompositing/Rust/src/display_list/canvas_2d_recorder.rs b/Libraries/LibCompositing/Rust/src/display_list/canvas_2d_recorder.rs
index 8ef70149484..25be0e9e3bd 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/canvas_2d_recorder.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/canvas_2d_recorder.rs
@@ -131,12 +131,12 @@ impl<T: Transport> Recorder<T> {
self.transport.append_command(self.tape.bytes());
}
- /// `path` is a serialized Gfx::Path.
+ /// `path` is a serialized `libgfx_rust::path::Path`.
pub fn fill_path(&mut self, path: &[u8], paint: &Paint, winding_rule: WindingRule, compositing: &Compositing) {
self.record(|tape| tape.fill_path(path, paint, winding_rule, compositing));
}
- /// `path` is a serialized Gfx::Path.
+ /// `path` is a serialized `libgfx_rust::path::Path`.
pub fn stroke_path(&mut self, path: &[u8], paint: &Paint, stroke: &Stroke, compositing: &Compositing) {
self.record(|tape| tape.stroke_path(path, paint, stroke, compositing));
}
@@ -234,7 +234,7 @@ impl<T: Transport> Recorder<T> {
self.record(TapeWriter::restore);
}
- /// `path` is a serialized Gfx::Path.
+ /// `path` is a serialized `libgfx_rust::path::Path`.
pub fn clip_path(&mut self, path: &[u8], winding_rule: WindingRule) {
self.record(|tape| tape.clip_path(path, winding_rule));
}
diff --git a/Libraries/LibGfx/CMakeLists.txt b/Libraries/LibGfx/CMakeLists.txt
index 70a06646b53..47f7571e082 100644
--- a/Libraries/LibGfx/CMakeLists.txt
+++ b/Libraries/LibGfx/CMakeLists.txt
@@ -22,6 +22,7 @@ set(SOURCES
Font/WOFF/Loader.cpp
Font/WOFF2/Loader.cpp
FontCascadeList.cpp
+ GlyphOutlines.cpp
GpuDeviceIdentity.cpp
LinuxDmaBufHandle.cpp
DecodedImageFrame.cpp
@@ -30,7 +31,7 @@ set(SOURCES
ImageFormats/PNGWriter.cpp
PaintStyle.cpp
Palette.cpp
- Path.cpp
+ PathData.cpp
Point.cpp
Rect.cpp
SharedImage.cpp
diff --git a/Libraries/LibGfx/Forward.h b/Libraries/LibGfx/Forward.h
index 73d9ac43cf7..6fc219af4fb 100644
--- a/Libraries/LibGfx/Forward.h
+++ b/Libraries/LibGfx/Forward.h
@@ -22,7 +22,6 @@ struct FontPixelMetrics;
class Palette;
class YUVData;
class PaletteImpl;
-class Path;
struct PathData;
class SharedImage;
class SharedImageBuffer;
diff --git a/Libraries/LibGfx/Path.cpp b/Libraries/LibGfx/GlyphOutlines.cpp
similarity index 78%
rename from Libraries/LibGfx/Path.cpp
rename to Libraries/LibGfx/GlyphOutlines.cpp
index d114addc0e1..0ae92a36d8b 100644
--- a/Libraries/LibGfx/Path.cpp
+++ b/Libraries/LibGfx/GlyphOutlines.cpp
@@ -7,7 +7,6 @@
#include <AK/ScopeGuard.h>
#include <AK/TypeCasts.h>
#include <LibGfx/Font/Font.h>
-#include <LibGfx/Path.h>
#include <LibGfx/RustFFI.h>
#include <harfbuzz/hb.h>
@@ -16,95 +15,8 @@
# include <LibGfx/Font/TypefaceCoreText.h>
#endif
-static_assert(sizeof(Gfx::FloatPoint) == sizeof(Gfx::FFI::FloatPoint));
-static_assert(to_underlying(Gfx::WindingRule::Nonzero) == 0 && to_underlying(Gfx::WindingRule::EvenOdd) == 1);
-static_assert(to_underlying(Gfx::PathVerb::Move) == to_underlying(Gfx::FFI::PathVerb::Move));
-static_assert(to_underlying(Gfx::PathVerb::Line) == to_underlying(Gfx::FFI::PathVerb::Line));
-static_assert(to_underlying(Gfx::PathVerb::Quad) == to_underlying(Gfx::FFI::PathVerb::Quad));
-static_assert(to_underlying(Gfx::PathVerb::Conic) == to_underlying(Gfx::FFI::PathVerb::Conic));
-static_assert(to_underlying(Gfx::PathVerb::Cubic) == to_underlying(Gfx::FFI::PathVerb::Cubic));
-static_assert(to_underlying(Gfx::PathVerb::Close) == to_underlying(Gfx::FFI::PathVerb::Close));
-
namespace Gfx {
-Path::Path()
- : m_geometry(FFI::path_geometry_create())
-{
-}
-
-Path::Path(FFI::PathGeometry* geometry)
- : m_geometry(geometry)
-{
-}
-
-Path::~Path()
-{
- FFI::path_geometry_destroy(m_geometry);
-}
-
-Path::Path(Path const& other)
- : m_geometry(FFI::path_geometry_clone(other.m_geometry))
-{
-}
-
-Path& Path::operator=(Path const& other)
-{
- if (this != &other) {
- FFI::path_geometry_destroy(m_geometry);
- m_geometry = FFI::path_geometry_clone(other.m_geometry);
- }
- return *this;
-}
-
-Path::Path(Path&& other)
- : m_geometry(exchange(other.m_geometry, nullptr))
-{
-}
-
-Path& Path::operator=(Path&& other)
-{
- if (this != &other)
- swap(m_geometry, other.m_geometry);
- return *this;
-}
-
-Path Path::from_serialized_bytes(ReadonlyBytes bytes)
-{
- return Path { FFI::path_geometry_decode(bytes.data(), bytes.size()) };
-}
-
-void Path::move_to(FloatPoint const& point)
-{
- FFI::path_geometry_move_to(m_geometry, point.x(), point.y());
-}
-
-void Path::line_to(FloatPoint const& point)
-{
- FFI::path_geometry_line_to(m_geometry, point.x(), point.y());
-}
-
-void Path::close()
-{
- FFI::path_geometry_close(m_geometry);
-}
-
-PathData PathData::from_ffi(FFI::PathGeometryData const& data)
-{
- return {
- .verbs = { reinterpret_cast<PathVerb const*>(data.verbs), data.verb_count },
- .points = { reinterpret_cast<FloatPoint const*>(data.points), data.point_count },
- .conic_weights = { data.conic_weights, data.conic_weight_count },
- .winding_rule = static_cast<WindingRule>(data.fill_rule),
- };
-}
-
-PathData Path::data() const
-{
- FFI::PathGeometryData data;
- FFI::path_geometry_data(m_geometry, &data);
- return PathData::from_ffi(data);
-}
-
namespace {
// Maps the coordinates of a glyph outline from font units, with y up, to pixels, with y down. A contour starts only at
diff --git a/Libraries/LibGfx/PathData.cpp b/Libraries/LibGfx/PathData.cpp
new file mode 100644
index 00000000000..3a1b0a804fb
--- /dev/null
+++ b/Libraries/LibGfx/PathData.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2024, Andreas Kling <[email protected]>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/Function.h>
+#include <AK/ScopeGuard.h>
+#include <LibGfx/PathData.h>
+#include <LibGfx/RustFFI.h>
+
+static_assert(sizeof(Gfx::FloatPoint) == sizeof(Gfx::FFI::FloatPoint));
+static_assert(to_underlying(Gfx::WindingRule::Nonzero) == 0 && to_underlying(Gfx::WindingRule::EvenOdd) == 1);
+static_assert(to_underlying(Gfx::PathVerb::Move) == to_underlying(Gfx::FFI::PathVerb::Move));
+static_assert(to_underlying(Gfx::PathVerb::Line) == to_underlying(Gfx::FFI::PathVerb::Line));
+static_assert(to_underlying(Gfx::PathVerb::Quad) == to_underlying(Gfx::FFI::PathVerb::Quad));
+static_assert(to_underlying(Gfx::PathVerb::Conic) == to_underlying(Gfx::FFI::PathVerb::Conic));
+static_assert(to_underlying(Gfx::PathVerb::Cubic) == to_underlying(Gfx::FFI::PathVerb::Cubic));
+static_assert(to_underlying(Gfx::PathVerb::Close) == to_underlying(Gfx::FFI::PathVerb::Close));
+
+namespace Gfx {
+
+PathData PathData::from_ffi(FFI::PathGeometryData const& data)
+{
+ return {
+ .verbs = { reinterpret_cast<PathVerb const*>(data.verbs), data.verb_count },
+ .points = { reinterpret_cast<FloatPoint const*>(data.points), data.point_count },
+ .conic_weights = { data.conic_weights, data.conic_weight_count },
+ .winding_rule = static_cast<WindingRule>(data.fill_rule),
+ };
+}
+
+void with_contours_of_serialized_path(ReadonlyBytes serialized_path, Function<void(PathData const&)> const& callback)
+{
+ auto* decoded_path = FFI::path_geometry_decode(serialized_path.data(), serialized_path.size());
+ ScopeGuard destroy_decoded_path = [&] { FFI::path_geometry_destroy(decoded_path); };
+ FFI::PathGeometryData data;
+ FFI::path_geometry_data(decoded_path, &data);
+ callback(PathData::from_ffi(data));
+}
+
+}
diff --git a/Libraries/LibGfx/Path.h b/Libraries/LibGfx/PathData.h
similarity index 52%
rename from Libraries/LibGfx/Path.h
rename to Libraries/LibGfx/PathData.h
index 3586276ab36..fe5d05138db 100644
--- a/Libraries/LibGfx/Path.h
+++ b/Libraries/LibGfx/PathData.h
@@ -7,21 +7,15 @@
#pragma once
#include <AK/Forward.h>
-#include <AK/NonnullRefPtr.h>
-#include <AK/String.h>
-#include <AK/Vector.h>
-#include <AK/kmalloc.h>
-#include <LibGfx/AffineTransform.h>
+#include <AK/Span.h>
#include <LibGfx/Forward.h>
#include <LibGfx/Point.h>
-#include <LibGfx/Rect.h>
#include <LibGfx/WindingRule.h>
namespace Gfx {
namespace FFI {
-struct PathGeometry;
struct PathGeometryData;
}
@@ -46,32 +40,7 @@ struct PathData {
WindingRule winding_rule { WindingRule::Nonzero };
};
-class Path {
-public:
- AK_ALLOC_WITH_KMALLOC;
-
- Path();
- ~Path();
-
- Path(Path const&);
- Path& operator=(Path const&);
- Path(Path&&);
- Path& operator=(Path&&);
-
- [[nodiscard]] static Path from_serialized_bytes(ReadonlyBytes);
-
- void move_to(Gfx::FloatPoint const&);
- void line_to(Gfx::FloatPoint const&);
- void close();
-
- Gfx::Path clone() const { return *this; }
-
- PathData data() const;
-
-private:
- explicit Path(FFI::PathGeometry*);
-
- FFI::PathGeometry* m_geometry { nullptr };
-};
+// The contours are valid only during the call. Bytes that describe no path give no contours.
+void with_contours_of_serialized_path(ReadonlyBytes serialized_path, Function<void(PathData const&)> const& callback);
}
diff --git a/Libraries/LibGfx/Rust/src/path.rs b/Libraries/LibGfx/Rust/src/path.rs
index 45385c3a085..2ce349645f8 100644
--- a/Libraries/LibGfx/Rust/src/path.rs
+++ b/Libraries/LibGfx/Rust/src/path.rs
@@ -95,7 +95,6 @@ pub struct StrokeStyle {
pub dash_offset: f32,
}
-/// A path, with the rules of `Gfx::Path` for each operation.
pub struct Path {
geometry: PathGeometry,
// A process-unique, never-reused identity, so that consumers that hold a copied snapshot can
@@ -192,7 +191,7 @@ impl Path {
self.geometry_mut().set_fill_rule(fill_rule);
}
- /// Whether the path has no current point, which Gfx::Path::is_empty() calls empty.
+ /// Whether the path has no current point.
pub fn is_empty(&self) -> bool {
self.geometry.is_empty()
}
diff --git a/Libraries/LibGfx/Rust/src/path/ffi.rs b/Libraries/LibGfx/Rust/src/path/ffi.rs
index 6caca83b2ac..1e11522494f 100644
--- a/Libraries/LibGfx/Rust/src/path/ffi.rs
+++ b/Libraries/LibGfx/Rust/src/path/ffi.rs
@@ -4,10 +4,10 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-//! The functions through which `Gfx::Path` in C++ owns, builds and reads a path.
+//! The functions through which C++ builds glyph outlines, decodes paths and reads their contours.
//!
-//! Only LibGfx's copy of this crate makes and frees the paths of `Gfx::Path`. Rust code builds and
-//! queries its own paths with `Path`.
+//! Only LibGfx's copy of this crate makes and frees these paths. Rust code builds and queries its
+//! own paths with `Path`.
use super::encoding;
use super::geometry::{PathGeometry, PathVerb};
@@ -39,14 +39,6 @@ pub extern "C" fn path_geometry_create() -> *mut PathGeometry {
into_raw(PathGeometry::new())
}
-/// # Safety
-/// `path` must be a live path from this module.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn path_geometry_clone(path: *const PathGeometry) -> *mut PathGeometry {
- // SAFETY: Forwarded from the caller.
- into_raw(unsafe { &*path }.clone())
-}
-
/// # Safety
/// `path` must be a path from this module that nothing uses afterwards, or null.
#[unsafe(no_mangle)]
@@ -65,31 +57,7 @@ pub unsafe extern "C" fn path_geometry_clear(path: *mut PathGeometry) {
unsafe { &mut *path }.clear();
}
-/// # Safety
-/// `path` must be a live path from this module, which nothing else uses for the call.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn path_geometry_move_to(path: *mut PathGeometry, x: f32, y: f32) {
- // SAFETY: Forwarded from the caller.
- unsafe { &mut *path }.move_to(point(x, y));
-}
-
-/// # Safety
-/// `path` must be a live path from this module, which nothing else uses for the call.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn path_geometry_line_to(path: *mut PathGeometry, x: f32, y: f32) {
- // SAFETY: Forwarded from the caller.
- unsafe { &mut *path }.line_to(point(x, y));
-}
-
-/// # Safety
-/// `path` must be a live path from this module, which nothing else uses for the call.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn path_geometry_close(path: *mut PathGeometry) {
- // SAFETY: Forwarded from the caller.
- unsafe { &mut *path }.close();
-}
-
-// Contour building for outlines, without the rules of Gfx::Path for a path that has no current point.
+// Contour building for outlines, without the rules of Path for a path that has no current point.
/// # Safety
/// `path` must be a live path from this module, which nothing else uses for the call.
diff --git a/Libraries/LibGfx/Rust/src/path/geometry.rs b/Libraries/LibGfx/Rust/src/path/geometry.rs
index 73ad4540f3b..09e92f579c4 100644
--- a/Libraries/LibGfx/Rust/src/path/geometry.rs
+++ b/Libraries/LibGfx/Rust/src/path/geometry.rs
@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-//! The data of a `Gfx::Path`: its verbs, the points that they use and the weights of its conics,
-//! and the rules by which the operations of `Gfx::Path` add to them.
+//! The data of a path: its verbs, the points that they use and the weights of its conics, and the
+//! rules by which the operations of `Path` add to them.
use super::arcs;
use crate::geometry::FloatPoint;
@@ -108,7 +108,7 @@ pub struct PathGeometry {
fill_rule: WindingRule,
has_only_finite_points: bool,
- // What the operations of Gfx::Path remember between calls: whether there is a point to draw from,
+ // What the operations of Path remember between calls: whether there is a point to draw from,
// and where the last subpath started.
has_current_point: bool,
last_move_to: FloatPoint,
@@ -163,7 +163,7 @@ impl PathGeometry {
self.has_only_finite_points && !self.verbs.is_empty()
}
- /// Whether the path has no current point, which Gfx::Path::is_empty() calls empty.
+ /// Whether the path has no current point.
pub fn is_empty(&self) -> bool {
!self.has_current_point
}
@@ -209,7 +209,7 @@ impl PathGeometry {
[left, top, right - left, bottom - top]
}
- // Contour building, without the rules of Gfx::Path for a path that has no current point.
+ // Contour building, without the rules of Path for a path that has no current point.
fn push_point(&mut self, point: FloatPoint) {
self.has_only_finite_points &= is_finite_point(point);
@@ -298,7 +298,7 @@ impl PathGeometry {
self.verbs.push(PathVerb::Close);
}
- // The operations of Gfx::Path.
+ // The operations of Path.
pub fn move_to(&mut self, point: FloatPoint) {
self.last_move_to = point;
@@ -371,7 +371,7 @@ impl PathGeometry {
}
/// Adds the contours of the other path with its points mapped, as for glyph outlines. The state of
- /// Gfx::Path is left as it was; update_state_from_contours() sets it.
+ /// Path is left as it was; update_state_from_contours() sets it.
pub fn append_mapped(&mut self, other: &PathGeometry, map: impl Fn(FloatPoint) -> FloatPoint) {
self.append_mapped_contours(&other.verbs, &other.points, &other.conic_weights, map);
}
@@ -401,7 +401,7 @@ impl PathGeometry {
.all(|point| is_finite_point(*point));
}
- /// Sets the state of Gfx::Path from the contours, for a path that was not built by its operations.
+ /// Sets the state of Path from the contours, for a path that was not built by its operations.
pub fn update_state_from_contours(&mut self) {
self.has_current_point = !self.verbs.is_empty();
self.last_move_to = self.start_of_last_contour();
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_path.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_path.rs
index 4fe07cfdf68..e8644d6a945 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_path.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_path.rs
@@ -175,10 +175,7 @@ fn point(x: f32, y: f32) -> FloatPoint {
FloatPoint { x, y }
}
-#[allow(
- clippy::cast_possible_truncation,
- reason = "a point of a Gfx::Path is in floats, as the C++ made it"
-)]
+#[allow(clippy::cast_possible_truncation, reason = "a point of a path is in floats")]
fn point_from_doubles(x: f64, y: f64) -> FloatPoint {
point(x as f32, y as f32)
}
@@ -351,7 +348,7 @@ pub(crate) fn ellipse(
let tau = core::f32::consts::TAU;
#[allow(
clippy::cast_possible_truncation,
- reason = "the angles of an arc of a Gfx::Path are floats"
+ reason = "the angles of an arc of a path are floats"
)]
let (start_angle, end_angle) = ((start_angle as f32) % tau, (end_angle as f32) % tau);
@@ -523,7 +520,7 @@ pub(crate) fn arc_to(
// the subpath.
#[allow(
clippy::cast_possible_truncation,
- reason = "the radius of an arc of a Gfx::Path is a float"
+ reason = "the radius of an arc of a path is a float"
)]
path.arc_to(end_tangent, radius as f32, large_arc, sweep);
Ok(())
@@ -670,7 +667,7 @@ pub(crate) fn round_rect(
let sweep = x_direction * y_direction > 0.0;
#[allow(
clippy::cast_possible_truncation,
- reason = "the radii of an arc of a Gfx::Path are floats"
+ reason = "the radii of an arc of a path are floats"
)]
let radii_of = |radius: RoundRectRadius| FloatSize {
width: radius.x as f32,
@@ -766,7 +763,7 @@ mod tests {
Close,
}
- /// The operations that a path was given, with the rules of a Gfx::Path for its current point.
+ /// The operations that a path was given, with the rules of `Path` for its current point.
#[derive(Default)]
struct RecordingPath {
ops: Vec<Op>,
diff --git a/Libraries/LibWeb/Rust/src/painting/image_map_areas.rs b/Libraries/LibWeb/Rust/src/painting/image_map_areas.rs
index 7b1da1087a8..0e5d41583a0 100644
--- a/Libraries/LibWeb/Rust/src/painting/image_map_areas.rs
+++ b/Libraries/LibWeb/Rust/src/painting/image_map_areas.rs
@@ -71,7 +71,7 @@ pub struct PublishedImageMapArea {
// https://html.spec.whatwg.org/multipage/image-maps.html#image-map-processing-model
/// The shape to layer onto the image, built with the same operations the DOM side built it with,
-/// so that the containment test is the one `Gfx::Path` already answered.
+/// so that the containment test gives the same answer.
fn shape_path(shape: AreaShape, coords: &[f64]) -> Option<Path> {
// Each area element in areas must be processed as follows to obtain a shape to layer onto the image:
diff --git a/Services/Compositor/Canvas2DCommandPlayer.cpp b/Services/Compositor/Canvas2DCommandPlayer.cpp
index 90169a617fa..3298dd6041e 100644
--- a/Services/Compositor/Canvas2DCommandPlayer.cpp
+++ b/Services/Compositor/Canvas2DCommandPlayer.cpp
@@ -15,7 +15,6 @@
#include <LibGfx/Color.h>
#include <LibGfx/DecodedImageFrame.h>
#include <LibGfx/PaintStyle.h>
-#include <LibGfx/Path.h>
#include <core/SkCanvas.h>
#include <core/SkPaint.h>
@@ -84,9 +83,9 @@ static Vector<T> inline_objects(ReadonlyBytes bytes)
return objects;
}
-Gfx::Path Canvas2DCommandPlayer::path_from(DisplayListDataSpan path_data) const
+SkPath Canvas2DCommandPlayer::path_from(DisplayListDataSpan path_data) const
{
- return Gfx::Path::from_serialized_bytes(inline_data(path_data));
+ return Gfx::skia_path_from_serialized_bytes(inline_data(path_data));
}
sk_sp<SkImageFilter> Canvas2DCommandPlayer::image_filter_from(Canvas2DCompositing const& compositing) const
@@ -157,7 +156,7 @@ void Canvas2DCommandPlayer::play_command(Canvas2DFillPath const& command)
auto paint_style = paint_style_from(command.paint);
if (!paint_style)
return;
- m_painter->fill_path(path, *paint_style, image_filter_from(command.compositing), command.compositing.global_alpha, command.compositing.compositing_and_blending_operator, command.winding_rule, shadow_from(command.compositing));
+ m_painter->fill_path(move(path), *paint_style, image_filter_from(command.compositing), command.compositing.global_alpha, command.compositing.compositing_and_blending_operator, command.winding_rule, shadow_from(command.compositing));
}
void Canvas2DCommandPlayer::play_command(Canvas2DStrokePath const& command)
diff --git a/Services/Compositor/Canvas2DCommandPlayer.h b/Services/Compositor/Canvas2DCommandPlayer.h
index 8e968cc6731..1893b93fe33 100644
--- a/Services/Compositor/Canvas2DCommandPlayer.h
+++ b/Services/Compositor/Canvas2DCommandPlayer.h
@@ -23,6 +23,7 @@
class SkImage;
class SkImageFilter;
+class SkPath;
template<typename T>
class sk_sp;
@@ -70,7 +71,7 @@ private:
void draw_image(SkImage const&, Gfx::FloatRect const& dst_rect, Gfx::FloatRect const& src_rect, Gfx::ScalingMode, Compositing::Canvas2DCompositing const&);
ReadonlyBytes inline_data(Compositing::DisplayListDataSpan) const;
- Gfx::Path path_from(Compositing::DisplayListDataSpan) const;
+ SkPath path_from(Compositing::DisplayListDataSpan) const;
sk_sp<SkImageFilter> image_filter_from(Compositing::Canvas2DCompositing const&) const;
RefPtr<Gfx::PaintStyle> paint_style_from(Compositing::Canvas2DPaint const&) const;
diff --git a/Services/Compositor/DisplayListPlayer.cpp b/Services/Compositor/DisplayListPlayer.cpp
index 31151443cc7..dc2bc51065a 100644
--- a/Services/Compositor/DisplayListPlayer.cpp
+++ b/Services/Compositor/DisplayListPlayer.cpp
@@ -8,7 +8,7 @@
#include <Compositor/DisplayListPlayer.h>
#include <Compositor/PaintingSurface.h>
#include <LibCompositing/RustFFI.h>
-#include <LibGfx/Path.h>
+#include <LibGfx/PathData.h>
namespace Compositor {
diff --git a/Services/Compositor/DisplayListPlayerSkia.cpp b/Services/Compositor/DisplayListPlayerSkia.cpp
index 704598bf3c0..7bd4775da3d 100644
--- a/Services/Compositor/DisplayListPlayerSkia.cpp
+++ b/Services/Compositor/DisplayListPlayerSkia.cpp
@@ -801,7 +801,7 @@ void DisplayListPlayerSkia::play_command(PaintOuterBoxShadow const& command)
// shadows are.
void DisplayListPlayerSkia::play_command(PaintPathBoxShadow const& command)
{
- auto shape = Gfx::to_skia_path(path_from_data(command.shape_path_data));
+ auto shape = path_from_data(command.shape_path_data);
// The spread distance grows the shape of an outer shadow, and shrinks the shape whose outside casts an inner one,
// by the outline of a stroke along the shape twice as wide.
@@ -1123,15 +1123,14 @@ SkPaint DisplayListPlayerSkia::paint_style_to_skia_paint(DisplayListPaintStyle c
VERIFY_NOT_REACHED();
}
-Gfx::Path DisplayListPlayerSkia::path_from_data(DisplayListDataSpan path_data) const
+SkPath DisplayListPlayerSkia::path_from_data(DisplayListDataSpan path_data) const
{
- auto bytes = inline_data(path_data);
- return Gfx::Path::from_serialized_bytes(bytes);
+ return Gfx::skia_path_from_serialized_bytes(inline_data(path_data));
}
void DisplayListPlayerSkia::play_command(FillPath const& command)
{
- auto path = Gfx::to_skia_path(path_from_data(command.path_data));
+ auto path = path_from_data(command.path_data);
path.setFillType(to_skia_path_fill_type(command.winding_rule));
SkPaint paint;
@@ -1148,7 +1147,7 @@ void DisplayListPlayerSkia::play_command(FillPath const& command)
void DisplayListPlayerSkia::play_command(StrokePath const& command)
{
- auto path = Gfx::to_skia_path(path_from_data(command.path_data));
+ auto path = path_from_data(command.path_data);
SkPaint paint;
if (command.paint_kind == PathPaintKind::PaintStyle) {
paint = paint_style_to_skia_paint(command.paint_style, command.path_bounding_rect);
@@ -1510,7 +1509,7 @@ void DisplayListPlayerSkia::push_clip_path(Gfx::PathData const& path, u64 path_i
void DisplayListPlayerSkia::push_clip_path_bytes(ReadonlyBytes path_bytes, Gfx::WindingRule winding_rule)
{
surface().canvas().save();
- clip_path(Gfx::to_skia_path(Gfx::Path::from_serialized_bytes(path_bytes)), winding_rule, true);
+ clip_path(Gfx::skia_path_from_serialized_bytes(path_bytes), winding_rule, true);
}
void DisplayListPlayerSkia::push_transform(Gfx::AffineTransform const& transform)
diff --git a/Services/Compositor/DisplayListPlayerSkia.h b/Services/Compositor/DisplayListPlayerSkia.h
index 580d6704954..4c957a966c0 100644
--- a/Services/Compositor/DisplayListPlayerSkia.h
+++ b/Services/Compositor/DisplayListPlayerSkia.h
@@ -83,7 +83,7 @@ private:
sk_sp<SkImageFilter> layer_image_filter(Compositing::ReplayLayer const&);
sk_sp<SkImageFilter> backdrop_image_filter(Compositing::ReplayLayer const&, bool limited_to_region);
sk_sp<SkImageFilter> image_filter_from_bytes(ReadonlyBytes, Optional<Gfx::FloatRect> blur_edge = {});
- Gfx::Path path_from_data(Compositing::DisplayListDataSpan) const;
+ SkPath path_from_data(Compositing::DisplayListDataSpan) const;
sk_sp<SkImage> rasterize_records_into_tile(ReadonlyBytes tile_records, Gfx::IntRect tile_rect);
ReadonlySpan<Color> gradient_colors(Compositing::DisplayListGradientColorStops) const;
ReadonlySpan<float> gradient_positions(Compositing::DisplayListGradientColorStops) const;
diff --git a/Services/Compositor/PainterSkia.cpp b/Services/Compositor/PainterSkia.cpp
index c0046dc07ba..b59bb7922d2 100644
--- a/Services/Compositor/PainterSkia.cpp
+++ b/Services/Compositor/PainterSkia.cpp
@@ -353,13 +353,13 @@ 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::CapStyle const& cap_style, Gfx::JoinStyle const& join_style, float miter_limit, Vector<float> const& dash_array, float dash_offset, Optional<CanvasShadow> const& shadow)
+void PainterSkia::stroke_path(SkPath 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)
return;
- auto sk_path = prune_path_for_stroking(to_skia_path(path));
+ auto pruned_path = prune_path_for_stroking(path);
auto paint = to_skia_paint(paint_style, move(image_filter), color_space());
paint.setAntiAlias(true);
float alpha = paint.getAlphaf();
@@ -371,20 +371,19 @@ void PainterSkia::stroke_path(Gfx::Path const& path, Gfx::PaintStyle const& pain
paint.setStrokeMiter(miter_limit);
paint.setPathEffect(SkDashPathEffect::Make({ dash_array.data(), dash_array.size() }, dash_offset));
draw_with_compositing(m_painting_surface->canvas(), paint, compositing_and_blending_operator, shadow, [&](SkCanvas& canvas, SkPaint const& paint) {
- canvas.drawPath(sk_path, paint);
+ canvas.drawPath(pruned_path, paint);
});
}
-void PainterSkia::fill_path(Gfx::Path const& path, Gfx::PaintStyle const& paint_style, sk_sp<SkImageFilter> image_filter, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::WindingRule winding_rule, Optional<CanvasShadow> const& shadow)
+void PainterSkia::fill_path(SkPath path, Gfx::PaintStyle const& paint_style, sk_sp<SkImageFilter> image_filter, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::WindingRule winding_rule, Optional<CanvasShadow> const& shadow)
{
- auto sk_path = to_skia_path(path);
- sk_path.setFillType(to_skia_path_fill_type(winding_rule));
+ path.setFillType(to_skia_path_fill_type(winding_rule));
auto paint = to_skia_paint(paint_style, move(image_filter), color_space());
paint.setAntiAlias(true);
float alpha = paint.getAlphaf();
paint.setAlphaf(alpha * global_alpha);
draw_with_compositing(m_painting_surface->canvas(), paint, compositing_and_blending_operator, shadow, [&](SkCanvas& canvas, SkPaint const& paint) {
- canvas.drawPath(sk_path, paint);
+ canvas.drawPath(path, paint);
});
}
@@ -469,12 +468,11 @@ void PainterSkia::restore()
canvas.restore();
}
-void PainterSkia::clip(Gfx::Path const& path, Gfx::WindingRule winding_rule)
+void PainterSkia::clip(SkPath path, Gfx::WindingRule winding_rule)
{
- auto sk_path = to_skia_path(path);
- sk_path.setFillType(to_skia_path_fill_type(winding_rule));
+ path.setFillType(to_skia_path_fill_type(winding_rule));
auto& canvas = m_painting_surface->canvas();
- canvas.clipPath(sk_path, SkClipOp::kIntersect, true);
+ canvas.clipPath(path, SkClipOp::kIntersect, true);
}
void PainterSkia::reset()
diff --git a/Services/Compositor/PainterSkia.h b/Services/Compositor/PainterSkia.h
index 032c1b5c8b2..1e95953f015 100644
--- a/Services/Compositor/PainterSkia.h
+++ b/Services/Compositor/PainterSkia.h
@@ -14,7 +14,6 @@
#include <LibGfx/CompositingAndBlendingOperator.h>
#include <LibGfx/Forward.h>
#include <LibGfx/PaintStyle.h>
-#include <LibGfx/Path.h>
#include <LibGfx/Point.h>
#include <LibGfx/ScalingMode.h>
#include <LibGfx/StrokeStyle.h>
@@ -23,6 +22,7 @@
class SkColorSpace;
class SkImage;
class SkImageFilter;
+class SkPath;
template<typename T>
class sk_sp;
@@ -57,13 +57,13 @@ 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::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 stroke_path(SkPath 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(SkPath, 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&);
void save();
void restore();
- void clip(Gfx::Path const&, Gfx::WindingRule);
+ void clip(SkPath, Gfx::WindingRule);
void reset();
private:
diff --git a/Services/Compositor/SkiaUtils.cpp b/Services/Compositor/SkiaUtils.cpp
index 5c0aadb71b9..0a0390bd07b 100644
--- a/Services/Compositor/SkiaUtils.cpp
+++ b/Services/Compositor/SkiaUtils.cpp
@@ -13,6 +13,7 @@
#include <LibGfx/ColorSpace.h>
#include <LibGfx/DecodedImageFrame.h>
#include <LibGfx/InterpolationColorSpace.h>
+#include <LibGfx/PathData.h>
#include <LibGfx/RustFFI.h>
#include <core/SkBitmap.h>
#include <core/SkBlender.h>
@@ -38,11 +39,6 @@ static_assert(to_underlying(PathVerb::Close) == to_underlying(SkPathVerb::kClose
static_assert(sizeof(PathVerb) == sizeof(SkPathVerb));
static_assert(sizeof(FloatPoint) == sizeof(SkPoint));
-SkPath to_skia_path(Path const& path)
-{
- return to_skia_path(path.data());
-}
-
SkPath to_skia_path(PathData const& data)
{
return SkPath::Raw(
@@ -52,6 +48,15 @@ SkPath to_skia_path(PathData const& data)
to_skia_path_fill_type(data.winding_rule));
}
+SkPath skia_path_from_serialized_bytes(ReadonlyBytes serialized_path)
+{
+ SkPath path;
+ with_contours_of_serialized_path(serialized_path, [&](PathData const& data) {
+ path = to_skia_path(data);
+ });
+ return path;
+}
+
namespace {
// Reads a serialized filter graph node by node and builds the SkImageFilter tree as it goes. The
diff --git a/Services/Compositor/SkiaUtils.h b/Services/Compositor/SkiaUtils.h
index 65db9a33fa6..55f873ef3ef 100644
--- a/Services/Compositor/SkiaUtils.h
+++ b/Services/Compositor/SkiaUtils.h
@@ -14,7 +14,6 @@
#include <LibGfx/Bitmap.h>
#include <LibGfx/CompositingAndBlendingOperator.h>
#include <LibGfx/PaintStyle.h>
-#include <LibGfx/Path.h>
#include <LibGfx/ScalingMode.h>
#include <LibGfx/StrokeStyle.h>
#include <LibGfx/WindingRule.h>
@@ -141,7 +140,7 @@ constexpr SkSamplingOptions to_skia_sampling_options(ScalingMode scaling_mode)
}
SkPath to_skia_path(PathData const&);
-SkPath to_skia_path(Path const& path);
+SkPath skia_path_from_serialized_bytes(ReadonlyBytes);
// Builds the SkImageFilter tree a serialized filter graph describes; `image_frame` supplies the
// frames the graph names by id.
// With `blur_edge`, every blur() filter function reads its input mirrored at that rect, not what lies outside it.