1 /* Copyright (C) 1999, 2000 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 import java
.awt
.Rectangle
;
15 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
17 public class Drawable
extends XID
19 private GC
[] gcCache
= new GC
[10];
20 private int gcCachedCount
= 0;
22 public Drawable(Display display
, int xid
)
28 * Gets as much as possible of the image data within the requested
29 * region. Data from obscured parts of windows may not be
32 * @param dest where to place the image data.
34 * @return the actual region of image data that was retrieved.
36 public Rectangle
copyIntoXImage(XImage dest
, Rectangle bounds
,
39 Rectangle newBounds
= null;
41 while (!bounds
.isEmpty())
43 if (copyIntoXImageImpl(dest
, bounds
.x
, bounds
.y
,
44 bounds
.width
, bounds
.height
,
48 // failed, likely due to wrong bounds...
50 newBounds
= getBounds(newBounds
);
52 bounds
= newBounds
.intersection(bounds
);
57 throw new RuntimeException("copyIntoXImage is buggy");
61 return bounds
; // always empty
67 * Performs an XGetSubImage. This method will fail if the X server
68 * does not possess the requested image data. This might occur when
69 * requesting the image date of a window that is partially obscured.
71 * @param desitantionImage where to place the image data
73 * @return false if method was unable to read the requested region.
75 private native boolean copyIntoXImageImpl(XImage destinationImage
,
77 int width
, int height
,
78 int destX
, int destY
);
80 public native Rectangle
getBounds(Rectangle rv
);
82 public native int getDepth ();
84 private static final String MSG_XGETSUBIMAGE_FAILED
=
85 "XGetSubImage() failed.";
87 protected void finalize() throws Throwable
89 // Dispose all the cached GCs, to reduce X server resource usage
90 for (int i
=0; i
<gcCachedCount
; i
++)
91 gcCache
[i
].disposeImpl ();
96 /** Put a GC in the cache for this drawable, so it can be retrieved later.
97 * @param gc The GC to put
99 void putGCInCache (GC gc
)
101 if (gcCachedCount
>= gcCache
.length
)
103 // List full - extend it to double its present size
104 GC
[] oldList
= gcCache
;
105 gcCache
= new GC
[oldList
.length
*2];
106 System
.arraycopy (oldList
,0,gcCache
,0,oldList
.length
);
108 gcCache
[gcCachedCount
++] = gc
;
111 /** Get a GC from the cache, if available
112 * @return A GC from the cache, or null if the cache is empty
116 return (gcCachedCount
>0) ? gcCache
[--gcCachedCount
] : null;