From 5c3b7b560dd38cc4795ee0e4b072be1b99c01c38 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Sun, 19 Jul 2026 13:55:33 +0000 Subject: [PATCH 27/71] fix(macos): draw the frame right-side up in the flipped view With the app finally running (gcc-4.2 frontend), the terminal rendered upside down (a 180 rotation: our top-left-origin buffer drawn bottom-up by CGContextDrawImage in the flipped view). Flip the CTM about the frame height (translate up by h, scale Y by -1) before CGContextDrawImage so row 0 lands at the top. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01AeG2jwYMX5gdvvtUnx3PJa --- src/contour_macos/TerminalView.mm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/contour_macos/TerminalView.mm b/src/contour_macos/TerminalView.mm index a32ac2f2..cf3c0185 100644 --- a/src/contour_macos/TerminalView.mm +++ b/src/contour_macos/TerminalView.mm @@ -235,8 +235,15 @@ void cbOnClosed(void* userData) CGImageRef image = CGBitmapContextCreateImage(bmp); if (image) { - CGContextRef view = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; - CGContextDrawImage(view, CGRectMake(0, 0, w, h), image); + CGContextRef ctx = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; + // Our buffer is top-left origin (row 0 = top). In this flipped view a plain + // CGContextDrawImage draws the frame upside down, so flip the CTM about the + // frame height (translate up by h, scale Y by -1) to land row 0 at the top. + CGContextSaveGState(ctx); + CGContextTranslateCTM(ctx, 0, (CGFloat) h); + CGContextScaleCTM(ctx, 1.0, -1.0); + CGContextDrawImage(ctx, CGRectMake(0, 0, (CGFloat) w, (CGFloat) h), image); + CGContextRestoreGState(ctx); CGImageRelease(image); } CGContextRelease(bmp);