diff options
| author | doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-06-03 23:18:43 +0000 |
|---|---|---|
| committer | doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-06-03 23:18:43 +0000 |
| commit | 5bf762459121cc397663d22498d62d71fa179ef6 (patch) | |
| tree | a9c9e7d91c484d53fe154f9285fc57325572ce50 /libjava/classpath/gnu/java/awt/peer/gtk/CairoSurface.java | |
| parent | 6d7301dc346a198a89ac987c1008aac09f191ee6 (diff) | |
| download | ppe42-gcc-5bf762459121cc397663d22498d62d71fa179ef6.tar.gz ppe42-gcc-5bf762459121cc397663d22498d62d71fa179ef6.zip | |
libjava/classpath/ChangeLog.gcj:
2007-05-31 Matthias Klose <doko@ubuntu.com>
* javax/management/NotificationBroadcasterSupport.java
(getNotificationInfo): Add cast.
* native/jni/qt-peer/Makefile.am (AM_CXXFLAGS): Add libstdc++ include
directories.
* native/jni/qt-peer/Makefile.in: Regenerate.
libjava/ChangeLog:
2007-06-03 Matthias Klose <doko@ubuntu.com>
* java/io/natFileWin32.cc (setFilePermissions): New (stub only).
_access: Handle EXEC query, stub only.
2007-06-03 Matthias Klose <doko@ubuntu.com>
Merged from classpath:
* gnu/java/nio/SelectorProviderImpl.java: Whitespace merge.
* java/lang/System.java(inheritedChannel): New.
* java/lang/Character.java: Remove stray`;'.
* java/net/MulticastSocket.java: Merged.
* java/text/DateFormatSymbols.java(getInstance): New, comment updates.
* java/text/Collator.java(getInstance): Merged.
* java/util/Calendar.java: New attributes ALL_STYLES, SHORT, LONG.
getDisplayName, getDisplayNames: New.
* java/util/logging/Logger.java: Merged.
* Regenerate .class and .h files.
2007-06-03 Matthias Klose <doko@ubuntu.com>
* java/io/File.java: Merge with classpath-0.95, new method
setFilePermissions, new attribute EXEC.
* java/io/natFilePosix.cc (setFilePermissions): New.
_access: Handle EXEC query.
* classpath/lib/java/io/File.class, java/io/File.h: Regenerate.
2007-06-03 Matthias Klose <doko@ubuntu.com>
Imported GNU Classpath 0.95.
* classpath/Makefile.in,
classpath/native/jni/midi-dssi/Makefile.in,
classpath/native/jni/classpath/Makefile.in,
classpath/native/jni/Makefile.in,
classpath/native/jni/gconf-peer/Makefile.in,
classpath/native/jni/java-io/Makefile.in,
classpath/native/jni/native-lib/Makefile.in,
classpath/native/jni/java-util/Makefile.in,
classpath/native/jni/midi-alsa/Makefile.in,
classpath/native/jni/java-lang/Makefile.in,
classpath/native/jni/java-nio/Makefile.in,
classpath/native/jni/java-net/Makefile.in,
classpath/native/jni/xmlj/Makefile.in,
classpath/native/jni/qt-peer/Makefile.in,
classpath/native/jni/gtk-peer/Makefile.in,
classpath/native/Makefile.in, classpath/native/jawt/Makefile.in,
classpath/native/fdlibm/Makefile.in,
classpath/native/plugin/Makefile.in,
classpath/resource/Makefile.in, classpath/scripts/Makefile.in,
classpath/tools/Makefile.in, classpath/doc/Makefile.in,
classpath/doc/api/Makefile.in, classpath/lib/Makefile.in,
classpath/external/Makefile.in, classpath/external/jsr166/Makefile.in,
classpath/external/sax/Makefile.in,
classpath/external/w3c_dom/Makefile.in,
classpath/external/relaxngDatatype/Makefile.in,
classpath/include/Makefile.in,
classpath/examples/Makefile.in: Regenerate.
* classpath/config.guess, classpath/config.sub,
classpath/ltmain.sh : Update.
* classpath/configure, classpath/depcomp, classpath/missing,
classpath/aclocal.m4, classpath/install-sh: Regenerate.
* gnu/classpath/Configuration.java (CLASSPATH_VERSION): Now 0.95.
* sources.am: Regenerate.
* Makefile.in: Regenerate.
* Update the .class files and generated CNI header files, add new
.class and generated CNI header files.
* Remove generated files for removed java source files:
classpath/gnu/java/net/BASE64.java,
classpath/gnu/java/security/util/Base64.java,
classpath/gnu/java/awt/peer/gtk/GThreadMutex.java,
classpath/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java,
classpath/gnu/java/awt/font/autofit/Scaler.java,
classpath/gnu/classpath/jdwp/util/Value.java,
classpath/gnu/javax/net/ssl/Base64.java.
* Remove empty directories.
* Makefile.am(nat_source_files): Add natVMOperatingSystemMXBeanImpl.cc.
* java/lang/Class.java(setAccessible): Merge from classpath.
* java/util/Locale.java: Remove.
* gnu/java/lang/management/VMOperatingSystemMXBeanImpl.java,
gnu/java/lang/management/natVMOperatingSystemMXBeanImpl.cc: New.
* gcj/javaprims.h: Update class declarations.
* scripts/classes.pl: Update usage.
* HACKING: Mention to build all peers.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@125302 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/gnu/java/awt/peer/gtk/CairoSurface.java')
| -rw-r--r-- | libjava/classpath/gnu/java/awt/peer/gtk/CairoSurface.java | 299 |
1 files changed, 190 insertions, 109 deletions
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/CairoSurface.java b/libjava/classpath/gnu/java/awt/peer/gtk/CairoSurface.java index 5b63e62e7ed..b45a79fd6e7 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/CairoSurface.java +++ b/libjava/classpath/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. @@ -42,15 +42,22 @@ import gnu.java.awt.Buffers; import java.awt.Graphics2D; import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Shape; import java.awt.color.ColorSpace; +import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.DataBuffer; +import java.awt.image.DataBufferInt; import java.awt.image.DirectColorModel; +import java.awt.image.Raster; +import java.awt.image.RasterFormatException; import java.awt.image.SampleModel; import java.awt.image.SinglePixelPackedSampleModel; import java.awt.image.WritableRaster; import java.nio.ByteOrder; +import java.util.Arrays; import java.util.Hashtable; /** @@ -68,9 +75,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? @@ -98,22 +105,12 @@ public class CairoSurface extends WritableRaster * @param width, height - the image size * @param stride - the buffer row stride. (in ints) */ - private native void create(int width, int height, int stride); + private native void create(int width, int height, int stride, int[] buf); /** * Destroys the cairo surface and frees the buffer. */ - private native void destroy(long surfacePointer, long bufferPointer); - - /** - * 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, @@ -123,33 +120,30 @@ public class CairoSurface extends WritableRaster double[] i2u, double alpha, int interpolation); - public void drawSurface(long contextPointer, double[] i2u, double alpha, - int interpolation) - { - nativeDrawSurface(surfacePointer, contextPointer, i2u, alpha, interpolation); - } - /** - * getPixels -return the pixels as a java array. + * 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 int[] nativeGetPixels(long bufferPointer, int size); - - public int[] getPixels(int size) - { - return nativeGetPixels(bufferPointer, size); - } - + native void syncNativeToJava(long surfacePointer, int[] buffer); + /** - * getPixels -return the pixels as a java array. + * 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 nativeSetPixels(long bufferPointer, int[] pixels); - - public void setPixels(int[] pixels) - { - nativeSetPixels(bufferPointer, pixels); - } - - native long getFlippedBuffer(long bufferPointer, int size); + native void syncJavaToNative(long surfacePointer, int[] buffer); + + /** + * 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 long getFlippedBuffer(long surfacePointer); /** * Create a cairo_surface_t with specified width and height. @@ -158,20 +152,38 @@ public class CairoSurface extends WritableRaster */ public CairoSurface(int width, int height) { - super(createCairoSampleModel(width, height), - null, new Point(0, 0)); + this(0, 0, width, height); + } + + public CairoSurface(int x, int y, int width, int height) + { + super(createCairoSampleModel(width, height), null, new Point(x, y)); if(width <= 0 || height <= 0) throw new IllegalArgumentException("Image must be at least 1x1 pixels."); this.width = width; this.height = height; - create(width, height, width); + dataBuffer = new DataBufferInt(width * height); + create(width, height, width, getData()); - if(surfacePointer == 0 || bufferPointer == 0) + if(surfacePointer == 0) throw new Error("Could not allocate bitmap."); - - dataBuffer = new CairoDataBuffer(); + } + + /** + * Create a Cairo Surface that is a subimage of another Cairo Surface + */ + public CairoSurface(SampleModel sm, CairoSurface parent, Rectangle bounds, + Point origin) + { + super(sm, parent.dataBuffer, bounds, origin, parent); + + this.width = super.width; + this.height = super.height; + this.surfacePointer = parent.surfacePointer; + this.sharedBuffer = parent.sharedBuffer; + this.dataBuffer = parent.dataBuffer; } /** @@ -188,39 +200,39 @@ public class CairoSurface extends WritableRaster // Swap ordering from GdkPixbuf to Cairo if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) { - for (int i = 0; i < data.length; i++ ) - { - // On a big endian system we get a RRGGBBAA data array. - int alpha = data[i] & 0xFF; - if( alpha == 0 ) // I do not know why we need this, but it works. - data[i] = 0; - else - { - // Cairo needs a ARGB32 native array. - data[i] = (data[i] >>> 8) | (alpha << 24); - } - } + for (int i = 0; i < data.length; i++ ) + { + // On a big endian system we get a RRGGBBAA data array. + int alpha = data[i] & 0xFF; + if( alpha == 0 ) // I do not know why we need this, but it works. + data[i] = 0; + else + { + // Cairo needs a ARGB32 native array. + data[i] = (data[i] >>> 8) | (alpha << 24); + } + } } else { - for (int i = 0; i < data.length; i++ ) - { - // On a little endian system we get a AABBGGRR data array. - int alpha = data[i] & 0xFF000000; - if( alpha == 0 ) // I do not know why we need this, but it works. - data[i] = 0; - else - { - int b = (data[i] & 0xFF0000) >> 16; - int g = (data[i] & 0xFF00); - int r = (data[i] & 0xFF) << 16; - // Cairo needs a ARGB32 native array. - data[i] = alpha | r | g | b; - } - } + for (int i = 0; i < data.length; i++ ) + { + // On a little endian system we get a AABBGGRR data array. + int alpha = data[i] & 0xFF000000; + if( alpha == 0 ) // I do not know why we need this, but it works. + data[i] = 0; + else + { + int b = (data[i] & 0xFF0000) >> 16; + int g = (data[i] & 0xFF00); + int r = (data[i] & 0xFF) << 16; + // Cairo needs a ARGB32 native array. + data[i] = alpha | r | g | b; + } + } } - setPixels( data ); + System.arraycopy(data, 0, getData(), 0, data.length); } /** @@ -228,8 +240,8 @@ public class CairoSurface extends WritableRaster */ public void dispose() { - if(surfacePointer != 0) - destroy(surfacePointer, bufferPointer); + if(surfacePointer != 0 && parent == null) + destroy(surfacePointer, getData()); } /** @@ -245,8 +257,17 @@ public class CairoSurface extends WritableRaster */ public GtkImage getGtkImage() { - return new GtkImage( width, height, - getFlippedBuffer(bufferPointer, width * height )); + return new GtkImage(width, height, getFlippedBuffer(surfacePointer)); + } + + /** + * Convenience method to quickly grab the data array backing this Raster. + * + * @return The array behind the databuffer. + */ + public int[] getData() + { + return ((DataBufferInt)dataBuffer).getData(); } /** @@ -276,34 +297,6 @@ public class CairoSurface extends WritableRaster new Hashtable()); } - private class CairoDataBuffer extends DataBuffer - { - public CairoDataBuffer() - { - super(DataBuffer.TYPE_INT, width * height); - } - - /** - * DataBuffer.getElem implementation - */ - public int getElem(int bank, int i) - { - if(bank != 0 || i < 0 || i >= width * height) - throw new IndexOutOfBoundsException(i+" size: "+width * height); - return nativeGetElem(bufferPointer, i); - } - - /** - * DataBuffer.setElem implementation - */ - public void setElem(int bank, int i, int val) - { - if(bank != 0 || i < 0 || i >= width*height) - throw new IndexOutOfBoundsException(i+" size: "+width * height); - nativeSetElem(bufferPointer, i, val); - } - } - /** * Return a Graphics2D drawing to the CairoSurface. */ @@ -325,16 +318,25 @@ 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(surfacePointer, x, y, width, height, dx, dy, stride); } + native void copyAreaNative2(long surfacePointer, + int x, int y, int width, int height, + int dx, int dy, int stride); /** * Creates a SampleModel that matches Cairo's native format @@ -345,4 +347,83 @@ public class CairoSurface extends WritableRaster new int[]{0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}); } + + /** + * Returns whether this ColorModel is compatible with Cairo's native types. + * + * @param cm The color model to check. + * @return Whether it is compatible. + */ + public static boolean isCompatibleColorModel(ColorModel cm) + { + return (cm.equals(cairoCM_pre) || cm.equals(cairoCM_opaque) || + cm.equals(cairoColorModel)); + } + + /** + * Returns whether this SampleModel is compatible with Cairo's native types. + * + * @param sm The sample model to check. + * @return Whether it is compatible. + */ + public static boolean isCompatibleSampleModel(SampleModel sm) + { + return (sm instanceof SinglePixelPackedSampleModel + && sm.getDataType() == DataBuffer.TYPE_INT + && Arrays.equals(((SinglePixelPackedSampleModel)sm).getBitMasks(), + new int[]{0x00FF0000, 0x0000FF00, + 0x000000FF, 0xFF000000})); + } + + ///// Methods interhited from Raster and WritableRaster ///// + public Raster createChild(int parentX, int parentY, int width, int height, + int childMinX, int childMinY, int[] bandList) + { + return createWritableChild(parentX, parentY, width, height, + childMinX, childMinY, bandList); + } + + public WritableRaster createCompatibleWritableRaster() + { + return new CairoSurface(width, height); + } + + public WritableRaster createCompatibleWritableRaster (int x, int y, + int w, int h) + { + return new CairoSurface(x, y, w, h); + } + + public Raster createTranslatedChild(int childMinX, int childMinY) + { + return createWritableTranslatedChild(childMinX, childMinY); + } + + public WritableRaster createWritableChild(int parentX, int parentY, + int w, int h, int childMinX, + int childMinY, int[] bandList) + { + if (parentX < minX || parentX + w > minX + width + || parentY < minY || parentY + h > minY + height) + throw new RasterFormatException("Child raster extends beyond parent"); + + SampleModel sm = (bandList == null) ? + sampleModel : + sampleModel.createSubsetSampleModel(bandList); + + return new CairoSurface(sm, this, + new Rectangle(childMinX, childMinY, w, h), + new Point(sampleModelTranslateX + childMinX - parentX, + sampleModelTranslateY + childMinY - parentY)); + } + + public WritableRaster createWritableTranslatedChild(int x, int y) + { + int tcx = sampleModelTranslateX - minX + x; + int tcy = sampleModelTranslateY - minY + y; + + return new CairoSurface(sampleModel, this, + new Rectangle(x, y, width, height), + new Point(tcx, tcy)); + } } |

