Skip to content

Commit a7c2ebc

Browse files
committed
8239894: Xserver crashes when the wrong high refresh rate is used
Reviewed-by: kizune
1 parent 2f47c39 commit a7c2ebc

File tree

5 files changed

+18
-307
lines changed

5 files changed

+18
-307
lines changed

src/java.desktop/unix/classes/sun/awt/X11GraphicsDevice.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -386,7 +386,10 @@ public synchronized DisplayMode getDisplayMode() {
386386

387387
@Override
388388
public synchronized DisplayMode[] getDisplayModes() {
389-
if (!isFullScreenSupported()) {
389+
if (!isFullScreenSupported()
390+
|| ((X11GraphicsEnvironment) GraphicsEnvironment
391+
.getLocalGraphicsEnvironment()).runningXinerama()) {
392+
// only the current mode will be returned
390393
return super.getDisplayModes();
391394
}
392395
ArrayList<DisplayMode> modes = new ArrayList<DisplayMode>();
Lines changed: 3 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,169 +24,7 @@
2424
*/
2525

2626
#include "systemScale.h"
27-
#include "jni.h"
28-
#include "jni_util.h"
29-
#include "jvm_md.h"
30-
#include <dlfcn.h>
31-
#include <stdio.h>
3227
#include <stdlib.h>
33-
#include <string.h>
34-
35-
typedef void* g_settings_schema_source_get_default();
36-
typedef void* g_settings_schema_source_ref(void *);
37-
typedef void g_settings_schema_source_unref(void *);
38-
typedef void* g_settings_schema_source_lookup(void *, char *, int);
39-
typedef int g_settings_schema_has_key(void *, char *);
40-
typedef void* g_settings_new_full(void *, void *, char *);
41-
typedef void* g_settings_get_value(void *, char *);
42-
typedef int g_variant_is_of_type(void *, char *);
43-
typedef unsigned long g_variant_n_children(void *);
44-
typedef void* g_variant_get_child_value(void *, unsigned long);
45-
typedef void g_variant_unref(void *);
46-
typedef char* g_variant_get_string(void *, unsigned long *);
47-
typedef int g_variant_get_int32(void *);
48-
typedef double g_variant_get_double(void *);
49-
50-
static g_settings_schema_has_key* fp_g_settings_schema_has_key;
51-
static g_settings_new_full* fp_g_settings_new_full;
52-
static g_settings_get_value* fp_g_settings_get_value;
53-
static g_variant_is_of_type* fp_g_variant_is_of_type;
54-
static g_variant_n_children* fp_g_variant_n_children;
55-
static g_variant_get_child_value* fp_g_variant_get_child_value;
56-
static g_variant_get_string* fp_g_variant_get_string;
57-
static g_variant_get_int32* fp_g_variant_get_int32;
58-
static g_variant_get_double* fp_g_variant_get_double;
59-
static g_variant_unref* fp_g_variant_unref;
60-
61-
static void* get_schema_value(char *name, char *key) {
62-
static void *lib_handle;
63-
static int initialized = 0;
64-
static void * default_schema;
65-
static g_settings_schema_source_lookup* schema_lookup;
66-
void *schema = NULL, *fp = NULL;
67-
if (!initialized) {
68-
initialized = 1;
69-
lib_handle = dlopen(JNI_LIB_NAME("gio-2.0"), RTLD_GLOBAL | RTLD_LAZY);
70-
if (!lib_handle) {
71-
CHECK_NULL_RETURN(lib_handle =
72-
dlopen(VERSIONED_JNI_LIB_NAME("gio-2.0", "0"),
73-
RTLD_GLOBAL | RTLD_LAZY), NULL);
74-
}
75-
CHECK_NULL_RETURN(fp_g_settings_schema_has_key =
76-
(g_settings_schema_has_key*)
77-
dlsym(lib_handle, "g_settings_schema_has_key"), NULL);
78-
CHECK_NULL_RETURN(fp_g_settings_new_full =
79-
(g_settings_new_full*)
80-
dlsym(lib_handle, "g_settings_new_full"), NULL);
81-
CHECK_NULL_RETURN(fp_g_settings_get_value =
82-
(g_settings_get_value*)
83-
dlsym(lib_handle, "g_settings_get_value"), NULL);
84-
CHECK_NULL_RETURN(fp_g_variant_is_of_type =
85-
(g_variant_is_of_type*)
86-
dlsym(lib_handle, "g_variant_is_of_type"), NULL);
87-
CHECK_NULL_RETURN(fp_g_variant_n_children =
88-
(g_variant_n_children*)
89-
dlsym(lib_handle, "g_variant_n_children"), NULL);
90-
CHECK_NULL_RETURN(fp_g_variant_get_child_value =
91-
(g_variant_get_child_value*)
92-
dlsym(lib_handle, "g_variant_get_child_value"), NULL);
93-
CHECK_NULL_RETURN(fp_g_variant_get_string =
94-
(g_variant_get_string*)
95-
dlsym(lib_handle, "g_variant_get_string"), NULL);
96-
CHECK_NULL_RETURN(fp_g_variant_get_int32 =
97-
(g_variant_get_int32*)
98-
dlsym(lib_handle, "g_variant_get_int32"), NULL);
99-
CHECK_NULL_RETURN(fp_g_variant_get_double =
100-
(g_variant_get_double*)
101-
dlsym(lib_handle, "g_variant_get_double"), NULL);
102-
CHECK_NULL_RETURN(fp_g_variant_unref =
103-
(g_variant_unref*)
104-
dlsym(lib_handle, "g_variant_unref"), NULL);
105-
106-
fp = dlsym(lib_handle, "g_settings_schema_source_get_default");
107-
if (fp) {
108-
default_schema = ((g_settings_schema_source_get_default*)fp)();
109-
}
110-
if (default_schema) {
111-
fp = dlsym(lib_handle, "g_settings_schema_source_ref");
112-
if (fp) {
113-
((g_settings_schema_source_ref*)fp)(default_schema);
114-
}
115-
}
116-
schema_lookup = (g_settings_schema_source_lookup*)
117-
dlsym(lib_handle, "g_settings_schema_source_lookup");
118-
}
119-
120-
if (!default_schema || !schema_lookup) {
121-
return NULL;
122-
}
123-
124-
schema = schema_lookup(default_schema, name, 1);
125-
if (schema) {
126-
if (fp_g_settings_schema_has_key(schema, key)) {
127-
void *settings = fp_g_settings_new_full(schema, NULL, NULL);
128-
if (settings) {
129-
return fp_g_settings_get_value(settings, key);
130-
}
131-
}
132-
}
133-
return NULL;
134-
}
135-
136-
137-
static double getDesktopScale(char *output_name) {
138-
double result = -1;
139-
if(output_name) {
140-
void *value = get_schema_value("com.ubuntu.user-interface",
141-
"scale-factor");
142-
if (value) {
143-
if(fp_g_variant_is_of_type(value, "a{si}")) {
144-
int num = fp_g_variant_n_children(value);
145-
int i = 0;
146-
while (i < num) {
147-
void *entry = fp_g_variant_get_child_value(value, i++);
148-
if (entry) {
149-
void *screen = fp_g_variant_get_child_value(entry, 0);
150-
void *scale = fp_g_variant_get_child_value(entry, 1);
151-
if (screen && scale) {
152-
char *name = fp_g_variant_get_string(screen, NULL);
153-
if (name && !strcmp(name, output_name)) {
154-
result = fp_g_variant_get_int32(scale) / 8.;
155-
}
156-
fp_g_variant_unref(screen);
157-
fp_g_variant_unref(scale);
158-
}
159-
fp_g_variant_unref(entry);
160-
}
161-
if (result > 0) {
162-
break;
163-
}
164-
}
165-
}
166-
fp_g_variant_unref(value);
167-
}
168-
if (result > 0) {
169-
value = get_schema_value("com.canonical.Unity.Interface",
170-
"text-scale-factor");
171-
if (value && fp_g_variant_is_of_type(value, "d")) {
172-
result *= fp_g_variant_get_double(value);
173-
fp_g_variant_unref(value);
174-
}
175-
}
176-
}
177-
178-
if (result <= 0) {
179-
void *value = get_schema_value("org.gnome.desktop.interface",
180-
"text-scaling-factor");
181-
if (value && fp_g_variant_is_of_type(value, "d")) {
182-
result = fp_g_variant_get_double(value);
183-
fp_g_variant_unref(value);
184-
}
185-
}
186-
187-
return result;
188-
189-
}
19028

19129
static int getScale(const char *name) {
19230
char *uiScale = getenv(name);
@@ -200,10 +38,8 @@ static int getScale(const char *name) {
20038
return -1;
20139
}
20240

203-
double getNativeScaleFactor(char *output_name) {
41+
double getNativeScaleFactor() {
20442
static int scale = -2.0;
205-
double native_scale = 0;
206-
int gdk_scale = 0;
20743

20844
if (scale == -2) {
20945
scale = getScale("J2D_UISCALE");
@@ -213,13 +49,5 @@ double getNativeScaleFactor(char *output_name) {
21349
return scale;
21450
}
21551

216-
native_scale = getDesktopScale(output_name);
217-
218-
if (native_scale <= 0) {
219-
native_scale = 1;
220-
}
221-
222-
gdk_scale = getScale("GDK_SCALE");
223-
224-
return gdk_scale > 0 ? native_scale * gdk_scale : native_scale;
52+
return getScale("GDK_SCALE");
22553
}

src/java.desktop/unix/native/common/awt/systemscale/systemScale.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,7 +28,7 @@
2828
#include <signal.h>
2929
#include <stdlib.h>
3030

31-
double getNativeScaleFactor(char *output_name);
31+
double getNativeScaleFactor();
3232

3333
#endif
3434

0 commit comments

Comments
 (0)