Metal: fix inline images rendering upside down

mtl_texture_for_image flipped the CGBitmapContext CTM before drawing the
NSImage, but an upright draw into a bitmap context already places the
visual top of the image in the first memory row, which is what Metal's
texture row 0 (V=0, top of the quad) expects. The extra flip was the lone
inversion, so images came out upside down. Drop it.

Verified with a top-red/bottom-blue probe: red now lands on top.
This commit is contained in:
Andros Fenollosa 2026-06-02 14:53:33 +02:00
parent 0e1e6f983d
commit df8a190e28

View file

@ -1736,10 +1736,10 @@ mtl_texture_for_image (struct image *img)
CGColorSpaceRelease (cs);
if (!ctx) { free (px); return nil; }
/* Flip Y so that Metal's top-left origin matches */
CGContextTranslateCTM (ctx, 0, (CGFloat)h);
CGContextScaleCTM (ctx, 1.0, -1.0);
/* No CTM flip: drawing the image upright into a CGBitmapContext already puts
the visual top of the image in the first memory row, which is exactly what
Metal's texture row 0 (V=0, the top of the quad) expects. Flipping here
would invert the lone orientation and render the image upside down. */
NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:ctx
flipped:NO];
[NSGraphicsContext saveGraphicsState];