Mercurial > hg > indyvon
changeset 88:18abc7d66d49
Async-layer uses daemon thread. Added arg to set the thread priority.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Wed, 06 Oct 2010 18:45:51 +0400 |
parents | beb89bd18839 |
children | 54f6e6d196c3 |
files | src/net/kryshen/indyvon/async.clj src/net/kryshen/indyvon/layers.clj |
diffstat | 2 files changed, 28 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/net/kryshen/indyvon/async.clj Wed Oct 06 18:09:37 2010 +0400 +++ b/src/net/kryshen/indyvon/async.clj Wed Oct 06 18:45:51 2010 +0400 @@ -25,7 +25,7 @@ (net.kryshen.indyvon.core Size Location) (java.awt Image) (java.awt.image BufferedImage) - (java.util.concurrent ThreadPoolExecutor + (java.util.concurrent ThreadFactory ThreadPoolExecutor ThreadPoolExecutor$DiscardOldestPolicy ArrayBlockingQueue TimeUnit))) @@ -139,14 +139,30 @@ (layer-size [layer] (Size. width height))) +(defn- create-thread-factory [priority] + (reify + ThreadFactory + (newThread [_ runnable] + (let [thread (Thread. runnable)] + (when priority + (.setPriority thread priority)) + (.setDaemon thread true) + thread)))) + +(defn- create-executor [priority] + (doto (ThreadPoolExecutor. + (int 1) (int 1) + (long 0) TimeUnit/SECONDS + (ArrayBlockingQueue. 1) + (ThreadPoolExecutor$DiscardOldestPolicy.)) + (.setThreadFactory (create-thread-factory priority)))) + (defn async-layer "Creates layer that draws the content asynchronously using offscreen buffer." - [content width height] - (AsyncLayer. content width height - (ThreadPoolExecutor. - (int 1) (int 1) - (long 0) TimeUnit/SECONDS - (ArrayBlockingQueue. 1) - (ThreadPoolExecutor$DiscardOldestPolicy.)) - (ref nil))) + ([content width height] + (async-layer content width height nil)) + ([content width height priority] + (AsyncLayer. content width height + (create-executor priority) + (ref nil))))
--- a/src/net/kryshen/indyvon/layers.clj Wed Oct 06 18:09:37 2010 +0400 +++ b/src/net/kryshen/indyvon/layers.clj Wed Oct 06 18:45:51 2010 +0400 @@ -202,6 +202,8 @@ height (if (pos? height) height 1)] (Size. width height)))))) +(def *miniature-thread-priority* 2) + (defn miniature "Creates layer that asynchronously renders view of the content scaled to the specified size." @@ -217,7 +219,7 @@ (draw! content 0 0 (:width size) (:height size)))) (layer-size [this] (Size. width height))) - width height)) + width height *miniature-thread-priority*)) (defrecord Viewport [content h-align v-align ;; State (refs)