This implements VolatileImage and DataBuffer for the Escher peers.
2007-07-13 Roman Kennke <[EMAIL PROTECTED]> * gnu/java/awt/peer/x/PixmapVolatileImage.java: New class. * gnu/java/awt/peer/x/XGraphicsConfiguration.java (createCompatibleImage(int,int)): Delegate to the 3-int overload. (createCompatibleImage(int,int,int)): Implemented. Using the ZPixmapDataBuffer for OPAQUE images. (createCompatibleVolatileImage(int,int)): Delegate to the 3-int overload. (createCompatibleVolatileImage(int,int,int)): Implemented. Using PixmapVolatileImage. * gnu/java/awt/peer/x/XWindowPeer.java (createImage): Return a PixmapVolatileImage (for now). (createVolatileImage): Implemented, using PixmapVolatileImage. * gnu/java/awt/peer/x/ZPixmapDataBuffer.java New class. /Roman -- Dipl.-Inform. (FH) Roman Kennke, Software Engineer, http://kennke.org aicas Allerton Interworks Computer Automated Systems GmbH Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany http://www.aicas.com * Tel: +49-721-663 968-0 USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe Geschäftsführer: Dr. James J. Hunt
? gnu/java/awt/peer/x/PixmapVolatileImage.java ? gnu/java/awt/peer/x/ZPixmapDataBuffer.java Index: gnu/java/awt/peer/x/XGraphicsConfiguration.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XGraphicsConfiguration.java,v retrieving revision 1.1 diff -u -1 -0 -r1.1 XGraphicsConfiguration.java --- gnu/java/awt/peer/x/XGraphicsConfiguration.java 29 Jun 2006 15:15:56 -0000 1.1 +++ gnu/java/awt/peer/x/XGraphicsConfiguration.java 13 Jul 2007 19:32:25 -0000 @@ -32,64 +32,107 @@ module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package gnu.java.awt.peer.x; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; +import java.awt.Point; import java.awt.Rectangle; +import java.awt.Transparency; +import java.awt.color.ColorSpace; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; +import java.awt.image.ComponentColorModel; +import java.awt.image.ComponentSampleModel; +import java.awt.image.DataBuffer; +import java.awt.image.Raster; +import java.awt.image.SampleModel; import java.awt.image.VolatileImage; +import java.awt.image.WritableRaster; public class XGraphicsConfiguration extends GraphicsConfiguration { XGraphicsDevice device; XGraphicsConfiguration(XGraphicsDevice dev) { device = dev; } public GraphicsDevice getDevice() { return device; } public BufferedImage createCompatibleImage(int w, int h) { - return new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); + return createCompatibleImage(w, h, Transparency.OPAQUE); } - public VolatileImage createCompatibleVolatileImage(int w, int h) + public BufferedImage createCompatibleImage(int w, int h, int transparency) { - // TODO: Implement this. - throw new UnsupportedOperationException("Not yet implemented."); + BufferedImage bi; + switch (transparency) + { + case Transparency.OPAQUE: + DataBuffer buffer = new ZPixmapDataBuffer(w, h); + SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, + 4, w * 4, + new int[]{0, 1, 2, 3 }); + ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB); + ColorModel cm = new ComponentColorModel(cs, true, false, + Transparency.OPAQUE, + DataBuffer.TYPE_BYTE); + WritableRaster raster = Raster.createWritableRaster(sm, buffer, + new Point(0, 0)); + bi = new BufferedImage(cm, raster, false, null); + break; + case Transparency.BITMASK: + case Transparency.TRANSLUCENT: + bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); + break; + default: + throw new IllegalArgumentException("Illegal transparency: " + + transparency); + } + return bi; } - public VolatileImage createCompatibleVolatileImage(int width, int height, - int transparency) + public VolatileImage createCompatibleVolatileImage(int w, int h) { - // TODO: Implement this. - throw new UnsupportedOperationException("Not yet implemented."); + return createCompatibleVolatileImage(w, h, Transparency.OPAQUE); } - public BufferedImage createCompatibleImage(int w, int h, int transparency) + public VolatileImage createCompatibleVolatileImage(int width, int height, + int transparency) { - // TODO: Implement this. - throw new UnsupportedOperationException("Not yet implemented."); + VolatileImage im; + switch (transparency) + { + case Transparency.OPAQUE: + im = new PixmapVolatileImage(width, height); + break; + case Transparency.BITMASK: + case Transparency.TRANSLUCENT: + throw new UnsupportedOperationException("Not yet implemented"); + default: + throw new IllegalArgumentException("Unknown transparency type: " + + transparency); + } + return im; } public ColorModel getColorModel() { // TODO: Implement this. throw new UnsupportedOperationException("Not yet implemented."); } public ColorModel getColorModel(int transparency) { Index: gnu/java/awt/peer/x/XWindowPeer.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XWindowPeer.java,v retrieving revision 1.3 diff -u -1 -0 -r1.3 XWindowPeer.java --- gnu/java/awt/peer/x/XWindowPeer.java 30 Apr 2007 20:30:56 -0000 1.3 +++ gnu/java/awt/peer/x/XWindowPeer.java 13 Jul 2007 19:32:25 -0000 @@ -36,26 +36,30 @@ exception statement from your version. */ package gnu.java.awt.peer.x; import java.awt.Component; import java.awt.EventQueue; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; import java.awt.Image; import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.PaintEvent; import java.awt.event.WindowEvent; +import java.awt.image.VolatileImage; import gnu.x11.Window; import gnu.x11.event.Event; import gnu.java.awt.peer.swing.SwingWindowPeer; public class XWindowPeer extends SwingWindowPeer { @@ -133,21 +137,31 @@ * * @return a XGraphics suitable for drawing on this frame */ public Graphics getGraphics() { return new XGraphics2D(xwindow); } public Image createImage(int w, int h) { - return new XImage(w, h); + // FIXME: Should return a buffered image. + return createVolatileImage(w, h); + } + + @Override + public VolatileImage createVolatileImage(int width, int height) + { + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice gd = ge.getDefaultScreenDevice(); + GraphicsConfiguration gc = gd.getDefaultConfiguration(); + return gc.createCompatibleVolatileImage(width, height); } /** * Makes the component visible. This is called by [EMAIL PROTECTED] Component#show()}. * * This is implemented to call setVisible(true) on the Swing component. */ public void show() { // // Prevent ResizeRedirect events.