Index: libjava/Makefile.am =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/Makefile.am,v retrieving revision 1.298 diff -u -r1.298 Makefile.am --- libjava/Makefile.am 11 Jun 2003 18:20:39 -0000 1.298 +++ libjava/Makefile.am 19 Jun 2003 15:04:06 -0000 @@ -2635,6 +2635,7 @@ gnu/awt/xlib/XFramePeer.java \ gnu/awt/xlib/XGraphics.java \ gnu/awt/xlib/XGraphicsConfiguration.java \ +gnu/awt/xlib/XOffScreenImage.java \ gnu/awt/xlib/XPanelPeer.java \ gnu/awt/xlib/XToolkit.java Index: libjava/Makefile.in =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/Makefile.in,v retrieving revision 1.322 diff -u -r1.322 Makefile.in --- libjava/Makefile.in 11 Jun 2003 18:27:39 -0000 1.322 +++ libjava/Makefile.in 19 Jun 2003 15:04:12 -0000 @@ -2397,6 +2397,7 @@ gnu/awt/xlib/XFramePeer.java \ gnu/awt/xlib/XGraphics.java \ gnu/awt/xlib/XGraphicsConfiguration.java \ +gnu/awt/xlib/XOffScreenImage.java \ gnu/awt/xlib/XPanelPeer.java \ gnu/awt/xlib/XToolkit.java @@ -2688,10 +2689,11 @@ .deps/gnu/awt/xlib/XFontMetrics.P .deps/gnu/awt/xlib/XFramePeer.P \ .deps/gnu/awt/xlib/XGraphics.P \ .deps/gnu/awt/xlib/XGraphicsConfiguration.P \ -.deps/gnu/awt/xlib/XPanelPeer.P .deps/gnu/awt/xlib/XToolkit.P \ -.deps/gnu/classpath/Configuration.P .deps/gnu/gcj/Core.P \ -.deps/gnu/gcj/RawData.P .deps/gnu/gcj/convert/BytesToUnicode.P \ -.deps/gnu/gcj/convert/Convert.P .deps/gnu/gcj/convert/IOConverter.P \ +.deps/gnu/awt/xlib/XOffScreenImage.P .deps/gnu/awt/xlib/XPanelPeer.P \ +.deps/gnu/awt/xlib/XToolkit.P .deps/gnu/classpath/Configuration.P \ +.deps/gnu/gcj/Core.P .deps/gnu/gcj/RawData.P \ +.deps/gnu/gcj/convert/BytesToUnicode.P .deps/gnu/gcj/convert/Convert.P \ +.deps/gnu/gcj/convert/IOConverter.P \ .deps/gnu/gcj/convert/Input_8859_1.P \ .deps/gnu/gcj/convert/Input_ASCII.P \ .deps/gnu/gcj/convert/Input_EUCJIS.P \ Index: libjava/gnu/awt/j2d/IntegerGraphicsState.java =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/gnu/awt/j2d/IntegerGraphicsState.java,v retrieving revision 1.4 diff -u -r1.4 IntegerGraphicsState.java --- libjava/gnu/awt/j2d/IntegerGraphicsState.java 12 Jun 2003 03:08:58 -0000 1.4 +++ libjava/gnu/awt/j2d/IntegerGraphicsState.java 19 Jun 2003 15:04:13 -0000 @@ -44,6 +44,19 @@ DirectRasterGraphics directGfx; Shape clip; + /** Interface for images which are coupled to a GraphicsConfiguration, + * as is typically the case for an off-screen buffer used in + * double-buffering. Any image which implements this interface is + * rendered directly by DirectRasterGraphics (i.e. by directGfx.drawImage) + */ + public interface ScreenCoupledImage + { + /** Get the GraphicsConfiguration to which this image is coupled + * @return the GraphicsConfiguration + */ + GraphicsConfiguration getGraphicsConfiguration (); + } + public IntegerGraphicsState(DirectRasterGraphics directGfx) { this.directGfx = directGfx; @@ -245,66 +258,72 @@ x += tx; y += ty; + if (image instanceof ScreenCoupledImage) + { + GraphicsConfiguration config + = ((ScreenCoupledImage)image).getGraphicsConfiguration (); + if (config == frontend.config) + return directGfx.drawImage (image, x, y, observer); + } if (image instanceof BufferedImage) + { + BufferedImage bImage = (BufferedImage) image; + // FIXME: eliminate? ScreenCoupledImage is probably more efficient + Object config = bImage.getProperty ("java.awt.GraphicsConfiguration"); + if (config == frontend.config) + return directGfx.drawImage (image, x, y, observer); + + int width = image.getWidth (null); + int height = image.getHeight (null); + + Rectangle bounds = new Rectangle (x, y, width, height); + + MappedRaster mr = directGfx.mapRaster (bounds); + + // manipulate raster here... + ColorModel colorModel = mr.getColorModel (); + WritableRaster raster = mr.getRaster (); + + int xEnd = x + width; + int yEnd = y + height; + + // FIXME: Use the following code only as a fallback. It's SLOW! + + Object rgbElem = null; + for (int yy=0; yy>> 24) & 0xff) + 1; - int sr = ((srgb >>> 16) & 0xff) + 1; - int sg = ((srgb >>> 8) & 0xff) + 1; - int sb = (srgb & 0xff) + 1; - - rgbElem = raster.getDataElements(xx+x, yy+y, rgbElem); - int drgb = colorModel.getRGB(rgbElem); - int dr = ((drgb >>> 16) & 0xff) + 1; - int dg = ((drgb >>> 8) & 0xff) + 1; - int db = (drgb & 0xff) + 1; - int da = 256 - sa; - - dr = ((sr*sa + dr*da) >>> 8) - 1; - dg = ((sg*sa + dg*da) >>> 8) - 1; - db = ((sb*sa + db*da) >>> 8) - 1; - - drgb = (dr<<16) | (dg<<8) | db; - - rgbElem = colorModel.getDataElements(drgb, rgbElem); - - raster.setDataElements(xx+x, yy+y, rgbElem); - } - } - directGfx.unmapRaster(mr); - return true; - + for (int xx=0; xx>> 24) & 0xff) + 1; + int sr = ((srgb >>> 16) & 0xff) + 1; + int sg = ((srgb >>> 8) & 0xff) + 1; + int sb = (srgb & 0xff) + 1; + + rgbElem = raster.getDataElements (xx+x, yy+y, rgbElem); + int drgb = colorModel.getRGB (rgbElem); + int dr = ((drgb >>> 16) & 0xff) + 1; + int dg = ((drgb >>> 8) & 0xff) + 1; + int db = (drgb & 0xff) + 1; + int da = 256 - sa; + + dr = ((sr*sa + dr*da) >>> 8) - 1; + dg = ((sg*sa + dg*da) >>> 8) - 1; + db = ((sb*sa + db*da) >>> 8) - 1; + + drgb = (dr<<16) | (dg<<8) | db; + + rgbElem = colorModel.getDataElements (drgb, rgbElem); + + raster.setDataElements (xx+x, yy+y, rgbElem); + } } - throw new UnsupportedOperationException("drawing image " + image + - "not implemented"); + directGfx.unmapRaster (mr); + return true; + + } + throw new UnsupportedOperationException ("drawing image " + image + + "not implemented"); } Index: libjava/gnu/awt/xlib/XCanvasPeer.java =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/gnu/awt/xlib/XCanvasPeer.java,v retrieving revision 1.3 diff -u -r1.3 XCanvasPeer.java --- libjava/gnu/awt/xlib/XCanvasPeer.java 1 Mar 2003 22:14:20 -0000 1.3 +++ libjava/gnu/awt/xlib/XCanvasPeer.java 19 Jun 2003 15:04:13 -0000 @@ -214,7 +214,7 @@ } public Image createImage(int width, int height) { - throw new UnsupportedOperationException("FIXME, not implemented"); + return new XOffScreenImage (config, window, width, height); } public void dispose() { Index: libjava/gnu/awt/xlib/XEventLoop.java =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/gnu/awt/xlib/XEventLoop.java,v retrieving revision 1.1 diff -u -r1.1 XEventLoop.java --- libjava/gnu/awt/xlib/XEventLoop.java 22 Oct 2000 17:46:09 -0000 1.1 +++ libjava/gnu/awt/xlib/XEventLoop.java 19 Jun 2003 15:04:14 -0000 @@ -127,57 +127,66 @@ * AWT event. */ - AWTEvent createEvent() + AWTEvent createEvent () { + int type = anyEvent.getType (); + // Ignore some events without further processing + switch (type) + { + // ignore "no expose" events, which are generated whenever a pixmap + // is copied to copied to a window which is entirely unobscured + case XAnyEvent.TYPE_NO_EXPOSE: + case XAnyEvent.TYPE_UNMAP_NOTIFY: // ignore for now + case XAnyEvent.TYPE_MAP_NOTIFY: // ignore for now + case XAnyEvent.TYPE_REPARENT_NOTIFY: // ignore for now + return null; + default: + break; // continue processing events not in ignore list + } /* avoid attempting to get client data before client data has been set. */ Object peer; synchronized (this) - { - peer = anyEvent.getWindow().getClientData(); - } - + { + peer = anyEvent.getWindow ().getClientData (); + } + Component source = null; - + // Try to identify source component - + if (peer instanceof XCanvasPeer) - { - source = ((XCanvasPeer) peer).getComponent(); - } - + { + source = ((XCanvasPeer) peer).getComponent (); + } + if (source == null) - { - String msg = "unable to locate source for event (" + - anyEvent + ")"; - throw new RuntimeException(msg); - } - + { + String msg = "unable to locate source for event (" + + anyEvent + "): peer=" + peer; + throw new RuntimeException (msg); + } + /* if a mapping from anyEvent to AWTEvent is possible, construct a new AWTEvent and return it. */ - - int type = anyEvent.getType(); + switch (type) - { + { case XAnyEvent.TYPE_EXPOSE: - return createPaintEvent(source); + return createPaintEvent (source); case XAnyEvent.TYPE_BUTTON_PRESS: case XAnyEvent.TYPE_BUTTON_RELEASE: - return createMouseEvent(type, source); - case XAnyEvent.TYPE_UNMAP_NOTIFY: - case XAnyEvent.TYPE_MAP_NOTIFY: - case XAnyEvent.TYPE_REPARENT_NOTIFY: - return null; // ignore for now + return createMouseEvent (type, source); case XAnyEvent.TYPE_CONFIGURE_NOTIFY: - configureNotify(peer); - return null; - + configureNotify (peer); + return null; + default: - String msg = "Do no know how to handle event (" + anyEvent + ")"; - throw new RuntimeException(msg); - } + String msg = "Do no know how to handle event (" + anyEvent + ")"; + throw new RuntimeException (msg); + } } - + AWTEvent createPaintEvent(Component src) { XExposeEvent expose = new XExposeEvent(anyEvent); Index: libjava/gnu/awt/xlib/XGraphics.java =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/gnu/awt/xlib/XGraphics.java,v retrieving revision 1.4 diff -u -r1.4 XGraphics.java --- libjava/gnu/awt/xlib/XGraphics.java 12 Jun 2003 03:08:58 -0000 1.4 +++ libjava/gnu/awt/xlib/XGraphics.java 19 Jun 2003 15:04:14 -0000 @@ -20,6 +20,7 @@ import gnu.gcj.xlib.Drawable; import gnu.gcj.xlib.Window; import gnu.gcj.xlib.Drawable; +import gnu.gcj.xlib.Pixmap; import gnu.gcj.xlib.Visual; import gnu.awt.j2d.DirectRasterGraphics; import gnu.awt.j2d.MappedRaster; @@ -191,6 +192,16 @@ public boolean drawImage(Image img, int x, int y, ImageObserver observer) { + if (img instanceof XOffScreenImage) + { + // FIXME: have to enforce clip, or is it OK as-is? + XGraphicsConfiguration.XOffScreenImage offScreenImage + = ((XGraphicsConfiguration.XOffScreenImage)img); + Pixmap pixmap = offScreenImage.getPixmap (); + context.copyArea (pixmap, 0, 0, x, y, + offScreenImage.getWidth (), offScreenImage.getHeight ()); + return true; + } if (clipBounds == null) return false; // ***FIXME*** Index: libjava/gnu/awt/xlib/XOffScreenImage.java =================================================================== RCS file: libjava/gnu/awt/xlib/XOffScreenImage.java diff -N libjava/gnu/awt/xlib/XOffScreenImage.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ libjava/gnu/awt/xlib/XOffScreenImage.java 19 Jun 2003 18:23:28 -0000 @@ -0,0 +1,175 @@ +/* Copyright (C) 2000, 2003 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.awt.xlib; + +import java.awt.Image; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.image.ColorModel; +import java.awt.image.ImageObserver; +import java.awt.image.ImageProducer; +import java.util.Hashtable; +import gnu.awt.j2d.DirectRasterGraphics; +import gnu.awt.j2d.Graphics2DImpl; +import gnu.awt.j2d.IntegerGraphicsState; +import gnu.gcj.xlib.Drawable; +import gnu.gcj.xlib.Pixmap; +import gnu.gcj.xlib.Screen; +import gnu.gcj.xlib.Visual; + +/** Image class for xlib off-screen buffers. + * The image is stored in a server-side pixmap for best performance. + * This class supports getGraphics, so you can draw on the pixmap, and is + * specially handled when doing drawImage, so that the image copy is done + * entirely in the X server. + * This class does not support rasterization, for which you'd need an XImage. + * + * @author scott gilbertson + */ +public class XOffScreenImage extends Image + implements IntegerGraphicsState.ScreenCoupledImage +{ + private Pixmap pixmap; + private XGraphicsConfiguration config; + private int width; + private int height; + + /** Create a new XOffScreenImage + * @param config Graphics configuration, to compare against on-screen + * components and to create the appropriate Graphics + * @param drawable The drawable with which the image is compatible + * @param width The width of the image + * @param height The height of the image + */ + XOffScreenImage (XGraphicsConfiguration config, Drawable drawable, int width, int height) + { + this.config = config; + this.width = width; + this.height = height; + pixmap = new Pixmap (drawable, width, height, drawable.getDepth ()); + } + + /** Get the pixmap which contains this image + * @return The pixmap + */ + public Pixmap getPixmap () + { + return pixmap; + } + + /** Flushes (that is, destroys) any resources used for this image. This + * includes the actual image data. + */ + public void flush () + { + // FIXME: should dispose pixmap + pixmap = null; + } + + /** Returns a graphics context object for drawing an off-screen object. + * This method is only valid for off-screen objects. + * + * @return a graphics context object for an off-screen object + * @see Graphics#createImage(int, int) + */ + public Graphics getGraphics () + { + DirectRasterGraphics gfxDevice = new XGraphics (pixmap, config); + IntegerGraphicsState igState = new IntegerGraphicsState (gfxDevice); + Graphics2DImpl gfx2d = new Graphics2DImpl (config); + gfx2d.setState (igState); + return gfx2d; + } + + /** Returns the height of the image, or -1 if it is unknown. If the + * image height is unknown, the observer object will be notified when + * the value is known. + * + * @param observer the image observer for this object + * @return the height in pixels + * @see #getWidth(ImageObserver) + */ + public int getHeight (ImageObserver observer) + { + return height; + } + + /** Returns the height of the image, or -1 if it is unknown. If the + * image height is unknown, the observer object will be notified when + * the value is known. + * + * @return the height in pixels + * @see #getWidth() + */ + public int getHeight () + { + return height; + } + + /** Returns the image producer object for this object. The producer is the + * object which generates pixels for this image. + * + * @return the image producer for this object + */ + public ImageProducer getSource () + { + throw new UnsupportedOperationException ("getSource not supported"); + } + + /** Returns the width of the image, or -1 if it is unknown. If the + * image width is unknown, the observer object will be notified when + * the value is known. + * + * @param observer the image observer for this object + * @return the width in pixels + * @see #getHeight(ImageObserver) + */ + public int getWidth (ImageObserver observer) + { + return width; + } + + /** Returns the width of the image, or -1 if it is unknown. If the + * image width is unknown, the observer object will be notified when + * the value is known. + * + * @return the width in pixels + * @see #getHeight() + */ + public int getWidth () + { + return width; + } + + /** This method requests a named property for an object. The value of the + * property is returned. The value UndefinedProperty is + * returned if there is no property with the specified name. The value + * null is returned if the properties for the object are + * not yet known. In this case, the specified image observer is notified + * when the properties are known. + * + * @param name the requested property name + * @param observer the image observer for this object + * @return the named property, if available + * @see #UndefinedProperty + */ + public Object getProperty (String name, ImageObserver observer) + { + return null; + } + + /** Get the GraphicsConfiguration to which this image is coupled + * @return the GraphicsConfiguration + */ + public GraphicsConfiguration getGraphicsConfiguration () + { + return config; + } +} Index: libjava/gnu/gcj/xlib/Drawable.java =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/gnu/gcj/xlib/Drawable.java,v retrieving revision 1.2 diff -u -r1.2 Drawable.java --- libjava/gnu/gcj/xlib/Drawable.java 19 Apr 2003 19:54:39 -0000 1.2 +++ libjava/gnu/gcj/xlib/Drawable.java 19 Jun 2003 15:04:15 -0000 @@ -79,6 +79,8 @@ public native Rectangle getBounds(Rectangle rv); + public native int getDepth (); + private static final String MSG_XGETSUBIMAGE_FAILED = "XGetSubImage() failed."; Index: libjava/gnu/gcj/xlib/GC.java =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/gnu/gcj/xlib/GC.java,v retrieving revision 1.4 diff -u -r1.4 GC.java --- libjava/gnu/gcj/xlib/GC.java 12 Jun 2003 03:08:58 -0000 1.4 +++ libjava/gnu/gcj/xlib/GC.java 19 Jun 2003 15:04:15 -0000 @@ -130,6 +130,11 @@ int destX, int destY, int width, int height); + public native void copyArea (Drawable source, + int srcX, int srcY, + int destX, int destY, + int width, int height); + public Drawable getDrawable() { return target; Index: libjava/gnu/gcj/xlib/XAnyEvent.java =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/gnu/gcj/xlib/XAnyEvent.java,v retrieving revision 1.1 diff -u -r1.1 XAnyEvent.java --- libjava/gnu/gcj/xlib/XAnyEvent.java 22 Oct 2000 17:46:09 -0000 1.1 +++ libjava/gnu/gcj/xlib/XAnyEvent.java 19 Jun 2003 15:04:15 -0000 @@ -19,14 +19,40 @@ public final class XAnyEvent { // Must match the definitions in X.h: - public static final int TYPE_BUTTON_PRESS = 4, - TYPE_BUTTON_RELEASE = 5, - TYPE_EXPOSE = 12, - TYPE_UNMAP_NOTIFY = 18, - TYPE_MAP_NOTIFY = 19, - TYPE_REPARENT_NOTIFY = 21, - TYPE_CONFIGURE_NOTIFY = 22, - TYPE_CLIENT_MESSAGE = 33; + public static final int + TYPE_KEY_PRESS = 2, + TYPE_KEY_RELEASE = 3, + TYPE_BUTTON_PRESS = 4, + TYPE_BUTTON_RELEASE = 5, + TYPE_MOTION_NOTIFY = 6, + TYPE_ENTER_NOTIFY = 7, + TYPE_LEAVE_NOTIFY = 8, + TYPE_FOCUS_IN = 9, + TYPE_FOCUS_OUT = 10, + TYPE_KEYMAP_NOTIFY = 11, + TYPE_EXPOSE = 12, + TYPE_GRAPHICS_EXPOSE = 13, + TYPE_NO_EXPOSE = 14, + TYPE_VISIBILITY_NOTIFY = 15, + TYPE_CREATE_NOTIFY = 16, + TYPE_DESTROY_NOTIFY = 17, + TYPE_UNMAP_NOTIFY = 18, + TYPE_MAP_NOTIFY = 19, + TYPE_MAP_REQUEST = 20, + TYPE_REPARENT_NOTIFY = 21, + TYPE_CONFIGURE_NOTIFY = 22, + TYPE_CONFIGURE_REQUEST = 23, + TYPE_GRAVITY_NOTIFY = 24, + TYPE_RESIZE_REQUEST = 25, + TYPE_CIRCULATE_NOTIFY = 26, + TYPE_CIRCULATE_REQUEST = 27, + TYPE_PROPERTY_NOTIFY = 28, + TYPE_SELECTION_CLEAR = 29, + TYPE_SELECTION_REQUEST = 30, + TYPE_SELECTION_NOTIFY = 31, + TYPE_COLORMAP_NOTIFY = 32, + TYPE_CLIENT_MESSAGE = 33, + TYPE_MAPPING_NOTIFY = 34; // Must match the definitions in X.h: public final static long MASK_SUBSTRUCTURE_NOTIFY = 1L<<19, Index: libjava/gnu/gcj/xlib/natDrawable.cc =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/gnu/gcj/xlib/natDrawable.cc,v retrieving revision 1.2 diff -u -r1.2 natDrawable.cc --- libjava/gnu/gcj/xlib/natDrawable.cc 26 Mar 2001 07:05:32 -0000 1.2 +++ libjava/gnu/gcj/xlib/natDrawable.cc 19 Jun 2003 15:04:15 -0000 @@ -43,6 +43,26 @@ return true; } +jint gnu::gcj::xlib::Drawable::getDepth () +{ + ::Display* dpy = (::Display*) (getDisplay ()->display); + ::Window root; + int x, y; + unsigned int w, h, bw, depth; + + Status status = XGetGeometry (dpy, getXID(), &root, + &x, &y, &w, &h, + &bw, &depth); + switch (status) + { + case BadDrawable: + throw new XException (display, status); + default: + ; // All OK, NOP. + } + return (jint)depth; +} + java::awt::Rectangle* gnu::gcj::xlib::Drawable::getBounds(java::awt::Rectangle* rv) { Index: libjava/gnu/gcj/xlib/natGC.cc =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/gnu/gcj/xlib/natGC.cc,v retrieving revision 1.6 diff -u -r1.6 natGC.cc --- libjava/gnu/gcj/xlib/natGC.cc 12 Jun 2003 03:08:58 -0000 1.6 +++ libjava/gnu/gcj/xlib/natGC.cc 19 Jun 2003 15:04:15 -0000 @@ -237,3 +237,18 @@ ordering); // no fast fail } + +void gnu::gcj::xlib::GC::copyArea (gnu::gcj::xlib::Drawable * source, + jint srcX, jint srcY, + jint destX, jint destY, + jint width, jint height) +{ + Display* display = target->getDisplay (); + ::Display* dpy = (::Display*) (display->display); + ::Drawable drawableXID = target->getXID (); + ::GC gc = (::GC) structure; + ::Drawable srcXID = source->getXID (); + + XCopyArea (dpy, srcXID, drawableXID, gc, srcX, srcY, width, height, + destX, destY); +} Index: libjava/java/awt/Component.java =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/java/awt/Component.java,v retrieving revision 1.25 diff -u -r1.25 Component.java --- libjava/java/awt/Component.java 2 Mar 2003 14:31:39 -0000 1.25 +++ libjava/java/awt/Component.java 19 Jun 2003 15:04:21 -0000 @@ -1865,12 +1865,17 @@ * @param height the height of the image * @return the requested image, or null if it is not supported */ - public Image createImage(int width, int height) + public Image createImage (int width, int height) { - if (GraphicsEnvironment.isHeadless()) - return null; - GraphicsConfiguration config = getGraphicsConfiguration(); - return config == null ? null : config.createCompatibleImage(width, height); + Image returnValue = null; + if (!GraphicsEnvironment.isHeadless ()) + { + if (isLightweight () && parent != null) + returnValue = parent.createImage (width, height); + else if (peer != null) + returnValue = peer.createImage (width, height); + } + return returnValue; } /**