diff options
| author | Francis Kung <fkung@redhat.com> | 2007-02-21 21:47:36 +0000 |
|---|---|---|
| committer | Francis Kung <fkung@redhat.com> | 2007-02-21 21:47:36 +0000 |
| commit | 8eb22cea0742a536471b8ab2110153ea7c23d205 (patch) | |
| tree | 903e9ead6dd9e212257d84f286c3080cf3353d7f /gnu/java | |
| parent | 94b1db85132222c4d4874bacf7bc01e995c7c5d8 (diff) | |
| download | classpath-8eb22cea0742a536471b8ab2110153ea7c23d205.tar.gz | |
2007-02-21 Francis Kung <fkung@redhat.com>
* gnu/java/awt/peer/gtk/BufferedImageGraphcs.java
(constructor): Add pre-multiplied colour model to types available for
optimization.
(updateBufferedImage): Change surface.getPixels() call to surface.getData().
* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(drawImage): Add checks before using CairoSurface optimization.
* gnu/java/awt/peer/gtk/CairoSurface.java
(bufferPointer): Removed field.
(sharedBuffer): New field.
(CairoSurface(GtkImage)): Copy array rather than using setPixels() call.
(CairoSurface(int,int,int)): Use getData() convenience method.
(CairoSurface(SampleModel,CairoSurface,Rectangle,Point)): Remove reference
to deleted bufferPointer field.
(copyAreaNative): Update documentation, remove reference to bufferPointer.
(copyAreaNative2): Remove reference to deleted bufferPointer field.
(destroy): Remove reference to deleted bufferPointer field.
(dispose): Updated to reflect new method signature for destroy().
(drawSurface): Added documentation.
(getData): New convience method.
(getFlippedBuffer): Removed method parameters.
(getGtkImage): Updated to reflect new method signature.
(getPixels): Removed method.
(nativeGetElem): Removed method.
(netiveGetPixels): Removed method.
(nativeSetElem): Removed method.
(nativeSetPixels): Removed method.
(setPixels): Removed method.
(syncJavaToNative): New method.
(syncNativeToJava): New method.
* gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java
(draw): Sync buffers if necessary.
(drawGlyphVector): Likewise.
(drawImage): Likewise.
(drawRenderedImage): Likewise,
(fill): Likewise.
* include/gnu_java_awt_peer_gtk_CairoSurface.h: Regenerated.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
(Java_gnu_java_awt_peer_gtk_CairoSurface_copyAreaNative2): Use pointer to
surface rather than pointer to buffer.
(Java_gnu_java_awt_peer_gtk_CairoSurface_create): Provide fall-back for
copied arrays.
(Java_gnu_java_awt_peer_gtk_CairoSurface_destroy): Handle copied arrays.
(Java_gnu_java_awt_peer_gtk_CairoSurface_getFlippedBuffer): Retrieve
information on size using JNI calls.
(Java_gnu_java_awt_peer_gtk_CairoSurface_getElem): Removed.
(Java_gnu_java_awt_peer_gtk_CairoSurface_getPixels): Removed.
(Java_gnu_java_awt_peer_gtk_CairoSurface_setElem): Removed.
(Java_gnu_java_awt_peer_gtk_CairoSurface_setPixels): Removed.
(Java_gnu_java_awt_peer_gtk_CairoSurface_syncJavaToNative): New function.
(Java_gnu_java_awt_peer_gtk_CairoSurface_syncNativeToJava): New function.
(BUFFER): Removed constant.
(SHARED): New constant.
Diffstat (limited to 'gnu/java')
| -rw-r--r-- | gnu/java/awt/peer/gtk/BufferedImageGraphics.java | 15 | ||||
| -rw-r--r-- | gnu/java/awt/peer/gtk/CairoGraphics2D.java | 4 | ||||
| -rw-r--r-- | gnu/java/awt/peer/gtk/CairoSurface.java | 112 | ||||
| -rw-r--r-- | gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java | 38 |
4 files changed, 108 insertions, 61 deletions
diff --git a/gnu/java/awt/peer/gtk/BufferedImageGraphics.java b/gnu/java/awt/peer/gtk/BufferedImageGraphics.java index d5d26ee7e..31c5e641e 100644 --- a/gnu/java/awt/peer/gtk/BufferedImageGraphics.java +++ b/gnu/java/awt/peer/gtk/BufferedImageGraphics.java @@ -112,7 +112,8 @@ public class BufferedImageGraphics extends CairoGraphics2D hasFastCM = true; hasAlpha = false; } - else if(bi.getColorModel().equals(CairoSurface.cairoColorModel)) + else if(bi.getColorModel().equals(CairoSurface.cairoColorModel) + || bi.getColorModel().equals(CairoSurface.cairoCM_pre)) { hasFastCM = true; hasAlpha = true; @@ -142,10 +143,7 @@ public class BufferedImageGraphics extends CairoGraphics2D int minY = image.getRaster().getSampleModelTranslateY(); // Pull pixels directly out of data buffer - if(raster instanceof CairoSurface) - pixels = ((CairoSurface)raster).getPixels(raster.getWidth() * raster.getHeight()); - else - pixels = ((DataBufferInt)raster.getDataBuffer()).getData(); + pixels = ((DataBufferInt)raster.getDataBuffer()).getData(); // Discard pixels that fall outside of the image's bounds // (ie, this image is actually a subimage of a different image) @@ -170,10 +168,11 @@ public class BufferedImageGraphics extends CairoGraphics2D { pixels = CairoGraphics2D.findSimpleIntegerArray(image.getColorModel(), image.getData()); + if (pixels != null) + System.arraycopy(pixels, 0, surface.getData(), + 0, pixels.length); } - surface.setPixels( pixels ); - setup( cairo_t ); setClip(0, 0, imageWidth, imageHeight); } @@ -204,7 +203,7 @@ public class BufferedImageGraphics extends CairoGraphics2D width = bounds.width; height = bounds.height; - int[] pixels = surface.getPixels(imageWidth * imageHeight); + int[] pixels = surface.getData(); if( x > imageWidth || y > imageHeight ) return; diff --git a/gnu/java/awt/peer/gtk/CairoGraphics2D.java b/gnu/java/awt/peer/gtk/CairoGraphics2D.java index 5e9893bc7..68febb12d 100644 --- a/gnu/java/awt/peer/gtk/CairoGraphics2D.java +++ b/gnu/java/awt/peer/gtk/CairoGraphics2D.java @@ -1520,7 +1520,9 @@ public abstract class CairoGraphics2D extends Graphics2D if (comp instanceof AlphaComposite) alpha = ((AlphaComposite) comp).getAlpha(); - if(raster instanceof CairoSurface) + if(raster instanceof CairoSurface + && ((CairoSurface)raster).getParent() == null + && ((CairoSurface)raster).sharedBuffer == true) { ((CairoSurface)raster).drawSurface(nativePointer, i2u, alpha, getInterpolation()); diff --git a/gnu/java/awt/peer/gtk/CairoSurface.java b/gnu/java/awt/peer/gtk/CairoSurface.java index cef420733..7be38be0f 100644 --- a/gnu/java/awt/peer/gtk/CairoSurface.java +++ b/gnu/java/awt/peer/gtk/CairoSurface.java @@ -1,5 +1,5 @@ /* CairoSurface.java - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -73,9 +73,9 @@ public class CairoSurface extends WritableRaster long surfacePointer; /** - * The native pointer to the image's data buffer + * Whether the data buffer is shared between java and cairo. */ - long bufferPointer; + boolean sharedBuffer; // FIXME: use only the cairoCM_pre colormodel // since that's what Cairo really uses (is there a way to do this cheaply? @@ -108,17 +108,7 @@ public class CairoSurface extends WritableRaster /** * Destroys the cairo surface and frees the buffer. */ - private native void destroy(long surfacePointer, long bufferPointer, int[] buf); - - /** - * Gets buffer elements - */ - private native int nativeGetElem(long bufferPointer, int i); - - /** - * Sets buffer elements. - */ - private native void nativeSetElem(long bufferPointer, int i, int val); + private native void destroy(long surfacePointer, int[] buf); /** * Draws this image to a given CairoGraphics context, @@ -128,6 +118,30 @@ public class CairoSurface extends WritableRaster double[] i2u, double alpha, int interpolation); + /** + * Synchronizes the image's data buffers, copying any changes made in the + * Java array into the native array. + * + * This method should only be called if (sharedBuffers == false). + */ + native void syncNativeToJava(long surfacePointer, int[] buffer); + + /** + * Synchronizes the image's data buffers, copying any changes made in the + * native array into the Java array. + * + * This method should only be called if (sharedBuffers == false). + */ + native void syncJavaToNative(long surfacePointer, int[] buffer); + + /** + * Draw this CairoSurface image onto a given Cairo context. + * + * @param contextPointer A pointer to the context to draw onto. + * @param i2u The transformation matrix (cannot be null). + * @param alpha The alpha value to paint with ( 0 <= alpha <= 1). + * @param interpolation The interpolation type, as defined in CairoGraphcs2D. + */ public void drawSurface(long contextPointer, double[] i2u, double alpha, int interpolation) { @@ -135,26 +149,13 @@ public class CairoSurface extends WritableRaster } /** - * getPixels -return the pixels as a java array. - */ - native int[] nativeGetPixels(long bufferPointer, int size); - - public int[] getPixels(int size) - { - return nativeGetPixels(bufferPointer, size); - } - - /** - * getPixels -return the pixels as a java array. + * Return the buffer, with the sample values of each pixel reversed + * (ie, in ABGR instead of ARGB). + * + * @return A pointer to a flipped buffer. The memory is allocated in native + * code, and must be explicitly freed when it is no longer needed. */ - native void nativeSetPixels(long bufferPointer, int[] pixels); - - public void setPixels(int[] pixels) - { - nativeSetPixels(bufferPointer, pixels); - } - - native long getFlippedBuffer(long bufferPointer, int size); + native long getFlippedBuffer(); /** * Create a cairo_surface_t with specified width and height. @@ -168,8 +169,7 @@ public class CairoSurface extends WritableRaster public CairoSurface(int x, int y, int width, int height) { - super(createCairoSampleModel(width, height), - null, new Point(x, y)); + super(createCairoSampleModel(width, height), null, new Point(x, y)); if(width <= 0 || height <= 0) throw new IllegalArgumentException("Image must be at least 1x1 pixels."); @@ -177,11 +177,10 @@ public class CairoSurface extends WritableRaster this.width = width; this.height = height; dataBuffer = new DataBufferInt(width * height); - create(width, height, width, ((DataBufferInt)dataBuffer).getData()); + create(width, height, width, getData()); - if(surfacePointer == 0 || bufferPointer == 0) + if(surfacePointer == 0) throw new Error("Could not allocate bitmap."); - } /** @@ -194,7 +193,6 @@ public class CairoSurface extends WritableRaster this.width = parent.width; this.height = parent.height; - this.bufferPointer = parent.bufferPointer; this.surfacePointer = parent.surfacePointer; this.dataBuffer = parent.dataBuffer; } @@ -245,7 +243,7 @@ public class CairoSurface extends WritableRaster } } - setPixels( data ); + System.arraycopy(data, 0, getData(), 0, data.length); } /** @@ -254,8 +252,7 @@ public class CairoSurface extends WritableRaster public void dispose() { if(surfacePointer != 0 && parent == null) - destroy(surfacePointer, bufferPointer, - ((DataBufferInt)dataBuffer).getData()); + destroy(surfacePointer, getData()); } /** @@ -271,8 +268,17 @@ public class CairoSurface extends WritableRaster */ public GtkImage getGtkImage() { - return new GtkImage( width, height, - getFlippedBuffer(bufferPointer, width * height )); + return new GtkImage(width, height, getFlippedBuffer()); + } + + /** + * Convenience method to quickly grab the data array backing this Raster. + * + * @return The array behind the databuffer. + */ + public int[] getData() + { + return ((DataBufferInt)dataBuffer).getData(); } /** @@ -323,16 +329,24 @@ public class CairoSurface extends WritableRaster } /** - * Copy an area of the surface. Expects parameters must be within bounds. - * Count on a segfault otherwise. + * Copy a portion of this surface to another area on the surface. The given + * parameters must be within bounds - count on a segfault otherwise. + * + * @param x The x coordinate of the area to be copied from. + * @param y The y coordinate of the area to be copied from. + * @param width The width of the area to be copied. + * @param height The height of the area to be copied. + * @param dx The destination x coordinate. + * @param dy The destination y coordinate. + * @param stride The scanline stride. */ - native void copyAreaNative2(long bufferPointer, int x, int y, int width, - int height, int dx, int dy, int stride); public void copyAreaNative(int x, int y, int width, int height, int dx, int dy, int stride) { - copyAreaNative2(bufferPointer, x, y, width, height, dx, dy, stride); + copyAreaNative2(x, y, width, height, dx, dy, stride); } + native void copyAreaNative2(int x, int y, int width, int height, + int dx, int dy, int stride); /** * Creates a SampleModel that matches Cairo's native format diff --git a/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java b/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java index 547946e0f..540aed66d 100644 --- a/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java +++ b/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java @@ -116,6 +116,9 @@ public class CairoSurfaceGraphics extends CairoGraphics2D */ public void draw(Shape s) { + if (!surface.sharedBuffer) + surface.syncJavaToNative(surface.surfacePointer, surface.getData()); + // Find total bounds of shape Rectangle r = findStrokedBounds(s); if (shiftDrawCalls) @@ -140,10 +143,16 @@ public class CairoSurfaceGraphics extends CairoGraphics2D drawComposite(r.getBounds2D(), null); } + + if (!surface.sharedBuffer) + surface.syncNativeToJava(surface.surfacePointer, surface.getData()); } public void fill(Shape s) { + if (!surface.sharedBuffer) + surface.syncJavaToNative(surface.surfacePointer, surface.getData()); + if (comp == null || comp instanceof AlphaComposite) super.fill(s); @@ -159,10 +168,16 @@ public class CairoSurfaceGraphics extends CairoGraphics2D drawComposite(s.getBounds2D(), null); } + + if (!surface.sharedBuffer) + surface.syncNativeToJava(surface.surfacePointer, surface.getData()); } public void drawRenderedImage(RenderedImage image, AffineTransform xform) { + if (!surface.sharedBuffer) + surface.syncJavaToNative(surface.surfacePointer, surface.getData()); + if (comp == null || comp instanceof AlphaComposite) super.drawRenderedImage(image, xform); @@ -177,14 +192,20 @@ public class CairoSurfaceGraphics extends CairoGraphics2D drawComposite(buffer.getRaster().getBounds(), null); } - + + if (!surface.sharedBuffer) + surface.syncNativeToJava(surface.surfacePointer, surface.getData()); } protected boolean drawImage(Image img, AffineTransform xform, Color bgcolor, ImageObserver obs) { + if (!surface.sharedBuffer) + surface.syncJavaToNative(surface.surfacePointer, surface.getData()); + + boolean ret; if (comp == null || comp instanceof AlphaComposite) - return super.drawImage(img, xform, bgcolor, obs); + ret = super.drawImage(img, xform, bgcolor, obs); else { @@ -212,12 +233,20 @@ public class CairoSurfaceGraphics extends CairoGraphics2D g2d.drawImage(img, xform, obs); // Perform compositing - return drawComposite(bounds, obs); + ret = drawComposite(bounds, obs); } + + if (!surface.sharedBuffer) + surface.syncNativeToJava(surface.surfacePointer, surface.getData()); + + return ret; } public void drawGlyphVector(GlyphVector gv, float x, float y) { + if (!surface.sharedBuffer) + surface.syncJavaToNative(surface.surfacePointer, surface.getData()); + if (comp == null || comp instanceof AlphaComposite) super.drawGlyphVector(gv, x, y); @@ -235,6 +264,9 @@ public class CairoSurfaceGraphics extends CairoGraphics2D bounds.getWidth(), bounds.getHeight()); drawComposite(bounds, null); } + + if (!surface.sharedBuffer) + surface.syncNativeToJava(surface.surfacePointer, surface.getData()); } private boolean drawComposite(Rectangle2D bounds, ImageObserver observer) |
