JBR-5594 Pass display configuration from outside on full display update

This commit is contained in:
Nikita Gubarkov
2025-11-04 16:33:29 +01:00
committed by jbrbot
parent 0a3bb8842e
commit 318bfa96c5
3 changed files with 8 additions and 99 deletions

View File

@@ -70,7 +70,7 @@ public final class CGraphicsDevice extends GraphicsDevice
private DisplayMode originalMode;
private DisplayMode initialMode;
public CGraphicsDevice(final int displayID) {
public CGraphicsDevice(final int displayID, DisplayConfiguration config) {
this.displayID = displayID;
this.initialMode = getDisplayMode();
StringBuilder errorMessage = new StringBuilder();
@@ -94,7 +94,7 @@ public final class CGraphicsDevice extends GraphicsDevice
}
// [JBR] we don't call displayChanged after creating a device, so call it here.
displayChanged();
updateDevice(config);
}
int getDisplayID() {
@@ -177,8 +177,6 @@ public final class CGraphicsDevice extends GraphicsDevice
yResolution = nativeGetYResolution(displayID);
isMirroring = nativeIsMirroring(displayID);
bounds = nativeGetBounds(displayID).getBounds(); //does integer rounding
screenInsets = nativeGetScreenInsets(displayID);
initScaleFactor();
resizeFSWindow(getFullScreenWindow(), bounds);
//TODO configs?
}
@@ -186,11 +184,12 @@ public final class CGraphicsDevice extends GraphicsDevice
/**
* @return false if display parameters were changed, so we need to recreate the device.
*/
boolean updateDevice() {
boolean updateDevice(DisplayConfiguration config) {
int s = scale;
double xr = xResolution, yr = yResolution;
boolean m = isMirroring;
var b = bounds;
updateDisplayParameters(config);
displayChanged();
return s == scale && xr == xResolution && yr == yResolution && m == isMirroring && b.equals(bounds);
}
@@ -368,23 +367,6 @@ public final class CGraphicsDevice extends GraphicsDevice
}
}
private void initScaleFactor() {
int _scale = scale;
if (SunGraphicsEnvironment.isUIScaleEnabled()) {
double debugScale = SunGraphicsEnvironment.getDebugScale();
scale = (int) (debugScale >= 1
? Math.round(debugScale)
: nativeGetScaleFactor(displayID));
} else {
scale = 1;
}
if (_scale != scale && logger.isLoggable(PlatformLogger.Level.FINE)) {
logger.fine("current scale = " + _scale + ", new scale = " + scale + " (" + this + ")");
}
}
private static native double nativeGetScaleFactor(int displayID);
private static native void nativeResetDisplayMode();
private static native void nativeSetDisplayMode(int displayID, int w, int h, int bpp, int refrate);
@@ -399,8 +381,6 @@ public final class CGraphicsDevice extends GraphicsDevice
private static native boolean nativeIsMirroring(int displayID);
private static native Insets nativeGetScreenInsets(int displayID);
private static native Rectangle2D nativeGetBounds(int displayID);
private static native void nativeGetDisplayConfiguration(DisplayConfiguration config);

View File

@@ -251,6 +251,7 @@ public final class CGraphicsEnvironment extends SunGraphicsEnvironment {
Map<Integer, CGraphicsDevice> old = new HashMap<>(devices);
devices.clear();
mainDisplayID = getMainDisplayID();
CGraphicsDevice.DisplayConfiguration config = CGraphicsDevice.DisplayConfiguration.get();
// initialization of the graphics device may change list of displays on
// hybrid systems via an activation of discrete video.
@@ -258,7 +259,7 @@ public final class CGraphicsEnvironment extends SunGraphicsEnvironment {
// of displays, and then recheck the main display again.
if (!old.containsKey(mainDisplayID)) {
try {
old.put(mainDisplayID, new CGraphicsDevice(mainDisplayID));
old.put(mainDisplayID, new CGraphicsDevice(mainDisplayID, config));
} catch (IllegalStateException e) {
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
logger.fine("Unable to initialize graphics device for displayID=" +
@@ -274,13 +275,13 @@ public final class CGraphicsEnvironment extends SunGraphicsEnvironment {
}
for (int id : displayIDs) {
old.compute(id, (i, d) -> {
if (d != null && d.updateDevice()) {
if (d != null && d.updateDevice(config)) {
// Device didn't change -> reuse
devices.put(i, d);
return null;
} else {
// Device changed -> create new
devices.put(i, new CGraphicsDevice(i));
devices.put(i, new CGraphicsDevice(i, config));
return d;
}
});

View File

@@ -363,47 +363,6 @@ Java_sun_awt_CGraphicsDevice_nativeGetBounds
return CGToJavaRect(env, rect);
}
/*
* Class: sun_awt_CGraphicsDevice
* Method: nativeGetScreenInsets
* Signature: (I)D
*/
JNIEXPORT jobject JNICALL
Java_sun_awt_CGraphicsDevice_nativeGetScreenInsets
(JNIEnv *env, jclass class, jint displayID)
{
jobject ret = NULL;
__block NSRect frame = NSZeroRect;
__block NSRect visibleFrame = NSZeroRect;
JNI_COCOA_ENTER(env);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
NSArray *screens = [NSScreen screens];
for (NSScreen *screen in screens) {
NSDictionary *screenInfo = [screen deviceDescription];
NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
if ([screenID unsignedIntValue] == displayID){
frame = [screen frame];
visibleFrame = [screen visibleFrame];
break;
}
}
}];
// Convert between Cocoa's coordinate system and Java.
jint bottom = visibleFrame.origin.y - frame.origin.y;
jint top = frame.size.height - visibleFrame.size.height - bottom;
jint left = visibleFrame.origin.x - frame.origin.x;
jint right = frame.size.width - visibleFrame.size.width - left;
DECLARE_CLASS_RETURN(jc_Insets, "java/awt/Insets", ret);
DECLARE_METHOD_RETURN(jc_Insets_ctor, jc_Insets, "<init>", "(IIII)V", ret);
ret = (*env)->NewObject(env, jc_Insets, jc_Insets_ctor, top, left, bottom, right);
JNI_COCOA_EXIT(env);
return ret;
}
/*
* Class: sun_awt_CGraphicsDevice
* Method: nativeResetDisplayMode
@@ -555,37 +514,6 @@ Java_sun_awt_CGraphicsDevice_nativeGetDisplayModes
return jreturnArray;
}
/*
* Class: sun_awt_CGraphicsDevice
* Method: nativeGetScaleFactor
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_sun_awt_CGraphicsDevice_nativeGetScaleFactor
(JNIEnv *env, jclass class, jint displayID)
{
__block jdouble ret = 1.0f;
JNI_COCOA_ENTER(env);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
NSArray *screens = [NSScreen screens];
for (NSScreen *screen in screens) {
NSDictionary *screenInfo = [screen deviceDescription];
NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
if ([screenID unsignedIntValue] == displayID){
if ([screen respondsToSelector:@selector(backingScaleFactor)]) {
ret = [screen backingScaleFactor];
}
break;
}
}
}];
JNI_COCOA_EXIT(env);
return ret;
}
/*
* Class: sun_awt_CGraphicsDevice
* Method: nativeGetDisplayConfiguration