libjava/
[official-gcc.git] / libjava / classpath / gnu / java / awt / peer / x / ZPixmapDataBuffer.java
blobcf40f4d697737a11543ceaac81d14bedfaf7e119
1 package gnu.java.awt.peer.x;
3 import gnu.x11.Display;
4 import gnu.x11.image.ZPixmap;
6 import java.awt.GraphicsEnvironment;
7 import java.awt.image.DataBuffer;
9 /**
10 * A DataBuffer implementation that is based on a ZPixmap. This is used
11 * as backing store for BufferedImages.
13 class ZPixmapDataBuffer
14 extends DataBuffer
17 /**
18 * The backing ZPixmap.
20 private ZPixmap zpixmap;
22 /**
23 * Creates a new ZPixmapDataBuffer with a specified width and height.
25 * @param d the X display
26 * @param w the width
27 * @param h the height
29 ZPixmapDataBuffer(int w, int h)
31 super(TYPE_BYTE, w * h * 3); // TODO: Support non-24-bit-resolutions.
32 GraphicsEnvironment env =
33 GraphicsEnvironment.getLocalGraphicsEnvironment();
34 XGraphicsDevice dev = (XGraphicsDevice) env.getDefaultScreenDevice();
35 Display d = dev.getDisplay();
36 zpixmap = new ZPixmap(d, w, h, d.default_pixmap_format);
39 /**
40 * Creates a ZPixmapDataBuffer from an existing ZPixmap.
42 * @param zpixmap the ZPixmap to wrap
44 ZPixmapDataBuffer(ZPixmap zpixmap)
46 super(TYPE_BYTE, zpixmap.get_data_length());
47 this.zpixmap = zpixmap;
50 @Override
51 public int getElem(int bank, int i)
53 return 0xff & zpixmap.get_data_element(i);
56 @Override
57 public void setElem(int bank, int i, int val)
59 zpixmap.set_data_element(i, (byte) val);
62 ZPixmap getZPixmap()
64 return zpixmap;