Skip to content

Commit 5ab2950

Browse files
YaaZjbrbot
authored andcommitted
JBR-5594 Pass display configuration from outside on full display update
1 parent 1dfaadf commit 5ab2950

File tree

3 files changed

+8
-99
lines changed

3 files changed

+8
-99
lines changed

src/java.desktop/macosx/classes/sun/awt/CGraphicsDevice.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public final class CGraphicsDevice extends GraphicsDevice
7070
private DisplayMode originalMode;
7171
private DisplayMode initialMode;
7272

73-
public CGraphicsDevice(final int displayID) {
73+
public CGraphicsDevice(final int displayID, DisplayConfiguration config) {
7474
this.displayID = displayID;
7575
this.initialMode = getDisplayMode();
7676
StringBuilder errorMessage = new StringBuilder();
@@ -94,7 +94,7 @@ public CGraphicsDevice(final int displayID) {
9494
}
9595

9696
// [JBR] we don't call displayChanged after creating a device, so call it here.
97-
displayChanged();
97+
updateDevice(config);
9898
}
9999

100100
int getDisplayID() {
@@ -177,20 +177,19 @@ public void displayChanged() {
177177
yResolution = nativeGetYResolution(displayID);
178178
isMirroring = nativeIsMirroring(displayID);
179179
bounds = nativeGetBounds(displayID).getBounds(); //does integer rounding
180-
screenInsets = nativeGetScreenInsets(displayID);
181-
initScaleFactor();
182180
resizeFSWindow(getFullScreenWindow(), bounds);
183181
//TODO configs?
184182
}
185183

186184
/**
187185
* @return false if display parameters were changed, so we need to recreate the device.
188186
*/
189-
boolean updateDevice() {
187+
boolean updateDevice(DisplayConfiguration config) {
190188
int s = scale;
191189
double xr = xResolution, yr = yResolution;
192190
boolean m = isMirroring;
193191
var b = bounds;
192+
updateDisplayParameters(config);
194193
displayChanged();
195194
return s == scale && xr == xResolution && yr == yResolution && m == isMirroring && b.equals(bounds);
196195
}
@@ -368,23 +367,6 @@ public DisplayMode[] getDisplayModes() {
368367
}
369368
}
370369

371-
private void initScaleFactor() {
372-
int _scale = scale;
373-
if (SunGraphicsEnvironment.isUIScaleEnabled()) {
374-
double debugScale = SunGraphicsEnvironment.getDebugScale();
375-
scale = (int) (debugScale >= 1
376-
? Math.round(debugScale)
377-
: nativeGetScaleFactor(displayID));
378-
} else {
379-
scale = 1;
380-
}
381-
if (_scale != scale && logger.isLoggable(PlatformLogger.Level.FINE)) {
382-
logger.fine("current scale = " + _scale + ", new scale = " + scale + " (" + this + ")");
383-
}
384-
}
385-
386-
private static native double nativeGetScaleFactor(int displayID);
387-
388370
private static native void nativeResetDisplayMode();
389371

390372
private static native void nativeSetDisplayMode(int displayID, int w, int h, int bpp, int refrate);
@@ -399,8 +381,6 @@ private void initScaleFactor() {
399381

400382
private static native boolean nativeIsMirroring(int displayID);
401383

402-
private static native Insets nativeGetScreenInsets(int displayID);
403-
404384
private static native Rectangle2D nativeGetBounds(int displayID);
405385

406386
private static native void nativeGetDisplayConfiguration(DisplayConfiguration config);

src/java.desktop/macosx/classes/sun/awt/CGraphicsEnvironment.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,15 @@ private synchronized void initDevices() {
251251
Map<Integer, CGraphicsDevice> old = new HashMap<>(devices);
252252
devices.clear();
253253
mainDisplayID = getMainDisplayID();
254+
CGraphicsDevice.DisplayConfiguration config = CGraphicsDevice.DisplayConfiguration.get();
254255

255256
// initialization of the graphics device may change list of displays on
256257
// hybrid systems via an activation of discrete video.
257258
// So, we initialize the main display first, then retrieve actual list
258259
// of displays, and then recheck the main display again.
259260
if (!old.containsKey(mainDisplayID)) {
260261
try {
261-
old.put(mainDisplayID, new CGraphicsDevice(mainDisplayID));
262+
old.put(mainDisplayID, new CGraphicsDevice(mainDisplayID, config));
262263
} catch (IllegalStateException e) {
263264
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
264265
logger.fine("Unable to initialize graphics device for displayID=" +
@@ -274,13 +275,13 @@ private synchronized void initDevices() {
274275
}
275276
for (int id : displayIDs) {
276277
old.compute(id, (i, d) -> {
277-
if (d != null && d.updateDevice()) {
278+
if (d != null && d.updateDevice(config)) {
278279
// Device didn't change -> reuse
279280
devices.put(i, d);
280281
return null;
281282
} else {
282283
// Device changed -> create new
283-
devices.put(i, new CGraphicsDevice(i));
284+
devices.put(i, new CGraphicsDevice(i, config));
284285
return d;
285286
}
286287
});

src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -363,47 +363,6 @@ static jobject createJavaDisplayMode(CGDisplayModeRef mode, JNIEnv *env) {
363363
return CGToJavaRect(env, rect);
364364
}
365365

366-
/*
367-
* Class: sun_awt_CGraphicsDevice
368-
* Method: nativeGetScreenInsets
369-
* Signature: (I)D
370-
*/
371-
JNIEXPORT jobject JNICALL
372-
Java_sun_awt_CGraphicsDevice_nativeGetScreenInsets
373-
(JNIEnv *env, jclass class, jint displayID)
374-
{
375-
jobject ret = NULL;
376-
__block NSRect frame = NSZeroRect;
377-
__block NSRect visibleFrame = NSZeroRect;
378-
JNI_COCOA_ENTER(env);
379-
380-
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
381-
NSArray *screens = [NSScreen screens];
382-
for (NSScreen *screen in screens) {
383-
NSDictionary *screenInfo = [screen deviceDescription];
384-
NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
385-
if ([screenID unsignedIntValue] == displayID){
386-
frame = [screen frame];
387-
visibleFrame = [screen visibleFrame];
388-
break;
389-
}
390-
}
391-
}];
392-
// Convert between Cocoa's coordinate system and Java.
393-
jint bottom = visibleFrame.origin.y - frame.origin.y;
394-
jint top = frame.size.height - visibleFrame.size.height - bottom;
395-
jint left = visibleFrame.origin.x - frame.origin.x;
396-
jint right = frame.size.width - visibleFrame.size.width - left;
397-
398-
DECLARE_CLASS_RETURN(jc_Insets, "java/awt/Insets", ret);
399-
DECLARE_METHOD_RETURN(jc_Insets_ctor, jc_Insets, "<init>", "(IIII)V", ret);
400-
ret = (*env)->NewObject(env, jc_Insets, jc_Insets_ctor, top, left, bottom, right);
401-
402-
JNI_COCOA_EXIT(env);
403-
404-
return ret;
405-
}
406-
407366
/*
408367
* Class: sun_awt_CGraphicsDevice
409368
* Method: nativeResetDisplayMode
@@ -555,37 +514,6 @@ static jobject createJavaDisplayMode(CGDisplayModeRef mode, JNIEnv *env) {
555514
return jreturnArray;
556515
}
557516

558-
/*
559-
* Class: sun_awt_CGraphicsDevice
560-
* Method: nativeGetScaleFactor
561-
* Signature: (I)D
562-
*/
563-
JNIEXPORT jdouble JNICALL
564-
Java_sun_awt_CGraphicsDevice_nativeGetScaleFactor
565-
(JNIEnv *env, jclass class, jint displayID)
566-
{
567-
__block jdouble ret = 1.0f;
568-
569-
JNI_COCOA_ENTER(env);
570-
571-
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
572-
NSArray *screens = [NSScreen screens];
573-
for (NSScreen *screen in screens) {
574-
NSDictionary *screenInfo = [screen deviceDescription];
575-
NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
576-
if ([screenID unsignedIntValue] == displayID){
577-
if ([screen respondsToSelector:@selector(backingScaleFactor)]) {
578-
ret = [screen backingScaleFactor];
579-
}
580-
break;
581-
}
582-
}
583-
}];
584-
585-
JNI_COCOA_EXIT(env);
586-
return ret;
587-
}
588-
589517
/*
590518
* Class: sun_awt_CGraphicsDevice
591519
* Method: nativeGetDisplayConfiguration

0 commit comments

Comments
 (0)