From 595631d26670a36063d5a5c5a24b7decebbace76 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 24 Nov 2013 19:46:33 -0700 Subject: [PATCH] racket/gui cocoa: repair for canvas creation in hidden top-level window Fixes 9cb646bbd2 for the case that a frame or dialog is shown, then hidden, then a new canvas is created or a new compatible bitmap is requested via the `make-bitmap` method. The test for this change is just the "windowing.rktl" test, which I forgot to run before (as opposed to the drawing test suite). original commit: d234c0c2e30e7ed0c649f8bcf2577e23865304c3 --- .../gui-lib/mred/private/wx/cocoa/dc.rkt | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/dc.rkt b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/dc.rkt index 4a003fcc..827d0271 100644 --- a/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/dc.rkt +++ b/pkgs/gui-pkgs/gui-lib/mred/private/wx/cocoa/dc.rkt @@ -9,6 +9,7 @@ racket/draw/private/gl-context "types.rkt" "utils.rkt" + "const.rkt" "window.rkt" "../../lock.rkt" "../common/queue.rkt" @@ -22,7 +23,7 @@ make-screen-bitmap make-window-bitmap) -(import-class NSOpenGLContext NSScreen NSGraphicsContext) +(import-class NSOpenGLContext NSScreen NSGraphicsContext NSWindow) (define NSOpenGLCPSwapInterval 222) @@ -263,7 +264,24 @@ (define (make-layer win w h) (atomically (with-autorelease - (let* ([ctx (tell NSGraphicsContext graphicsContextWithWindow: win)] + (let* ([ctx (if ((tell #:type _NSInteger win windowNumber) . <= . 0) + ;; Window's device is gone, probably because it was hidden, + ;; and we configure windows with setOneShot: YES. + ;; Just make a new window... + (let ([alt-win (make-temp-window)]) + (begin0 + (tell NSGraphicsContext graphicsContextWithWindow: alt-win) + (tellv alt-win release))) + ;; Use canvas's window: + (tell NSGraphicsContext graphicsContextWithWindow: win))] [tmp-cg (tell #:type _CGContextRef ctx graphicsPort)] [layer (CGLayerCreateWithContext tmp-cg (make-NSSize w h) #f)]) layer)))) + +(define (make-temp-window) + (tell (tell NSWindow alloc) + initWithContentRect: #:type _NSRect (make-NSRect (make-NSPoint 0 0) + (make-NSSize 10 10)) + styleMask: #:type _int 0 + backing: #:type _int NSBackingStoreBuffered + defer: #:type _BOOL NO))