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
This commit is contained in:
Matthew Flatt 2013-11-24 19:46:33 -07:00
parent c7134a00af
commit 595631d266

View File

@ -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))