Files
photocraft/crates/ui-egui/examples/cursor_bench/args.rs
T
Khawar Zamman WaniandFredApps fba5d43a02 Use native Pen cursors to avoid canvas-frame delay (#10860)
* feat(ui-egui): native Pen cursor bitmaps with bounded cache (#9122)

- Render standard Pen cursors (Pen, Freeform Pen, Curvature Pen, Add
  Anchor, Delete Anchor, Convert Point) as OS cursor bitmaps to eliminate
  presentation/canvas frame dependency and tracking latency.
- Preserve exact 8-offset dark outline and white foreground composition,
  native platform scaling, and tool hotspots.
- Implement bounded caching (up to 16 entries) keyed on shape and scale to
  ensure zero re-rasterization on warm pointer movement and rapid tool toggling.
- Preserve precise/crosshair mode, vector close-path cursor state, and painted
  tooltip fallback for unsupported platforms/viewports.
- Add comprehensive regression tests for rasterization, alpha/color fidelity,
  hotspots, lifecycle, and cache bounding.
- Add release benchmark example (cursor_bench) measuring cold rasterization
  and warm movement/cache performance with optional PNG artifact export.
- Retain Pencil painted outline: documented that rigid OS cursor hardware
  planes cannot preserve document pixel grid snapping across fractional
  zoom/scales without continuous drift or per-frame churn.

* fix(ui-egui): correct Pen cursor rasterization, caching, and benchmark (#9122)

- Fix cursor_bench imports to use public tool_cursor::pen with correct frame lifecycle.
- Apply and verify requested native scale per platform in benchmark Context.
- Replace benchmark hardcoded metrics with truthful measured counters and Result error returns.
- Fix Arc::ptr_eq identity checks, unused imports, and Image::from_raw codecs API.
- Add baseline painted fallback measurements to benchmark for real speedup comparisons.
- Keep original single-entry cache for non-Pen shapes and add separately bounded 6-entry Pen cache without whole-cache cloning.
- Preserve fractional-scale logical geometry via subpixel resampling and compensate for OS integer hotspot quantization.
- Add independent comparison test against painted path across scales and backgrounds (light/dark/midgrey).
- Fix Shape::Pen tuple match hazard and doc comments on pen().
- Register cursor_bench in perf/budgets.toml for xtask perf runner integration.

* fix(ui): benchmark cursor preparation inside real egui frames

* feat(ui-egui): visual validation reference, comparison metrics, and contact sheet for native Pen cursors (#9122)

* fix(ui): render cursor reference pairs without duplicate Area ids

* fix(ui): use egui 0.37 frame API in cursor benchmark

* fix(ui): retain rendered cursor textures and restore existing documentation

* fix(ui-egui): restore crisp Pen cursor rasterization and update cursor tests (#9122)

- Eliminate double-resampling blur in Pen cursor rasterization: use direct discrete
  vector glyph rasterization matching the painted fallback without fractional softening.
- Update CapsLock test to assert native OS cursor bitmap and fallback Crosshair for
  Pen tools, validating exact bitmap RGBA, dimensions, and hotspot.
- Add synthetic test proving mathematical equivalence between straight RGBA hardware
  blending and multi-pass painter fallback across dark, midgrey, and light backgrounds.

* test(ui): expect the native bitmap for Precise crosshair cursors

* fix(ui): bound cursor benchmark samples and strengthen bitmap tests

(cherry picked from commit 118c673e5d822742da0a1d99c5aa3a9989b47ff8)

* test(ui): pin cursor percentile rank and glyph-derived hotspots

* test(ui): cover every Pen cursor mapping and per-variant edge samples

---------

Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
2026-11-05 04:54:22 +01:00

33 lines
1.3 KiB
Rust

/// Validate before allocating samples. Twenty-four cases retain three timing vectors,
/// so 20,000 samples per case bounds raw timing storage to about 12 MiB.
pub(super) fn checked_sample_count(moves: usize, reps: usize) -> Result<usize, &'static str> {
if moves == 0 || moves > 100_000 {
return Err("moves count must be in 1..=100000");
}
if reps == 0 || reps > 100 {
return Err("reps count must be in 1..=100");
}
let count = moves.checked_mul(reps).ok_or("move count overflow")?;
if count > 20_000 {
return Err("moves * reps must not exceed 20000 samples per cursor case");
}
Ok(count)
}
#[cfg(test)]
mod argument_tests {
use super::checked_sample_count;
#[test]
fn sample_budget_accepts_defaults_and_boundary_but_rejects_excess() {
assert_eq!(checked_sample_count(1000, 5), Ok(5000));
assert_eq!(checked_sample_count(200, 2), Ok(400));
assert_eq!(checked_sample_count(200, 100), Ok(20_000));
assert!(checked_sample_count(10_001, 2).is_err());
assert!(checked_sample_count(100_000, 100).is_err());
assert!(checked_sample_count(usize::MAX, 2).is_err());
assert!(checked_sample_count(0, 1).is_err());
assert!(checked_sample_count(1, 0).is_err());
}
}