Skip to content

Commit b13f519

Browse files
mkartashevYaaZ
authored andcommitted
JBR-9948 Wayland: blank window does not appear on screen
1 parent e55b4a5 commit b13f519

File tree

8 files changed

+141
-6
lines changed

8 files changed

+141
-6
lines changed

src/java.desktop/unix/classes/sun/awt/wl/WLComponentPeer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public class WLComponentPeer implements ComponentPeer, WLSurfaceSizeListener {
132132

133133
protected WLComponentPeer(Component target, boolean dropShadow) {
134134
this.target = target;
135-
this.background = target.getBackground();
135+
this.background = target.isBackgroundSet() ? target.getBackground() : SystemColor.window;
136136
Dimension size = constrainSize(target.getBounds().getSize());
137137
final WLGraphicsConfig config = (WLGraphicsConfig) target.getGraphicsConfiguration();
138138
displayScale = config.getDisplayScale();
@@ -999,7 +999,8 @@ public void setBackground(Color c) {
999999
return;
10001000
}
10011001
background = c;
1002-
// TODO: propagate this change to WLSurfaceData
1002+
SurfaceData.convertTo(WLSurfaceDataExt.class, surfaceData).setBackground(c);
1003+
postPaintEvent();
10031004
}
10041005
}
10051006

src/java.desktop/unix/classes/sun/java2d/vulkan/WLVKWindowSurfaceData.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package sun.java2d.vulkan;
2727

28+
import java.awt.Color;
2829
import java.awt.Component;
2930
import java.awt.GraphicsConfiguration;
3031
import java.awt.Rectangle;
@@ -112,6 +113,11 @@ public void revalidate(GraphicsConfiguration gc, int width, int height, int scal
112113
configure();
113114
}
114115

116+
@Override
117+
public void setBackground(Color background) {
118+
// TODO
119+
}
120+
115121
@Override
116122
public synchronized void commit() {
117123
VKRenderQueue rq = VKRenderQueue.getInstance();

src/java.desktop/unix/classes/sun/java2d/wl/WLSMSurfaceData.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ public void revalidate(GraphicsConfiguration gc, int width, int height, int scal
171171
@Override
172172
public native void commit();
173173

174+
@Override
175+
public void setBackground(Color background) {
176+
nativeSetBackground(background.getRGB());
177+
}
178+
174179
public int getRGBPixelAt(int x, int y) {
175180
int pixel = pixelAt(x, y);
176181
return getSurfaceType().rgbFor(pixel, getColorModel());
@@ -213,6 +218,7 @@ private void countDroppedFrame() {
213218
}
214219

215220
private native void nativeRevalidate(int width, int height, int scale);
221+
private native void nativeSetBackground(int rgb);
216222
private native int pixelAt(int x, int y);
217223
private native int [] pixelsAt(int x, int y, int width, int height);
218224
}

src/java.desktop/unix/classes/sun/java2d/wl/WLSurfaceDataExt.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626

2727
package sun.java2d.wl;
2828

29+
import java.awt.Color;
2930
import java.awt.GraphicsConfiguration;
3031

3132
public interface WLSurfaceDataExt {
3233
void assignSurface(long surfacePtr);
3334
void revalidate(GraphicsConfiguration gc, int width, int height, int scale);
35+
void setBackground(Color background);
3436
void commit();
3537
}

src/java.desktop/unix/native/common/java2d/wl/WLBuffers.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ CopyDrawBufferToShowBuffer(WLSurfaceBufferManager * manager);
5858
static void
5959
SendShowBufferToWayland(WLSurfaceBufferManager * manager);
6060

61+
static void
62+
DrawBufferResize(WLSurfaceBufferManager * manager);
63+
6164
static inline void
6265
ReportFatalError(const char* file, int line, const char *msg)
6366
{
@@ -140,7 +143,7 @@ DamageList_Add(DamageList* list, jint x, jint y, jint width, jint height)
140143
l = l->next;
141144
}
142145
}
143-
146+
144147
// Keep the list sorted so that adjacent areas follow one another
145148
// in memory in hope that this facilitates faster damage copying.
146149
l = list;
@@ -911,9 +914,16 @@ CopyDrawBufferToShowBuffer(WLSurfaceBufferManager * manager)
911914
ASSERT_SHOW_LOCK_IS_HELD(manager);
912915
ASSERT_DRAW_LOCK_IS_HELD(manager);
913916

914-
if (manager->bufferForShow.wlSurfaceBuffer == NULL
915-
|| manager->bufferForDraw.data == NULL
916-
|| manager->bufferForDraw.resizePending) {
917+
if (manager->bufferForShow.wlSurfaceBuffer == NULL) {
918+
return;
919+
}
920+
921+
if (manager->bufferForDraw.resizePending) {
922+
// Paint the background in case an empty window needs to be shown
923+
DrawBufferResize(manager);
924+
}
925+
926+
if (manager->bufferForDraw.data == NULL) {
917927
return;
918928
}
919929

@@ -1012,6 +1022,8 @@ DrawBufferResize(WLSurfaceBufferManager * manager)
10121022
for (jint i = 0; i < DrawBufferSizeInPixels(manager); ++i) {
10131023
manager->bufferForDraw.data[i] = manager->bgPixel;
10141024
}
1025+
// This is so that an empty window can still get displayed
1026+
manager->bufferForDraw.damageList = DamageList_Add(NULL, 0, 0, manager->bufferForDraw.width, manager->bufferForDraw.height);
10151027
}
10161028

10171029
static void ResetBuffers(WLSurfaceBufferManager * manager) {
@@ -1283,4 +1295,13 @@ WLSBM_SizeChangeTo(WLSurfaceBufferManager * manager, jint width, jint height)
12831295
MUTEX_UNLOCK(manager->showLock);
12841296
}
12851297

1298+
void
1299+
WLSBM_SetBackground(WLSurfaceBufferManager * manager, jint bg)
1300+
{
1301+
WLBufferTrace(manager, "WLSBM_SetBackground to 0x%x", bg);
1302+
MUTEX_LOCK(manager->drawLock);
1303+
manager->bgPixel = bg;
1304+
MUTEX_UNLOCK(manager->drawLock);
1305+
}
1306+
12861307
#endif

src/java.desktop/unix/native/common/java2d/wl/WLBuffers.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ jint WLSBM_HeightGet(WLSurfaceBufferManager *);
117117
*/
118118
void WLSBM_SizeChangeTo(WLSurfaceBufferManager *, jint width, jint height);
119119

120+
/**
121+
* Changes the background color (an ARGB value) for buffers managed by
122+
* the buffer manager.
123+
* Note: an extra repaint is needed after this call for the new background
124+
* to get used or repainted.
125+
*/
126+
void WLSBM_SetBackground(WLSurfaceBufferManager *, jint bg);
127+
120128
/**
121129
* Returns a buffer managed by the WayLand Surface Buffer Manager
122130
* that is suitable for drawing on it.

src/java.desktop/unix/native/common/java2d/wl/WLSMSurfaceData.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ Java_sun_java2d_wl_WLSMSurfaceData_nativeRevalidate(JNIEnv *env, jobject wsd,
139139
#endif /* !HEADLESS */
140140
}
141141

