Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/ui-egui/src/panels/detail/masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ fn grip_gestures(
if Some(mask) != active {
let _ = app.run("mask.select", json!({"id": mask}));
}
let _ = app.run("develop.beginInteraction", json!({"label": "Edit Mask"}));
let _ = app.run("develop.beginInteraction", json!({"label": crate::region::SHARP_DRAG}));
// (read after it begins: an old mask is on the photo from then on, in its coordinates)
if let Some(original_shape) = current_shape(app, mask, comp)
.or_else(|| d.masks.iter().find(|m| m.id == mask).and_then(|m| m.components.get(comp)).map(|c| c.shape.clone()))
Expand Down Expand Up @@ -852,7 +852,7 @@ fn mask_keys(app: &mut LightcraftApp, ui: &mut egui::Ui, map: &CanvasMap, d: &De
if app.session.active_mask != Some(mid) {
let _ = app.run("mask.select", json!({"id": mid}));
}
let _ = app.run("develop.beginInteraction", json!({"label": "Edit Mask"}));
let _ = app.run("develop.beginInteraction", json!({"label": crate::region::SHARP_DRAG}));
// (read after it begins: an old mask is on the photo from then on, in its coordinates)
let (shape, map) = match (current_shape(app, mid, ci), current_on_photo(app, mid)) {
(Some(s), Some(on)) => (s, map.for_mask(on)),
Expand Down
11 changes: 9 additions & 2 deletions crates/ui-egui/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ pub struct LoupePlan {
/// it, or full-size drafts of this drag went over [`DRAFT_BUDGET_MS`]), against the render at rest.
pub const CPU_DRAFT_SCALE: f32 = 0.6;

/// The interaction label of a mask edit on the photo (moving, resizing or turning a gradient or
/// pin). Its drafts are always full size, on the CPU too, and never drop to [`CPU_DRAFT_SCALE`]:
/// the edit changes part of the photo, and a smaller draft blurred the whole photo for it (#1679).
/// A slow machine shows fewer drafts instead.
pub const SHARP_DRAG: &str = "Edit Mask";

/// The slider budget (ms): a drag whose full-size drafts take longer gets smaller drafts next time.
/// A draft's time is its render plus the frame that shows it (the texture upload is part of it).
pub const DRAFT_BUDGET_MS: f64 = 16.0;
Expand Down Expand Up @@ -185,7 +191,7 @@ impl DragScale {
}
let key = (photo, control.to_string());
let small = matches!(self.verdict(&key), Some(Verdict::Slow { until, .. }) if now < until);
let s = if gpu && !small { 1.0 } else { CPU_DRAFT_SCALE };
let s = if control == SHARP_DRAG || (gpu && !small) { 1.0 } else { CPU_DRAFT_SCALE };
self.current = Some((key, s));
self.seen = shown;
Some(s)
Expand All @@ -209,7 +215,8 @@ impl DragScale {
}
if self.samples.len() > GIVE_UP_AFTER
&& median_after_first(&self.samples).is_some_and(|m| m > DRAFT_BUDGET_MS * GIVE_UP_FACTOR)
&& let Some((_, s)) = self.current.as_mut()
&& let Some(((_, control), s)) = self.current.as_mut()
&& control != SHARP_DRAG

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3. Keep sharp drags out of quality-adaptation sampling. The exempt drag still copies and sorts samples for the median after the cutoff and then ignores the verdict. Finishing also records an entry in the shared history used by sliders. Bypass measurement and recording for the exempt drag. The existing regression can assert that it leaves no adaptation verdict while slider adaptation still works.

{
*s = CPU_DRAFT_SCALE;
return;
Expand Down
23 changes: 23 additions & 0 deletions crates/ui-egui/src/region/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,26 @@ fn a_window_is_bounded() {
let w = window_for(100_000, 100_000, (0.0, 0.0, 90_000.0, 90_000.0), MAX_SPAN).unwrap();
assert!(w.w <= MAX_SPAN && w.h <= MAX_SPAN);
}

// Given a mask edit on the photo (a gradient's handle or pin dragged), its drafts are full size
// even on the CPU, after slow drags, and when they are far over budget: the photo stays sharp (#1679)
#[test]
fn a_mask_edit_always_drafts_at_full_size() {
use lightcraft_catalog::PhotoId;
let mut d = DragScale::default();
let mask = Some((PhotoId(1), SHARP_DRAG));
assert_eq!(d.scale(mask, false, None, 0.0), Some(1.0), "on the CPU too");
d.scale(None, false, None, 0.0);
for i in 0..3 {
assert_eq!(timed_drag(&mut d, mask, 400.0, f64::from(i)), Some(1.0), "drag {i}: slow drags don't shrink the next");
}
// far over budget within one drag: it doesn't give up on full size
assert_eq!(d.scale(mask, true, None, 10.0), Some(1.0));
for key in 100..110 {
d.observe(key, 400.0, None);
}
assert_eq!(d.scale(mask, true, None, 10.0), Some(1.0));
// a slider drag on the same photo still drafts small on the CPU
d.scale(None, true, None, 10.0);
assert_eq!(d.scale(Some((PhotoId(1), "Exposure")), false, None, 10.0), Some(CPU_DRAFT_SCALE));
}
Loading
Loading