racket/gui cocoa: delay `on-paint' if a GL context isn't ready

The relevant `on-paint' call is one that is forced for a GL
canvas to try to draw a frame's content before the frame is
shown. Sometimes, thread scheduling would let the frame get
sufficiently initialized at the Cocoa level before the `on-paint'
call happened, but sometimes not.
This commit is contained in:
Matthew Flatt 2013-04-12 14:39:19 -06:00
parent fff88eeb92
commit 9420855879
4 changed files with 25 additions and 4 deletions

View File

@ -69,6 +69,7 @@
(when wxb
(let ([wx (->wx wxb)])
(when wx
(send wx drawing-requested)
(unless (send wx paint-or-queue-paint)
(clear-background wxb)
;; ensure that `nextEventMatchingMask:' returns
@ -280,6 +281,22 @@
(cancel-flush-delay req)))
(define/public (queue-canvas-refresh-event thunk)
(queue-window-refresh-event this thunk))
(define/public (skip-pre-paint?)
(cond
[is-gl?
;; We can't use GL on the window until it is ready,
;; as indicated by a request to draw.
(unless drawing-requested?
(sync/timeout 0.1 drawing-requested-sema))
(not drawing-requested?)]
[else #f]))
(define drawing-requested? #f)
(define drawing-requested-sema (make-semaphore))
(define/public (drawing-requested)
(unless drawing-requested?
(set! drawing-requested? #t)
(semaphore-post drawing-requested-sema)))
(define/public (paint-or-queue-paint)
(cond

View File

@ -125,7 +125,8 @@
on-paint
queue-backing-flush
get-dc
get-canvas-background-for-backing)
get-canvas-background-for-backing
skip-pre-paint?)
;; Avoid multiple queued paints, and also allow cancel
;; of queued paint:
@ -169,9 +170,10 @@
(cancel-canvas-flush-delay req)))
(define/override (paint-children)
(when (or paint-queued
(not (send (get-dc) can-backing-flush?)))
(do-on-paint #f #f)))
(unless (skip-pre-paint?)
(when (or paint-queued
(not (send (get-dc) can-backing-flush?)))
(do-on-paint #f #f))))
(define flush-box #f)

View File

@ -454,6 +454,7 @@
(cancel-flush-delay req))
(define/public (queue-canvas-refresh-event thunk)
(queue-window-refresh-event this thunk))
(define/public (skip-pre-paint?) #f)
(define/public (paint-or-queue-paint)
;; in atomic mode

View File

@ -299,6 +299,7 @@
(cancel-flush-delay req))
(define/public (queue-canvas-refresh-event thunk)
(queue-window-refresh-event this thunk))
(define/public (skip-pre-paint?) #f)
(define/public (get-flush-window) canvas-hwnd)