Skip to content

Commit

Permalink
8285217: [Android] Window's screen is not updated after native screen…
Browse files Browse the repository at this point in the history
… was disposed

Reviewed-by: jvos
  • Loading branch information
Jose Pereda committed May 10, 2022
1 parent 7bb4819 commit 6c6545f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
Expand Up @@ -264,6 +264,11 @@ protected boolean _maximize(long nativeWindowPointer, boolean maximize,
return true;
}

@Override
protected void notifyMoveToAnotherScreen(Screen screen) {
super.notifyMoveToAnotherScreen(screen);
}

void setFullScreen(boolean fullscreen) {
NativeScreen screen = NativePlatformFactory.getNativePlatform().getScreen();
int x = getX();
Expand Down
Expand Up @@ -173,19 +173,18 @@ void repaintAll() {
}
}

static void repaintFromNative () {
Platform.runLater(new Runnable () {

@Override
public void run() {
Screen.notifySettingsChanged();
MonocleWindow focusedWindow = instance.getFocusedWindow();
if (focusedWindow != null) {
focusedWindow.setFullScreen(true);
static void repaintFromNative(Screen screen) {
Platform.runLater(() -> {
Screen.notifySettingsChanged();
MonocleWindow focusedWindow = instance.getFocusedWindow();
if (focusedWindow != null) {
if (screen != null && screen.getNativeScreen() != focusedWindow.getScreen().getNativeScreen()) {
focusedWindow.notifyMoveToAnotherScreen(screen);
}
instance.repaintAll();
Toolkit.getToolkit().requestNextPulse();
focusedWindow.setFullScreen(true);
}
instance.repaintAll();
Toolkit.getToolkit().requestNextPulse();
});
}

Expand Down
Expand Up @@ -33,11 +33,13 @@ JavaVM *jVM = NULL;

static jclass jAndroidInputDeviceRegistryClass;
static jclass jMonocleWindowManagerClass;
static jclass jScreenClass;

static jmethodID monocle_gotTouchEventFromNative;
static jmethodID monocle_dispatchKeyEventFromNative;
static jmethodID monocle_repaintAll;
static jmethodID monocle_registerDevice;
static jmethodID screen_init;

ANativeWindow* androidWindow = NULL;
jfloat androidDensity = 0.f;
Expand All @@ -51,16 +53,18 @@ void initializeFromJava (JNIEnv *env) {
(*env)->FindClass(env, "com/sun/glass/ui/monocle/MonocleWindowManager"));
jAndroidInputDeviceRegistryClass = (*env)->NewGlobalRef(env,
(*env)->FindClass(env, "com/sun/glass/ui/monocle/AndroidInputDeviceRegistry"));
jScreenClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "com/sun/glass/ui/Screen"));
monocle_repaintAll = (*env)->GetStaticMethodID(
env, jMonocleWindowManagerClass, "repaintFromNative",
"()V");
"(Lcom/sun/glass/ui/Screen;)V");
monocle_gotTouchEventFromNative = (*env)->GetStaticMethodID(
env, jAndroidInputDeviceRegistryClass, "gotTouchEventFromNative",
"(I[I[I[I[II)V");
monocle_dispatchKeyEventFromNative = (*env)->GetStaticMethodID(
env, jAndroidInputDeviceRegistryClass, "dispatchKeyEventFromNative",
"(II[CI)V");
monocle_registerDevice = (*env)->GetStaticMethodID(env, jAndroidInputDeviceRegistryClass, "registerDevice","()V");
screen_init = (*env)->GetMethodID(env, jScreenClass,"<init>", "(JIIIIIIIIIIIIIIIFFFF)V");
GLASS_LOG_FINE("Initializing native Android Bridge done");
}

Expand Down Expand Up @@ -153,7 +157,19 @@ void androidJfx_requestGlassToRedraw() {
GLASS_LOG_WARNING("we can't do this yet, no monocle_repaintAll\n");
return;
}
(*javaEnv)->CallStaticVoidMethod(javaEnv, jMonocleWindowManagerClass, monocle_repaintAll);
if (androidWindow == NULL) {
GLASS_LOG_WARNING("we can't do this yet, no androidWindow\n");
return;
}
int32_t width = ANativeWindow_getWidth(androidWindow) / androidDensity;
int32_t height = ANativeWindow_getHeight(androidWindow) / androidDensity;
jobject screen = (*javaEnv)->NewObject(javaEnv, jScreenClass, screen_init,
(jlong) androidWindow, 24,
0, 0, (jint) width, (jint) height,
0, 0, (jint) width, (jint) height,
0, 0, (jint) width, (jint) height,
SCREEN_DPI, SCREEN_DPI, (jfloat) 1, (jfloat) 1, androidDensity, androidDensity);
(*javaEnv)->CallStaticVoidMethod(javaEnv, jMonocleWindowManagerClass, monocle_repaintAll, screen);
}

/* ===== called from Java ===== */
Expand Down
Expand Up @@ -36,6 +36,8 @@ void androidJfx_requestGlassToRedraw();
#define GLASS_LOG_FINEST(...) ((void)__android_log_print(ANDROID_LOG_INFO,"GLASS", __VA_ARGS__))
#define GLASS_LOG_WARNING(...) ((void)__android_log_print(ANDROID_LOG_INFO,"GLASS", __VA_ARGS__))

static const jint SCREEN_DPI = 100;

ANativeWindow* android_getNativeWindow(JNIEnv *env);
jfloat android_getDensity(JNIEnv *env);

Expand Down

1 comment on commit 6c6545f

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.