mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-17 04:15:44 +00:00
a/android: Store a native pointer in the MonadoView.
This commit is contained in:
parent
3bc84cca9e
commit
ce3750bfe1
|
@ -99,7 +99,8 @@ android_custom_surface_async_start(struct _JavaVM *vm, void *activity)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->monadoView = MonadoView::attachToActivity(ret->activity);
|
ret->monadoView =
|
||||||
|
MonadoView::attachToActivity(ret->activity, ret.get());
|
||||||
|
|
||||||
return ret.release();
|
return ret.release();
|
||||||
} catch (std::exception const &e) {
|
} catch (std::exception const &e) {
|
||||||
|
|
|
@ -16,8 +16,8 @@ namespace org::freedesktop::monado::auxiliary {
|
||||||
: MetaBase(MonadoView::getTypeName(), clazz),
|
: MetaBase(MonadoView::getTypeName(), clazz),
|
||||||
attachToActivity(classRef().getStaticMethod(
|
attachToActivity(classRef().getStaticMethod(
|
||||||
"attachToActivity",
|
"attachToActivity",
|
||||||
"(Landroid/app/Activity;)Lorg/freedesktop/monado/"
|
"(Landroid/app/Activity;J)Lorg/freedesktop/"
|
||||||
"auxiliary/MonadoView;")),
|
"monado/auxiliary/MonadoView;")),
|
||||||
waitGetSurfaceHolder(classRef().getMethod(
|
waitGetSurfaceHolder(classRef().getMethod(
|
||||||
"waitGetSurfaceHolder", "(I)Landroid/view/SurfaceHolder;")),
|
"waitGetSurfaceHolder", "(I)Landroid/view/SurfaceHolder;")),
|
||||||
markAsDiscardedByNative(
|
markAsDiscardedByNative(
|
||||||
|
|
|
@ -47,14 +47,15 @@ namespace org::freedesktop::monado::auxiliary {
|
||||||
*
|
*
|
||||||
* Java prototype:
|
* Java prototype:
|
||||||
* `public static org.freedesktop.monado.auxiliary.MonadoView
|
* `public static org.freedesktop.monado.auxiliary.MonadoView
|
||||||
* attachToActivity(android.app.Activity);`
|
* attachToActivity(android.app.Activity, long);`
|
||||||
*
|
*
|
||||||
* JNI signature:
|
* JNI signature:
|
||||||
* (Landroid/app/Activity;)Lorg/freedesktop/monado/auxiliary/MonadoView;
|
* (Landroid/app/Activity;J)Lorg/freedesktop/monado/auxiliary/MonadoView;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static MonadoView
|
static MonadoView
|
||||||
attachToActivity(android::app::Activity const &activity);
|
attachToActivity(android::app::Activity const &activity,
|
||||||
|
void *nativePointer);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Wrapper for the waitGetSurfaceHolder method
|
* Wrapper for the waitGetSurfaceHolder method
|
||||||
|
|
|
@ -16,10 +16,13 @@
|
||||||
namespace wrap {
|
namespace wrap {
|
||||||
namespace org::freedesktop::monado::auxiliary {
|
namespace org::freedesktop::monado::auxiliary {
|
||||||
inline MonadoView
|
inline MonadoView
|
||||||
MonadoView::attachToActivity(android::app::Activity const &activity)
|
MonadoView::attachToActivity(android::app::Activity const &activity,
|
||||||
|
void *nativePointer)
|
||||||
{
|
{
|
||||||
return MonadoView(Meta::data().clazz().call<jni::Object>(
|
return MonadoView(Meta::data().clazz().call<jni::Object>(
|
||||||
Meta::data().attachToActivity, activity.object()));
|
Meta::data().attachToActivity, activity.object(),
|
||||||
|
static_cast<long long>(
|
||||||
|
reinterpret_cast<intptr_t>(nativePointer))));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline android::view::SurfaceHolder
|
inline android::view::SurfaceHolder
|
||||||
|
|
|
@ -55,10 +55,13 @@ public class MonadoView extends SurfaceView implements SurfaceHolder.Callback, S
|
||||||
private SurfaceHolder currentSurfaceHolder = null;
|
private SurfaceHolder currentSurfaceHolder = null;
|
||||||
/// Guarded by usedByNativeCodeSync
|
/// Guarded by usedByNativeCodeSync
|
||||||
private boolean usedByNativeCode = false;
|
private boolean usedByNativeCode = false;
|
||||||
|
/// Contains the pointer to the native android_custom_surface object.
|
||||||
|
private long nativePointer = 0;
|
||||||
|
|
||||||
private MonadoView(Activity activity) {
|
private MonadoView(Activity activity, long nativePointer) {
|
||||||
super(activity);
|
super(activity);
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
|
this.nativePointer = nativePointer;
|
||||||
Method method;
|
Method method;
|
||||||
try {
|
try {
|
||||||
method = activity.getWindow().getDecorView().getClass().getMethod("setSystemUiVisibility", int.class);
|
method = activity.getWindow().getDecorView().getClass().getMethod("setSystemUiVisibility", int.class);
|
||||||
|
@ -78,10 +81,10 @@ public class MonadoView extends SurfaceView implements SurfaceHolder.Callback, S
|
||||||
@NonNull
|
@NonNull
|
||||||
@Keep
|
@Keep
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static MonadoView attachToActivity(@NonNull final Activity activity) {
|
public static MonadoView attachToActivity(@NonNull final Activity activity, long nativePointer) {
|
||||||
Log.i(TAG, "Starting to add a new surface!");
|
Log.i(TAG, "Starting to add a new surface!");
|
||||||
|
|
||||||
final MonadoView view = new MonadoView(activity);
|
final MonadoView view = new MonadoView(activity, nativePointer);
|
||||||
|
|
||||||
activity.runOnUiThread(() -> {
|
activity.runOnUiThread(() -> {
|
||||||
Log.i(TAG, "Starting runOnUiThread");
|
Log.i(TAG, "Starting runOnUiThread");
|
||||||
|
@ -152,6 +155,7 @@ public class MonadoView extends SurfaceView implements SurfaceHolder.Callback, S
|
||||||
Log.w(TAG, "This should not have happened: Discarding by native code, but not marked as used!");
|
Log.w(TAG, "This should not have happened: Discarding by native code, but not marked as used!");
|
||||||
}
|
}
|
||||||
usedByNativeCode = false;
|
usedByNativeCode = false;
|
||||||
|
nativePointer = 0;
|
||||||
usedByNativeCodeSync.notifyAll();
|
usedByNativeCodeSync.notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue