diff --git a/crates/render/src/frame.rs b/crates/render/src/frame.rs index 90a35458cc..49e252d206 100644 --- a/crates/render/src/frame.rs +++ b/crates/render/src/frame.rs @@ -157,8 +157,9 @@ pub struct FrameStats { /// their object moved, or made over such rasters ([`RenderOptions::interacting`]), and those it /// drew at a drag's lower resolution ([`Self::previewed`]). pub moved: usize, - /// The filtered contents, shadows and glows the frame drew at a drag's lower resolution - /// ([`RenderOptions::dragging`]). [`Self::moved`] counts them too. + /// The filtered contents, shadows and glows the frame filtered at a drag's lower resolution + /// ([`RenderOptions::dragging`]). [`Self::moved`] counts them too, and counts alone a raster a + /// drag's earlier frame kept that this frame draws again. pub previewed: usize, /// What the frame drew in a way that depends on the frame's size: effect rasters and filter /// layers cropped to it or made at a lower resolution, blending groups drawn as layers past its diff --git a/crates/render/src/fx/pixels.rs b/crates/render/src/fx/pixels.rs index 673082bfb5..df6119fcd1 100644 --- a/crates/render/src/fx/pixels.rs +++ b/crates/render/src/fx/pixels.rs @@ -33,6 +33,33 @@ pub(crate) fn paint_names(doc: &Document) -> u64 { h.finish() } +/// Whether a raster of content filtered by `chain` can move with its object +/// ([`Renderer::move_pixel_content`]): not under De-Interlace, nor under a Rasterize first in the +/// chain. +fn movable(chain: &[&RasterFx]) -> bool { + !chain.iter().any(|fx| matches!(fx, RasterFx::Pixel(PixelFx::DeInterlace { .. }))) && !matches!(chain.first(), Some(RasterFx::Rasterize(_))) +} + +/// The device pixels a frame onto `screen` shows of content reaching `full`, against the device +/// position `at` of the content's anchor. Each side where `screen` cuts the content includes one +/// device pixel for placement rounding and, for raster scale `k` below 1, `ceil(1 / k)` more for +/// bilinear sampling, up to the content's edges. Uncut sides stay at the content's edges. +fn shown(full: Rect, screen: Rect, at: vectorcraft_geom::Point, k: f64) -> Rect { + let s = full.intersect(screen); + let margin = if k < 1.0 { 1.0 + (1.0 / k).ceil() } else { 1.0 }; + let cut = |c: bool| if c { margin } else { 0.0 }; + Rect::new(s.x0 - cut(screen.x0 > full.x0), s.y0 - cut(screen.y0 > full.y0), s.x1 + cut(screen.x1 < full.x1), s.y1 + cut(screen.y1 < full.y1)) + .intersect(full) + - at.to_vec2() +} + +/// Whether `outer` holds all of `inner`, to a millionth of a pixel: the edges of moved content, +/// against its anchor, can differ by rounding. +fn holds(outer: Rect, inner: Rect) -> bool { + let e = 1e-6; + outer.x0 <= inner.x0 + e && outer.y0 <= inner.y0 + e && outer.x1 + e >= inner.x1 && outer.y1 + e >= inner.y1 +} + impl Renderer { /// Paint `content` through the content-changing effects of `rfx` (Gaussian Blur, Feather, the /// Photoshop-style filters and Rasterize) in stack order on its pixels: rendered offscreen over @@ -51,7 +78,9 @@ impl Renderer { /// a drag and for content without a [`Kept`] image, the view with [`pan_margin`] around it. A /// lower-resolution one is kept resampled to the view's pixels ([`Self::resampled`]). /// While dragging, content without such a raster to draw renders within [`DRAG_PIXEL_BUDGET`] - /// pixels and is not cached. + /// pixels and is not cached, except content cropped to the view whose raster can move: its + /// raster covers the view with [`pan_margin`] around it, and the drag's later frames move it with + /// the object while what they show of it lies within ([`PixelEntry::valid`]). pub(super) fn pixel_content( &mut self, ctx: &mut RenderContext, @@ -101,11 +130,23 @@ impl Renderer { let key = content.cache.map(|slot| (content.node as *const Node as usize, slot, f.ink)); // Made again at this zoom and rotation (after a pan), a raster cropped to the view covers a // margin around the view too, so that later pans within the margin draw it. - let again = key.and_then(|key| self.pixel_fx.get(&key)).is_some_and(|e| e.linear == linear) + let again = key.and_then(|key| self.pixel_fx.get(&key)).is_some_and(|e| e.linear == linear && e.valid.is_none()) && content.kept.is_none_or(|k| k.shared) && !f.opts.dragging; - let room = match margin { - Some(m) if !fits && again => { + // A drag's raster of content cropped to the view covers a margin around the view too, of + // twice the view's area with the reach around it, and is kept: the drag's later frames move + // it with the object while what they show of it lies within. + let drag_margin = margin + .filter(|_| f.opts.dragging && f.opts.interacting && !fits && key.is_some() && content.kept.is_none() && movable(&chain)) + .map(|m| { + let (w, h) = (screen.width(), screen.height()); + pan_margin((w, h), m, 2.0 * (w + 2.0 * m) * (h + 2.0 * m), f64::from(crate::MAX_RASTER_SIDE)) + }) + .filter(|e| *e > 0.0); + let drag_keep = drag_margin.is_some(); + let room = match (margin, drag_margin) { + (_, Some(e)) => screen.inflate(e, e), + (Some(m), None) if !fits && again => { let e = pan_margin((screen.width(), screen.height()), m, PIXEL_BUDGET, f64::from(crate::MAX_RASTER_SIDE)); screen.inflate(e, e) } @@ -121,6 +162,17 @@ impl Renderer { let side = f64::from(crate::MAX_RASTER_SIDE); let k = (PIXEL_BUDGET / (rw * rh)).sqrt().min(side / rw).min(side / rh).min(1.0); let (w, h) = ((rw * k).ceil().clamp(1.0, side), (rh * k).ceil().clamp(1.0, side)); + // The scale of a drag's kept raster: 1 when the frame's region fits the drag's budget at full + // resolution, else the scale at which the view, its margin and the reach around them fit + // it, the same for each frame of the drag whatever part of the object the frame shows. + let keep_k = drag_keep.then(|| { + if rw * rh <= DRAG_PIXEL_BUDGET { + return 1.0; + } + let around = room.inflate(margin.unwrap_or(0.0), margin.unwrap_or(0.0)); + let (aw, ah) = (around.width().ceil() + 1.0, around.height().ceil() + 1.0); + (DRAG_PIXEL_BUDGET / (aw * ah)).sqrt().min(side / aw).min(side / ah).min(1.0) + }); // The cached raster: of the whole content at full size at this zoom, else of this view (and // the margin around it). let whole = fits && k >= 1.0; @@ -146,18 +198,27 @@ impl Renderer { let interacting = f.opts.interacting; let in_place = |e: &PixelEntry| match e.view { None => whole, - Some(v) => !whole && v.serves(f.view, screen), + Some(v) => !whole && (e.valid.is_some() || v.serves(f.view, screen)), }; + // A raster a drag kept draws during a drag, while what the frame shows of the content lies + // where its pixels are right ([`PixelEntry::valid`]). let exact = |e: &PixelEntry| { - e.linear == linear && in_place(e) && e.node.is(content.node) && Some(&e.inputs) == inputs.as_ref() && (interacting || !e.moved) + e.linear == linear + && in_place(e) + && e.valid.is_none_or(|v| f.opts.dragging && holds(v, shown(full, screen, f.view * e.anchor, e.k))) + && e.node.is(content.node) + && Some(&e.inputs) == inputs.as_ref() + && (interacting || !e.moved) }; + // During a drag, what the frame shows of the content, against the content's anchor. + let crop = keep_k.map(|d| (d, shown(full, screen, f.view * content.reach.origin(), d))); if interacting - && whole + && (whole || crop.is_some()) && let Some(key) = key && let Some(inputs) = &inputs && !self.pixel_fx.get(&key).is_some_and(exact) { - self.move_pixel_content(f, content, key, &chain, channels, inputs, paint); + self.move_pixel_content(f, content, key, &chain, channels, inputs, crop, paint); } if let Some(e) = key.and_then(|key| self.pixel_fx.get_mut(&key)).filter(|e| exact(e)) { e.stamp = stamp; @@ -171,15 +232,20 @@ impl Renderer { draw_scaled(ctx, image, at, k); return; } - // During a drag, content without a raster to draw renders within the drag's budget and keeps - // no raster (#2558). - let (k, w, h, key) = match drag_scale(f.opts.dragging, (rw, rh), k) { - Some(d) => { + // During a drag, content without a raster to draw renders within the drag's budget (#2558). + // Its raster is kept, marked moved, only when it is cropped to the view and can move. + let (k, w, h, key) = match (keep_k, drag_scale(f.opts.dragging, (rw, rh), k)) { + (Some(d), _) => { + self.stats.moved += 1; + self.stats.previewed += usize::from(d < 1.0); + (d, (rw * d).ceil().clamp(1.0, side), (rh * d).ceil().clamp(1.0, side), key) + } + (None, Some(d)) => { self.stats.moved += 1; self.stats.previewed += 1; (d, (rw * d).ceil().clamp(1.0, side), (rh * d).ceil().clamp(1.0, side), None) } - None => (k, w, h, key), + (None, None) => (k, w, h, key), }; let (wu, hu) = (w as u16, h as u16); let view = Affine::scale(k) * Affine::translate((-x0, -y0)) * f.view; @@ -237,12 +303,12 @@ impl Renderer { let failed = crate::paint::decode_failures() - decoded; let image_left_out = self.image_left_out.unwrap_or(false) || crate::pattern::images_left_out() > pattern_images_left_out; self.image_left_out = outer_image_left_out.map(|outer| outer || image_left_out); - // Content drawn over moved rasters makes a moved raster. - let moved = self.stats.moved > before; - // What the raster is made from, for its object once it moves (`move_pixel_content`): a - // cropped or coarser raster never moves. + // Content drawn over moved rasters makes a moved raster, as does a drag. + let moved = drag_keep || self.stats.moved > before; + // What the raster is made from, for its object once it moves (`move_pixel_content`): of + // the rasters cropped to the view or made coarser, only a drag's moves. let made = key.map(|_| Made { - pixels: if whole { pm.data_as_u8_slice().to_vec() } else { Vec::new() }, + pixels: if whole || drag_keep { pm.data_as_u8_slice().to_vec() } else { Vec::new() }, fx: chain.iter().map(|fx| (*fx).clone()).collect(), size: content.reach.size(), channels: Some(channels), @@ -297,7 +363,7 @@ impl Renderer { // A raster kept for this view alone at a lower resolution than the view's is resampled to the // view's pixels once: each frame that draws it then copies it pixel for pixel, where sampling // it again across the whole view cost several times as much as a plain fill. - let view_raster = key.is_some() && in_view.is_some() && k < 1.0 && content.kept.is_none_or(|k| k.shared); + let view_raster = key.is_some() && in_view.is_some() && k < 1.0 && content.kept.is_none_or(|k| k.shared) && !drag_keep; let (image, x0, y0, k) = match view_raster.then(|| self.resampled(f, image.clone(), (x0, y0), k, screen)).flatten() { Some((image, x, y)) => (image, x, y, 1.0), None => (image, x0, y0, k), @@ -311,8 +377,24 @@ impl Renderer { let rel = (x0 - p.x, y0 - p.y); let owner = content.owner.cloned().or_else(|| self.fx_owner.clone().filter(|o| std::ptr::eq(&**o, content.node))); let node = Drawn::of(content.node, owner.as_ref()); - let entry = - PixelEntry { node, linear, anchor, rel, k, image: image.clone(), view: in_view, made, inputs, moved, failed, image_left_out, stamp }; + // The effects saw all they look at for the pixels of the view and its margin. + let valid = drag_keep.then(|| full.intersect(room) - p.to_vec2()); + let entry = PixelEntry { + node, + linear, + anchor, + rel, + k, + image: image.clone(), + view: in_view, + valid, + made, + inputs, + moved, + failed, + image_left_out, + stamp, + }; self.pixel_fx.insert(key, entry); self.trim_fx_rasters(FX_RASTER_BUDGET); } @@ -362,7 +444,13 @@ impl Renderer { /// (and the same Feather outline against its anchor), and whose pixels are the pixels of /// `content` drawn into a raster placed as that one was against its anchor. The raster is kept /// as `content`'s, marked moved, and is drawn at the nearest whole pixel. Content under - /// De-Interlace, or under a Rasterize first in the chain, takes none. + /// De-Interlace, or under a Rasterize first in the chain, takes none ([`movable`]). + /// + /// With `crop` (a drag's frame of content cropped to the view: the scale its raster is made at, + /// and the device pixels the frame shows of the content against its anchor), the raster is + /// instead one a drag's earlier frame kept at that scale or at full resolution + /// ([`PixelEntry::valid`]), whose pixels the effects decided with all they look at over the + /// part the frame shows. #[allow(clippy::too_many_arguments)] fn move_pixel_content( &mut self, @@ -372,10 +460,10 @@ impl Renderer { chain: &[&RasterFx], channels: Channels, inputs: &Inputs, + crop: Option<(f64, Rect)>, paint: &mut dyn FnMut(&mut Self, &mut RenderContext, &Frame), ) { - if chain.iter().any(|fx| matches!(fx, RasterFx::Pixel(PixelFx::DeInterlace { .. }))) || matches!(chain.first(), Some(RasterFx::Rasterize(_))) - { + if !movable(chain) { return; } let (linear, stamp, anchor) = (linear_key(f.view), self.stamp, content.reach.origin()); @@ -384,23 +472,29 @@ impl Renderer { (k.1, k.2) == (key.1, key.2) && e.stamp < stamp && e.linear == linear - && e.k >= 1.0 - && e.view.is_none() + && match crop { + None => e.k >= 1.0 && e.view.is_none(), + Some((scale, need)) => { + (e.k.to_bits() == scale.to_bits() || e.k == 1.0) && e.view.is_some() && e.valid.is_some_and(|v| holds(v, need)) + } + } && e.node.id() == content.node.id && e.inputs == *inputs && e.made.fits(chain, content.reach.size(), Some(channels), outline.as_ref()) }; - let Some((old, rel, w, h)) = self.pixel_fx.iter().find(|(k, e)| fits(k, e)).map(|(k, e)| (*k, e.rel, e.image.width(), e.image.height())) + let Some((old, rel, k, w, h)) = + self.pixel_fx.iter().find(|(k, e)| fits(k, e)).map(|(k, e)| (*k, e.rel, e.k, e.image.width(), e.image.height())) else { return; }; // The content drawn where the old content lies in its raster. let p = f.view * anchor; - let view = Affine::translate((-(p.x + rel.0), -(p.y + rel.1))) * f.view; + let view = Affine::scale(k) * Affine::translate((-(p.x + rel.0), -(p.y + rel.1))) * f.view; let visible = view.inverse().transform_rect_bbox(Rect::new(0.0, 0.0, f64::from(w), f64::from(h))); - let frame = Frame { mt: false, view, visible, ..*f }; + let px = f.px / k; + let frame = Frame { mt: false, view, visible, px, ..*f }; let mut off = f.offscreen_context(w, h); - if hard_edged(chain, f.px) { + if hard_edged(chain, px) { off.set_aliasing_threshold(crate::AntiAlias::None.threshold()); } self.inside_layer(|r| paint(r, &mut off, &frame)); diff --git a/crates/render/src/fx/raster.rs b/crates/render/src/fx/raster.rs index efbab00da4..02bf918089 100644 --- a/crates/render/src/fx/raster.rs +++ b/crates/render/src/fx/raster.rs @@ -95,6 +95,11 @@ pub(crate) struct PixelEntry { /// made for: it draws only there, so dragging other art over the object keeps it (a wide blur, /// or any blur zoomed in, reaches past the pixel budget). pub(super) view: Option, + /// For a raster a drag's frame kept of content cropped to the view, the device pixels (against + /// the anchor's view position) whose pixels the effects decided with all they look at: the + /// drag's later frames move the raster with its object while what they show of it lies within + /// ([`Renderer::move_pixel_content`]). `None` for other rasters. + pub(super) valid: Option, pub(super) made: Made, /// What the content read when the raster was made, with the channels the effects ran on and, /// under De-Interlace, the raster resolution. diff --git a/crates/render/src/fx/tests.rs b/crates/render/src/fx/tests.rs index f843ce01f7..1c58a7da96 100644 --- a/crates/render/src/fx/tests.rs +++ b/crates/render/src/fx/tests.rs @@ -1718,7 +1718,7 @@ fn a_drag_renders_raster_effects_within_the_drag_budget() { let dragged = r.render(&d, 1600, 1000, view, &drag).pixels; assert_eq!(r.stats.previewed, 2, "the shadow and the filtered content"); assert_eq!(r.stats.moved, 2, "counted as moved: the frame after the drag renders them again"); - assert!(r.pixel_fx.is_empty() && r.shadows.values().all(|e| e.stamp < r.stamp), "no raster kept"); + assert!(r.pixel_fx.values().all(|e| e.moved) && r.shadows.values().all(|e| e.stamp < r.stamp), "only rasters marked moved kept"); assert!(dragged != fresh, "at the drag's lower resolution"); let after = r.render(&d, 1600, 1000, view, &still).pixels; assert_eq!((r.stats.previewed, r.stats.moved), (0, 0)); @@ -1742,6 +1742,112 @@ fn a_drag_renders_raster_effects_within_the_drag_budget() { assert!(after == threaded().render(&scaled, 1600, 1000, view, &still).pixels, "the frame after the drag"); } +/// At 6400% a Texturized 200 × 150 pt rectangle covers 12800 × 9600 px, past the pixel budget, +/// so its raster is cropped to the view. A drag filters it once, and the drag's later frames +/// move that raster with the object until the object leaves the raster's slack, also when the +/// view shows an edge of the object, and until a pan shows what the raster does not cover. +#[test] +fn a_zoomed_drag_moves_the_cropped_raster_with_its_object() { + let base = doc_with(Rect::new(100.0, 100.0, 300.0, 250.0), Color::rgb(0.9, 0.4, 0.1), vec![("texture.texturizer", json!({}))]); + let id = base.layers[0].children().unwrap()[0].id; + let still = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() }; + let drag = RenderOptions { interacting: true, dragging: true, ..still.clone() }; + // The rectangle moved by (`dx`, `dy`) device pixels. + let moved = |dx: f64, dy: f64| { + let mut d = base.clone(); + d.node_mut(id).unwrap().transform(Affine::translate((dx / 64.0, dy / 64.0)), false); + d + }; + // A still frame, then eight drag frames: the filters each ran. + let drag_through = |r: &mut Renderer, view: Affine| { + let _ = r.render(&base, 1600, 1000, view, &still); + (1..=8).fold(0, |n, i| { + let _ = r.render(&moved(20.0 * f64::from(i), 13.0 * f64::from(i)), 1600, 1000, view, &drag); + n + r.stats.previewed + }) + }; + // Centered on (290, 175), the view shows the rectangle's right edge. + let edge = Affine::translate((800.0, 500.0)) * Affine::scale(64.0) * Affine::translate((-290.0, -175.0)); + assert_eq!(drag_through(&mut Renderer::new(), edge), 1, "with the object's edge in view"); + let view = Affine::translate((800.0, 500.0)) * Affine::scale(64.0) * Affine::translate((-200.0, -175.0)); + let mut panned = Renderer::new(); + assert_eq!(drag_through(&mut panned, view), 1, "the first drag frame filters the content, and the next seven move its raster"); + // The raster covers between 250 and 300 px around the view as it was when the drag began, and + // the rectangle moved 160 px to the right of where it was. + let held = moved(160.0, 104.0); + let _ = panned.render(&held, 1600, 1000, view, &drag); + assert_eq!(panned.stats.previewed, 0, "where the drag's last frame left it"); + for dx in [40.0, 10.5] { + let _ = panned.render(&held, 1600, 1000, Affine::translate((dx, 0.0)) * view, &drag); + assert_eq!(panned.stats.previewed, 0, "a pan within the raster's margin draws the kept raster ({dx} px)"); + } + let _ = panned.render(&held, 1600, 1000, Affine::translate((200.0, 0.0)) * view, &drag); + assert_eq!(panned.stats.previewed, 1, "a pan that shows what the moved raster does not cover filters the content again"); + let live = RenderOptions { dragging: false, ..drag.clone() }; + let pixels = panned.render(&held, 1600, 1000, view, &live).pixels; + assert!(pixels == Renderer::new().render(&held, 1600, 1000, view, &live).pixels, "an interaction without a drag"); + let mut r = Renderer::new(); + assert_eq!(drag_through(&mut r, view), 1); + let last = moved(1000.0, 0.0); + let _ = r.render(&last, 1600, 1000, view, &drag); + assert_eq!(r.stats.previewed, 1, "a move past the raster's slack filters the content again"); + let after = r.render(&last, 1600, 1000, view, &still).pixels; + let mut fresh = Renderer::new(); + assert!(after == fresh.render(&last, 1600, 1000, view, &still).pixels, "the frame after the drag"); + let kept = r.pixel_fx.values().find(|e| e.node.is(last.node(id).unwrap()) && e.valid.is_none()).unwrap(); + let fresh = fresh.pixel_fx.values().next().unwrap(); + assert_eq!( + (kept.image.width(), kept.image.height()), + (fresh.image.width(), fresh.image.height()), + "the first still frame keeps the same crop as a fresh renderer" + ); + + // Only a narrow strip at the rectangle's right edge lies in view, so its crop fits the drag budget. + let strip = Affine::translate((300.0, 500.0)) * Affine::scale(64.0) * Affine::translate((-300.0, -175.0)); + let mut r = Renderer::new(); + let _ = r.render(&moved(20.0, 13.0), 1600, 1000, strip, &drag); + assert_eq!(r.stats.previewed, 0, "the narrow crop keeps full resolution"); + assert_eq!(r.pixel_fx.values().filter(|e| e.valid.is_some()).count(), 1, "the drag keeps one cropped raster"); + assert!(r.pixel_fx.values().any(|e| e.valid.is_some() && e.k == 1.0), "the kept raster uses scale 1"); + let image = r.pixel_fx.values().find(|e| e.valid.is_some()).unwrap().image.clone(); + for i in 2..=4 { + let _ = r.render(&moved(20.0 * f64::from(i), 13.0 * f64::from(i)), 1600, 1000, strip, &drag); + assert_eq!(r.stats.previewed, 0, "a later frame within the slack keeps full resolution"); + assert_eq!(r.pixel_fx.values().filter(|e| e.valid.is_some()).count(), 1, "the drag keeps one cropped raster"); + let kept = r.pixel_fx.values().find(|e| e.valid.is_some()).unwrap(); + assert!(std::sync::Arc::ptr_eq(&image, &kept.image), "a later frame within the slack draws the kept raster"); + } + // The crop grows past the drag budget while the visible content stays within the 255 px slack. + let _ = r.render(&moved(120.0, 13.0), 1600, 1000, strip, &drag); + assert_eq!(r.stats.previewed, 0, "crossing the drag budget draws the full-resolution raster"); + let kept = r.pixel_fx.values().find(|e| e.valid.is_some()).unwrap(); + assert!(std::sync::Arc::ptr_eq(&image, &kept.image), "crossing the drag budget draws the kept raster"); +} + +#[test] +fn a_zoomed_drag_keeps_the_sampling_footprint_inside_the_valid_crop() { + let base = doc_with(Rect::new(100.0, 100.0, 300.0, 250.0), Color::rgb(0.9, 0.4, 0.1), vec![("texture.texturizer", json!({}))]); + let id = base.layers[0].children().unwrap()[0].id; + let drag = RenderOptions { interacting: true, dragging: true, background: Some([255, 255, 255, 255]), ..Default::default() }; + let view = Affine::translate((800.0, 500.0)) * Affine::scale(64.0) * Affine::translate((-200.0, -175.0)); + let mut r = Renderer::new(); + let _ = r.render(&base, 1600, 1000, view, &drag); + let kept = r.pixel_fx.values().find(|e| e.valid.is_some()).unwrap(); + assert!(kept.k < 1.0, "the drag raster uses a lower resolution"); + let valid = kept.valid.unwrap(); + let at = view * kept.anchor; + let footprint = 1.0 + (1.0 / kept.k).ceil(); + let gap = (1.0 + footprint) / 2.0; + let dx = -at.x - valid.x0 - gap; + let left = -(at.x + dx); + assert!(left - 1.0 > valid.x0, "the visible edge and placement rounding stay inside the valid crop"); + assert!(left - footprint < valid.x0, "the sampling footprint reaches past the valid crop"); + let mut moved = base.clone(); + moved.node_mut(id).unwrap().transform(Affine::translate((dx / 64.0, 0.0)), false); + let _ = r.render(&moved, 1600, 1000, view, &drag); + assert_eq!(r.stats.previewed, 1, "the sampling footprint outside the valid crop filters the content again"); +} + #[test] fn a_drag_glow_fallback_cannot_be_spliced_into_a_still_frame() { let doc = doc_with( diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index e7fec25534..1388bf9ef2 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -2086,8 +2086,9 @@ fn dragging_with_raster_effects() { } /// A tool's drag on the canvas renders with `dragging` (#2558). At 3200% a rectangle with -/// Texturizer covers more than the raster budget, so no raster is kept for it, and each frame -/// of a Selection tool drag draws its filtered content at the drag's lower resolution. The +/// Texturizer covers more than the raster budget, so its raster is cropped to the view: the first +/// frame of a Selection tool drag filters its content at the drag's lower resolution, and the +/// next moves that raster with the rectangle. The /// frame after the drag draws what a fresh renderer draws. A dialog's preview, an interaction /// without a drag, renders without `dragging` and draws the same. #[test] @@ -2139,7 +2140,9 @@ fn a_drag_at_a_lower_resolution(fits_frame: bool) { for step in [1.0, 2.0] { let drawn = run(&mut app, vec![egui::Event::PointerMoved(at + vec2(13.0, 7.0) * step)]).expect("each frame of the drag renders"); assert!(app.canvas.key.as_ref().is_some_and(|k| k.interacting && k.dragging), "step {step}"); - assert_eq!(app.canvas.renderer.stats.previewed, 1, "the filtered content, step {step}"); + // Cropped to the view, the first frame's raster moves with the rectangle on the second. + let filtered = usize::from(fits_frame || step == 1.0); + assert_eq!(app.canvas.renderer.stats.previewed, filtered, "the filtered content, step {step}"); if fits_frame { assert_eq!(app.canvas.renderer.stats.view_sized, 0, "only the drag budget reduced the raster"); assert!(app.canvas.whole_frames, "a whole drag preview cannot accept a full-resolution patch");