anchor.diff:             (setf (xlib:gcontext-foreground mask-gc) 0)
              (xlib:draw-rectangle mask mask-gc 0 0 (+ x1 width) (+ y1 height) t)
              (setf (xlib:gcontext-foreground mask-gc) 1)
  -           (flet ((%draw-lines (scan-line)
  -                    (map-over-region-set-regions
  -                     (lambda (reg)
  -                       (when (linep reg)
  -                         (multiple-value-bind (lx1 ly1) (line-start-point* reg)
  -                           (multiple-value-bind (lx2 ly2) (line-end-point* reg)
  -                             (xlib:draw-line mask mask-gc
  -                                             (round-coordinate lx1)
  -                                             (round-coordinate ly1)
  -                                             (round-coordinate lx2)
  -                                             (round-coordinate ly2))))))
  -                     scan-line)))
  -             (if (<= width height)
  -                 (loop for x from x1 to (+ x1 width) do
  -                      (%draw-lines (region-intersection
  -                                    clipping-region
  -                                    (make-line* x y1 x (+ y1 height)))))
  -                 (loop for y from y1 to (+ y1 height) do
  -                      (%draw-lines (region-intersection
  -                                    clipping-region
  -                                    (make-line* x1 y (+ x1 width) y))))))
  -           (setf (xlib:gcontext-clip-mask gc :yx-banded) mask))))
  -      (t
  -       (multiple-value-bind (x1 y1 width height)
  -           (region->clipping-values (bounding-rectangle clipping-region))
  -         (let* ((drawable (sheet-xmirror (medium-sheet medium)))
  -                (mask (xlib:create-pixmap :drawable drawable
  -                                          :depth 1
  -                                          :width (+ x1 width)
  -                                          :height (+ y1 height)))
  -                (mask-gc (xlib:create-gcontext :drawable mask :foreground 1)))
  -           (setf (xlib:gcontext-foreground mask-gc) 0)
  -           (xlib:draw-rectangle mask mask-gc 0 0 (+ x1 width) (+ y1 height) t)
  -           (setf (xlib:gcontext-foreground mask-gc) 1)
  -           (loop for x from x1 to (+ x1 width) do
  -                (loop for y from y1 to (+ y1 height) do
  -                     (when (region-contains-position-p clipping-region x y)
  -                       (xlib:draw-point mask mask-gc x y))))
  +           (%clip-region-pixmap medium mask mask-gc clipping-region x1 y1 width height)
  +           (xlib:free-gcontext mask-gc)
  +           (push #'(lambda () (xlib:free-pixmap mask)) ^cleanup)
              (setf (xlib:gcontext-clip-mask gc :yx-banded) mask)))))))
   
   
positive.code:                   ((t nil) (round (* (line-style-scale line-style medium) 3)))
                    (otherwise (line-style-effective-dashes line-style medium)))))))))
  
  (defun %set-gc-clipping-region (medium gc)
    (declare (type clx-medium medium))
    (let ((clipping-region (medium-device-region medium))
          (tmp (slot-value medium 'clipping-region-tmp)))
      (cond
        ((region-equal clipping-region +nowhere+)
         (setf (xlib:gcontext-clip-mask gc) #()))
        ((typep clipping-region 'standard-rectangle)
         (multiple-value-bind (x1 y1 width height)
             (region->clipping-values clipping-region)
           (setf (aref tmp 0) x1
  
negative.code:    (last-medium-device-region :initform nil
                                :accessor last-medium-device-region)
     ;; CLIPPING-REGION-TMP is reused to avoid consing in the most common case
     ;; when configuring the clipping region.
     (clipping-region-tmp :initform (vector 0 0 0 0))))
  
  ;; Variable is used to deallocate lingering resources after the operation.
  (defvar ^cleanup)
  
  
  