From be8caf7ad85484e88e4ec4292acd81039934265c Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Thu, 8 Aug 2013 15:59:38 -0500 Subject: [PATCH] make un/cache-image accept everything that image? accepts I'm not sure if the precise details of how this function behaves (specifically that it copies snips that aren't cacheable) is important, but I suspect the implementation is more authoritative that the docs in this case, so document what it really does. closes PR 13956 original commit: fb91397d24551dbef0db7c40a9d12042e6c7326b --- .../gui-doc/mrlib/scribblings/image-core.scrbl | 5 +++++ pkgs/gui-pkgs/gui-lib/mrlib/image-core.rkt | 15 +++++++++++---- pkgs/gui-pkgs/gui-test/mrlib/tests/image-core.rkt | 10 ++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 pkgs/gui-pkgs/gui-test/mrlib/tests/image-core.rkt diff --git a/pkgs/gui-pkgs/gui-doc/mrlib/scribblings/image-core.scrbl b/pkgs/gui-pkgs/gui-doc/mrlib/scribblings/image-core.scrbl index 01568bab..90936124 100644 --- a/pkgs/gui-pkgs/gui-doc/mrlib/scribblings/image-core.scrbl +++ b/pkgs/gui-pkgs/gui-doc/mrlib/scribblings/image-core.scrbl @@ -26,6 +26,11 @@ up an image. @defproc[(un/cache-image [image image?] [b any/c]) image?]{ Returns an image that either caches its drawing in the snip @method[snip% draw] method or doesn't, depending on @racket[b]. + + Not all @racket[image?] values have special caching capabilities; + in those cases, this returns a copy of the value if it is a + @racket[snip%]; otherwise it returns the value itself (if it + isn't a @racket[snip%]). } @defproc[(compute-image-cache [image image?]) void?]{ diff --git a/pkgs/gui-pkgs/gui-lib/mrlib/image-core.rkt b/pkgs/gui-pkgs/gui-lib/mrlib/image-core.rkt index 2ccb2d93..3dcbaa13 100644 --- a/pkgs/gui-pkgs/gui-lib/mrlib/image-core.rkt +++ b/pkgs/gui-pkgs/gui-lib/mrlib/image-core.rkt @@ -84,10 +84,17 @@ has been moved out). (define (un/cache-image img bitmap-cache?) (unless (image? img) - (error 'un/cache-image "expected an image as the first argument, got ~e" img)) - (define res (send img copy)) - (send res set-use-bitmap-cache?! (and bitmap-cache? #t)) - res) + (raise-argument-error 'un/cache-image + "image?" + 0 + img bitmap-cache?)) + (cond + [(is-a? img snip%) + (define res (send img copy)) + (when (is-a? res image%) + (send res set-use-bitmap-cache?! (and bitmap-cache? #t))) + res] + [else img])) (define (compute-image-cache img) (unless (image? img) diff --git a/pkgs/gui-pkgs/gui-test/mrlib/tests/image-core.rkt b/pkgs/gui-pkgs/gui-test/mrlib/tests/image-core.rkt new file mode 100644 index 00000000..e8bf39be --- /dev/null +++ b/pkgs/gui-pkgs/gui-test/mrlib/tests/image-core.rkt @@ -0,0 +1,10 @@ +#lang racket/base + +(require rackunit + mrlib/image-core + (only-in racket/gui/base make-bitmap)) + +;; just check there is no error +(check-equal? (begin (un/cache-image (make-bitmap 1 1) #t) + (void)) + (void)) \ No newline at end of file