aboutsummaryrefslogtreecommitdiff
path: root/libjava/gnu/awt
diff options
context:
space:
mode:
authorScott Gilbertson <scottg@mantatest.com>2003-08-25 19:02:29 +0000
committerScott Gilbertson <sgilbertson@gcc.gnu.org>2003-08-25 19:02:29 +0000
commit81f7282f978588f883d8363e8cd5e69d090bc331 (patch)
treecf8eb4ec21e611ee7dbea198fd5f8dce39ee903d /libjava/gnu/awt
parent1281fe11033eebaaa8a4fbc70770eca204c9c504 (diff)
downloadgcc-81f7282f978588f883d8363e8cd5e69d090bc331.zip
gcc-81f7282f978588f883d8363e8cd5e69d090bc331.tar.gz
gcc-81f7282f978588f883d8363e8cd5e69d090bc331.tar.bz2
Makefile.am: added gnu/awt/xlib/XOffScreenImage.java.
* Makefile.am: added gnu/awt/xlib/XOffScreenImage.java. * Makefile.in: re-generated. * gnu/awt/j2d/IntegerGraphicsState.java (ScreenCoupledImage): new interface. (drawImage): detect ScreenCoupledImage instances. * gnu/awt/xlib/XCanvasPeer.java (createImage) implemented. * gnu/awt/xlib/XEventLoop.java (createEvent): re-formatted, and rearranged to avoid null pointer. * gnu/awt/xlib/XGraphics.java (drawImage): added XOffScreenImage handling. * gnu/awt/xlib/XOffScreenImage.java: new file. * gnu/gcj/xlib/Drawable.java (getDepth): new native method. * gnu/gcj/xlib/GC.java (copyArea): new native method. * gnu/gcj/xlib/XAnyEvent.java (TYPE_KEY_PRESS): new constant. (TYPE_KEY_RELEASE): new constant. (TYPE_MOTION_NOTIFY): new constant. (TYPE_ENTER_NOTIFY): new constant. (TYPE_LEAVE_NOTIFY): new constant. (TYPE_FOCUS_IN): new constant. (TYPE_FOCUS_OUT): new constant. (TYPE_KEYMAP_NOTIFY): new constant. (TYPE_GRAPHICS_EXPOSE): new constant. (TYPE_NO_EXPOSE): new constant. (TYPE_VISIBILITY_NOTIFY): new constant. (TYPE_CREATE_NOTIFY): new constant. (TYPE_DESTROY_NOTIFY): new constant. (TYPE_MAP_REQUEST): new constant. (TYPE_CONFIGURE_REQUEST): new constant. (TYPE_GRAVITY_NOTIFY): new constant. (TYPE_RESIZE_REQUEST): new constant. (TYPE_CIRCULATE_NOTIFY): new constant. (TYPE_CIRCULATE_REQUEST): new constant. (TYPE_PROPERTY_NOTIFY): new constant. (TYPE_SELECTION_CLEAR): new constant. (TYPE_SELECTION_REQUEST): new constant. (TYPE_SELECTION_NOTIFY): new constant. (TYPE_COLORMAP_NOTIFY): new constant. (TYPE_MAPPING_NOTIFY): new constant. * gnu/gcj/xlib/natDrawable.cc (getDepth): new method. * gnu/gcj/xlib/natGC.cc (copyArea): new method * java/awt/Component.java (createImage): changed to use peer method. From-SVN: r70776
Diffstat (limited to 'libjava/gnu/awt')
-rw-r--r--libjava/gnu/awt/j2d/IntegerGraphicsState.java133
-rw-r--r--libjava/gnu/awt/xlib/XCanvasPeer.java2
-rw-r--r--libjava/gnu/awt/xlib/XEventLoop.java75
-rw-r--r--libjava/gnu/awt/xlib/XGraphics.java11
-rw-r--r--libjava/gnu/awt/xlib/XOffScreenImage.java175
5 files changed, 305 insertions, 91 deletions
diff --git a/libjava/gnu/awt/j2d/IntegerGraphicsState.java b/libjava/gnu/awt/j2d/IntegerGraphicsState.java
index 3befcb4..4eb4c61 100644
--- a/libjava/gnu/awt/j2d/IntegerGraphicsState.java
+++ b/libjava/gnu/awt/j2d/IntegerGraphicsState.java
@@ -44,6 +44,19 @@ public class IntegerGraphicsState extends AbstractGraphicsState
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 @@ public class IntegerGraphicsState extends AbstractGraphicsState
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<height; yy++)
{
- BufferedImage bImage = (BufferedImage) image;
- 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<height; yy++)
- {
- for (int xx=0; xx<width; xx++)
- {
- int srgb = bImage.getRGB(xx, yy);
- int sa = ((srgb >>> 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<width; xx++)
+ {
+ int srgb = bImage.getRGB (xx, yy);
+ int sa = ((srgb >>> 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");
}
diff --git a/libjava/gnu/awt/xlib/XCanvasPeer.java b/libjava/gnu/awt/xlib/XCanvasPeer.java
index 4c141a4..6ecf7bf 100644
--- a/libjava/gnu/awt/xlib/XCanvasPeer.java
+++ b/libjava/gnu/awt/xlib/XCanvasPeer.java
@@ -214,7 +214,7 @@ public class XCanvasPeer implements CanvasPeer
}
public Image createImage(int width, int height)
{
- throw new UnsupportedOperationException("FIXME, not implemented");
+ return new XOffScreenImage (config, window, width, height);
}
public void dispose()
{
diff --git a/libjava/gnu/awt/xlib/XEventLoop.java b/libjava/gnu/awt/xlib/XEventLoop.java
index ad5e963..5f5026b 100644
--- a/libjava/gnu/awt/xlib/XEventLoop.java
+++ b/libjava/gnu/awt/xlib/XEventLoop.java
@@ -118,57 +118,66 @@ public class XEventLoop implements Runnable
* 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);
diff --git a/libjava/gnu/awt/xlib/XGraphics.java b/libjava/gnu/awt/xlib/XGraphics.java
index b861402..e27b0a1 100644
--- a/libjava/gnu/awt/xlib/XGraphics.java
+++ b/libjava/gnu/awt/xlib/XGraphics.java
@@ -20,6 +20,7 @@ import gnu.gcj.xlib.XImage;
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;
@@ -199,6 +200,16 @@ public class XGraphics implements Cloneable, DirectRasterGraphics
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***
diff --git a/libjava/gnu/awt/xlib/XOffScreenImage.java b/libjava/gnu/awt/xlib/XOffScreenImage.java
new file mode 100644
index 0000000..71791c1
--- /dev/null
+++ b/libjava/gnu/awt/xlib/XOffScreenImage.java
@@ -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 <scottg@mantatest.com> <sgilbertson@cogeco.ca>
+ */
+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 <code>UndefinedProperty</code> is
+ * returned if there is no property with the specified name. The value
+ * <code>null</code> 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;
+ }
+}