diff --git a/render-wasm/src/render.rs b/render-wasm/src/render.rs index b840563f4f..cfc3ed1a0f 100644 --- a/render-wasm/src/render.rs +++ b/render-wasm/src/render.rs @@ -986,7 +986,12 @@ impl RenderState { } pub fn set_background_color(&mut self, color: skia::Color) { + if self.background_color == color { + return; + } self.background_color = color; + // Tiles bake the background in; old atlas pixels would show on pan/zoom. + self.surfaces.atlas.clear(); } pub fn set_preview_mode(&mut self, enabled: bool) { diff --git a/render-wasm/src/render/surfaces.rs b/render-wasm/src/render/surfaces.rs index 761b2d02d6..9d07a6362e 100644 --- a/render-wasm/src/render/surfaces.rs +++ b/render-wasm/src/render/surfaces.rs @@ -185,6 +185,12 @@ impl DocAtlas { self.size.width <= 0 || self.size.height <= 0 } + /// Drops all atlas content while keeping its allocation and placement. + pub fn clear(&mut self) { + self.surface.canvas().clear(skia::Color::TRANSPARENT); + self.tile_doc_rects.clear(); + } + /// Sets the document-space bounds used to clamp atlas updates. /// Pass `None` to disable clamping. pub fn set_doc_bounds(&mut self, bounds: Option) {