8298876: Swing applications do not get repainted coming out of sleep on Windows 10

Reviewed-by: angorya, prr
This commit is contained in:
Prasanta Sadhukhan 2023-01-09 10:14:06 +00:00
parent a503ec2cc7
commit 4072412c1f
2 changed files with 4 additions and 92 deletions
src/java.desktop/windows/classes/sun/java2d/d3d
test/jdk/sun/java2d/DirectX/MultiPaintEventTest

@ -258,7 +258,7 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager
{
if (!done && sd instanceof D3DWindowSurfaceData) {
D3DWindowSurfaceData d3dw = (D3DWindowSurfaceData)sd;
if (!d3dw.isSurfaceLost() || validate(d3dw, false)) {
if (!d3dw.isSurfaceLost() || validate(d3dw)) {
trackScreenSurface(d3dw);
return new SunGraphics2D(sd, fgColor, bgColor, font);
}
@ -452,7 +452,7 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager
} finally {
rq.unlock();
}
} else if (!validate(sd, true)) {
} else if (!validate(sd)) {
// it is possible that the validation may never
// succeed, we need to detect this and replace
// the d3dw surface with gdi; the replacement of
@ -474,7 +474,7 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager
* @return true if surface wasn't lost or if restoration was successful,
* false otherwise
*/
private boolean validate(D3DWindowSurfaceData sd, boolean postEvent) {
private boolean validate(D3DWindowSurfaceData sd) {
if (sd.isSurfaceLost()) {
try {
sd.restoreSurface();
@ -491,9 +491,7 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager
sd.markClean();
// since the surface was successfully restored we need to
// repaint whole window to repopulate the back-buffer
if (postEvent) {
repaintPeerTarget(sd.getPeer());
}
repaintPeerTarget(sd.getPeer());
} catch (InvalidPipeException ipe) {
return false;
}

@ -1,86 +0,0 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @key headful
* @bug 8275715
* @summary Tests that paint method is not called twice
* @run main/othervm MultiPaintEventTest
*/
import java.awt.*;
public class MultiPaintEventTest extends Canvas {
private int count = 0;
private final Object lock = new Object();
public void paint(Graphics g) {
synchronized(lock) {
count++;
}
int w = getWidth();
int h = getHeight();
Graphics2D g2d = (Graphics2D)g;
if (count % 2 == 1) {
g2d.setColor(Color.green);
} else {
g2d.setColor(Color.red);
}
g2d.fillRect(0, 0, w, h);
}
public int getCount() {
synchronized(lock) {
return count;
}
}
public Dimension getPreferredSize() {
return new Dimension(400, 400);
}
public static void main(String[] args) {
MultiPaintEventTest test = new MultiPaintEventTest();
Frame frame = new Frame();
frame.setUndecorated(true);
frame.add(test);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
try {
Thread.sleep(2000);
if (test.getCount() > 1) {
throw new RuntimeException("Processed unnecessary paint().");
}
} catch (InterruptedException ex) {
throw new RuntimeException("Failed: Interrupted");
} finally {
frame.dispose();
}
}
}