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:
parent
fff88eeb92
commit
9420855879
|
@ -69,6 +69,7 @@
|
||||||
(when wxb
|
(when wxb
|
||||||
(let ([wx (->wx wxb)])
|
(let ([wx (->wx wxb)])
|
||||||
(when wx
|
(when wx
|
||||||
|
(send wx drawing-requested)
|
||||||
(unless (send wx paint-or-queue-paint)
|
(unless (send wx paint-or-queue-paint)
|
||||||
(clear-background wxb)
|
(clear-background wxb)
|
||||||
;; ensure that `nextEventMatchingMask:' returns
|
;; ensure that `nextEventMatchingMask:' returns
|
||||||
|
@ -280,6 +281,22 @@
|
||||||
(cancel-flush-delay req)))
|
(cancel-flush-delay req)))
|
||||||
(define/public (queue-canvas-refresh-event thunk)
|
(define/public (queue-canvas-refresh-event thunk)
|
||||||
(queue-window-refresh-event this 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)
|
(define/public (paint-or-queue-paint)
|
||||||
(cond
|
(cond
|
||||||
|
|
|
@ -125,7 +125,8 @@
|
||||||
on-paint
|
on-paint
|
||||||
queue-backing-flush
|
queue-backing-flush
|
||||||
get-dc
|
get-dc
|
||||||
get-canvas-background-for-backing)
|
get-canvas-background-for-backing
|
||||||
|
skip-pre-paint?)
|
||||||
|
|
||||||
;; Avoid multiple queued paints, and also allow cancel
|
;; Avoid multiple queued paints, and also allow cancel
|
||||||
;; of queued paint:
|
;; of queued paint:
|
||||||
|
@ -169,9 +170,10 @@
|
||||||
(cancel-canvas-flush-delay req)))
|
(cancel-canvas-flush-delay req)))
|
||||||
|
|
||||||
(define/override (paint-children)
|
(define/override (paint-children)
|
||||||
(when (or paint-queued
|
(unless (skip-pre-paint?)
|
||||||
(not (send (get-dc) can-backing-flush?)))
|
(when (or paint-queued
|
||||||
(do-on-paint #f #f)))
|
(not (send (get-dc) can-backing-flush?)))
|
||||||
|
(do-on-paint #f #f))))
|
||||||
|
|
||||||
|
|
||||||
(define flush-box #f)
|
(define flush-box #f)
|
||||||
|
|
|
@ -454,6 +454,7 @@
|
||||||
(cancel-flush-delay req))
|
(cancel-flush-delay req))
|
||||||
(define/public (queue-canvas-refresh-event thunk)
|
(define/public (queue-canvas-refresh-event thunk)
|
||||||
(queue-window-refresh-event this thunk))
|
(queue-window-refresh-event this thunk))
|
||||||
|
(define/public (skip-pre-paint?) #f)
|
||||||
|
|
||||||
(define/public (paint-or-queue-paint)
|
(define/public (paint-or-queue-paint)
|
||||||
;; in atomic mode
|
;; in atomic mode
|
||||||
|
|
|
@ -299,6 +299,7 @@
|
||||||
(cancel-flush-delay req))
|
(cancel-flush-delay req))
|
||||||
(define/public (queue-canvas-refresh-event thunk)
|
(define/public (queue-canvas-refresh-event thunk)
|
||||||
(queue-window-refresh-event this thunk))
|
(queue-window-refresh-event this thunk))
|
||||||
|
(define/public (skip-pre-paint?) #f)
|
||||||
|
|
||||||
(define/public (get-flush-window) canvas-hwnd)
|
(define/public (get-flush-window) canvas-hwnd)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user