(C-include "gl")
+(define-syntax error-if-null
+ (syntax-rules ()
+ ((_ ALIEN MESSAGE ...)
+ (if (alien-null? ALIEN)
+ (error MESSAGE ...)))))
+
(define (with-glx-widget widget thunk)
(let ((xdisplay (glx-widget-xdisplay widget))
(xwindow (glx-widget-xwindow widget))
(define-method initialize-instance ((widget <glx-widget>) width height)
(call-next-method widget width height '())
+ (assert-glib-locked '(initialize-instance <glx-widget>))
(add-glib-cleanup widget (make-glx-widget-cleanup
(glx-widget-xdisplay widget)
(glx-widget-glxcontext widget)))
(cleanup-glx-widget xdisplay glxcontext)))
(define (cleanup-glx-widget xdisplay glxcontext)
- ;;without-interrupts
+ (assert-without-interruption 'cleanup-glx-widget)
(if (not (alien-null? glxcontext))
(begin
(C-call "glXDestroyContext" xdisplay glxcontext)
(alien-null! glxcontext))))
(define-method gtk-widget-destroy-callback ((widget <glx-widget>))
- (without-interrupts
+ (without-interruption
(lambda ()
(execute-glib-cleanup widget)))
(call-next-method widget))
(define-method fix-widget-realize-callback ((widget <glx-widget>))
+ (assert-glib-locked '(fix-widget-realize-callback <glx-widget>))
(let* ((GtkWidget (gobject-alien widget))
(parent
(C-call "gtk_widget_get_parent_window" (make-alien '|GdkWindow|)
(cleanup-fb-configs alien)))
#;(define (cleanup-fb-configs alien)
- ;;without-interrupts
+ (assert-without-interrupts 'cleanup-fb-configs)
(if (not (alien-null? alien))
(begin
(C-call "XFree" alien)
(make-glxgears-demo-device 400 400 "gl-glxgears.scm"))
(define (make-glxgears-demo-device width height title)
- (let ((window (gtk-window-new 'toplevel)))
- (gtk-window-set-title window title)
- (set-gtk-window-delete-event-callback!
- window (lambda (w) (%trace "closed "w) 0))
- (gtk-container-set-border-width window 5)
- (let ((widget (%make-glxgears-demo width height)))
- (gtk-container-add window widget)
- (gtk-widget-show-all window)
- widget)))
+ (with-glib-lock
+ (lambda ()
+ (let ((window (gtk-window-new 'toplevel)))
+ (gtk-window-set-title window title)
+ (set-gtk-window-delete-event-callback!
+ window (lambda (w) (%trace "closed "w) 0))
+ (gtk-container-set-border-width window 5)
+ (let ((widget (%make-glxgears-demo width height)))
+ (gtk-container-add window widget)
+ (gtk-widget-show-all window)
+ widget)))))
(define-class (<glxgears-demo>
(constructor %make-glxgears-demo () (width height)))
(with-thread-events-blocked
(lambda ()
(%trace2 "draw-frame: request draw")
- (gtk-widget-queue-draw widget)
+ (with-glib-lock (lambda () (gtk-widget-queue-draw widget)))
(%trace2 "draw-frame: sleep")
(suspend-current-thread)
(%trace2 "draw-frame: awake")))
(import (runtime ffi)
%set-alien/address!)
(import (glib)
+ assert-glib-locked assert-without-interruption
add-glib-cleanup execute-glib-cleanup)
(import (gobject)
gobject-alien)
fix-widget-geometry fix-widget-window)
(import (gtk)
<fix-widget>
- error-if-null
fix-widget-new-geometry-callback
fix-widget-realize-callback
gtk-container-add
(define-package (gl glxgears)
(files "gl-glxgears")
(parent (gl))
+ (import (glib)
+ with-glib-lock)
(import (gtk)
fix-widget-new-geometry-callback
fix-widget-realize-callback