Canvas: themes without a dot pattern draw no dots texture (#4542) (#5093)

* Canvas: themes without a dot pattern draw no dots texture (#4542)

Switching the dark theme to Pro filled the empty workspace with red and
black blocks on the reporter's machine. The blocks repeat every 22 px,
the tile of the canvas-surround dots texture, so it is that texture
showing wrong contents.

Pro and ten other themes set canvas_dot to their canvas colour: they
have no dot pattern, yet still uploaded a texture for it and tiled it
over the whole pasteboard. dots() now returns None for them, so nothing
is uploaded or drawn. Studio, Studio Light and Solarized Dark, whose
dots differ from the canvas, are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Contributors: credit Higgs32584 by GitHub profile name

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Michael HigginsandClaude Opus 5.5 authored and GitHub committed 2026-10-14 13:06:18 -04:00
1 parent 08d9c1d67d
commit 42c5cc64be
1 file changed
+29 -2
+29 -2
View File
@@ -2575,9 +2575,10 @@ pub fn fmt_zoom(pct: f32) -> String {
if (pct - pct.round()).abs() < 0.05 { format!("{}", pct.round() as i64) } else { format!("{pct:.1}") }
}
/// Repeating dot-grid texture for the canvas surround.
/// Repeating dot-grid texture for the canvas surround. A theme whose dots are its canvas colour
/// has no pattern to show, so it gets no texture at all rather than an invisible one (#4542).
fn dots(ctx: &egui::Context, t: &crate::theme::Tokens) -> Option<egui::TextureId> {
if t.bevel {
if t.bevel || t.canvas_dot == t.canvas {
return None;
}
let key = egui::Id::new(("canvas-dots", format!("{:?}", t.kind)));
@@ -6003,6 +6004,32 @@ mod tests {
assert_ne!(ensure_texture(&mut app, &ctx, 1, Some(1)).unwrap().0, a, "reopening a preserved ID creates a fresh texture");
}
#[test]
fn only_themes_with_a_dot_pattern_tile_the_canvas_surround() {
// #4542: switching to Pro filled the empty workspace with red blocks on one GPU. Pro's
// dots are its canvas colour, so the tiled texture had nothing to show in the first place.
use crate::theme::ThemeKind;
let tiles = |ctx: &egui::Context, kind: ThemeKind| {
crate::theme::apply(ctx, kind);
let mut output = ctx.run_ui(Default::default(), |ui| paint_dots(ui, ui.max_rect(), true));
output.textures_delta.clear();
output.shapes.iter().any(|s| matches!(s.shape, egui::Shape::Mesh(_)))
};
let uploaded = |ctx: &egui::Context| ctx.tex_manager().read().allocated().filter(|(_, meta)| meta.name == "canvas-dots").count();
for kind in ThemeKind::ALL {
let ctx = egui::Context::default();
let dotted = matches!(kind, ThemeKind::Studio | ThemeKind::StudioLight | ThemeKind::SolarizedDark);
assert_eq!(tiles(&ctx, kind), dotted, "{kind:?}");
assert_eq!(uploaded(&ctx), usize::from(dotted), "{kind:?}");
}
// The reported switch: a dotted theme, then Pro.
let ctx = egui::Context::default();
assert!(tiles(&ctx, ThemeKind::Studio));
assert!(!tiles(&ctx, ThemeKind::Pro));
assert!(!tiles(&ctx, ThemeKind::ProMedium));
assert_eq!(uploaded(&ctx), 1, "only Studio's dots were uploaded");
}
#[test]
fn closed_documents_release_cpu_canvas_textures() {
let mut app = app_on_two_displays();