diff --git a/.clippy.toml b/.clippy.toml index 91b13d7cf..0ad0680b4 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1 +1,12 @@ +# LINEBENDER LINT SET - .clippy.toml - v1 +# See https://linebender.org/wiki/canonical-lints/ + +# The default Clippy value is capped at 8 bytes, which was chosen to improve performance on 32-bit. +# Given that we are building for the future and even low-end mobile phones have 64-bit CPUs, +# it makes sense to optimize for 64-bit and accept the performance hits on 32-bit. +# 16 bytes is the number of bytes that fits into two 64-bit CPU registers. +trivial-copy-size-limit = 16 + +# END LINEBENDER LINT SET + doc-valid-idents = ["MotionMark", "WebGPU", "PostScript", ".."] diff --git a/Cargo.lock b/Cargo.lock index 30f63f82d..a3ec299c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2445,7 +2445,6 @@ dependencies = [ "log", "peniko", "png", - "raw-window-handle", "skrifa", "static_assertions", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 253bc725c..473192554 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,11 +7,11 @@ members = [ "vello_tests", "examples/headless", - "examples/with_winit", "examples/run_wasm", "examples/scenes", "examples/simple", "examples/simple_sdl2", + "examples/with_winit", ] [workspace.package] @@ -32,11 +32,64 @@ license = "Apache-2.0 OR MIT" repository = "https://github.com/linebender/vello" [workspace.lints] +# LINEBENDER LINT SET - Cargo.toml - v2 +# See https://linebender.org/wiki/canonical-lints/ +rust.keyword_idents_2024 = "forbid" +rust.non_ascii_idents = "forbid" +rust.non_local_definitions = "forbid" +rust.unsafe_op_in_unsafe_fn = "forbid" + +rust.elided_lifetimes_in_paths = "warn" +rust.let_underscore_drop = "warn" +rust.missing_debug_implementations = "warn" +rust.missing_docs = "warn" +rust.single_use_lifetimes = "warn" +rust.trivial_numeric_casts = "warn" +rust.unexpected_cfgs = "warn" +rust.unit_bindings = "warn" +rust.unnameable_types = "warn" +rust.unreachable_pub = "warn" +rust.unused_import_braces = "warn" +rust.unused_lifetimes = "warn" +rust.unused_macro_rules = "warn" +rust.unused_qualifications = "warn" +rust.variant_size_differences = "warn" + +clippy.allow_attributes = "warn" +clippy.allow_attributes_without_reason = "warn" +clippy.cast_possible_truncation = "warn" +clippy.collection_is_never_read = "warn" +clippy.dbg_macro = "warn" +clippy.debug_assert_with_mut_call = "warn" clippy.doc_markdown = "warn" +clippy.exhaustive_enums = "warn" +clippy.fn_to_numeric_cast_any = "warn" # Can't be forbid due to 'scenes' requiring an exception. +clippy.infinite_loop = "warn" +clippy.large_include_file = "warn" +clippy.large_stack_arrays = "warn" +clippy.match_same_arms = "warn" +clippy.mismatching_type_param_order = "warn" +clippy.missing_assert_message = "warn" +clippy.missing_errors_doc = "warn" +clippy.missing_fields_in_debug = "warn" +clippy.missing_panics_doc = "warn" +clippy.partial_pub_fields = "warn" +clippy.return_self_not_must_use = "warn" +clippy.same_functions_in_if_condition = "warn" clippy.semicolon_if_nothing_returned = "warn" -# We use a modified version of `unreachable_pub`, where we mark associated functions of pub(crate) items as pub. -# This policy was implemented as it could gain begrudging consensus - there is no lint for this. -# rust.unreachable_pub = "warn" +clippy.shadow_unrelated = "warn" +clippy.should_panic_without_expect = "warn" +clippy.todo = "warn" +clippy.trivially_copy_pass_by_ref = "warn" +clippy.unseparated_literal_suffix = "warn" +clippy.use_self = "warn" +clippy.wildcard_imports = "warn" + +clippy.cargo_common_metadata = "warn" +clippy.negative_feature_names = "warn" +clippy.redundant_feature_names = "warn" +clippy.wildcard_dependencies = "warn" +# END LINEBENDER LINT SET [workspace.dependencies] vello = { version = "0.3.0", path = "vello" } @@ -50,7 +103,6 @@ peniko = "0.2.0" # FIXME: This can be removed once peniko supports the schemars feature. kurbo = "0.11.1" futures-intrusive = "0.5.0" -raw-window-handle = "0.6.2" smallvec = "1.13.2" static_assertions = "1.1.0" thiserror = "1.0.64" diff --git a/examples/headless/src/main.rs b/examples/headless/src/main.rs index 22f48a801..d8045cd1b 100644 --- a/examples/headless/src/main.rs +++ b/examples/headless/src/main.rs @@ -1,6 +1,16 @@ // Copyright 2023 the Vello Authors // SPDX-License-Identifier: Apache-2.0 OR MIT +//! Headless + +// The following lints are part of the Linebender standard set, +// but resolving them has been deferred for now. +// Feel free to send a PR that solves one or more of these. +#![allow( + clippy::cast_possible_truncation, + clippy::allow_attributes_without_reason +)] + use std::fs::File; use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; @@ -206,10 +216,10 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> { .join(&example_scene.config.name) .with_extension("png"); let mut file = File::create(&out_path)?; - let mut encoder = png::Encoder::new(&mut file, width, height); - encoder.set_color(png::ColorType::Rgba); - encoder.set_depth(png::BitDepth::Eight); - let mut writer = encoder.write_header()?; + let mut png_encoder = png::Encoder::new(&mut file, width, height); + png_encoder.set_color(png::ColorType::Rgba); + png_encoder.set_depth(png::BitDepth::Eight); + let mut writer = png_encoder.write_header()?; writer.write_image_data(&result_unpadded)?; writer.finish()?; println!("Wrote result ({width}x{height}) to {out_path:?}"); diff --git a/examples/run_wasm/src/main.rs b/examples/run_wasm/src/main.rs index 0651fb3f4..4df8804ca 100644 --- a/examples/run_wasm/src/main.rs +++ b/examples/run_wasm/src/main.rs @@ -1,6 +1,8 @@ // Copyright 2022 the Vello Authors // SPDX-License-Identifier: Apache-2.0 OR MIT +//! Wasm + /// Use [cargo-run-wasm](https://github.com/rukai/cargo-run-wasm) to build an example for web /// /// Usage: diff --git a/examples/scenes/src/lib.rs b/examples/scenes/src/lib.rs index c6c951664..06e21d79a 100644 --- a/examples/scenes/src/lib.rs +++ b/examples/scenes/src/lib.rs @@ -1,8 +1,30 @@ // Copyright 2022 the Vello Authors // SPDX-License-Identifier: Apache-2.0 OR MIT -// This is not a published crate, so we don't need to understand our public API -#![allow(unreachable_pub)] +//! Scenes + +// The following lints are part of the Linebender standard set, +// but resolving them has been deferred for now. +// Feel free to send a PR that solves one or more of these. +#![allow( + missing_debug_implementations, + elided_lifetimes_in_paths, + single_use_lifetimes, + unreachable_pub, + missing_docs, + clippy::wildcard_imports, + clippy::unseparated_literal_suffix, + clippy::cast_possible_truncation, + clippy::shadow_unrelated, + clippy::missing_panics_doc, + clippy::missing_errors_doc, + clippy::partial_pub_fields, + clippy::use_self, + clippy::match_same_arms, + clippy::allow_attributes_without_reason, + clippy::allow_attributes, + clippy::fn_to_numeric_cast_any +)] mod images; mod mmark; @@ -32,7 +54,7 @@ pub struct SceneParams<'a> { pub text: &'a mut SimpleText, pub images: &'a mut ImageCache, pub resolution: Option, - pub base_color: Option, + pub base_color: Option, pub complexity: usize, } diff --git a/examples/scenes/src/mmark.rs b/examples/scenes/src/mmark.rs index 3deea8d79..bd901155e 100644 --- a/examples/scenes/src/mmark.rs +++ b/examples/scenes/src/mmark.rs @@ -69,7 +69,7 @@ impl MMark { } impl TestScene for MMark { - fn render(&mut self, scene: &mut Scene, params: &mut SceneParams) { + fn render(&mut self, scene: &mut Scene, params: &mut SceneParams<'_>) { let c = params.complexity; let n = if c < 10 { (c + 1) * 1000 @@ -101,7 +101,7 @@ impl TestScene for MMark { ); path.truncate(0); // Should have clear method, to avoid allocations. } - if rng.gen::() > 0.995 { + if rng.r#gen::() > 0.995 { element.is_split ^= true; } } @@ -161,8 +161,8 @@ impl Element { ) }; let color = *COLORS.choose(&mut rng).unwrap(); - let width = rng.gen::().powi(5) * 20.0 + 1.0; - let is_split = rng.gen(); + let width = rng.r#gen::().powi(5) * 20.0 + 1.0; + let is_split = rng.r#gen(); Element { seg, color, @@ -191,7 +191,7 @@ impl GridPoint { GridPoint(x, y) } - fn coordinate(&self) -> Point { + fn coordinate(self) -> Point { let scale_x = WIDTH as f64 / ((GRID_WIDTH + 1) as f64); let scale_y = HEIGHT as f64 / ((GRID_HEIGHT + 1) as f64); Point::new( diff --git a/examples/scenes/src/pico_svg.rs b/examples/scenes/src/pico_svg.rs index 22aaf79e5..bf8a2707f 100644 --- a/examples/scenes/src/pico_svg.rs +++ b/examples/scenes/src/pico_svg.rs @@ -133,7 +133,7 @@ impl Parser { fn rec_parse( &mut self, - node: Node, + node: Node<'_, '_>, properties: &RecursiveProperties, items: &mut Vec, ) -> Result<(), Box> { @@ -274,7 +274,7 @@ fn parse_color(color: &str) -> Color { } } -fn modify_opacity(mut color: Color, attr_name: &str, node: Node) -> Color { +fn modify_opacity(mut color: Color, attr_name: &str, node: Node<'_, '_>) -> Color { if let Some(opacity) = node.attribute(attr_name) { let alpha: f64 = if let Some(o) = opacity.strip_suffix('%') { let pctg = o.parse().unwrap_or(100.0); diff --git a/examples/scenes/src/svg.rs b/examples/scenes/src/svg.rs index 937093695..06027b545 100644 --- a/examples/scenes/src/svg.rs +++ b/examples/scenes/src/svg.rs @@ -185,7 +185,7 @@ pub fn svg_function_of>( None, 48., None, - vello::kurbo::Affine::translate((110.0, 600.0)), + Affine::translate((110.0, 600.0)), &format!("Loading {name}"), ), Err(RecvTimeoutError::Disconnected) => { diff --git a/examples/scenes/src/test_scenes.rs b/examples/scenes/src/test_scenes.rs index 89c131d68..583188071 100644 --- a/examples/scenes/src/test_scenes.rs +++ b/examples/scenes/src/test_scenes.rs @@ -735,7 +735,7 @@ mod impls { Affine::IDENTITY, &Brush::Solid(Color::rgb8(128, 0, 0)), None, - &[PathEl::MoveTo(center), PathEl::LineTo(p1)], + &[MoveTo(center), LineTo(p1)], ); scene.fill( Fill::NonZero, @@ -1128,7 +1128,7 @@ mod impls { scene.push_layer(Mix::Clip, 1.0, translate * rot, &base_tri); } let rot = Affine::rotate(rng.gen_range(0.0..PI)); - let color = Color::rgb(rng.gen(), rng.gen(), rng.gen()); + let color = Color::rgb(rng.r#gen(), rng.r#gen(), rng.r#gen()); scene.fill(Fill::NonZero, translate * rot, color, None, &base_tri); for _ in 0..CLIPS_PER_FILL { scene.pop_layer(); @@ -1141,7 +1141,7 @@ mod impls { pub(super) fn render_cardioid(scene: &mut Scene) { let n = 601; - let dth = std::f64::consts::PI * 2.0 / (n as f64); + let dth = PI * 2.0 / (n as f64); let center = Point::new(1024.0, 768.0); let r = 750.0; let mut path = BezPath::new(); @@ -1571,21 +1571,21 @@ mod impls { } scene.pop_layer(); - let large_background_rect = kurbo::Rect::new(-1000.0, -1000.0, 2000.0, 2000.0); - let inside_clip_rect = kurbo::Rect::new(11.0, 13.399999999999999, 59.0, 56.6); - let outside_clip_rect = kurbo::Rect::new( + let large_background_rect = Rect::new(-1000.0, -1000.0, 2000.0, 2000.0); + let inside_clip_rect = Rect::new(11.0, 13.399999999999999, 59.0, 56.6); + let outside_clip_rect = Rect::new( 12.599999999999998, 12.599999999999998, 57.400000000000006, 57.400000000000006, ); - let clip_rect = kurbo::Rect::new(0.0, 0.0, 74.4, 339.20000000000005); + let clip_rect = Rect::new(0.0, 0.0, 74.4, 339.20000000000005); let scale = 2.0; scene.push_layer( BlendMode { - mix: peniko::Mix::Normal, - compose: peniko::Compose::SrcOver, + mix: Mix::Normal, + compose: Compose::SrcOver, }, 1.0, Affine::new([scale, 0.0, 0.0, scale, 27.07470703125, 176.40660533027858]), @@ -1593,15 +1593,15 @@ mod impls { ); scene.fill( - peniko::Fill::NonZero, - kurbo::Affine::new([scale, 0.0, 0.0, scale, 27.07470703125, 176.40660533027858]), - peniko::Color::rgb8(0, 0, 255), + Fill::NonZero, + Affine::new([scale, 0.0, 0.0, scale, 27.07470703125, 176.40660533027858]), + Color::rgb8(0, 0, 255), None, &large_background_rect, ); scene.fill( - peniko::Fill::NonZero, - kurbo::Affine::new([ + Fill::NonZero, + Affine::new([ scale, 0.0, 0.0, @@ -1609,13 +1609,13 @@ mod impls { 29.027636718750003, 182.9755506427786, ]), - peniko::Color::rgb8(0, 255, 0), + Color::rgb8(0, 255, 0), None, &inside_clip_rect, ); scene.fill( - peniko::Fill::NonZero, - kurbo::Affine::new([ + Fill::NonZero, + Affine::new([ scale, 0.0, 0.0, @@ -1623,7 +1623,7 @@ mod impls { 29.027636718750003, scale * 559.3583631427786, ]), - peniko::Color::rgb8(255, 0, 0), + Color::rgb8(255, 0, 0), None, &outside_clip_rect, ); @@ -1778,8 +1778,8 @@ mod impls { blob.push(b[1]); blob.push(b[0]); }); - let data = vello::peniko::Blob::new(Arc::new(blob)); - let image = vello::peniko::Image::new(data, vello::peniko::Format::Rgba8, 2, 2); + let data = Blob::new(Arc::new(blob)); + let image = Image::new(data, Format::Rgba8, 2, 2); scene.draw_image( &image, @@ -1820,8 +1820,8 @@ mod impls { blob.push(b[1]); blob.push(b[0]); }); - let data = vello::peniko::Blob::new(Arc::new(blob)); - let image = vello::peniko::Image::new(data, vello::peniko::Format::Rgba8, 2, 2); + let data = Blob::new(Arc::new(blob)); + let image = Image::new(data, Format::Rgba8, 2, 2); let image = image.with_extend(Extend::Pad); // Pad extend mode scene.fill( diff --git a/examples/simple/src/main.rs b/examples/simple/src/main.rs index d0e997d02..044ea12a8 100644 --- a/examples/simple/src/main.rs +++ b/examples/simple/src/main.rs @@ -1,6 +1,8 @@ // Copyright 2024 the Vello Authors // SPDX-License-Identifier: Apache-2.0 OR MIT +//! Simple example. + use anyhow::Result; use std::num::NonZeroUsize; use std::sync::Arc; @@ -10,12 +12,13 @@ use vello::util::{RenderContext, RenderSurface}; use vello::{AaConfig, Renderer, RendererOptions, Scene}; use winit::application::ApplicationHandler; use winit::dpi::LogicalSize; -use winit::event::*; +use winit::event::WindowEvent; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::window::Window; use vello::wgpu; -// Simple struct to hold the state of the renderer +/// Simple struct to hold the state of the renderer +#[derive(Debug)] pub struct ActiveRenderState<'s> { // The fields MUST be in this order, so that the surface is dropped before the window surface: RenderSurface<'s>, @@ -45,7 +48,7 @@ struct SimpleVelloApp<'s> { scene: Scene, } -impl<'s> ApplicationHandler for SimpleVelloApp<'s> { +impl ApplicationHandler for SimpleVelloApp<'_> { fn resumed(&mut self, event_loop: &ActiveEventLoop) { let RenderState::Suspended(cached_window) = &mut self.state else { return; @@ -188,7 +191,7 @@ fn create_winit_window(event_loop: &ActiveEventLoop) -> Arc { } /// Helper function that creates a vello `Renderer` for a given `RenderContext` and `RenderSurface` -fn create_vello_renderer(render_cx: &RenderContext, surface: &RenderSurface) -> Renderer { +fn create_vello_renderer(render_cx: &RenderContext, surface: &RenderSurface<'_>) -> Renderer { Renderer::new( &render_cx.devices[surface.dev_id].device, RendererOptions { diff --git a/examples/simple_sdl2/src/main.rs b/examples/simple_sdl2/src/main.rs index 9db667ed4..52ecd7fc3 100644 --- a/examples/simple_sdl2/src/main.rs +++ b/examples/simple_sdl2/src/main.rs @@ -20,7 +20,7 @@ use vello::{AaConfig, Renderer, RendererOptions, Scene}; use vello::wgpu; -pub fn main() { +fn main() { let sdl_context = sdl2::init().unwrap(); let video_subsystem = sdl_context.video().unwrap(); @@ -103,7 +103,7 @@ pub fn main() { } } -fn create_vello_renderer(render_cx: &RenderContext, surface: &RenderSurface) -> Renderer { +fn create_vello_renderer(render_cx: &RenderContext, surface: &RenderSurface<'_>) -> Renderer { Renderer::new( &render_cx.devices[surface.dev_id].device, RendererOptions { diff --git a/examples/with_winit/src/hot_reload.rs b/examples/with_winit/src/hot_reload.rs index 9dc3fe376..4d4a1180d 100644 --- a/examples/with_winit/src/hot_reload.rs +++ b/examples/with_winit/src/hot_reload.rs @@ -4,7 +4,7 @@ use std::time::Duration; use anyhow::Result; -use notify_debouncer_mini::notify::*; +use notify_debouncer_mini::notify::RecursiveMode; use notify_debouncer_mini::{new_debouncer, DebounceEventResult}; pub fn hot_reload(mut f: impl FnMut() -> Option<()> + Send + 'static) -> Result { diff --git a/examples/with_winit/src/lib.rs b/examples/with_winit/src/lib.rs index f13bbd651..aa25a4e7e 100644 --- a/examples/with_winit/src/lib.rs +++ b/examples/with_winit/src/lib.rs @@ -1,8 +1,20 @@ // Copyright 2022 the Vello Authors // SPDX-License-Identifier: Apache-2.0 OR MIT -// This is not a published crate, so we don't need to understand our public API -#![allow(unreachable_pub)] +//! Winit example. + +// The following lints are part of the Linebender standard set, +// but resolving them has been deferred for now. +// Feel free to send a PR that solves one or more of these. +#![allow( + unreachable_pub, + clippy::allow_attributes_without_reason, + clippy::allow_attributes, + clippy::cast_possible_truncation, + clippy::shadow_unrelated, + clippy::missing_errors_doc, + clippy::missing_panics_doc +)] use std::collections::HashSet; use std::num::NonZeroUsize; @@ -14,8 +26,8 @@ use vello::low_level::DebugLayers; #[cfg(target_arch = "wasm32")] use web_time::Instant; use winit::application::ApplicationHandler; -use winit::event::*; -use winit::keyboard::*; +use winit::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent}; +use winit::keyboard::{Key, ModifiersState, NamedKey}; #[cfg(all(feature = "wgpu-profiler", not(target_arch = "wasm32")))] use std::time::Duration; @@ -166,13 +178,13 @@ struct VelloApp<'s> { debug: DebugLayers, } -impl<'s> ApplicationHandler for VelloApp<'s> { +impl ApplicationHandler for VelloApp<'_> { #[cfg(target_arch = "wasm32")] fn resumed(&mut self, _event_loop: &winit::event_loop::ActiveEventLoop) {} #[cfg(not(target_arch = "wasm32"))] fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) { - let Option::None = self.state else { + let None = self.state else { return; }; let window = self @@ -232,7 +244,7 @@ impl<'s> ApplicationHandler for VelloApp<'s> { &mut self, event_loop: &winit::event_loop::ActiveEventLoop, window_id: winit::window::WindowId, - event: winit::event::WindowEvent, + event: WindowEvent, ) { let Some(render_state) = &mut self.state else { return; @@ -650,15 +662,15 @@ fn run( args: Args, scenes: SceneSet, render_cx: RenderContext, - #[cfg(target_arch = "wasm32")] render_state: RenderState, + #[cfg(target_arch = "wasm32")] render_state: RenderState<'_>, ) { - use winit::keyboard::*; + use winit::keyboard::ModifiersState; #[allow(unused_mut)] let mut renderers: Vec> = vec![]; #[cfg(not(target_arch = "wasm32"))] - let render_state = None::; + let render_state = None::>; // The design of `RenderContext` forces delayed renderer initialisation to // not work on wasm, as WASM futures effectively must be 'static. @@ -807,6 +819,7 @@ fn display_error_message() -> Option<()> { Some(()) } +/// Entry point. #[cfg(not(target_os = "android"))] pub fn main() -> anyhow::Result<()> { // TODO: initializing both env_logger and console_logger fails on wasm. @@ -846,7 +859,7 @@ pub fn main() -> anyhow::Result<()> { .and_then(|body| body.append_child(canvas.as_ref()).ok()) .expect("couldn't append canvas to document body"); // Best effort to start with the canvas focused, taking input - _ = web_sys::HtmlElement::from(canvas).focus(); + drop(web_sys::HtmlElement::from(canvas).focus()); wasm_bindgen_futures::spawn_local(async move { let (width, height, scale_factor) = web_sys::window() .map(|w| { @@ -952,5 +965,6 @@ fn android_main(app: AndroidApp) { // aligns to the same version that vello's peniko dependency resolves to. fn test_kurbo_schemars_with_peniko() { use std::marker::PhantomData; + #[expect(unused_qualifications)] let _: PhantomData = PhantomData::; } diff --git a/examples/with_winit/src/main.rs b/examples/with_winit/src/main.rs index 32a48feac..9a3642573 100644 --- a/examples/with_winit/src/main.rs +++ b/examples/with_winit/src/main.rs @@ -1,6 +1,8 @@ // Copyright 2022 the Vello Authors // SPDX-License-Identifier: Apache-2.0 OR MIT +//! Winit example. + use anyhow::Result; fn main() -> Result<()> { diff --git a/examples/with_winit/src/stats.rs b/examples/with_winit/src/stats.rs index b67ad7910..bd4b12ec8 100644 --- a/examples/with_winit/src/stats.rs +++ b/examples/with_winit/src/stats.rs @@ -3,6 +3,8 @@ use scenes::SimpleText; use std::collections::VecDeque; +#[cfg(feature = "wgpu-profiler")] +use vello::kurbo::Line; use vello::kurbo::{Affine, PathEl, Rect, Stroke}; use vello::peniko::{Brush, Color, Fill}; use vello::{low_level::BumpAllocators, AaConfig, Scene}; @@ -195,8 +197,8 @@ pub struct Stats { } impl Stats { - pub fn new() -> Stats { - Stats { + pub fn new() -> Self { + Self { count: 0, sum: 0, min: u64::MAX, @@ -452,7 +454,7 @@ pub fn draw_gpu_profiling( offset, &Brush::Solid(color), None, - &vello::kurbo::Line::new( + &Line::new( (x + depth_size, (end_normalised + start_normalised) / 2.), (width * 0.31, cur_text_y - text_size as f64 * 0.35), ), diff --git a/vello/Cargo.toml b/vello/Cargo.toml index 3bcba6b06..4b5936412 100644 --- a/vello/Cargo.toml +++ b/vello/Cargo.toml @@ -25,7 +25,7 @@ bump_estimate = ["vello_encoding/bump_estimate"] # Adds labels to buffers created by Vello. # May improve debugability at the cost of slightly higher memory usage (TODO: We should just not make these optional). buffer_labels = [] -wgpu = ["dep:wgpu"] +wgpu = ["dep:wgpu", "dep:vello_shaders", "dep:futures-intrusive"] # Development only features @@ -46,15 +46,14 @@ workspace = true [dependencies] vello_encoding = { workspace = true } -vello_shaders = { workspace = true } +vello_shaders = { workspace = true, optional = true } bytemuck = { workspace = true } skrifa = { workspace = true } peniko = { workspace = true } wgpu = { workspace = true, optional = true } log = { workspace = true } -raw-window-handle = { workspace = true } static_assertions = { workspace = true } -futures-intrusive = { workspace = true } +futures-intrusive = { workspace = true, optional = true } wgpu-profiler = { workspace = true, optional = true } thiserror = { workspace = true } # TODO: Add feature for built-in bitmap emoji support? diff --git a/vello/src/debug/renderer.rs b/vello/src/debug/renderer.rs index 3be8f4d10..139de1821 100644 --- a/vello/src/debug/renderer.rs +++ b/vello/src/debug/renderer.rs @@ -1,6 +1,10 @@ // Copyright 2023 the Vello Authors // SPDX-License-Identifier: Apache-2.0 OR MIT +// size_of is not part of the prelude until Rust 1.80 and our MSRV is below that +#[allow(unused_imports)] +use core::mem::size_of; + use super::DebugLayers; use crate::{ debug::validate::{validate_line_soup, LineEndpoint}, @@ -72,7 +76,7 @@ impl DebugRenderer { }, // This mirrors the layout of the PathBbox structure. Some(wgpu::VertexBufferLayout { - array_stride: std::mem::size_of::() as u64, + array_stride: size_of::() as u64, step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { @@ -103,7 +107,7 @@ impl DebugRenderer { }, // This mirrors the layout of the LineSoup structure. Some(wgpu::VertexBufferLayout { - array_stride: std::mem::size_of::() as u64, + array_stride: size_of::() as u64, step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { @@ -144,7 +148,7 @@ impl DebugRenderer { // render all points. All unpaired points alone get drawn by the `unpaired_points` // pipeline, so no point should get missed. Some(wgpu::VertexBufferLayout { - array_stride: std::mem::size_of::() as u64, + array_stride: size_of::() as u64, step_mode: wgpu::VertexStepMode::Instance, attributes: &[wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x2, @@ -181,7 +185,7 @@ impl DebugRenderer { }, // This mirrors the layout of the LineSoup structure. Some(wgpu::VertexBufferLayout { - array_stride: std::mem::size_of::() as u64, + array_stride: size_of::() as u64, step_mode: wgpu::VertexStepMode::Instance, attributes: &[wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x2, @@ -301,7 +305,7 @@ impl DebugRenderer { ResourceProxy::BufferRange { proxy: linepoints_uniforms_buf, offset: 0, - size: std::mem::size_of::() as u64, + size: size_of::() as u64, }, ], target, @@ -318,8 +322,8 @@ impl DebugRenderer { uniforms_buf, ResourceProxy::BufferRange { proxy: linepoints_uniforms_buf, - offset: std::mem::size_of::() as u64, - size: std::mem::size_of::() as u64, + offset: size_of::() as u64, + size: size_of::() as u64, }, ], target, diff --git a/vello/src/lib.rs b/vello/src/lib.rs index 923e24797..1e7760ce3 100644 --- a/vello/src/lib.rs +++ b/vello/src/lib.rs @@ -81,7 +81,41 @@ //! //! See the [`examples/`](https://github.com/linebender/vello/tree/main/examples) folder to see how that code integrates with frameworks like winit. +// LINEBENDER LINT SET - lib.rs - v1 +// See https://linebender.org/wiki/canonical-lints/ +// These lints aren't included in Cargo.toml because they +// shouldn't apply to examples and tests +#![warn(unused_crate_dependencies)] +#![warn(clippy::print_stdout, clippy::print_stderr)] +// END LINEBENDER LINT SET #![cfg_attr(docsrs, feature(doc_auto_cfg))] +// The following lints are part of the Linebender standard set, +// but resolving them has been deferred for now. +// Feel free to send a PR that solves one or more of these. +#![allow( + missing_debug_implementations, + elided_lifetimes_in_paths, + single_use_lifetimes, + unnameable_types, + unreachable_pub, + missing_docs, + clippy::return_self_not_must_use, + clippy::cast_possible_truncation, + clippy::missing_assert_message, + clippy::shadow_unrelated, + clippy::missing_panics_doc, + clippy::missing_errors_doc, + clippy::exhaustive_enums, + clippy::todo, + clippy::print_stderr, + clippy::partial_pub_fields, + clippy::use_self, + clippy::match_same_arms +)] + +// size_of is not part of the prelude until Rust 1.80 and our MSRV is below that +#[allow(unused_imports)] +use core::mem::size_of; mod debug; mod recording; @@ -121,7 +155,12 @@ pub use wgpu; pub use scene::{DrawGlyphs, Scene}; pub use vello_encoding::Glyph; -use low_level::*; +use low_level::ShaderId; +#[cfg(feature = "wgpu")] +use low_level::{ + BindType, BumpAllocators, FullShaders, ImageFormat, ImageProxy, Recording, Render, + ResourceProxy, +}; use thiserror::Error; #[cfg(feature = "wgpu")] @@ -815,13 +854,13 @@ struct TargetTexture { view: TextureView, width: u32, height: u32, - format: wgpu::TextureFormat, + format: TextureFormat, } #[cfg(feature = "wgpu")] impl TargetTexture { fn new(device: &Device, width: u32, height: u32) -> Self { - let format = wgpu::TextureFormat::Rgba8Unorm; + let format = TextureFormat::Rgba8Unorm; let texture = device.create_texture(&wgpu::TextureDescriptor { label: None, size: wgpu::Extent3d { @@ -925,7 +964,7 @@ impl<'a> DebugDownloads<'a> { return Err(Error::DownloadError("linesoup")); }; - let lines = lines_buf.slice(..bump.lines as u64 * std::mem::size_of::() as u64); + let lines = lines_buf.slice(..bump.lines as u64 * size_of::() as u64); let (sender, receiver) = futures_intrusive::channel::shared::oneshot_channel(); lines.map_async(wgpu::MapMode::Read, move |v| sender.send(v).unwrap()); receiver.receive().await.expect("channel was closed")?; diff --git a/vello/src/render.rs b/vello/src/render.rs index cd26c369b..fd31574dd 100644 --- a/vello/src/render.rs +++ b/vello/src/render.rs @@ -3,7 +3,9 @@ //! Take an encoded scene and create a graph to render it -use std::mem::size_of; +// size_of is not part of the prelude until Rust 1.80 and our MSRV is below that +#[allow(unused_imports)] +use core::mem::size_of; use crate::recording::{BufferProxy, ImageFormat, ImageProxy, Recording, ResourceProxy}; use crate::shaders::FullShaders; diff --git a/vello/src/scene.rs b/vello/src/scene.rs index 83c5fc3eb..51c32f095 100644 --- a/vello/src/scene.rs +++ b/vello/src/scene.rs @@ -524,7 +524,7 @@ impl<'a> DrawGlyphs<'a> { }); self.run.glyphs.start = self.run.glyphs.end; self.run.stream_offsets = self.scene.encoding.stream_offsets(); - outline_count += self.draw_outline_glyphs(clone_style_ref(&style), outline_glyphs); + outline_count += self.draw_outline_glyphs(style, outline_glyphs); let Some((emoji, glyph)) = final_glyph.take() else { // All of the remaining glyphs were outline glyphs @@ -781,8 +781,7 @@ impl ColorPainter for DrawColorGlyphs<'_> { }; let mut path = BezPathOutline(BezPath::new()); - let draw_settings = - DrawSettings::unhinted(skrifa::instance::Size::unscaled(), self.location); + let draw_settings = DrawSettings::unhinted(Size::unscaled(), self.location); let Ok(_) = outline.draw(draw_settings, &mut path) else { return; @@ -816,7 +815,7 @@ impl ColorPainter for DrawColorGlyphs<'_> { } fn fill(&mut self, brush: skrifa::color::Brush<'_>) { - let brush = conv_brush(brush, self.cpal, &self.foreground_brush); + let brush = conv_brush(brush, self.cpal, self.foreground_brush); self.scene.fill( Fill::NonZero, Affine::IDENTITY, @@ -864,8 +863,7 @@ impl ColorPainter for DrawColorGlyphs<'_> { }; let mut path = BezPathOutline(BezPath::new()); - let draw_settings = - DrawSettings::unhinted(skrifa::instance::Size::unscaled(), self.location); + let draw_settings = DrawSettings::unhinted(Size::unscaled(), self.location); let Ok(_) = outline.draw(draw_settings, &mut path) else { return; @@ -875,7 +873,7 @@ impl ColorPainter for DrawColorGlyphs<'_> { self.scene.fill( Fill::NonZero, transform.to_kurbo(), - &conv_brush(brush, self.cpal, &self.foreground_brush), + &conv_brush(brush, self.cpal, self.foreground_brush), brush_transform .map(conv_skrifa_transform) .map(|it| it.to_kurbo()), @@ -884,14 +882,6 @@ impl ColorPainter for DrawColorGlyphs<'_> { } } -// TODO: Move this into Peniko -fn clone_style_ref<'first>(first: &StyleRef<'first>) -> StyleRef<'first> { - match first { - StyleRef::Fill(fill) => StyleRef::Fill(*fill), - StyleRef::Stroke(stroke) => StyleRef::Stroke(stroke), - } -} - struct BezPathOutline(BezPath); impl OutlinePen for BezPathOutline { @@ -942,7 +932,7 @@ fn conv_skrifa_transform(transform: skrifa::color::Transform) -> Transform { fn conv_brush( brush: skrifa::color::Brush, cpal: &Cpal<'_>, - foreground_brush: &BrushRef<'_>, + foreground_brush: BrushRef<'_>, ) -> Brush { match brush { skrifa::color::Brush::Solid { @@ -1019,11 +1009,7 @@ fn conv_extend(extend: skrifa::color::Extend) -> Extend { } } -struct ColorStopsConverter<'a>( - &'a [skrifa::color::ColorStop], - &'a Cpal<'a>, - &'a BrushRef<'a>, -); +struct ColorStopsConverter<'a>(&'a [skrifa::color::ColorStop], &'a Cpal<'a>, BrushRef<'a>); impl ColorStopsSource for ColorStopsConverter<'_> { fn collect_stops(&self, vec: &mut ColorStops) { @@ -1034,7 +1020,7 @@ impl ColorStopsSource for ColorStopsConverter<'_> { // If we should use the "application defined fallback colour", // then *try* and determine that from the existing brush None => match self.2 { - BrushRef::Solid(c) => *c, + BrushRef::Solid(c) => c, // TODO: Report a warning? if either of these cases are reached // In theory, it's possible to have a gradient containing images and other gradients // but implementing that just for this case isn't worthwhile diff --git a/vello/src/shaders.rs b/vello/src/shaders.rs index f4694e8b2..835ae6b09 100644 --- a/vello/src/shaders.rs +++ b/vello/src/shaders.rs @@ -207,16 +207,16 @@ pub(crate) fn full_shaders( ] ); let fine_resources = [ - BindType::Uniform, - BindType::BufReadOnly, - BindType::BufReadOnly, - BindType::BufReadOnly, - BindType::Buffer, - BindType::Image(ImageFormat::Rgba8), - BindType::ImageRead(ImageFormat::Rgba8), - BindType::ImageRead(ImageFormat::Rgba8), + Uniform, + BufReadOnly, + BufReadOnly, + BufReadOnly, + Buffer, + Image(ImageFormat::Rgba8), + ImageRead(ImageFormat::Rgba8), + ImageRead(ImageFormat::Rgba8), // Mask LUT buffer, used only when MSAA is enabled. - BindType::BufReadOnly, + BufReadOnly, ]; let aa_support = &options.antialiasing_support; diff --git a/vello/src/util.rs b/vello/src/util.rs index 5a508dbbb..cbc1c5b83 100644 --- a/vello/src/util.rs +++ b/vello/src/util.rs @@ -76,7 +76,7 @@ impl RenderContext { .find(|it| matches!(it, TextureFormat::Rgba8Unorm | TextureFormat::Bgra8Unorm)) .ok_or(Error::UnsupportedSurfaceFormat)?; - let config = wgpu::SurfaceConfiguration { + let config = SurfaceConfiguration { usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format, width, diff --git a/vello/src/wgpu_engine.rs b/vello/src/wgpu_engine.rs index c3ad50bd1..1c8016ced 100644 --- a/vello/src/wgpu_engine.rs +++ b/vello/src/wgpu_engine.rs @@ -786,14 +786,14 @@ impl WgpuEngine { ty: if bind_type == BindType::ImageRead(format) { wgpu::BindingType::Texture { sample_type: wgpu::TextureSampleType::Float { filterable: true }, - view_dimension: wgpu::TextureViewDimension::D2, + view_dimension: TextureViewDimension::D2, multisampled: false, } } else { wgpu::BindingType::StorageTexture { access: wgpu::StorageTextureAccess::WriteOnly, format: format.to_wgpu(), - view_dimension: wgpu::TextureViewDimension::D2, + view_dimension: TextureViewDimension::D2, } }, count: None, diff --git a/vello_encoding/Cargo.toml b/vello_encoding/Cargo.toml index 5f3d66355..e22f4706c 100644 --- a/vello_encoding/Cargo.toml +++ b/vello_encoding/Cargo.toml @@ -2,6 +2,8 @@ name = "vello_encoding" version.workspace = true # We mimic Vello's version description = "Vello types that represent the data that needs to be rendered." +categories = ["rendering", "graphics"] +keywords = ["2d", "vector-graphics"] edition.workspace = true rust-version.workspace = true license.workspace = true @@ -18,7 +20,7 @@ default = ["full"] # Enables support for the full pipeline including late-bound # resources (gradients, images and glyph runs) -full = ["dep:skrifa", "dep:guillotiere"] +full = ["dep:skrifa", "dep:guillotiere", "dep:smallvec"] # Enables an optional GPU memory usage estimation utility. This can be used to # perform additional computations in order to estimate the minimum required allocations @@ -33,4 +35,4 @@ bytemuck = { workspace = true } skrifa = { workspace = true, optional = true } peniko = { workspace = true } guillotiere = { version = "0.6.2", optional = true } -smallvec = { workspace = true } +smallvec = { workspace = true, optional = true } diff --git a/vello_encoding/src/clip.rs b/vello_encoding/src/clip.rs index cb2ada050..52cd80671 100644 --- a/vello_encoding/src/clip.rs +++ b/vello_encoding/src/clip.rs @@ -22,6 +22,7 @@ pub struct ClipBic { /// Clip element. #[derive(Copy, Clone, Pod, Zeroable, Debug, Default)] #[repr(C)] +#[allow(clippy::partial_pub_fields)] pub struct ClipElement { pub parent_ix: u32, _padding: [u8; 12], @@ -35,7 +36,7 @@ pub struct ClipElement { #[derive(Copy, Clone, Pod, Zeroable, Debug, Default)] #[repr(C)] pub struct Clip { - // Index of the draw object. + /// Index of the draw object. pub ix: u32, /// This is a packed encoding of an enum with the sign bit as the tag. If positive, /// this entry is a `BeginClip` and contains the associated path index. If negative, @@ -52,7 +53,7 @@ pub struct ClipBbox { impl ClipBic { pub fn new(a: u32, b: u32) -> Self { - ClipBic { a, b } + Self { a, b } } /// The bicyclic semigroup operation. @@ -61,8 +62,8 @@ impl ClipBic { /// operation, it represents doing the pops of `self`, the pushes of /// `self`, the pops of `other`, and the pushes of `other`. The middle /// two can cancel each other out. - pub fn combine(self, other: ClipBic) -> Self { + pub fn combine(self, other: Self) -> Self { let m = self.b.min(other.a); - ClipBic::new(self.a + other.a - m, self.b + other.b - m) + Self::new(self.a + other.a - m, self.b + other.b - m) } } diff --git a/vello_encoding/src/config.rs b/vello_encoding/src/config.rs index 88da7fd46..3d0b2ba8b 100644 --- a/vello_encoding/src/config.rs +++ b/vello_encoding/src/config.rs @@ -1,6 +1,10 @@ // Copyright 2023 the Vello Authors // SPDX-License-Identifier: Apache-2.0 OR MIT +// size_of is not part of the prelude until Rust 1.80 and our MSRV is below that +#[allow(unused_imports)] +use core::mem::size_of; + use crate::SegmentCount; use super::{ @@ -8,7 +12,6 @@ use super::{ PathBbox, PathMonoid, PathSegment, Tile, }; use bytemuck::{Pod, Zeroable}; -use std::mem; const TILE_WIDTH: u32 = 16; const TILE_HEIGHT: u32 = 16; @@ -297,7 +300,7 @@ impl BufferSize { /// Creates a new buffer size from size in bytes. pub const fn from_size_in_bytes(size: u32) -> Self { - Self::new(size / mem::size_of::() as u32) + Self::new(size / size_of::() as u32) } /// Returns the number of elements. @@ -308,7 +311,7 @@ impl BufferSize { /// Returns the size in bytes. pub const fn size_in_bytes(self) -> u32 { - mem::size_of::() as u32 * self.len + size_of::() as u32 * self.len } /// Returns the size in bytes aligned up to the given value. diff --git a/vello_encoding/src/estimate.rs b/vello_encoding/src/estimate.rs index 62b943013..8cae121b3 100644 --- a/vello_encoding/src/estimate.rs +++ b/vello_encoding/src/estimate.rs @@ -272,7 +272,7 @@ impl LineSoup { (self.curves as f64 * scale.sqrt()).ceil() as u32 } - fn add(&mut self, other: &LineSoup, scale: f64) { + fn add(&mut self, other: &Self, scale: f64) { self.linetos += other.linetos; self.curves += other.scaled_curve_line_count(scale); self.curve_count += other.curve_count; @@ -363,7 +363,7 @@ fn count_segments_for_line_length(scaled_width: f64) -> u32 { /// over the continuous change in the number of flattened segments, with an error expressed in terms /// of curvature and infinitesimal arclength). mod wang { - use super::*; + use super::{transform, Transform, Vec2}; // The curve degree term sqrt(n * (n - 1) / 8) specialized for cubics: // @@ -377,19 +377,26 @@ mod wang { // const SQRT_OF_DEGREE_TERM_QUAD: f64 = 0.5; - pub fn quadratic(rsqrt_of_tol: f64, p0: Vec2, p1: Vec2, p2: Vec2, t: &Transform) -> f64 { + pub(crate) fn quadratic(rsqrt_of_tol: f64, p0: Vec2, p1: Vec2, p2: Vec2, t: &Transform) -> f64 { let v = -2. * p1 + p0 + p2; let v = transform(t, v); // transform is distributive let m = v.length(); - (SQRT_OF_DEGREE_TERM_QUAD * m.sqrt() * rsqrt_of_tol).ceil() as f64 + (SQRT_OF_DEGREE_TERM_QUAD * m.sqrt() * rsqrt_of_tol).ceil() } - pub fn cubic(rsqrt_of_tol: f64, p0: Vec2, p1: Vec2, p2: Vec2, p3: Vec2, t: &Transform) -> f64 { + pub(crate) fn cubic( + rsqrt_of_tol: f64, + p0: Vec2, + p1: Vec2, + p2: Vec2, + p3: Vec2, + t: &Transform, + ) -> f64 { let v1 = -2. * p1 + p0 + p2; let v2 = -2. * p2 + p1 + p3; let v1 = transform(t, v1); let v2 = transform(t, v2); - let m = v1.length().max(v2.length()) as f64; - (SQRT_OF_DEGREE_TERM_CUBIC * m.sqrt() * rsqrt_of_tol).ceil() as f64 + let m = v1.length().max(v2.length()); + (SQRT_OF_DEGREE_TERM_CUBIC * m.sqrt() * rsqrt_of_tol).ceil() } } diff --git a/vello_encoding/src/glyph_cache.rs b/vello_encoding/src/glyph_cache.rs index 31f290bd9..87ba8d9e0 100644 --- a/vello_encoding/src/glyph_cache.rs +++ b/vello_encoding/src/glyph_cache.rs @@ -23,7 +23,7 @@ pub(crate) struct GlyphCache { } impl GlyphCache { - pub fn session<'a>( + pub(crate) fn session<'a>( &'a mut self, font: &'a Font, coords: &'a [NormalizedCoord], @@ -85,7 +85,7 @@ impl GlyphCache { }) } - pub fn maintain(&mut self) { + pub(crate) fn maintain(&mut self) { // Maximum number of resolve phases where we'll retain an unused glyph const MAX_ENTRY_AGE: u64 = 64; // Maximum number of resolve phases before we force a prune @@ -149,7 +149,10 @@ pub(crate) struct GlyphCacheSession<'a> { } impl<'a> GlyphCacheSession<'a> { - pub fn get_or_insert(&mut self, glyph_id: u32) -> Option<(Arc, StreamOffsets)> { + pub(crate) fn get_or_insert( + &mut self, + glyph_id: u32, + ) -> Option<(Arc, StreamOffsets)> { let key = GlyphKey { font_id: self.font_id, font_index: self.font_index, @@ -270,7 +273,7 @@ struct HintCache { } impl HintCache { - fn get(&mut self, key: &HintKey) -> Option<&HintingInstance> { + fn get(&mut self, key: &HintKey<'_>) -> Option<&HintingInstance> { let entries = match key.outlines.format()? { OutlineGlyphFormat::Glyf => &mut self.glyf_entries, OutlineGlyphFormat::Cff | OutlineGlyphFormat::Cff2 => &mut self.cff_entries, @@ -298,7 +301,7 @@ struct HintEntry { serial: u64, } -fn find_hint_entry(entries: &mut Vec, key: &HintKey) -> Option<(usize, bool)> { +fn find_hint_entry(entries: &mut Vec, key: &HintKey<'_>) -> Option<(usize, bool)> { let mut found_serial = u64::MAX; let mut found_index = 0; for (ix, entry) in entries.iter().enumerate() { diff --git a/vello_encoding/src/image_cache.rs b/vello_encoding/src/image_cache.rs index a30989f53..2d8709ef1 100644 --- a/vello_encoding/src/image_cache.rs +++ b/vello_encoding/src/image_cache.rs @@ -31,7 +31,7 @@ impl Default for ImageCache { } impl ImageCache { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self { atlas: AtlasAllocator::new(size2(DEFAULT_ATLAS_SIZE, DEFAULT_ATLAS_SIZE)), map: Default::default(), @@ -39,7 +39,7 @@ impl ImageCache { } } - pub fn images(&self) -> Images { + pub(crate) fn images(&self) -> Images<'_> { Images { width: self.atlas.size().width as u32, height: self.atlas.size().height as u32, @@ -47,7 +47,7 @@ impl ImageCache { } } - pub fn bump_size(&mut self) -> bool { + pub(crate) fn bump_size(&mut self) -> bool { let new_size = self.atlas.size().width * 2; if new_size > MAX_ATLAS_SIZE { return false; @@ -58,13 +58,13 @@ impl ImageCache { true } - pub fn clear(&mut self) { + pub(crate) fn clear(&mut self) { self.atlas.clear(); self.map.clear(); self.images.clear(); } - pub fn get_or_insert(&mut self, image: &Image) -> Option<(u32, u32)> { + pub(crate) fn get_or_insert(&mut self, image: &Image) -> Option<(u32, u32)> { match self.map.entry(image.data.id()) { Entry::Occupied(occupied) => Some(*occupied.get()), Entry::Vacant(vacant) => { diff --git a/vello_encoding/src/lib.rs b/vello_encoding/src/lib.rs index 45888de35..cc792422e 100644 --- a/vello_encoding/src/lib.rs +++ b/vello_encoding/src/lib.rs @@ -3,7 +3,32 @@ //! Raw scene encoding. +// LINEBENDER LINT SET - lib.rs - v1 +// See https://linebender.org/wiki/canonical-lints/ +// These lints aren't included in Cargo.toml because they +// shouldn't apply to examples and tests +#![warn(unused_crate_dependencies)] +#![warn(clippy::print_stdout, clippy::print_stderr)] +// END LINEBENDER LINT SET #![cfg_attr(docsrs, feature(doc_auto_cfg))] +// The following lints are part of the Linebender standard set, +// but resolving them has been deferred for now. +// Feel free to send a PR that solves one or more of these. +#![allow( + missing_debug_implementations, + elided_lifetimes_in_paths, + single_use_lifetimes, + unnameable_types, + missing_docs, + variant_size_differences, + clippy::return_self_not_must_use, + clippy::unseparated_literal_suffix, + clippy::cast_possible_truncation, + clippy::missing_assert_message, + clippy::shadow_unrelated, + clippy::missing_panics_doc, + clippy::exhaustive_enums +)] mod binning; mod clip; diff --git a/vello_encoding/src/path.rs b/vello_encoding/src/path.rs index 783ed8b44..8d9423ac8 100644 --- a/vello_encoding/src/path.rs +++ b/vello_encoding/src/path.rs @@ -1,6 +1,10 @@ // Copyright 2022 the Vello Authors // SPDX-License-Identifier: Apache-2.0 OR MIT +// size_of is not part of the prelude until Rust 1.80 and our MSRV is below that +#[allow(unused_imports)] +use core::mem::size_of; + use bytemuck::{Pod, Zeroable}; use peniko::kurbo::{Cap, Join, Shape, Stroke}; use peniko::Fill; @@ -103,7 +107,7 @@ impl Style { } #[cfg(test)] - fn fill(&self) -> Option { + fn fill(self) -> Option { if self.is_fill() { Some( if (self.flags_and_miter_limit & Self::FLAGS_FILL_BIT) == 0 { @@ -118,7 +122,7 @@ impl Style { } #[cfg(test)] - fn stroke_width(&self) -> Option { + fn stroke_width(self) -> Option { if self.is_fill() { return None; } @@ -126,7 +130,7 @@ impl Style { } #[cfg(test)] - fn stroke_join(&self) -> Option { + fn stroke_join(self) -> Option { if self.is_fill() { return None; } @@ -140,7 +144,7 @@ impl Style { } #[cfg(test)] - fn stroke_start_cap(&self) -> Option { + fn stroke_start_cap(self) -> Option { if self.is_fill() { return None; } @@ -154,7 +158,7 @@ impl Style { } #[cfg(test)] - fn stroke_end_cap(&self) -> Option { + fn stroke_end_cap(self) -> Option { if self.is_fill() { return None; } @@ -168,7 +172,7 @@ impl Style { } #[cfg(test)] - fn stroke_miter_limit(&self) -> Option { + fn stroke_miter_limit(self) -> Option { if self.is_fill() { return None; } @@ -176,7 +180,7 @@ impl Style { } #[cfg(test)] - fn is_fill(&self) -> bool { + fn is_fill(self) -> bool { (self.flags_and_miter_limit & Self::FLAGS_STYLE_BIT) == 0 } } @@ -339,7 +343,7 @@ impl Monoid for PathMonoid { a += a >> 16; c.pathseg_offset = a & 0xff; c.path_ix = (tag_word & (PathTag::PATH.0 as u32 * 0x1010101)).count_ones(); - let style_size = (std::mem::size_of::