diff options
Diffstat (limited to 'libjava/classpath/gnu/java/awt')
4 files changed, 135 insertions, 21 deletions
diff --git a/libjava/classpath/gnu/java/awt/image/ImageDecoder.java b/libjava/classpath/gnu/java/awt/image/ImageDecoder.java index 141c8541794..8e8eecb2599 100644 --- a/libjava/classpath/gnu/java/awt/image/ImageDecoder.java +++ b/libjava/classpath/gnu/java/awt/image/ImageDecoder.java @@ -40,6 +40,8 @@ package gnu.java.awt.image; import java.awt.image.ImageConsumer; import java.awt.image.ImageProducer; import java.io.ByteArrayInputStream; +import java.io.DataInput; +import java.io.EOFException; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -55,6 +57,7 @@ public abstract class ImageDecoder implements ImageProducer int offset; int length; InputStream input; + DataInput datainput; static { @@ -79,6 +82,11 @@ public abstract class ImageDecoder implements ImageProducer this.input = is; } + public ImageDecoder (DataInput datainput) + { + this.datainput = datainput; + } + public ImageDecoder (byte[] imagedata, int imageoffset, int imagelength) { data = imagedata; @@ -119,6 +127,8 @@ public abstract class ImageDecoder implements ImageProducer { if (url != null) input = url.openStream(); + else if (datainput != null) + input = new DataInputStreamWrapper(datainput); else { if (filename != null) @@ -153,4 +163,26 @@ public abstract class ImageDecoder implements ImageProducer } public abstract void produce (Vector v, InputStream is) throws IOException; + + private static class DataInputStreamWrapper extends InputStream + { + private final DataInput datainput; + + DataInputStreamWrapper(DataInput datainput) + { + this.datainput = datainput; + } + + public int read() throws IOException + { + try + { + return datainput.readByte() & 0xFF; + } + catch (EOFException eofe) + { + return -1; + } + } + } } diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics.java index d80306c8a82..d7217aa7a3f 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics.java @@ -48,7 +48,6 @@ import java.awt.Graphics; import java.awt.Image; import java.awt.Rectangle; import java.awt.Shape; -import java.awt.SystemColor; import java.awt.image.ImageObserver; import java.text.AttributedCharacterIterator; @@ -81,18 +80,23 @@ public class GdkGraphics extends Graphics native void initStateUnlocked (GtkComponentPeer component); native void initState (int width, int height); native void initFromImage (GtkImage image); - native void copyState (GdkGraphics g); + native void nativeCopyState (GdkGraphics g); + + /** + * A cached instance that is used by {@link #create} in order to avoid + * massive allocation of graphics contexts. + */ + GdkGraphics cached = null; + + /** + * A link to the parent context. This is used in {@link #dispose} to put + * this graphics context into the cache. + */ + GdkGraphics parent = null; GdkGraphics (GdkGraphics g) { - color = g.color; - xorColor = g.xorColor; - font = g.font; - if (font == null) - font = new Font ("Dialog", Font.PLAIN, 12); - clip = new Rectangle (g.clip); - component = g.component; - + parent = g; copyState (g); } @@ -162,12 +166,54 @@ public class GdkGraphics extends Graphics public native void copyArea(int x, int y, int width, int height, int dx, int dy); - public Graphics create () + /** + * Creates a copy of this GdkGraphics instance. This implementation can + * reuse a cached instance to avoid massive instantiation of Graphics objects + * during painting. + * + * @return a copy of this graphics context + */ + public Graphics create() + { + GdkGraphics copy = cached; + if (copy == null) + copy = new GdkGraphics(this); + else + { + copy.copyState(this); + cached = null; + } + return copy; + } + + public native void nativeDispose(); + + /** + * Disposes this graphics object. This puts this graphics context into the + * cache of its parent graphics if there is one. + */ + public void dispose() { - return new GdkGraphics (this); + if (parent != null) + { + parent.cached = this; + parent = null; + } + else + nativeDispose(); } - public native void dispose(); + /** + * This is called when this object gets finalized by the garbage collector. + * In addition to {@link Graphics#finalize()} this calls nativeDispose() to + * make sure the native resources are freed before the graphics context is + * thrown away. + */ + public void finalize() + { + super.finalize(); + nativeDispose(); + } public boolean drawImage (Image img, int x, int y, Color bgcolor, ImageObserver observer) @@ -248,9 +294,8 @@ public class GdkGraphics extends Graphics public void drawString (String str, int x, int y) { drawString(getFontPeer(), str, x, y); - } + } - public void drawString (AttributedCharacterIterator ci, int x, int y) { throw new Error ("not implemented"); @@ -419,4 +464,23 @@ public class GdkGraphics extends Graphics translateNative (x, y); } + + /** + * Copies over the state of another GdkGraphics to this instance. This is + * used by the {@link #GdkGraphics(GdkGraphics)} constructor and the + * {@link #create()} method. + * + * @param g the GdkGraphics object to copy the state from + */ + private void copyState(GdkGraphics g) + { + color = g.color; + xorColor = g.xorColor; + font = g.font; + if (font == null) + font = new Font ("Dialog", Font.PLAIN, 12); + clip = new Rectangle (g.clip); + component = g.component; + nativeCopyState(g); + } } diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java index c9ed3012658..195304dcee2 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java @@ -180,11 +180,14 @@ public class GdkGraphics2D extends Graphics2D else fg = new Color(g.fg.getRGB()); - if (g.bg.getAlpha() != -1) - bg = new Color(g.bg.getRed(), g.bg.getGreen(), g.bg.getBlue(), - g.bg.getAlpha()); - else - bg = new Color(g.bg.getRGB()); + if (g.bg != null) + { + if (g.bg.getAlpha() != -1) + bg = new Color(g.bg.getRed(), g.bg.getGreen(), g.bg.getBlue(), + g.bg.getAlpha()); + else + bg = new Color(g.bg.getRGB()); + } if (g.clip == null) clip = null; @@ -1088,6 +1091,8 @@ public class GdkGraphics2D extends Graphics2D public void setBackground(Color c) { + if (c == null) + c = Color.WHITE; bg = c; } diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java index 85cb1e47a9e..054ebaaaef3 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java @@ -47,6 +47,7 @@ import java.awt.image.ImageConsumer; import java.awt.image.ImageProducer; import java.awt.image.Raster; import java.awt.image.RenderedImage; +import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.io.InputStream; @@ -102,6 +103,11 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder 0x00ff0000, 0x0000ff00, 0x000000ff); + public GdkPixbufDecoder (DataInput datainput) + { + super (datainput); + } + public GdkPixbufDecoder (InputStream in) { super (in); @@ -630,7 +636,14 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder boolean ignoreMetadata) { super.setInput(input, seekForwardOnly, ignoreMetadata); - dec = new GdkPixbufDecoder((InputStream) getInput()); + Object get = getInput(); + if (get instanceof InputStream) + dec = new GdkPixbufDecoder((InputStream) get); + else if (get instanceof DataInput) + dec = new GdkPixbufDecoder((DataInput) get); + else + throw new IllegalArgumentException("input object not supported: " + + get); } public BufferedImage read(int imageIndex, ImageReadParam param) |