}
private static class X11WindowUtils extends NativeWindowUtils {
private static Pixmap createBitmap(final Display dpy,
X11.Window win,
Raster raster) {
final X11 x11 = X11.INSTANCE;
Rectangle bounds = raster.getBounds();
int width = bounds.x + bounds.width;
int height = bounds.y + bounds.height;
final Pixmap pm = x11.XCreatePixmap(dpy, win, width, height, 1);
final GC gc = x11.XCreateGC(dpy, pm, new NativeLong(0), null);
if (gc == null) {
return null;
}
x11.XSetForeground(dpy, gc, new NativeLong(0));
x11.XFillRectangle(dpy, pm, gc, 0, 0, width, height);
final List<Rectangle> rlist = new ArrayList<Rectangle>();
try {
RasterRangesUtils.outputOccupiedRanges(raster, new RasterRangesUtils.RangesOutput() {
public boolean outputRange(int x, int y, int w, int h) {
rlist.add(new Rectangle(x, y, w, h));
return true;
}
});
X11.XRectangle[] rects = (X11.XRectangle[])
new X11.XRectangle().toArray(rlist.size());
for (int i=0;i < rects.length;i++) {
Rectangle r = (Rectangle)rlist.get(i);
rects[i].x = (short)r.x;
rects[i].y = (short)r.y;
rects[i].width = (short)r.width;
rects[i].height = (short)r.height;
// Optimization: write directly to native memory
Pointer p = rects[i].getPointer();
p.setShort(0, (short)r.x);
p.setShort(2, (short)r.y);
p.setShort(4, (short)r.width);
p.setShort(6, (short)r.height);
rects[i].setAutoSynch(false);
// End optimization
}
final int UNMASKED = 1;
x11.XSetForeground(dpy, gc, new NativeLong(UNMASKED));
x11.XFillRectangles(dpy, pm, gc, rects, rects.length);
}
finally {
x11.XFreeGC(dpy, gc);
}
return pm;
}