142+
JNIEXPORT void JNICALL
143+
Java_sun_java2d_wl_WLSMSurfaceData_nativeSetBackground(JNIEnv *env, jobject wsd,
144+
jint bg)
145+
{
146+
#ifndef HEADLESS
147+
J2dTrace(J2D_TRACE_INFO, "WLSMSurfaceData_nativeSetBackground to 0x%x\n", bg);
148+
WLSDOps *wsdo = (WLSDOps*)SurfaceData_GetOps(env, wsd);
149+
if (wsdo == NULL) {
150+
return;
151+
}
152+
153+
WLSBM_SetBackground(wsdo->bufferManager, bg);
154+
#endif
155+
}
156+
142157
JNIEXPORT jint JNICALL
143158
Java_sun_java2d_wl_WLSMSurfaceData_pixelAt(JNIEnv *env, jobject wsd, jint x, jint y)
144159
{
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2026, JetBrains s.r.o.. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.awt.Color;
25+
import java.awt.Frame;
26+
import java.awt.Robot;
27+
import java.awt.SystemColor;
28+
29+
/*
30+
* @test
31+
* @summary Verifies Window.setBackground() works correctly in various scenarios
32+
* @key headful
33+
* @run main WLSetBackground
34+
*/
35+
public class WLSetBackground {
36+
final static int PAUSE_MS = 500;
37+
38+
public static void main(String[] args) throws Exception {
39+
System.out.println("Color: default, size 500x500");
40+
Robot r = new Robot();
41+
Frame window = new Frame();
42+
window.setUndecorated(true);
43+
window.setVisible(true);
44+
window.setSize(500, 500);
45+
check(r, SystemColor.window);
46+
47+
System.out.println("Color: blue, size 100x500");
48+
window.setVisible(false);
49+
window.setBackground(Color.BLUE);
50+
window.setSize(100, 500);
51+
window.setVisible(true);
52+
check(r, Color.BLUE);
53+
54+
System.out.println("Color: green, size 200x200");
55+
window.setSize(200, 200);
56+
window.setBackground(Color.GREEN);
57+
window.repaint();
58+
check(r, Color.GREEN);
59+
60+
System.out.println("Color: red, size 200x200");
61+
window.setBackground(Color.RED);
62+
window.repaint();
63+
check(r, Color.RED);
64+
}
65+
66+
public static void check(Robot r, Color expectedBgColor) {
67+
r.waitForIdle();
68+
r.delay(PAUSE_MS);
69+
70+
Color c = r.getPixelColor(50, 50);
71+
System.out.println("Pixel color @(50, 50): " + c);
72+
if (!c.equals(expectedBgColor)) {
73+
throw new RuntimeException("Expected background color: " + expectedBgColor + ", actual: " + c);
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)