1:
8:
9: package ;
10:
11: import ;
12:
13:
17: public class Drawable extends XID
18: {
19: private GC[] gcCache = new GC[10];
20: private int gcCachedCount = 0;
21:
22: public Drawable(Display display, int xid)
23: {
24: super(display, xid);
25: }
26:
27:
36: public Rectangle copyIntoXImage(XImage dest, Rectangle bounds,
37: int destX, int destY)
38: {
39: Rectangle newBounds = null;
40: int tries = 5;
41: while (!bounds.isEmpty())
42: {
43: if (copyIntoXImageImpl(dest, bounds.x, bounds.y,
44: bounds.width, bounds.height,
45: destX, destY))
46: return bounds;
47:
48:
49:
50: newBounds = getBounds(newBounds);
51:
52: bounds = newBounds.intersection(bounds);
53:
54: tries--;
55:
56: if (tries < 0)
57: throw new RuntimeException("copyIntoXImage is buggy");
58:
59: }
60:
61: return bounds;
62: }
63:
64:
65:
66:
75: private native boolean copyIntoXImageImpl(XImage destinationImage,
76: int x, int y,
77: int width, int height,
78: int destX, int destY);
79:
80: public native Rectangle getBounds(Rectangle rv);
81:
82: public native int getDepth ();
83:
84: private static final String MSG_XGETSUBIMAGE_FAILED =
85: "XGetSubImage() failed.";
86:
87: protected void finalize() throws Throwable
88: {
89:
90: for (int i=0; i<gcCachedCount; i++)
91: gcCache[i].disposeImpl ();
92: gcCachedCount = 0;
93: super.finalize();
94: }
95:
96:
99: void putGCInCache (GC gc)
100: {
101: if (gcCachedCount >= gcCache.length)
102: {
103:
104: GC[] oldList = gcCache;
105: gcCache = new GC[oldList.length*2];
106: System.arraycopy (oldList,0,gcCache,0,oldList.length);
107: }
108: gcCache[gcCachedCount++] = gc;
109: }
110:
111:
114: GC getGCFromCache ()
115: {
116: return (gcCachedCount>0) ? gcCache[--gcCachedCount] : null;
117: }
118: }