Skip to content
Permalink
Browse files

8201567: QuantumRenderer modifies buffer in use by JavaFX Application…

… Thread

Reviewed-by: kcr, arapte
  • Loading branch information
jgneff authored and kevinrushforth committed Jul 10, 2020
1 parent 126637f commit d67c47fd6bd0b7e31c3d6adf61b3e2cef9d79b7d
@@ -167,8 +167,11 @@ public final int getBytesPerComponent() {
return this.bytesPerComponent;
}

/*
* Return the original pixels buffer.
/**
* Rewinds and returns the buffer used to create this {@code Pixels} object.
*
* @return the original pixels buffer with its position set to zero and its
* mark discarded
*/
public final Buffer getPixels() {
if (this.bytes != null) {
@@ -182,6 +185,21 @@ public final Buffer getPixels() {
}
}

/**
* Returns the buffer used to create this {@code Pixels} object.
*
* @return the original pixels buffer, unmodified
*/
public final Buffer getBuffer() {
if (this.bytes != null) {
return this.bytes;
} else if (this.ints != null) {
return this.ints;
} else {
throw new RuntimeException("Unexpected Pixels state.");
}
}

/*
* Return a copy of pixels as bytes.
*/
@@ -582,9 +582,11 @@ int getByteOffset() {
*/
ByteBuffer getOffscreenBuffer() {
/*
* Allocates a direct byte buffer to avoid bug JDK-8201567,
* "QuantumRenderer modifies buffer in use by JavaFX Application Thread"
* <https://bugs.openjdk.java.net/browse/JDK-8201567>.
* In this case, a direct byte buffer outside of the normal heap is
* faster than a non-direct byte buffer on the heap. The frame rate is
* roughly 10 to 40 percent faster for a framebuffer with 8 bits per
* pixel and 40 to 60 percent faster for a framebuffer with 16 bits per
* pixel, depending on the device processor and screen size.
*/
int size = xresVirtual * yres * Integer.BYTES;
return ByteBuffer.allocateDirect(size);
@@ -100,7 +100,7 @@ public synchronized void skipLatestPixels() {
private boolean usesSameBuffer(Pixels p1, Pixels p2) {
if (p1 == p2) return true;
if (p1 == null || p2 == null) return false;
return (p1.getPixels() == p2.getPixels());
return (p1.getBuffer() == p2.getBuffer());
}

/**

0 comments on commit d67c47f

Please sign in to comment.