Skip to content

Commit

Permalink
8201567: QuantumRenderer modifies buffer in use by JavaFX Application…
Browse files Browse the repository at this point in the history
… Thread

Reviewed-by: kcr, arapte
  • Loading branch information
jgneff authored and kevinrushforth committed Jul 10, 2020
1 parent 126637f commit d67c47f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
22 changes: 20 additions & 2 deletions modules/javafx.graphics/src/main/java/com/sun/glass/ui/Pixels.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit d67c47f

Please sign in to comment.