diff --git a/Cargo.lock b/Cargo.lock index 332ed67bd..255acc1e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4921,6 +4921,7 @@ dependencies = [ "winapi 0.3.9", "window", "windows", + "zeno", ] [[package]] @@ -5413,6 +5414,12 @@ dependencies = [ "syn", ] +[[package]] +name = "zeno" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea708573d4a67f939793b0d3f923d105bfdf06bbd6acb3f9cd02ce1bd905f6c8" + [[package]] name = "zstd" version = "0.6.1+zstd.1.4.9" diff --git a/wezterm-gui/Cargo.toml b/wezterm-gui/Cargo.toml index 01cf83aff..d3bde9a0d 100644 --- a/wezterm-gui/Cargo.toml +++ b/wezterm-gui/Cargo.toml @@ -71,6 +71,7 @@ wezterm-ssh = { path = "../wezterm-ssh" } wezterm-term = { path = "../term", features=["use_serde"] } wezterm-toast-notification = { path = "../wezterm-toast-notification" } window = { path = "../window" } +zeno = "0.2" [target."cfg(windows)".dependencies] shared_library = "0.1" diff --git a/wezterm-gui/src/glyphcache.rs b/wezterm-gui/src/glyphcache.rs index c64fc677a..12871fa0e 100644 --- a/wezterm-gui/src/glyphcache.rs +++ b/wezterm-gui/src/glyphcache.rs @@ -811,7 +811,6 @@ impl GlyphCache { self.metrics.cell_size.height as usize, ); let black = SrgbaPixel::rgba(0, 0, 0, 0); - let white = SrgbaPixel::rgba(0xff, 0xff, 0xff, 0xff); let cell_rect = Rect::new(Point::new(0, 0), self.metrics.cell_size); @@ -822,24 +821,25 @@ impl GlyphCache { buffer.clear_rect(cell_rect, black); // Fill a rectangular region described by the x and y ranges - // TODO: this could probably be a call to buffer.clear_rect? let fill_rect = |buffer: &mut Image, x: Range, y: Range| { - for y in y { - buffer.draw_line( - Point::new( - cell_rect.origin.x + x.start as isize, - cell_rect.origin.y + y as isize, - ), - Point::new( - // Note: draw_line uses inclusive coordinates, but our - // range is exclusive coordinates, so compensate here! - // We don't need to do this for `y` since we are already - // iterating over the correct set of `y` values in our loop. - cell_rect.origin.x + x.end.saturating_sub(1) as isize, - cell_rect.origin.y + y as isize, - ), - white, - ); + use zeno::{Command, Fill, Format, Mask, PathBuilder}; + let (width, height) = buffer.image_dimensions(); + let x = x.start as f32..x.end as f32; + let y = y.start as f32..y.end as f32; + let mut path: Vec = vec![]; + + path.add_rect([x.start, y.start], x.end - x.start, y.end - y.start); + let (alpha, _placement) = Mask::new(&path) + .format(Format::Alpha) + .size(width as u32, height as u32) + .style(Fill::NonZero) + .render(); + + for (alpha, dest) in alpha.into_iter().zip(buffer.pixels_mut()) { + let alpha = alpha as u32; + // If existing pixel was blank, we want to replace it. + // If alpha is blank then we don't want to replace existing non-blank. + *dest |= alpha << 24 | alpha << 16 | alpha << 8 | alpha; } };