(<fix-ink>)
;; Cairo Image Surface -- a |cairo_surface_t| alien.
- (surface define standard initial-value #f))
+ (surface define standard)
+
+ ;; For use by the glib thread only.
+ (exposed define standard initial-value #f))
(define-method initialize-instance ((ink <surface-ink>) width height)
(call-next-method ink)
(set-surface-ink-surface! ink (cairo-image-surface-create width height)))
(define-method fix-ink-draw-callback ((ink <surface-ink>) widget window cr area)
- (declare (ignore window area))
+ (declare (ignore area))
(%trace ";drawing "ink" on "widget"\n")
(let ((view (fix-layout-view widget))
(extent (fix-ink-extent ink))
- (surface (surface-ink-surface ink)))
+ (surface (get-exposed ink window)))
(let ((x (fix:- (fix-rect-x extent) (fix-rect-x view)))
(y (fix:- (fix-rect-y extent) (fix-rect-y view))))
(cairo-set-source-surface cr surface x y)
(cairo-paint cr))))
+(define (get-exposed ink window)
+ (or (surface-ink-exposed ink)
+ (let ((extent (fix-ink-extent ink))
+ (scale (C-call "gdk_window_get_scale_factor" window)))
+ (let ((width (fix:* scale (fix-rect-width extent)))
+ (height (fix:* scale (fix-rect-height extent))))
+ (let* ((surface (gdk-window-create-similar-surface window
+ width height))
+ (cr (cairo-create surface)))
+ (cairo-set-source-surface cr (surface-ink-surface ink) 0 0)
+ (cairo-paint cr)
+ (cairo-destroy cr)
+ (set-surface-ink-exposed! ink surface)
+ surface)))))
+
+(define (surface-ink-flush ink)
+ (let ((surface (surface-ink-surface ink))
+ (exposed (surface-ink-exposed ink)))
+ (cairo-surface-flush surface)
+ (if exposed
+ (signal-thread-event glib-thread
+ (lambda ()
+ (%trace2 ";surface-ink-flush copying\n")
+ (let ((cr (cairo-create exposed)))
+ (cairo-set-source-surface cr surface 0 0)
+ (cairo-paint cr)
+ (cairo-destroy cr))
+ (cairo-surface-flush exposed))))
+ (drawing-damage ink)))
+
(define (set-surface-ink-position! ink x y)
(set-fix-rect-position! (fix-ink-extent ink) x y))
\f
(cairo-fill cr))))
(define (gtk-graphics/flush device)
- (let ((graphics (graphics-device/descriptor device)))
- (cairo-surface-flush (surface-ink-surface graphics))
- (drawing-damage graphics)))
+ (surface-ink-flush (graphics-device/descriptor device)))
(define (gtk-graphics/set-background-color device name)
(let ((graphics (graphics-device/descriptor device)))