racket/draw: switch bitmap% accounting to phantom bytes

Avoids doubling the actual amount of memory used for a bitmap.
This commit is contained in:
Matthew Flatt 2012-12-19 18:41:45 -07:00
parent aa08a68424
commit 35744a7632

View File

@ -262,9 +262,9 @@
(set! alpha-s #f) (set! alpha-s #f)
(destroy s2)))) (destroy s2))))
;; Allocate memory proportional to the size of the bitmap, which ;; Claim memory proportional to the size of the bitmap, which
;; helps the GC see that we're using that much memory. ;; helps the GC see that we're using that much memory:
(define shadow (make-bytes (* width height 4))) (define shadow (make-phantom-bytes (* width height 4)))
(def/public (get-width) (max 1 width)) (def/public (get-width) (max 1 width))
(def/public (get-height) (max 1 height)) (def/public (get-height) (max 1 height))
@ -286,7 +286,8 @@
(when s (when s
(let ([s2 s]) (let ([s2 s])
(set! s #f) (set! s #f)
(destroy s2)))) (destroy s2)
(set! shadow #f))))
(define/public (get-bitmap-gl-context) (define/public (get-bitmap-gl-context)
#f) #f)
@ -302,7 +303,7 @@
(set!-values (s b&w?) (do-load-bitmap in kind bg complain-on-failure?)) (set!-values (s b&w?) (do-load-bitmap in kind bg complain-on-failure?))
(set! width (if s (cairo_image_surface_get_width s) 0)) (set! width (if s (cairo_image_surface_get_width s) 0))
(set! height (if s (cairo_image_surface_get_height s) 0)) (set! height (if s (cairo_image_surface_get_height s) 0))
(set! shadow (make-bytes (* width height 4))) (set! shadow (make-phantom-bytes (* width height 4)))
(and s #t)) (and s #t))
(define/private (do-load-bitmap in kind bg complain-on-failure?) (define/private (do-load-bitmap in kind bg complain-on-failure?)