Skip to content

Commit 34a06fd

Browse files
author
Not Zed
committed
JDK-8210547 synchronise with OpenGL after the last window is presented
1 parent e2c4a70 commit 34a06fd

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/GlassScene.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ abstract class GlassScene implements TKScene {
6565
private volatile boolean entireSceneDirty = true;
6666

6767
private boolean doPresent = true;
68+
private boolean doVSync = false;
6869
private final AtomicBoolean painting = new AtomicBoolean(false);
6970

7071
private final boolean depthBuffer;
@@ -307,6 +308,14 @@ public final synchronized boolean getDoPresent() {
307308
return doPresent;
308309
}
309310

311+
public final synchronized void setDoVSync(boolean value) {
312+
doVSync = value;
313+
}
314+
315+
public final synchronized boolean getDoVsync() {
316+
return doVSync;
317+
}
318+
310319
protected Color getClearColor() {
311320
WindowStage windowStage = stage instanceof WindowStage ? (WindowStage)stage : null;
312321
if (windowStage != null && windowStage.getPlatformWindow() != null &&

modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/PaintCollector.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,14 @@ final void renderAll() {
434434
if (!needsHint) {
435435
needsHint = gs.isSynchronous();
436436
}
437+
}
438+
439+
for (final GlassScene gs : dirtyScenes) {
437440
// On platforms with a window manager, we always set doPresent = true, because
438441
// we always need to rerender the scene if it's in the dirty list and we do a
439442
// swap on a per-window basis
440443
gs.setDoPresent(true);
444+
gs.setDoVSync(needsHint && dirtyScenes.getLast() == gs);
441445
try {
442446
gs.repaint();
443447
} catch (Throwable t) {

modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/PresentingPainter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ final class PresentingPainter extends ViewPainter {
104104

105105
/* present for vsync buffer swap */
106106
if (vs.getDoPresent()) {
107-
if (!presentable.present()) {
107+
if (!presentable.present(vs.getDoVsync())) {
108108
disposePresentable();
109109
sceneState.getScene().entireSceneNeedsRepaint();
110110
}

modules/javafx.graphics/src/main/java/com/sun/prism/Presentable.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public interface Presentable extends RenderTarget {
5757
*/
5858
public boolean present();
5959

60+
public default boolean present(boolean vsync) {
61+
return present();
62+
}
63+
6064
public float getPixelScaleFactorX();
6165
public float getPixelScaleFactorY();
6266
}

modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2SwapChain.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,16 @@ private void drawTexture(ES2Graphics g, RTTexture src,
183183

184184
@Override
185185
public boolean present() {
186-
boolean presented = drawable.swapBuffers(context.getGLContext());
187-
context.makeCurrent(null);
186+
return drawable.swapBuffers(context.getGLContext());
187+
}
188+
189+
@Override
190+
public boolean present(boolean vsync) {
191+
boolean presented = present();
192+
193+
if (vsync)
194+
context.getGLContext().finish();
195+
188196
return presented;
189197
}
190198

@@ -308,6 +316,7 @@ public void dispose() {
308316
}
309317

310318
if (drawable != null) {
319+
context.makeCurrent(null);
311320
drawable.dispose();
312321
drawable = null;
313322
}

0 commit comments

Comments
 (0)