@@ -93,6 +93,8 @@ pub struct Tex {
9393 pub quick : Option < QuickSource > ,
9494 /// These pixels are a native-resolution photo render, not a stand-in or a reduced view.
9595 pub full_res : bool ,
96+ /// One unchanged texel lets a sampler change avoid uploading the whole image.
97+ pub first_pixel : Option < egui:: Color32 > ,
9698 /// CPU copy of the pixels (only with [`Renderer::keep_pixels`]; for headless screenshots).
9799 pub pixels : Option < std:: sync:: Arc < egui:: ColorImage > > ,
98100}
@@ -290,6 +292,8 @@ pub struct Renderer {
290292 /// Slot → (key, priority) of the request in flight (queued or running).
291293 pending : HashMap < Slot , ( u64 , u32 ) > ,
292294 pub textures : HashMap < Slot , Tex > ,
295+ /// Each view owns its zoom; automatic Fit/Fill views default to linear.
296+ texture_zoom : HashMap < Slot , crate :: state:: Zoom > ,
293297 /// The last [`Slot::HdrHistogram`] result: (photo, job key, histogram).
294298 pub live_hdr_histogram : Option < ( PhotoId , u64 , Histogram ) > ,
295299 pub last_main_ms : f64 ,
@@ -340,8 +344,10 @@ const IDLE_TRIM: std::time::Duration = std::time::Duration::from_secs(3);
340344impl Slot {
341345 /// Only native photo-view renders expose original pixels. Thumbnails and stand-ins stay
342346 /// linear even when a small original fits their cache entry without losing any pixels.
343- fn texture_options ( self , full_res : bool ) -> egui:: TextureOptions {
347+ /// Fit and Fill also stay smooth: only explicit zoom past 100% exposes the pixel grid.
348+ fn texture_options ( self , full_res : bool , zoom : crate :: state:: Zoom ) -> egui:: TextureOptions {
344349 if full_res
350+ && matches ! ( zoom, crate :: state:: Zoom :: Percent ( p) if p > 100.0 )
345351 && matches ! (
346352 self ,
347353 Self :: Main
@@ -397,6 +403,7 @@ impl Renderer {
397403 seq : 0 ,
398404 pending : HashMap :: new ( ) ,
399405 textures : HashMap :: new ( ) ,
406+ texture_zoom : HashMap :: new ( ) ,
400407 live_hdr_histogram : None ,
401408 last_main_ms : 0.0 ,
402409 completed : 0 ,
@@ -422,6 +429,37 @@ impl Renderer {
422429}
423430
424431impl Renderer {
432+ /// The same choice drives uploads, retained samplers and software copies.
433+ fn texture_options ( & self , slot : Slot , full_res : bool ) -> egui:: TextureOptions {
434+ slot. texture_options ( full_res, self . texture_zoom . get ( & slot) . copied ( ) . unwrap_or_default ( ) )
435+ }
436+
437+ /// Automatic Fit views can borrow Main while their own render is pending, but must not
438+ /// enlarge its explicit-zoom nearest sampler. Shrinking it is still linear and safe.
439+ pub fn main_for_fit ( & self , photo : PhotoId , physical_bounds : [ f32 ; 2 ] ) -> Option < & Tex > {
440+ self . textures . get ( & Slot :: Main ) . filter ( |t| {
441+ t. photo == photo
442+ && ( self . texture_options ( Slot :: Main , t. full_res ) == egui:: TextureOptions :: LINEAR
443+ || physical_bounds[ 0 ] <= t. size [ 0 ] as f32
444+ || physical_bounds[ 1 ] <= t. size [ 1 ] as f32 )
445+ } )
446+ }
447+
448+ /// Refresh a view's sampler even while navigation keeps its existing render (SizeHold).
449+ /// egui has no sampler-only delta. Rewriting one unchanged texel updates its sampler
450+ /// without retaining or re-uploading a potentially large CPU image.
451+ pub fn set_texture_zoom ( & mut self , slot : Slot , zoom : crate :: state:: Zoom ) {
452+ let old = self . texture_zoom . insert ( slot, zoom) . unwrap_or_default ( ) ;
453+ if let Some ( t) = self . textures . get_mut ( & slot) {
454+ let options = slot. texture_options ( t. full_res , zoom) ;
455+ if options != slot. texture_options ( t. full_res , old)
456+ && let Some ( pixel) = t. first_pixel
457+ {
458+ t. tex . set_partial ( [ 0 , 0 ] , egui:: ColorImage :: filled ( [ 1 , 1 ] , pixel) , options) ;
459+ }
460+ }
461+ }
462+
425463 /// Would asking for this thumbnail again (at `priority`) change nothing?
426464 pub fn thumb_current ( & self , photo : & Arc < lightcraft_catalog:: Photo > , bucket : usize , priority : u32 ) -> bool {
427465 let Some ( & ( ref old, size, key, quick, _) ) = self . thumb_inputs . get ( & photo. id ) else { return false } ;
@@ -1133,11 +1171,13 @@ impl Renderer {
11331171 let color = color. unwrap_or_else ( || Arc :: new ( color_image ( img) ) ) ;
11341172 let pixels = self . keep_pixels . then ( || color. clone ( ) ) ;
11351173 let name = format ! ( "{slot:?}" ) ;
1136- let options = slot. texture_options ( full_res) ;
1174+ let options = self . texture_options ( slot, full_res) ;
1175+ let first_pixel = color. pixels . first ( ) . copied ( ) ;
11371176 match self . textures . get_mut ( & slot) {
11381177 Some ( t) => {
11391178 t. tex . set ( color, options) ;
11401179 t. full_res = full_res;
1180+ t. first_pixel = first_pixel;
11411181 t. pixels = pixels;
11421182 t. look = look;
11431183 t. key = r. key ;
@@ -1161,6 +1201,7 @@ impl Renderer {
11611201 ms,
11621202 quick : r. quick ,
11631203 full_res,
1204+ first_pixel,
11641205 pixels,
11651206 } ,
11661207 ) ;
@@ -1236,7 +1277,7 @@ impl Renderer {
12361277 self . textures
12371278 . iter ( )
12381279 . filter_map ( |( slot, t) | {
1239- let options = slot . texture_options ( t. full_res ) ;
1280+ let options = self . texture_options ( * slot , t. full_res ) ;
12401281 Some ( (
12411282 t. tex . id ( ) ,
12421283 crate :: softpaint:: CpuTexture {
@@ -1320,7 +1361,19 @@ mod stage_budget_tests {
13201361 let tex = ctx. load_texture ( "window" , egui:: ColorImage :: new ( [ 1 , 1 ] , vec ! [ egui:: Color32 :: BLACK ] ) , Default :: default ( ) ) ;
13211362 r. textures . insert (
13221363 Slot :: Region ,
1323- Tex { look : None , key : 1 , photo : PhotoId ( 1 ) , tex, size : [ 1 , 1 ] , histogram : None , ms : 0.0 , quick : None , full_res : false , pixels : None } ,
1364+ Tex {
1365+ look : None ,
1366+ key : 1 ,
1367+ photo : PhotoId ( 1 ) ,
1368+ tex,
1369+ size : [ 1 , 1 ] ,
1370+ histogram : None ,
1371+ ms : 0.0 ,
1372+ quick : None ,
1373+ full_res : false ,
1374+ first_pixel : None ,
1375+ pixels : None ,
1376+ } ,
13241377 ) ;
13251378 let long_ago = std:: time:: Instant :: now ( ) . checked_sub ( IDLE_TRIM * 2 ) . unwrap ( ) ;
13261379 r. idle = Some ( ( long_ago, false ) ) ;
0 commit comments