Skip to content

Commit

Permalink
JBR-6452 Wayland: measure and improve surface buffer management
Browse files Browse the repository at this point in the history
Improved rendering performance by
* reducing memory copy and making it more efficient,
* tying the next frame display to the frame event from Wayland,
  which dramatically reduces load for very quick Swing apps,
* limiting the number of buffers to 2.
  • Loading branch information
mkartashev authored and jbrbot committed Nov 8, 2024
1 parent 7d750cf commit e625eec
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 248 deletions.
10 changes: 6 additions & 4 deletions src/java.desktop/unix/classes/sun/awt/wl/WLComponentPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class WLComponentPeer implements ComponentPeer {
{"hand"}, // HAND_CURSOR
{"move"}, // MOVE_CURSOR
};
private static final int WHEEL_SCROLL_AMOUNT = 3;

private long nativePtr;
private volatile boolean surfaceAssigned = false;
Expand Down Expand Up @@ -381,16 +382,17 @@ public Graphics getGraphics() {
* Commits changes accumulated in the underlying SurfaceData object
* to the server for displaying on the screen. The request may not be
* granted immediately as the server may be busy reading data provided
* previously. In the latter case, the commit will happen later when
* the server notifies us (through an event on EDT) that the displaying
* buffer is ready to accept new data.
* previously. In the latter case, the commit will automatically happen
* later when the server notifies us (through an event on EDT) that
* the displaying buffer is ready to accept new data.
*/
public void commitToServer() {
performLocked(() -> {
if (getWLSurface(nativePtr) != 0) {
surfaceData.flush();
}
});
Toolkit.getDefaultToolkit().sync();
}

public Component getTarget() {
Expand Down Expand Up @@ -1068,7 +1070,7 @@ void dispatchPointerEventInContext(WLPointerEvent e, WLInputState oldInputState,
isPopupTrigger,
MouseWheelEvent.WHEEL_UNIT_SCROLL,
1,
e.getAxis0Value());
Integer.signum(e.getAxis0Value()) * WHEEL_SCROLL_AMOUNT);
postMouseEvent(mouseEvent);
}

Expand Down
18 changes: 11 additions & 7 deletions src/java.desktop/unix/classes/sun/awt/wl/WLToolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ public class WLToolkit extends UNIXToolkit implements Runnable {
@SuppressWarnings("removal")
public WLToolkit() {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
final String extraButtons = "sun.awt.enableExtraMouseButtons";
areExtraMouseButtonsEnabled =
Boolean.parseBoolean(System.getProperty(extraButtons, "true"));
System.setProperty(extraButtons, String.valueOf(areExtraMouseButtonsEnabled));
initSystemProperties();
return null;
});

Expand All @@ -181,6 +178,13 @@ public WLToolkit() {
}
}

private static void initSystemProperties() {
final String extraButtons = "sun.awt.enableExtraMouseButtons";
areExtraMouseButtonsEnabled =
Boolean.parseBoolean(System.getProperty(extraButtons, "true"));
System.setProperty(extraButtons, String.valueOf(areExtraMouseButtonsEnabled));
}

public static boolean isToolkitThread() {
return Thread.currentThread() == toolkitThread;
}
Expand Down Expand Up @@ -873,9 +877,9 @@ public boolean isAlwaysOnTopSupported() {

@Override
public boolean useBufferPerWindow() {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
log.fine("Not implemented: WLToolkit.useBufferPerWindow()");
}
// TODO: this may depend on the rendering engine used.
// When rendering is performed into memory buffers shared with Wayland,
// there's no sense in having additional buffers in AWT/Swing.
return false;
}

Expand Down
Loading

0 comments on commit e625eec

Please sign in to comment.