Truly independent web browser
LibGfx: Remove the Gfx::Path operations that nothing uses
Aliaksandr Kalenikd4695405556c
diff --git a/Libraries/LibGfx/Path.cpp b/Libraries/LibGfx/Path.cppindex e54eb939f39..6052a601dc5 100644--- a/Libraries/LibGfx/Path.cpp+++ b/Libraries/LibGfx/Path.cpp@@ -9,8 +9,6 @@#include <LibGfx/Font/Font.h>#include <LibGfx/Path.h>#include <LibGfx/RustFFI.h>-#include <LibIPC/Decoder.h>-#include <LibIPC/Encoder.h>#include <harfbuzz/hb.h>@@ -79,11 +77,6 @@ Path Path::from_serialized_bytes(ReadonlyBytes bytes)return Path { FFI::path_geometry_decode(bytes.data(), bytes.size()) };}-void Path::clear()-{- FFI::path_geometry_clear(m_geometry);-}-void Path::move_to(FloatPoint const& point){FFI::path_geometry_move_to(m_geometry, point.x(), point.y());@@ -99,11 +92,6 @@ void Path::close()FFI::path_geometry_close(m_geometry);}-void Path::elliptical_arc_to(FloatPoint point, FloatSize radii, float x_axis_rotation, bool large_arc, bool sweep)-{- FFI::path_geometry_elliptical_arc_to(m_geometry, point.x(), point.y(), radii.width(), radii.height(), x_axis_rotation, large_arc, sweep);-}-void Path::arc_to(FloatPoint point, float radius, bool large_arc, bool sweep){FFI::path_geometry_arc_to(m_geometry, point.x(), point.y(), radius, large_arc, sweep);@@ -114,52 +102,17 @@ void Path::quadratic_bezier_curve_to(FloatPoint through, FloatPoint point)FFI::path_geometry_quadratic_bezier_curve_to(m_geometry, through.x(), through.y(), point.x(), point.y());}-void Path::cubic_bezier_curve_to(FloatPoint c1, FloatPoint c2, FloatPoint p2)-{- FFI::path_geometry_cubic_bezier_curve_to(m_geometry, c1.x(), c1.y(), c2.x(), c2.y(), p2.x(), p2.y());-}--void Path::append_path(Path const& other)-{- FFI::path_geometry_append_path(m_geometry, other.m_geometry);-}--static void append_to_byte_vector(void* context, u8 const* bytes, size_t count)-{- static_cast<Vector<u8>*>(context)->append(bytes, count);-}-Vector<u8> Path::serialize_to_bytes() const{Vector<u8> bytes;- serialize_into(append_to_byte_vector, &bytes);+ FFI::path_geometry_encode(+ m_geometry, [](void* context, u8 const* bytes, size_t count) {+ static_cast<Vector<u8>*>(context)->append(bytes, count);+ },+ &bytes);return bytes;}-void Path::serialize_into(void (*append)(void*, u8 const*, size_t), void* context) const-{- FFI::path_geometry_encode(m_geometry, append, context);-}--bool Path::is_empty() const-{- return FFI::path_geometry_is_empty(m_geometry);-}--FloatPoint Path::last_point() const-{- float x_y[2];- FFI::path_geometry_last_point(m_geometry, x_y);- return { x_y[0], x_y[1] };-}--FloatRect Path::bounding_box() const-{- float x_y_width_height[4];- FFI::path_geometry_bounding_box(m_geometry, x_y_width_height);- return { x_y_width_height[0], x_y_width_height[1], x_y_width_height[2], x_y_width_height[3] };-}-float Path::length() const{return FFI::path_geometry_length(m_geometry);@@ -189,44 +142,6 @@ bool Path::contains(FloatPoint point, WindingRule winding_rule) constreturn FFI::path_geometry_contains(m_geometry, point.x(), point.y(), to_underlying(winding_rule));}-Path Path::stroke_to_fill(StrokeStyle const& style) const-{- return Path { FFI::path_geometry_stroke_to_fill(m_geometry, style.thickness, to_underlying(style.cap_style), to_underlying(style.join_style), style.miter_limit, style.dash_array.data(), style.dash_array.size(), style.dash_offset) };-}--void Path::set_fill_type(WindingRule winding_rule)-{- FFI::path_geometry_set_fill_rule(m_geometry, to_underlying(winding_rule));-}--static Array<float, 6> affine_values(AffineTransform const& transform)-{- return { transform.a(), transform.b(), transform.c(), transform.d(), transform.e(), transform.f() };-}--Path Path::copy_transformed(AffineTransform const& transform) const-{- auto values = affine_values(transform);- return Path { FFI::path_geometry_copy_transformed(m_geometry, values.data()) };-}--void Path::transform(AffineTransform const& transform)-{- auto values = affine_values(transform);- FFI::path_geometry_transform(m_geometry, values.data());-}--String Path::to_svg_string() const-{- String string;- FFI::path_geometry_svg_string(- m_geometry, [](void* context, u8 const* bytes, size_t count) {- *static_cast<String*>(context) = String::from_utf8_without_validation({ bytes, count });- },- &string);- return string;-}-PathData PathData::from_ffi(FFI::PathGeometryData const& data){return {@@ -244,11 +159,6 @@ PathData Path::data() constreturn PathData::from_ffi(data);}-bool Path::operator==(Path const& other) const-{- return FFI::path_geometry_equals(m_geometry, other.m_geometry);-}-namespace {// Maps the coordinates of a glyph outline from font units, with y up, to pixels, with y down. A contour starts only at@@ -431,23 +341,6 @@ public:}-namespace IPC {--template<>-ErrorOr<void> encode(Encoder& encoder, Gfx::Path const& path)-{- return encoder.encode(path.serialize_to_bytes());-}--template<>-ErrorOr<Gfx::Path> decode(Decoder& decoder)-{- auto path_data = TRY(decoder.decode<Vector<u8>>());- return Gfx::Path::from_serialized_bytes(path_data);-}--}-// The function through which Rust code builds glyph outlines into paths. See Rust/src/path.rs.extern "C" {diff --git a/Libraries/LibGfx/Path.h b/Libraries/LibGfx/Path.hindex de02e07de19..027fa93003d 100644--- a/Libraries/LibGfx/Path.h+++ b/Libraries/LibGfx/Path.h@@ -18,7 +18,6 @@#include <LibGfx/Rect.h>#include <LibGfx/Vector2.h>#include <LibGfx/WindingRule.h>-#include <LibIPC/Forward.h>namespace Gfx {@@ -74,7 +73,6 @@ public:[[nodiscard]] static Path from_serialized_bytes(ReadonlyBytes);- void clear();void move_to(Gfx::FloatPoint const&);void line_to(Gfx::FloatPoint const&);void close();@@ -91,49 +89,20 @@ public:Bevel,};- struct StrokeStyle {- float thickness { 1 };- CapStyle cap_style { CapStyle::Butt };- JoinStyle join_style { JoinStyle::Miter };- float miter_limit { 4 };- ReadonlySpan<float> dash_array;- float dash_offset { 0 };- };-- // The outline of the area that stroking this path with the given style covers, as a path to fill with the- // nonzero winding rule.- [[nodiscard]] Gfx::Path stroke_to_fill(StrokeStyle const&) const;-- void elliptical_arc_to(FloatPoint point, FloatSize radii, float x_axis_rotation, bool large_arc, bool sweep);void arc_to(FloatPoint point, float radius, bool large_arc, bool sweep);void quadratic_bezier_curve_to(FloatPoint through, FloatPoint point);- void cubic_bezier_curve_to(FloatPoint c1, FloatPoint c2, FloatPoint p2);-- void append_path(Gfx::Path const&);[[nodiscard]] Vector<u8> serialize_to_bytes() const;- void serialize_into(void (*append)(void*, u8 const*, size_t), void* context) const;- [[nodiscard]] bool is_empty() const;- Gfx::FloatPoint last_point() const;- Gfx::FloatRect bounding_box() const;float length() const;Optional<PointAlongPath> point_at_length(float distance) const;Vector<PathVertex> vertices() const;bool contains(FloatPoint point, Gfx::WindingRule) const;- void set_fill_type(Gfx::WindingRule);Gfx::Path clone() const { return *this; }- Gfx::Path copy_transformed(Gfx::AffineTransform const&) const;-- String to_svg_string() const;-- void transform(Gfx::AffineTransform const&);PathData data() const;- bool operator==(Path const&) const;-private:explicit Path(FFI::PathGeometry*);@@ -141,13 +110,3 @@ private:};}--namespace IPC {--template<>-ErrorOr<void> encode(Encoder&, Gfx::Path const&);--template<>-ErrorOr<Gfx::Path> decode(Decoder&);--}diff --git a/Libraries/LibGfx/Rust/src/path/ffi.rs b/Libraries/LibGfx/Rust/src/path/ffi.rsindex d95a38e7ae1..0af772da3de 100644--- a/Libraries/LibGfx/Rust/src/path/ffi.rs+++ b/Libraries/LibGfx/Rust/src/path/ffi.rs@@ -13,11 +13,8 @@ use super::encoding;use super::geometry::{PathGeometry, PathVerb};use super::hit_test;use super::measure::{self, PathVertex};-use super::stroke::{self, StrokeStyle};-use super::svg_text;use crate::geometry::FloatPoint;-use crate::matrix::AffineTransform;-use crate::paint_enums::{CapStyle, JoinStyle, WindingRule};+use crate::paint_enums::WindingRule;use std::ffi::c_void;/// The contours of a path, valid until the path changes or is destroyed. A path without geometry has@@ -37,15 +34,6 @@ fn point(x: f32, y: f32) -> FloatPoint {FloatPoint { x, y }}-/// # Safety-/// `transform` must point to the six values a, b, c, d, e and f of an affine transform.-unsafe fn read_transform(transform: *const f32) -> AffineTransform {- AffineTransform {- // SAFETY: The caller passes six floats.- values: unsafe { std::ptr::read(transform.cast::<[f32; 6]>()) },- }-}-/// # Safety/// `out_point_and_tangent` must point to four floats.unsafe fn write_point_and_tangent(out_point_and_tangent: *mut f32, (position, tangent): (FloatPoint, FloatPoint)) {@@ -58,26 +46,6 @@ unsafe fn write_point_and_tangent(out_point_and_tangent: *mut f32, (position, ta}}-/// Calls the function with the path and the other path. A path appended to itself is copied first.-///-/// # Safety-/// `path` and `other` must be live paths from this module; nothing else may use `path` for the call.-unsafe fn with_other_path(- path: *mut PathGeometry,- other: *const PathGeometry,- function: impl FnOnce(&mut PathGeometry, &PathGeometry),-) {- if std::ptr::eq(path, other) {- // SAFETY: Forwarded from the caller.- let copy = unsafe { &*other }.clone();- // SAFETY: Forwarded from the caller.- function(unsafe { &mut *path }, ©);- } else {- // SAFETY: Forwarded from the caller; the paths are distinct.- function(unsafe { &mut *path }, unsafe { &*other });- }-}-fn into_raw(geometry: PathGeometry) -> *mut PathGeometry {Box::into_raw(Box::new(geometry))}@@ -143,43 +111,6 @@ pub unsafe extern "C" fn path_geometry_quadratic_bezier_curve_to(unsafe { &mut *path }.quadratic_bezier_curve_to(point(control_x, control_y), 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_cubic_bezier_curve_to(- path: *mut PathGeometry,- control1_x: f32,- control1_y: f32,- control2_x: f32,- control2_y: f32,- x: f32,- y: f32,-) {- // SAFETY: Forwarded from the caller.- unsafe { &mut *path }.cubic_bezier_curve_to(- point(control1_x, control1_y),- point(control2_x, control2_y),- 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_elliptical_arc_to(- path: *mut PathGeometry,- x: f32,- y: f32,- radius_x: f32,- radius_y: f32,- x_axis_rotation: f32,- large_arc: bool,- sweep: bool,-) {- // SAFETY: Forwarded from the caller.- unsafe { &mut *path }.elliptical_arc_to(point(x, y), (radius_x, radius_y), x_axis_rotation, large_arc, sweep);-}-/// # Safety/// `path` must be a live path from this module, which nothing else uses for the call.#[unsafe(no_mangle)]@@ -263,50 +194,6 @@ pub unsafe extern "C" fn path_geometry_contour_close(path: *mut PathGeometry) {unsafe { &mut *path }.contour_close();}-/// # Safety-/// `path` and `other` must be live paths from this module; nothing else may use `path` for the call.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn path_geometry_append_path(path: *mut PathGeometry, other: *const PathGeometry) {- // SAFETY: Forwarded from the caller.- unsafe { with_other_path(path, other, |path, other| path.append_path(other)) };-}--/// # 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_set_fill_rule(path: *mut PathGeometry, winding_rule: i32) {- // SAFETY: Forwarded from the caller.- unsafe { &mut *path }.set_fill_rule(WindingRule::from_raw(winding_rule));-}--/// # Safety-/// `path` must be a live path from this module.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn path_geometry_is_empty(path: *const PathGeometry) -> bool {- // SAFETY: Forwarded from the caller.- unsafe { &*path }.is_empty()-}--/// # Safety-/// `path` must be a live path from this module, and `out_x_y` must point to two floats.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn path_geometry_last_point(path: *const PathGeometry, out_x_y: *mut f32) {- // SAFETY: Forwarded from the caller.- let last = unsafe { &*path }.last_point();- // SAFETY: The caller passes room for two floats.- unsafe { std::ptr::write(out_x_y.cast::<[f32; 2]>(), [last.x, last.y]) };-}--/// # Safety-/// `path` must be a live path from this module, and `out_x_y_width_height` must point to four floats.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn path_geometry_bounding_box(path: *const PathGeometry, out_x_y_width_height: *mut f32) {- // SAFETY: Forwarded from the caller.- let bounds = unsafe { &*path }.bounding_box();- // SAFETY: The caller passes room for four floats.- unsafe { std::ptr::write(out_x_y_width_height.cast::<[f32; 4]>(), bounds) };-}-/// # Safety/// `path` must be a live path from this module.#[unsafe(no_mangle)]@@ -359,70 +246,6 @@ pub unsafe extern "C" fn path_geometry_contains(path: *const PathGeometry, x: f3hit_test::contains(unsafe { &*path }, x, y, WindingRule::from_raw(winding_rule))}-/// The outline of the area that stroking the path covers, as a path to fill with the nonzero winding rule.-/// The cap and join styles have the values of `Gfx::Path::CapStyle` and `Gfx::Path::JoinStyle`.-///-/// # Safety-/// `path` must be a live path from this module, and `dash_array` must point to `dash_count` floats, or be-/// null with a count of zero.-#[allow(clippy::too_many_arguments)]-#[unsafe(no_mangle)]-pub unsafe extern "C" fn path_geometry_stroke_to_fill(- path: *const PathGeometry,- thickness: f32,- cap_style: i32,- join_style: i32,- miter_limit: f32,- dash_array: *const f32,- dash_count: usize,- dash_offset: f32,-) -> *mut PathGeometry {- let style = StrokeStyle {- thickness,- cap_style: match cap_style {- 1 => CapStyle::Round,- 2 => CapStyle::Square,- _ => CapStyle::Butt,- },- join_style: match join_style {- 1 => JoinStyle::Round,- 2 => JoinStyle::Bevel,- _ => JoinStyle::Miter,- },- miter_limit,- // SAFETY: Forwarded from the caller.- dash_array: unsafe { ak::slice_from_raw_parts(dash_array, dash_count) },- dash_offset,- };- // SAFETY: Forwarded from the caller.- into_raw(stroke::stroke_to_fill(unsafe { &*path }, &style))-}--/// # Safety-/// `path` must be a live path from this module, and `transform` must point to the six values a, b, c, d,-/// e and f of an affine transform.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn path_geometry_copy_transformed(- path: *const PathGeometry,- transform: *const f32,-) -> *mut PathGeometry {- // SAFETY: Forwarded from the caller.- let transform = unsafe { read_transform(transform) };- // SAFETY: Forwarded from the caller.- into_raw(unsafe { &*path }.copy_transformed(transform))-}--/// # Safety-/// `path` must be a live path from this module, which nothing else uses for the call, and `transform`-/// must point to the six values a, b, c, d, e and f of an affine transform.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn path_geometry_transform(path: *mut PathGeometry, transform: *const f32) {- // SAFETY: Forwarded from the caller.- let transform = unsafe { read_transform(transform) };- // SAFETY: Forwarded from the caller.- unsafe { &mut *path }.transform(transform);-}-/// Calls the callback once with the byte form of the path.////// # Safety@@ -450,30 +273,6 @@ pub unsafe extern "C" fn path_geometry_decode(bytes: *const u8, count: usize) ->into_raw(encoding::decode(bytes).unwrap_or_default())}-/// Calls the callback once with the SVG path data of the path, as UTF-8.-///-/// # Safety-/// `path` must be a live path from this module, and the callback must accept `context`.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn path_geometry_svg_string(- path: *const PathGeometry,- callback: unsafe extern "C" fn(*mut c_void, *const u8, usize),- context: *mut c_void,-) {- // SAFETY: Forwarded from the caller.- let string = svg_text::to_svg_string(unsafe { &*path });- // SAFETY: The string lives for the synchronous call.- unsafe { callback(context, string.as_ptr(), string.len()) };-}--/// # Safety-/// `a` and `b` must be live paths from this module.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn path_geometry_equals(a: *const PathGeometry, b: *const PathGeometry) -> bool {- // SAFETY: Forwarded from the caller.- unsafe { &*a }.has_same_contours(unsafe { &*b })-}-impl PathGeometryData {pub fn of(geometry: &PathGeometry) -> Self {let (verbs, points, conic_weights) = if geometry.has_geometry() {