add #:fail argument to with-gl-context' in canvas%'

This commit is contained in:
Matthew Flatt 2011-11-03 16:33:28 -06:00 committed by Matthew Flatt
parent 9bd0486ca0
commit 0f6c267798
2 changed files with 22 additions and 9 deletions

View File

@ -117,9 +117,17 @@
(check-label-string/false cwho label)))
(public
[on-scroll (lambda (e) (send wx do-on-scroll e))]
[swap-gl-buffers (lambda () (send (send (send wx get-dc) get-gl-context) swap-buffers))]
[with-gl-context (lambda (thunk)
(send (send (send wx get-dc) get-gl-context) call-as-current thunk))]
[swap-gl-buffers (lambda ()
(let ([ctx (send (send wx get-dc) get-gl-context)])
(when ctx
(send ctx swap-buffers))))]
[with-gl-context (lambda (thunk #:fail [fail (lambda ()
(error (who->name '(method canvas% with-gl-context))
"no gl context available"))])
(let ([ctx (send (send wx get-dc) get-gl-context)])
(if ctx
(send ctx call-as-current thunk)
(fail))))]
[accept-tab-focus (entry-point
(case-lambda
[() (send wx get-tab-focus)]

View File

@ -415,27 +415,32 @@ for this canvas's DC as returned by
@method[canvas<%> get-dc].
The
@method[gl-context<%> swap-buffers]
@xmethod[gl-context<%> swap-buffers]
method acquires a re-entrant lock, so nested calls to
@method[canvas% with-gl-context] on different threads or OpenGL contexts can block or deadlock.
@method[canvas% swap-gl-buffers] or @method[canvas% with-gl-context]
on different threads or OpenGL contexts can block or deadlock.
}
@defmethod[(with-gl-context [thunk (-> any)])
@defmethod[(with-gl-context [thunk (-> any)]
[#:fail fail (-> any) (lambda () (error ....))])
any]{
Passes the given thunk to
@method[gl-context<%> call-as-current]
of the result of
@method[dc<%> get-gl-context]
for this canvas's DC as returned by
@method[canvas<%> get-dc].
@method[canvas<%> get-dc]. If @method[dc<%> get-gl-context]
returns @racket[#f], then @racket[fail] is called,
instead.
The
@method[gl-context<%> call-as-current]
@xmethod[gl-context<%> call-as-current]
method acquires a re-entrant lock, so nested calls to
@method[canvas% with-gl-context] on different threads or OpenGL contexts can block or deadlock.
@method[canvas% with-gl-context] or @method[canvas% swap-gl-buffers]
on different threads or OpenGL contexts can block or deadlock.
}