Hi all! this patch fixes the renderScanline method. It would be great if it was a little faster and less generic, I'm searching for some algorithm that we may use, though it's like moving in a minefield, this kind of code is always very subject to patents (well, I'm in the old Europe, but, you know...)
I'm committing it in, have a nice day, Mario 2008-05-29 Mario Torre <[EMAIL PROTECTED]> * gnu/java/awt/java2d/AbstractGraphics2D.java (setColor): now set directly the foreground color the application wants to use to draw. On null, behave like OpenJDK, drawing black. (renderScanline): fixed NPE, paintContext never initialized. Correctely retrieve destination raster (getColor): Return the correct type. (static initializer): HashMap now typed. (background): now defaults to black and not null. (getPaintContext): new method. Initialize lazily the PaintContext. (foreground): new field. (isForegroundColorNull): likewise. (getDeviceBounds): made abstract. * gnu/java/awt/java2d/RasterGraphics.java (getDeviceBounds): new method. * gnu/java/awt/java2d/ScanlineConverter.java (renderShape): pass correct value of Y to doScanline. * gnu/java/awt/peer/x/GLGraphics.java (getDeviceBounds): new method. (setBackground): synch with new Escher 2.0 API. * gnu/java/awt/peer/x/XGraphicsConfiguration.java (getDefaultTransform): implemented. (getBounds): new method. * java/awt/AlphaComposite.java (derive(int) and derive(float)): new methods. * java/awt/image/WritableRaster.java (createWritableTranslatedChild): now call createWritableChild. (createWritableChild): reformatted. -- Mario Torre, Software Developer, http://www.jroller.com/neugens/ 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-53 pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF Fingerprint: BA39 9666 94EC 8B73 27FA FC7C 4086 63E3 80F2 40CF USt-Id: DE216375633, Handelsregister HRB 109481, AG Mannheim Geschäftsführer: Dr. James J. Hunt Please, support open standards: http://opendocumentfellowship.org/petition/ http://www.nosoftwarepatents.com/
### Eclipse Workspace Patch 1.0 #P classpath Index: gnu/java/awt/peer/x/XGraphicsConfiguration.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/awt/peer/x/XGraphicsConfiguration.java,v retrieving revision 1.3 diff -u -r1.3 XGraphicsConfiguration.java --- gnu/java/awt/peer/x/XGraphicsConfiguration.java 20 Sep 2007 14:01:08 -0000 1.3 +++ gnu/java/awt/peer/x/XGraphicsConfiguration.java 29 May 2008 16:34:26 -0000 @@ -146,8 +146,7 @@ public AffineTransform getDefaultTransform() { - // TODO: Implement this. - throw new UnsupportedOperationException("Not yet implemented."); + return new AffineTransform(); } public AffineTransform getNormalizingTransform() @@ -158,8 +157,10 @@ public Rectangle getBounds() { - // TODO: Implement this. - throw new UnsupportedOperationException("Not yet implemented."); + Display d = device.getDisplay(); + Screen screen = d.default_screen; + + return new Rectangle(0, 0, screen.width, screen.height); } /** Index: gnu/java/awt/peer/x/GLGraphics.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/awt/peer/x/GLGraphics.java,v retrieving revision 1.1 diff -u -r1.1 GLGraphics.java --- gnu/java/awt/peer/x/GLGraphics.java 29 Jun 2006 15:15:56 -0000 1.1 +++ gnu/java/awt/peer/x/GLGraphics.java 29 May 2008 16:34:26 -0000 @@ -39,7 +39,9 @@ import java.awt.Color; import java.awt.GraphicsConfiguration; +import java.awt.Rectangle; import java.awt.image.ColorModel; +import java.util.Map; import gnu.java.awt.java2d.AbstractGraphics2D; import gnu.x11.extension.glx.GL; @@ -70,7 +72,7 @@ public void setBackground(Color b) { super.setBackground(b); - gl.clear_color(b.getRed() / 255.F, b.getGreen() / 255.F, + gl.clearColor(b.getRed() / 255.F, b.getGreen() / 255.F, b.getBlue() / 255.F, b.getAlpha() / 255.F); } @@ -120,4 +122,12 @@ throw new UnsupportedOperationException("Not yet implemented"); } + @Override + protected Rectangle getDeviceBounds() + { + // FIXME: not sure it's correct + return new Rectangle(0, 0, + gl.display.default_screen.width, + gl.display.default_screen.height); + } } Index: java/awt/AlphaComposite.java =================================================================== RCS file: /sources/classpath/classpath/java/awt/AlphaComposite.java,v retrieving revision 1.10 diff -u -r1.10 AlphaComposite.java --- java/awt/AlphaComposite.java 21 Jun 2007 05:35:45 -0000 1.10 +++ java/awt/AlphaComposite.java 29 May 2008 16:34:26 -0000 @@ -158,18 +158,53 @@ return new AlphaCompositeContext(this, srcColorModel, dstColorModel); } + /** + * Return an <code>AlphaComposite</code> similar to <code>this</code>, + * that uses the specified rule. If <code>rule</code> is the same as + * <code>this.rule</code>, then <code>this</code> is returned. + * + * @since 1.6 + */ + public AlphaComposite derive(int rule) + { + if (this.rule == rule) + return this; + else + return AlphaComposite.getInstance(rule, this.getAlpha()); + } + + /** + * Return an <code>AlphaComposite</code> similar to <code>this</code>, + * that uses the specified <code>alpha</code>. + * + * If <code>alph</code> is the same as <code>this.alpha</code>, + * then <code>this</code> is returned. + * + * @since 1.6 + */ + public AlphaComposite derive(float alpha) + { + if (this.getAlpha() == alpha) + return this; + else + return AlphaComposite.getInstance(this.getRule(), alpha); + } + public float getAlpha() { return alpha; } + public int getRule() { return rule; } + public int hashCode() { return 31 * Float.floatToIntBits(alpha) + rule; } + public boolean equals(Object o) { if (! (o instanceof AlphaComposite)) Index: gnu/java/awt/java2d/AbstractGraphics2D.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/awt/java2d/AbstractGraphics2D.java,v retrieving revision 1.20 diff -u -r1.20 AbstractGraphics2D.java --- gnu/java/awt/java2d/AbstractGraphics2D.java 20 Sep 2007 14:01:08 -0000 1.20 +++ gnu/java/awt/java2d/AbstractGraphics2D.java 29 May 2008 16:34:26 -0000 @@ -37,6 +37,7 @@ package gnu.java.awt.java2d; +import gnu.java.awt.peer.x.XDialogPeer; import gnu.java.util.LRUCache; import java.awt.AWTError; @@ -210,14 +211,20 @@ /** * The paint context during rendering. */ - private PaintContext paintContext; + private PaintContext paintContext = null; /** * The background. */ - private Color background; + private Color background = Color.WHITE; /** + * Foreground color, as set by setColor. + */ + private Color foreground = Color.BLACK; + private boolean isForegroundColorNull = true; + + /** * The current font. */ private Font font; @@ -266,15 +273,19 @@ private static final BasicStroke STANDARD_STROKE = new BasicStroke(); - private static final HashMap STANDARD_HINTS; - static { - HashMap hints = new HashMap(); - hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, - RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); - hints.put(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_DEFAULT); - STANDARD_HINTS = hints; - } + private static final HashMap<Key, Object> STANDARD_HINTS; + static + { + + HashMap<Key, Object> hints = new HashMap<Key, Object>(); + hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); + hints.put(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_DEFAULT); + + STANDARD_HINTS = hints; + } + /** * Creates a new AbstractGraphics2D instance. */ @@ -1058,10 +1069,10 @@ */ public Color getColor() { - Color c = null; - if (paint instanceof Color) - c = (Color) paint; - return c; + if (isForegroundColorNull) + return null; + + return this.foreground; } /** @@ -1071,7 +1082,22 @@ */ public void setColor(Color color) { - setPaint(color); + if (color == null) + { + this.foreground = Color.BLACK; + isForegroundColorNull = true; + } + else + { + this.foreground = color; + isForegroundColorNull = false; + } + + // free resources if needed, then put the paint context to null + if (this.paintContext != null) + this.paintContext.dispose(); + + this.paintContext = null; } public void setPaintMode() @@ -1639,10 +1665,7 @@ * * @return the bounds of the target */ - protected Rectangle getDeviceBounds() - { - return destinationRaster.getBounds(); - } + protected abstract Rectangle getDeviceBounds(); /** * Draws a line in optimization mode. The implementation should respect the @@ -1763,7 +1786,8 @@ */ public void renderScanline(int y, ScanlineCoverage c) { - PaintContext pCtx = paintContext; + PaintContext pCtx = getPaintContext(); + int x0 = c.getMinX(); int x1 = c.getMaxX(); Raster paintRaster = pCtx.getRaster(x0, y, x1 - x0, 1); @@ -1797,9 +1821,11 @@ CompositeContext cCtx = composite.createContext(paintColorModel, getColorModel(), renderingHints); - WritableRaster targetChild = destinationRaster.createWritableTranslatedChild(-x0,- y); + WritableRaster raster = getDestinationRaster(); + WritableRaster targetChild = raster.createWritableTranslatedChild(-x0, -y); + cCtx.compose(paintRaster, targetChild, targetChild); - updateRaster(destinationRaster, x0, y, x1 - x0, 1); + updateRaster(raster, x0, y, x1 - x0, 1); cCtx.dispose(); } @@ -1986,4 +2012,20 @@ } } + private PaintContext getPaintContext() + { + if (this.paintContext == null) + { + return this.foreground.createContext(getColorModel(), + getDeviceBounds(), + getClipBounds(), + getTransform(), + getRenderingHints()); + } + else + { + return this.paintContext; + } + } + } Index: gnu/java/awt/java2d/ScanlineConverter.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/awt/java2d/ScanlineConverter.java,v retrieving revision 1.6 diff -u -r1.6 ScanlineConverter.java --- gnu/java/awt/java2d/ScanlineConverter.java 20 Sep 2007 14:01:08 -0000 1.6 +++ gnu/java/awt/java2d/ScanlineConverter.java 29 May 2008 16:34:26 -0000 @@ -206,7 +206,7 @@ // Ok, now we can perform the actual scanlining. int realY = Fixed.intValue(FIXED_DIGITS, y + resolution); boolean push = lastRealY != realY; - doScanline(p, y, push, haveClip); + doScanline(p, realY, push, haveClip); // Remove obsolete active edges. //activeEdges.remove(y + halfStep); Index: gnu/java/awt/java2d/RasterGraphics.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/awt/java2d/RasterGraphics.java,v retrieving revision 1.3 diff -u -r1.3 RasterGraphics.java --- gnu/java/awt/java2d/RasterGraphics.java 10 May 2006 09:13:20 -0000 1.3 +++ gnu/java/awt/java2d/RasterGraphics.java 29 May 2008 16:34:26 -0000 @@ -39,6 +39,7 @@ package gnu.java.awt.java2d; import java.awt.GraphicsConfiguration; +import java.awt.Rectangle; import java.awt.image.ColorModel; import java.awt.image.WritableRaster; @@ -100,4 +101,9 @@ return null; } + @Override + protected Rectangle getDeviceBounds() + { + return this.raster.getBounds(); + } } Index: java/awt/image/WritableRaster.java =================================================================== RCS file: /sources/classpath/classpath/java/awt/image/WritableRaster.java,v retrieving revision 1.10 diff -u -r1.10 WritableRaster.java --- java/awt/image/WritableRaster.java 27 Nov 2006 21:54:41 -0000 1.10 +++ java/awt/image/WritableRaster.java 29 May 2008 16:34:26 -0000 @@ -111,13 +111,8 @@ public WritableRaster createWritableTranslatedChild(int childMinX, int childMinY) { - // This mirrors the code from the super class - int tcx = sampleModelTranslateX - minX + childMinX; - int tcy = sampleModelTranslateY - minY + childMinY; - - return new WritableRaster(sampleModel, dataBuffer, - new Rectangle(childMinX, childMinY, width, height), - new Point(tcx, tcy), this); + return createWritableChild(minX, minY, width, height, + childMinX, childMinY, null); } /** @@ -143,12 +138,14 @@ SampleModel sm = (bandList == null) ? sampleModel : sampleModel.createSubsetSampleModel(bandList); - - return new WritableRaster(sm, dataBuffer, - new Rectangle(childMinX, childMinY, w, h), - new Point(sampleModelTranslateX + childMinX - parentX, - sampleModelTranslateY + childMinY - parentY), - this); + + return new WritableRaster(sm, getDataBuffer(), + new Rectangle(childMinX, childMinY, w, h), + new Point(sampleModelTranslateX + childMinX - + parentX, + sampleModelTranslateY + childMinY - + parentY), + this); } public Raster createChild(int parentX, int parentY, int width,