Skip to content

Commit 6c6545f

Browse files
author
Jose Pereda
committed
8285217: [Android] Window's screen is not updated after native screen was disposed
Reviewed-by: jvos
1 parent 7bb4819 commit 6c6545f

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/MonocleWindow.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ protected boolean _maximize(long nativeWindowPointer, boolean maximize,
264264
return true;
265265
}
266266

267+
@Override
268+
protected void notifyMoveToAnotherScreen(Screen screen) {
269+
super.notifyMoveToAnotherScreen(screen);
270+
}
271+
267272
void setFullScreen(boolean fullscreen) {
268273
NativeScreen screen = NativePlatformFactory.getNativePlatform().getScreen();
269274
int x = getX();

modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/MonocleWindowManager.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,18 @@ void repaintAll() {
173173
}
174174
}
175175

176-
static void repaintFromNative () {
177-
Platform.runLater(new Runnable () {
178-
179-
@Override
180-
public void run() {
181-
Screen.notifySettingsChanged();
182-
MonocleWindow focusedWindow = instance.getFocusedWindow();
183-
if (focusedWindow != null) {
184-
focusedWindow.setFullScreen(true);
176+
static void repaintFromNative(Screen screen) {
177+
Platform.runLater(() -> {
178+
Screen.notifySettingsChanged();
179+
MonocleWindow focusedWindow = instance.getFocusedWindow();
180+
if (focusedWindow != null) {
181+
if (screen != null && screen.getNativeScreen() != focusedWindow.getScreen().getNativeScreen()) {
182+
focusedWindow.notifyMoveToAnotherScreen(screen);
185183
}
186-
instance.repaintAll();
187-
Toolkit.getToolkit().requestNextPulse();
184+
focusedWindow.setFullScreen(true);
188185
}
186+
instance.repaintAll();
187+
Toolkit.getToolkit().requestNextPulse();
189188
});
190189
}
191190

modules/javafx.graphics/src/main/native-glass/monocle/android/nativeBridge.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ JavaVM *jVM = NULL;
3333

3434
static jclass jAndroidInputDeviceRegistryClass;
3535
static jclass jMonocleWindowManagerClass;
36+
static jclass jScreenClass;
3637

3738
static jmethodID monocle_gotTouchEventFromNative;
3839
static jmethodID monocle_dispatchKeyEventFromNative;
3940
static jmethodID monocle_repaintAll;
4041
static jmethodID monocle_registerDevice;
42+
static jmethodID screen_init;
4143

4244
ANativeWindow* androidWindow = NULL;
4345
jfloat androidDensity = 0.f;
@@ -51,16 +53,18 @@ void initializeFromJava (JNIEnv *env) {
5153
(*env)->FindClass(env, "com/sun/glass/ui/monocle/MonocleWindowManager"));
5254
jAndroidInputDeviceRegistryClass = (*env)->NewGlobalRef(env,
5355
(*env)->FindClass(env, "com/sun/glass/ui/monocle/AndroidInputDeviceRegistry"));
56+
jScreenClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "com/sun/glass/ui/Screen"));
5457
monocle_repaintAll = (*env)->GetStaticMethodID(
5558
env, jMonocleWindowManagerClass, "repaintFromNative",
56-
"()V");
59+
"(Lcom/sun/glass/ui/Screen;)V");
5760
monocle_gotTouchEventFromNative = (*env)->GetStaticMethodID(
5861
env, jAndroidInputDeviceRegistryClass, "gotTouchEventFromNative",
5962
"(I[I[I[I[II)V");
6063
monocle_dispatchKeyEventFromNative = (*env)->GetStaticMethodID(
6164
env, jAndroidInputDeviceRegistryClass, "dispatchKeyEventFromNative",
6265
"(II[CI)V");
6366
monocle_registerDevice = (*env)->GetStaticMethodID(env, jAndroidInputDeviceRegistryClass, "registerDevice","()V");
67+
screen_init = (*env)->GetMethodID(env, jScreenClass,"<init>", "(JIIIIIIIIIIIIIIIFFFF)V");
6468
GLASS_LOG_FINE("Initializing native Android Bridge done");
6569
}
6670

@@ -153,7 +157,19 @@ void androidJfx_requestGlassToRedraw() {
153157
GLASS_LOG_WARNING("we can't do this yet, no monocle_repaintAll\n");
154158
return;
155159
}
156-
(*javaEnv)->CallStaticVoidMethod(javaEnv, jMonocleWindowManagerClass, monocle_repaintAll);
160+
if (androidWindow == NULL) {
161+
GLASS_LOG_WARNING("we can't do this yet, no androidWindow\n");
162+
return;
163+
}
164+
int32_t width = ANativeWindow_getWidth(androidWindow) / androidDensity;
165+
int32_t height = ANativeWindow_getHeight(androidWindow) / androidDensity;
166+
jobject screen = (*javaEnv)->NewObject(javaEnv, jScreenClass, screen_init,
167+
(jlong) androidWindow, 24,
168+
0, 0, (jint) width, (jint) height,
169+
0, 0, (jint) width, (jint) height,
170+
0, 0, (jint) width, (jint) height,
171+
SCREEN_DPI, SCREEN_DPI, (jfloat) 1, (jfloat) 1, androidDensity, androidDensity);
172+
(*javaEnv)->CallStaticVoidMethod(javaEnv, jMonocleWindowManagerClass, monocle_repaintAll, screen);
157173
}
158174

159175
/* ===== called from Java ===== */

modules/javafx.graphics/src/main/native-glass/monocle/android/nativeBridge.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ void androidJfx_requestGlassToRedraw();
3636
#define GLASS_LOG_FINEST(...) ((void)__android_log_print(ANDROID_LOG_INFO,"GLASS", __VA_ARGS__))
3737
#define GLASS_LOG_WARNING(...) ((void)__android_log_print(ANDROID_LOG_INFO,"GLASS", __VA_ARGS__))
3838

39+
static const jint SCREEN_DPI = 100;
40+
3941
ANativeWindow* android_getNativeWindow(JNIEnv *env);
4042
jfloat android_getDensity(JNIEnv *env);
4143

0 commit comments

Comments
 (0)