From 9e9e204234b883d783914aa909e96c57d45ac081 Mon Sep 17 00:00:00 2001 From: Scott Gilbertson Date: Sat, 19 Apr 2003 19:54:39 +0000 Subject: XGraphics.java (XGraphics): Use new GC.create. 2003-04-19 Scott Gilbertson * gnu/awt/xlib/XGraphics.java (XGraphics): Use new GC.create. (dispose): Null metrics. * gnu/awt/xlib/XToolkit.java (sync): Implement. * gnu/gcj/xlib/Clip.java (dispose): Change name of native from finalize. (finalize): Call dispose. * gnu/gcj/xlib/Drawable.java (gcCache): New field. (gcCachedCount): New field. (finalize): New method. (putGCInCache): New method. (getGCFromCache): New method. * gnu/gcj/xlib/GC.java (GC): Make protected. (clone): Get new GC from cache if possible. (create): New static method. (dispose): Save old GC in cache. * gnu/gcj/xlib/natClip.cc (dispose): Check for null before deleting. * gnu/gcj/xlib/natGC.cc (initStructure): Call XCreateGC only if gc is null. * gnu/gcj/xlib/Pixmap.java (Pixmap): Use new GC.create. * java/awt/Container.java (visitChild): Dispose gfx2 when finished. From-SVN: r65827 --- libjava/gnu/gcj/xlib/Drawable.java | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'libjava/gnu/gcj/xlib/Drawable.java') diff --git a/libjava/gnu/gcj/xlib/Drawable.java b/libjava/gnu/gcj/xlib/Drawable.java index 5652792..551aca8 100644 --- a/libjava/gnu/gcj/xlib/Drawable.java +++ b/libjava/gnu/gcj/xlib/Drawable.java @@ -16,6 +16,9 @@ import java.awt.Rectangle; */ public class Drawable extends XID { + private GC[] gcCache = new GC[10]; + private int gcCachedCount = 0; + public Drawable(Display display, int xid) { super(display, xid); @@ -78,5 +81,36 @@ public class Drawable extends XID private static final String MSG_XGETSUBIMAGE_FAILED = "XGetSubImage() failed."; - + + protected void finalize() throws Throwable + { + // Dispose all the cached GCs, to reduce X server resource usage + for (int i=0; i= gcCache.length) + { + // List full - extend it to double its present size + GC[] oldList = gcCache; + gcCache = new GC[oldList.length*2]; + System.arraycopy (oldList,0,gcCache,0,oldList.length); + } + gcCache[gcCachedCount++] = gc; + } + + /** Get a GC from the cache, if available + * @return A GC from the cache, or null if the cache is empty + */ + GC getGCFromCache () + { + return (gcCachedCount>0) ? gcCache[--gcCachedCount] : null; + } } -- cgit v1.1