summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/java/awt/peer/x/ZPixmapDataBuffer.java
blob: cf40f4d697737a11543ceaac81d14bedfaf7e119 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package gnu.java.awt.peer.x;

import gnu.x11.Display;
import gnu.x11.image.ZPixmap;

import java.awt.GraphicsEnvironment;
import java.awt.image.DataBuffer;

/**
 * A DataBuffer implementation that is based on a ZPixmap. This is used
 * as backing store for BufferedImages.
 */
class ZPixmapDataBuffer
  extends DataBuffer
{

  /**
   * The backing ZPixmap.
   */
  private ZPixmap zpixmap;

  /**
   * Creates a new ZPixmapDataBuffer with a specified width and height.
   *
   * @param d the X display
   * @param w the width
   * @param h the height
   */
  ZPixmapDataBuffer(int w, int h)
  {
    super(TYPE_BYTE, w * h * 3); // TODO: Support non-24-bit-resolutions.
    GraphicsEnvironment env =
      GraphicsEnvironment.getLocalGraphicsEnvironment();
    XGraphicsDevice dev = (XGraphicsDevice) env.getDefaultScreenDevice();
    Display d = dev.getDisplay();
    zpixmap = new ZPixmap(d, w, h, d.default_pixmap_format);
  }

  /**
   * Creates a ZPixmapDataBuffer from an existing ZPixmap.
   *
   * @param zpixmap the ZPixmap to wrap
   */
  ZPixmapDataBuffer(ZPixmap zpixmap)
  {
    super(TYPE_BYTE, zpixmap.get_data_length());
    this.zpixmap = zpixmap;
  }

  @Override
  public int getElem(int bank, int i)
  {
    return 0xff & zpixmap.get_data_element(i);
  }

  @Override
  public void setElem(int bank, int i, int val)
  {
    zpixmap.set_data_element(i, (byte) val);
  }

  ZPixmap getZPixmap()
  {
    return zpixmap;
  }

}