changeset 94:649d12b6c9ec

Async layer: create-image does not depend on graphics context.
author Mikhail Kryshen <mikhail@kryshen.net>
date Thu, 03 Mar 2011 03:13:14 +0300
parents 017f5f14b876
children df9dedc80485
files src/net/kryshen/indyvon/async.clj
diffstat 1 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/net/kryshen/indyvon/async.clj	Thu Dec 23 09:00:24 2010 +0300
+++ b/src/net/kryshen/indyvon/async.clj	Thu Mar 03 03:13:14 2011 +0300
@@ -1,5 +1,5 @@
 ;;
-;; Copyright 2010 Mikhail Kryshen <mikhail@kryshen.net>
+;; Copyright 2010, 2011 Mikhail Kryshen <mikhail@kryshen.net>
 ;;
 ;; This file is part of Indyvon.
 ;;
@@ -23,6 +23,7 @@
    net.kryshen.indyvon.core)
   (:import
    (net.kryshen.indyvon.core Size Location)
+   java.awt.GraphicsConfiguration
    (java.awt Image AlphaComposite Transparency)
    (java.awt.image BufferedImage)
    (java.util.concurrent ThreadFactory ThreadPoolExecutor
@@ -40,14 +41,15 @@
 ;;   :free
 ;;      not in use
 
-(defn- create-image [async-layer]
+(defn- create-image [async-layer ^GraphicsConfiguration device-conf]
   ;; TODO: support different image types.
-  (.. *graphics* (getDeviceConfiguration)
-      (createCompatibleImage (:width async-layer) (:height async-layer)
-                             Transparency/TRANSLUCENT)))
+  (.createCompatibleImage device-conf
+                          (:width async-layer)
+                          (:height async-layer)
+                          Transparency/TRANSLUCENT))
 
-(defn- create-buffer [async-layer]
-  (Buffer. (Object.) (create-image async-layer) 0 :free))
+(defn- create-buffer [async-layer device-conf]
+  (Buffer. (Object.) (create-image async-layer device-conf) 0 :free))
 
 (defn- find-buffer
   "Find a buffer with the one of the specified states given
@@ -136,8 +138,9 @@
     (add-context-observer content (fn [_ _] (draw-offscreen-async layer)))
     (when-not @buffers
       ;; TODO: dynamic size, recreate buffers when size increases.
-      (let [cb (bound-fn [] (create-buffer layer))
-            new-buffers (repeatedly 2 cb)]
+      (let [device-conf (.getDeviceConfiguration *graphics*)
+            new-buffers (repeatedly 2
+                          (partial create-buffer layer device-conf))]
         (dosync
          (ref-set buffers new-buffers)))
       (draw-offscreen-async layer))