diff options
| author | Francis Kung <fkung@redhat.com> | 2006-12-22 19:50:30 +0000 |
|---|---|---|
| committer | Francis Kung <fkung@redhat.com> | 2006-12-22 19:50:30 +0000 |
| commit | d7b6265dd6eef4811d6805f33e0ba34bcbc9a30a (patch) | |
| tree | 468cdd63aab4fa2ca6833672698f923f3f096605 /gnu/java/awt/peer/gtk/BufferedImageGraphics.java | |
| parent | e9f4dda1cde4c6758b1856fa82dc9f0eb59ef49b (diff) | |
| download | classpath-d7b6265dd6eef4811d6805f33e0ba34bcbc9a30a.tar.gz | |
2006-12-22 Francis Kung <fkung@redhat.com>
* gnu/java/awt/peer/gtk/BufferedImageGraphics.java
(locked): Removed field.
(BufferedImageGraphics): Remove locked flag.
(drawComposite): Transform bounds properly; set cairo composite directly.
(drawImage): Transform bounds properly.
(updateBufferedImage): Remove locked flag; transform bounds properly.
* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(copyArea): Add comment.
(drawImage): Transform bounds properly; update clipping region.
(getClipInDevSpace): Transform bounds properly.
(getTransformedBounds): New method.
(setAntialias): Updated javadoc.
(setCustomPaint): Transform bounds properly.
(updateClip): Avoid use of GeneralPath when possible.
Diffstat (limited to 'gnu/java/awt/peer/gtk/BufferedImageGraphics.java')
| -rw-r--r-- | gnu/java/awt/peer/gtk/BufferedImageGraphics.java | 73 |
1 files changed, 25 insertions, 48 deletions
diff --git a/gnu/java/awt/peer/gtk/BufferedImageGraphics.java b/gnu/java/awt/peer/gtk/BufferedImageGraphics.java index 759dff53b..18182a77c 100644 --- a/gnu/java/awt/peer/gtk/BufferedImageGraphics.java +++ b/gnu/java/awt/peer/gtk/BufferedImageGraphics.java @@ -40,6 +40,7 @@ package gnu.java.awt.peer.gtk; import java.awt.AlphaComposite; import java.awt.Color; +import java.awt.Composite; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; @@ -49,7 +50,6 @@ import java.awt.Shape; import java.awt.Toolkit; import java.awt.font.GlyphVector; import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; @@ -75,12 +75,6 @@ public class BufferedImageGraphics extends CairoGraphics2D private BufferedImage image, buffer; /** - * Allows us to lock the image from updates (if we want to perform a few - * intermediary operations on the cairo surface, then update it all at once) - */ - private boolean locked; - - /** * Image size. */ private int imageWidth, imageHeight; @@ -109,7 +103,6 @@ public class BufferedImageGraphics extends CairoGraphics2D this.image = bi; imageWidth = bi.getWidth(); imageHeight = bi.getHeight(); - locked = false; if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel)) hasFastCM = false; @@ -189,7 +182,6 @@ public class BufferedImageGraphics extends CairoGraphics2D cairo_t = surface.newCairoContext(); imageWidth = copyFrom.imageWidth; imageHeight = copyFrom.imageHeight; - locked = false; hasFastCM = copyFrom.hasFastCM; hasAlpha = copyFrom.hasAlpha; @@ -202,15 +194,12 @@ public class BufferedImageGraphics extends CairoGraphics2D */ private void updateBufferedImage(int x, int y, int width, int height) { - if (locked) - return; - - double[] points = new double[]{x, y, width+x, height+y}; - transform.transform(points, 0, points, 0, 2); - x = (int)points[0]; - y = (int)points[1]; - width = (int)Math.ceil(points[2] - points[0]); - height = (int)Math.ceil(points[3] - points[1]); + Rectangle bounds = new Rectangle(x, y, width, height); + bounds = getTransformedBounds(bounds, transform).getBounds(); + x = bounds.x; + y = bounds.y; + width = bounds.width; + height = bounds.height; int[] pixels = surface.getPixels(imageWidth * imageHeight); @@ -403,14 +392,10 @@ public class BufferedImageGraphics extends CairoGraphics2D BufferedImage bImg = (BufferedImage) img; // Find translated bounds - Point2D origin = new Point2D.Double(bImg.getMinX(), bImg.getMinY()); - Point2D pt = new Point2D.Double(bImg.getWidth() + bImg.getMinX(), - bImg.getHeight() + bImg.getMinY()); + Rectangle2D bounds = new Rectangle(bImg.getMinX(), bImg.getMinY(), + bImg.getWidth(), bImg.getHeight()); if (xform != null) - { - origin = xform.transform(origin, origin); - pt = xform.transform(pt, pt); - } + bounds = getTransformedBounds(bounds, xform); // Create buffer and draw image createBuffer(); @@ -420,10 +405,7 @@ public class BufferedImageGraphics extends CairoGraphics2D g2d.drawImage(img, xform, obs); // Perform compositing - return drawComposite(new Rectangle2D.Double(origin.getX(), - origin.getY(), - pt.getX(), pt.getY()), - obs); + return drawComposite(bounds, obs); } } @@ -473,12 +455,7 @@ public class BufferedImageGraphics extends CairoGraphics2D private boolean drawComposite(Rectangle2D bounds, ImageObserver observer) { // Find bounds in device space - double[] points = new double[] {bounds.getX(), bounds.getY(), - bounds.getMaxX(), bounds.getMaxY()}; - transform.transform(points, 0, points, 0, 2); - bounds = new Rectangle2D.Double(points[0], points[1], - (points[2] - points[0]), - (points[3] - points[1])); + bounds = getTransformedBounds(bounds, transform); // Clip bounds by the stored clip, and by the internal buffer Rectangle2D devClip = this.getClipInDevSpace(); @@ -487,17 +464,15 @@ public class BufferedImageGraphics extends CairoGraphics2D buffer.getWidth(), buffer.getHeight()); Rectangle2D.intersect(bounds, devClip, bounds); - // Round bounds as needed, but be conservative in our rounding + // Round bounds as needed, but be careful in our rounding // (otherwise it may leave unpainted stripes) double x = bounds.getX(); double y = bounds.getY(); - double w = bounds.getWidth(); - double h = bounds.getHeight(); - if (Math.floor(x) != x) - w--; - if (Math.floor(y) != y) - h--; - bounds.setRect(Math.ceil(x), Math.ceil(y), Math.floor(w), Math.floor(h)); + double maxX = x + bounds.getWidth(); + double maxY = y + bounds.getHeight(); + x = Math.round(x); + y = Math.round(y); + bounds.setRect(x, y, Math.round(maxX - x), Math.round(maxY - y)); // Find subimage of internal buffer for updating BufferedImage buffer2 = buffer; @@ -516,9 +491,10 @@ public class BufferedImageGraphics extends CairoGraphics2D compCtx.compose(buffer2.getRaster(), current.getRaster(), current.getRaster()); - // Prevent the clearRect in CairoGraphics2D.drawImage from clearing - // our composited image - locked = true; + // Set cairo's composite to direct SRC, since we've already done our own + // compositing + Composite oldcomp = comp; + setComposite(AlphaComposite.Src); // This MUST call directly into the "action" method in CairoGraphics2D, // not one of the wrappers, to ensure that the composite isn't processed @@ -526,8 +502,9 @@ public class BufferedImageGraphics extends CairoGraphics2D boolean rv = super.drawImage(current, AffineTransform.getTranslateInstance(bounds.getX(), bounds.getY()), - new Color(0,0,0,0), null); - locked = false; + null, null); + setComposite(oldcomp); + updateColor(); return rv; } |
