Skip to content

Commit

Permalink
Send null window when surface gets destroyed (#1126)
Browse files Browse the repository at this point in the history
* Send null window when surface gets destroyed

* Fix typo

* Use handler to run delayed on ui thread

* Bump JavaFX version

Co-authored-by: jose.pereda <jose.pereda@gluonhq.com>
  • Loading branch information
José Pereda and jperedadnr authored May 23, 2022
1 parent 02d932e commit acb987c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/gluonhq/substrate/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public enum Profile {

public static final String DEFAULT_JAVA_STATIC_SDK_VERSION = "18-ea+prep18-8";
public static final String DEFAULT_JAVA_STATIC_SDK_VERSION11 = "11-ea+10";
public static final String DEFAULT_JAVAFX_STATIC_SDK_VERSION = "19-ea+4";
public static final String DEFAULT_JAVAFX_STATIC_SDK_VERSION = "19-ea+7";
public static final String DEFAULT_JAVAFX_JS_SDK_VERSION = "18-internal+0-2021-09-02-165800";
public static final String DEFAULT_SYSROOT_VERSION = "20210424";
public static final String DEFAULT_CLIBS_VERSION = "27";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Gluon
* Copyright (c) 2019, 2022, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -36,6 +36,7 @@
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.text.Editable;
import android.text.InputType;
Expand Down Expand Up @@ -149,7 +150,6 @@ public void surfaceCreated(SurfaceHolder holder) {
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
Log.v(TAG, "surfaceChanged start");
Log.v(TAG, "[MainActivity] surfaceChanged, format = "+format+", width = "+width+", height = "+height);
nativeSetSurface(holder.getSurface());
DisplayMetrics metrics = new DisplayMetrics();
Expand All @@ -160,25 +160,22 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width,

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
System.err.println("[MainGraalActivity] surfaceDestroyed, ignore for now");
// _surfaceChanged(null);
System.err.println("[MainGraalActivity] surfaceDestroyed");
nativeSetSurface(null);
}

@Override
public void surfaceRedrawNeeded(SurfaceHolder holder) {
Log.v(TAG, "SurfaceRedraw needed start");
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Log.v(TAG, "ask native graallayer to redraw surface");
Log.v(TAG, "SurfaceRedraw needed: ask native graal layer to redraw surface");
nativeSurfaceRedrawNeeded();
try {
Thread.sleep(500);
Log.v(TAG, "surfaceredraw needed part 1 done");
nativeSurfaceRedrawNeeded();
} catch (Exception e) {
e.printStackTrace();
}
Log.v(TAG, "surfaceredraw needed (and wait) done");
Log.v(TAG, "surfaceredraw needed part 1 done");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
nativeSurfaceRedrawNeeded();
Log.v(TAG, "surfaceredraw needed (and wait) done");
}
}, 100);
}

@Override
Expand Down
13 changes: 9 additions & 4 deletions src/main/resources/native/android/c/javafx_adapter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, Gluon
* Copyright (c) 2020, 2022, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -70,9 +70,14 @@ void registerJavaFXMethodHandles(JNIEnv *aenv) {}
JNIEXPORT void JNICALL Java_com_gluonhq_helloandroid_MainActivity_nativeSetSurface(JNIEnv *env, jobject activity, jobject surface)
{
LOGE(stderr, "nativeSetSurface called, env at %p and size %ld, surface at %p\n", env, sizeof(JNIEnv), surface);
window = ANativeWindow_fromSurface(env, surface);
androidJfx_setNativeWindow(window);
LOGE(stderr, "native setSurface Ready, native window at %p\n", window);
if (surface != NULL) {
window = ANativeWindow_fromSurface(env, surface);
androidJfx_setNativeWindow(window);
LOGE(stderr, "native setSurface Ready, native window at %p\n", window);
} else {
androidJfx_setNativeWindow(NULL);
LOGE(stderr, "native setSurface was null");
}
}

JNIEXPORT jlong JNICALL Java_com_gluonhq_helloandroid_MainActivity_surfaceReady(JNIEnv *env, jobject activity, jobject surface, jfloat mydensity)
Expand Down

0 comments on commit acb987c

Please sign in to comment.