Snap icon sprites to pixel grid

Antonio Scandurra created

This should resolve some rendering artifacts potentially caused by
floating point errors when sampling the texture. It should also lead
to crisper images when icons are rendered midway through a pixel.

Change summary

crates/gpui/src/platform/mac/renderer.rs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

Detailed changes

crates/gpui/src/platform/mac/renderer.rs 🔗

@@ -561,9 +561,10 @@ impl Renderer {
         }
 
         for icon in icons {
-            let origin = icon.bounds.origin() * scale_factor;
-            let target_size = icon.bounds.size() * scale_factor;
-            let source_size = (target_size * 2.).ceil().to_i32();
+            // Snap sprite to pixel grid.
+            let origin = (icon.bounds.origin() * scale_factor).floor();
+            let target_size = (icon.bounds.size() * scale_factor).ceil();
+            let source_size = (target_size * 2.).to_i32();
 
             let sprite =
                 self.sprite_cache