package gnu.gcj.xlib;
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);
}
public Rectangle copyIntoXImage(XImage dest, Rectangle bounds,
int destX, int destY)
{
Rectangle newBounds = null;
int tries = 5;
while (!bounds.isEmpty())
{
if (copyIntoXImageImpl(dest, bounds.x, bounds.y,
bounds.width, bounds.height,
destX, destY))
return bounds;
newBounds = getBounds(newBounds);
bounds = newBounds.intersection(bounds);
tries--;
if (tries < 0)
throw new RuntimeException("copyIntoXImage is buggy");
}
return bounds; }
private native boolean copyIntoXImageImpl(XImage destinationImage,
int x, int y,
int width, int height,
int destX, int destY);
public native Rectangle getBounds(Rectangle rv);
public native int getDepth ();
private static final String MSG_XGETSUBIMAGE_FAILED =
"XGetSubImage() failed.";
protected void finalize() throws Throwable
{
for (int i=0; i<gcCachedCount; i++)
gcCache[i].disposeImpl ();
gcCachedCount = 0;
super.finalize();
}
void putGCInCache (GC gc)
{
if (gcCachedCount >= gcCache.length)
{
GC[] oldList = gcCache;
gcCache = new GC[oldList.length*2];
System.arraycopy (oldList,0,gcCache,0,oldList.length);
}
gcCache[gcCachedCount++] = gc;
}
GC getGCFromCache ()
{
return (gcCachedCount>0) ? gcCache[--gcCachedCount] : null;
}
}