summaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-12-06 21:12:18 +0100
committerSven Gothel <[email protected]>2014-12-06 21:12:18 +0100
commita53e87a84c92444e8a3173f25ce86dcfd536d6a8 (patch)
treebd19e9f40e4c67203d579c28b3775a5c17adc106 /src/nativewindow/classes/com/jogamp
parent241d505749b7d2bd383673a378fdca268989d2fd (diff)
Bug 1107 - Refine PixelFormat, GLPixelBuffer and DirectDataBufferInt/BufferedImageInt
- PixelFormat Refine definition allowing complete format conversion by its attributes instead of static 'knowledge'. - PixelFormat has_a *new* PixelFormat.Composition - PixelFormat.Composition contains all pixel component layout information as required for inspection and conversion. Component names are enumerated via PixelFormat.CType. - PixelFormatUtil.convert(..) utilizes generic conversion based on PixelFormat.Composition rather static type mapping. However, a int32 RGBA static conversion is still supported for performance. Utilizes Bitstream for varying pixel component bit-width. - Complete w/ hashCode() and equals(..) - GLPixelBuffer - Take 'pack' mode into account when determine GLPixelAttributes, i.e. on GLES pack=true (e.g. glReadPixel) only RGBA is guaranteed to work. Hence querying GLPixelAttributes requires the GLProfile, PixelFormat and pack mode. - Complete GLPixelAttributes conversions from PixelFormat or GL format/data-type, while taking GL data-type into account, as well as pack-mode. - Complete w/ hashCode() and equals(..) - SingletonGLPixelBufferProvider queries singleton GLPixelBuffer via - PixelFormat.Composition hostPixelComp, - GLPixelAttributes pixelAttributes, - boolean pack which comprise a unique key, allowing the implementation to utilize a hash map. This is implemented in AWTSingletonGLPixelBufferProvider. This allows distinct singleton GLPixelBuffer for different host PixelFormat (conversion) and GLPixelAttributes (depending on GLProfile). - Removes field 'componentCount' which was 'hacked in' to pass information about an optional host memory layout. Implementations utilizing conversion, e.g. AWTGLPixelBuffer, can implement GLPixelBufferProvider's 'PixelFormat.Composition getHostPixelComp(final GLProfile glp, final int componentCount)' and manage such implementation details, see use-case GLJPanel. - DirectDataBufferInt/BufferedImageInt: Expose underlying NIO ByteBuffer - AWTMisc.createCursor(..) uses DirectDataBufferInt.BufferedImageInt exposed NIO ByteBuffer, allowing to use generic PixelFormatUtil.convert(..).
Diffstat (limited to 'src/nativewindow/classes/com/jogamp')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/DirectDataBufferInt.java93
1 files changed, 68 insertions, 25 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/DirectDataBufferInt.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/DirectDataBufferInt.java
index c7055099f..0f103bfb3 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/DirectDataBufferInt.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/DirectDataBufferInt.java
@@ -36,6 +36,7 @@ import java.awt.image.DirectColorModel;
import java.awt.image.SampleModel;
import java.awt.image.SinglePixelPackedSampleModel;
import java.awt.image.WritableRaster;
+import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.Hashtable;
@@ -54,9 +55,12 @@ public final class DirectDataBufferInt extends DataBuffer {
public static class BufferedImageInt extends BufferedImage {
final int customImageType;
- public BufferedImageInt (final int customImageType, final ColorModel cm, final WritableRaster raster, final Hashtable<?,?> properties) {
+ final DirectDataBufferInt dataBuffer;
+ public BufferedImageInt (final int customImageType, final ColorModel cm,
+ final DirectDataBufferInt dataBuffer, final WritableRaster raster, final Hashtable<?,?> properties) {
super(cm, raster, false /* isRasterPremultiplied */, properties);
this.customImageType = customImageType;
+ this.dataBuffer = dataBuffer;
}
/**
@@ -68,6 +72,11 @@ public final class DirectDataBufferInt extends DataBuffer {
return customImageType;
}
+ /**
+ * Returns the underlying {@link DirectDataBufferInt} associated with this instance via {@link Raster} {@link #getRaster() instance}.
+ */
+ public DirectDataBufferInt getDataBuffer() { return dataBuffer; }
+
@Override
public String toString() {
return "BufferedImageInt@"+Integer.toHexString(hashCode())
@@ -163,14 +172,18 @@ public final class DirectDataBufferInt extends DataBuffer {
// final WritableRaster raster = new SunWritableRaster(sppsm, dataBuffer, location);
final WritableRaster raster = new DirectWritableRaster(sppsm, dataBuffer, location);
- return new BufferedImageInt(imageType, colorModel, raster, properties);
+ return new BufferedImageInt(imageType, colorModel, dataBuffer, raster, properties);
}
- /** Default data bank. */
- private final IntBuffer data;
+ /** Default NIO data bank storage, {@link ByteBuffer} representation. */
+ private final ByteBuffer dataBytes;
+ /** Default NIO data bank storage, {@link IntBuffer} representation. */
+ private final IntBuffer dataInts;
- /** All data banks */
- private final IntBuffer bankdata[];
+ /** All NIO data banks, {@link ByteBuffer} representation. */
+ private final ByteBuffer bankdataBytes[];
+ /** All NIO data banks, {@link IntBuffer} representation. */
+ private final IntBuffer bankdataInts[];
/**
* Constructs an nio integer-based {@link DataBuffer} with a single bank
@@ -180,9 +193,12 @@ public final class DirectDataBufferInt extends DataBuffer {
*/
public DirectDataBufferInt(final int size) {
super(TYPE_INT, size);
- data = Buffers.newDirectIntBuffer(size);
- bankdata = new IntBuffer[1];
- bankdata[0] = data;
+ dataBytes = Buffers.newDirectByteBuffer(size * Buffers.SIZEOF_INT);
+ dataInts = dataBytes.asIntBuffer();
+ bankdataBytes = new ByteBuffer[1];
+ bankdataInts = new IntBuffer[1];
+ bankdataBytes[0] = dataBytes;
+ bankdataInts[0] = dataInts;
}
/**
@@ -194,11 +210,14 @@ public final class DirectDataBufferInt extends DataBuffer {
*/
public DirectDataBufferInt(final int size, final int numBanks) {
super(TYPE_INT,size,numBanks);
- bankdata = new IntBuffer[numBanks];
+ bankdataBytes = new ByteBuffer[numBanks];
+ bankdataInts = new IntBuffer[numBanks];
for (int i= 0; i < numBanks; i++) {
- bankdata[i] = Buffers.newDirectIntBuffer(size);
+ bankdataBytes[i] = Buffers.newDirectByteBuffer(size * Buffers.SIZEOF_INT);
+ bankdataInts[i] = bankdataBytes[i].asIntBuffer();
}
- data = bankdata[0];
+ dataBytes = bankdataBytes[0];
+ dataInts = bankdataInts[0];
}
/**
@@ -210,33 +229,57 @@ public final class DirectDataBufferInt extends DataBuffer {
* hold <code>size</code> elements.
* </p>
*
- * @param dataArray The integer array for the {@link DataBuffer}.
+ * @param dataArray The NIO {@link ByteBuffer} array, holding the integer data for the {@link DataBuffer}.
* @param size The size of the {@link DataBuffer} bank.
*/
- public DirectDataBufferInt(final IntBuffer dataArray, final int size) {
+ public DirectDataBufferInt(final ByteBuffer dataArray, final int size) {
super(TYPE_INT,size);
- data = dataArray;
- bankdata = new IntBuffer[1];
- bankdata[0] = data;
+ dataBytes = Buffers.nativeOrder(dataArray);
+ dataInts = dataBytes.asIntBuffer();
+ bankdataBytes = new ByteBuffer[1];
+ bankdataInts = new IntBuffer[1];
+ bankdataBytes[0] = dataBytes;
+ bankdataInts[0] = dataInts;
}
/**
- * Returns the default (first) int data array in {@link DataBuffer}.
+ * Returns the default (first) int data array in {@link DataBuffer} as an {@link IntBuffer} representation.
*
* @return The first integer data array.
+ * @see #getDataBytes()
*/
public IntBuffer getData() {
- return data;
+ return dataInts;
+ }
+ /**
+ * Returns the default (first) int data array in {@link DataBuffer} as a {@link ByteBuffer} representation.
+ *
+ * @return The first integer data array.
+ * @see #getData()
+ */
+ public ByteBuffer getDataBytes() {
+ return dataBytes;
}
/**
- * Returns the data array for the specified bank.
+ * Returns the data array for the specified bank as an {@link IntBuffer} representation.
*
* @param bank The bank whose data array you want to get.
* @return The data array for the specified bank.
+ * @see #getDataBytes(int)
*/
public IntBuffer getData(final int bank) {
- return bankdata[bank];
+ return bankdataInts[bank];
+ }
+ /**
+ * Returns the data array for the specified bank as a {@link ByteBuffer} representation.
+ *
+ * @param bank The bank whose data array you want to get.
+ * @return The data array for the specified bank.
+ * @see #getData(int)
+ */
+ public ByteBuffer getDataBytes(final int bank) {
+ return bankdataBytes[bank];
}
/**
@@ -249,7 +292,7 @@ public final class DirectDataBufferInt extends DataBuffer {
*/
@Override
public int getElem(final int i) {
- return data.get(i+offset);
+ return dataInts.get(i+offset);
}
/**
@@ -263,7 +306,7 @@ public final class DirectDataBufferInt extends DataBuffer {
*/
@Override
public int getElem(final int bank, final int i) {
- return bankdata[bank].get(i+offsets[bank]);
+ return bankdataInts[bank].get(i+offsets[bank]);
}
/**
@@ -277,7 +320,7 @@ public final class DirectDataBufferInt extends DataBuffer {
*/
@Override
public void setElem(final int i, final int val) {
- data.put(i+offset, val);
+ dataInts.put(i+offset, val);
}
/**
@@ -291,7 +334,7 @@ public final class DirectDataBufferInt extends DataBuffer {
*/
@Override
public void setElem(final int bank, final int i, final int val) {
- bankdata[bank].put(i+offsets[bank], val);
+ bankdataInts[bank].put(i+offsets[bank], val);
}
}