Skip to content

Commit

Permalink
8275715: D3D pipeline processes multiple PaintEvent at initial drawing
Browse files Browse the repository at this point in the history
Reviewed-by: prr
  • Loading branch information
Masanori Yano committed Mar 6, 2022
1 parent 974ef55 commit 415bf44
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public Graphics2D createGraphics(SurfaceData sd,
{
if (!done && sd instanceof D3DWindowSurfaceData) {
D3DWindowSurfaceData d3dw = (D3DWindowSurfaceData)sd;
if (!d3dw.isSurfaceLost() || validate(d3dw)) {
if (!d3dw.isSurfaceLost() || validate(d3dw, false)) {
trackScreenSurface(d3dw);
return new SunGraphics2D(sd, fgColor, bgColor, font);
}
Expand Down Expand Up @@ -452,7 +452,7 @@ public void run() {
} finally {
rq.unlock();
}
} else if (!validate(sd)) {
} else if (!validate(sd, true)) {
// it is possible that the validation may never
// succeed, we need to detect this and replace
// the d3dw surface with gdi; the replacement of
Expand All @@ -474,7 +474,7 @@ public void run() {
* @return true if surface wasn't lost or if restoration was successful,
* false otherwise
*/
private boolean validate(D3DWindowSurfaceData sd) {
private boolean validate(D3DWindowSurfaceData sd, boolean postEvent) {
if (sd.isSurfaceLost()) {
try {
sd.restoreSurface();
Expand All @@ -491,7 +491,9 @@ private boolean validate(D3DWindowSurfaceData sd) {
sd.markClean();
// since the surface was successfully restored we need to
// repaint whole window to repopulate the back-buffer
repaintPeerTarget(sd.getPeer());
if (postEvent) {
repaintPeerTarget(sd.getPeer());
}
} catch (InvalidPipeException ipe) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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();
}
}
}

1 comment on commit 415bf44

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.