Monado OpenXR Runtime
|
Object that tracks the native counterpart object for a type. More...
Public Member Functions | |
NativeCounterpart (long nativePointer) throws InvalidParameterException | |
Constructor. More... | |
void | markAsUsedByNativeCode () |
Set the flag to indicate that native code is using this. More... | |
void | markAsDiscardedByNative (String TAG) |
Change the flag and notify those waiting on it, to indicate that native code is done with this object. More... | |
long | getNativePointer () |
Retrieve the native pointer value. More... | |
boolean | blockUntilNativeDiscard (@NonNull String TAG) |
Wait until markAsDiscardedByNative has been called indicating that the native code is done with this. More... | |
Object that tracks the native counterpart object for a type.
Must be initialized on construction, and may have its native code destroyed/discarded, but may not "re-seat" it to new native code pointer.
Use as a member of any type with a native counterpart (a native-allocated-and-owned object that holds a reference to the owning class). Include the following field and delegating method to use (note: assumes you have a tag for logging purposes as TAG)
private final NativeCounterpart nativeCounterpart; @Keep public void markAsDiscardedByNative() { nativeCounterpart.markAsDiscardedByNative(TAG); }
Then, initialize it in your constructor, call markAsUsedByNativeCode()
where desired (often in your constructor), and call getNativePointer()
and
as needed.
blockUntilNativeDiscard()
Your native code can use this to turn a void* into a jlong: static_cast<long
long>(reinterpret_cast<intptr_t>(nativePointer))
|
inline |
Constructor.
nativePointer | The native pointer, cast appropriately. Must be non-zero. Can cast like: static_cast<long long>(reinterpret_cast<intptr_t>(nativePointer)) |
|
inline |
Wait until markAsDiscardedByNative
has been called indicating that the native code is done with this.
Be sure to check the result!
TAG | Your owning class's logging tag |
|
inline |
Retrieve the native pointer value.
Will be 0 if discarded by native code!.
|
inline |
Change the flag and notify those waiting on it, to indicate that native code is done with this object.
TAG | Your owning class's logging tag |
Referenced by org.freedesktop.monado.auxiliary.MonadoView.markAsDiscardedByNative(), and org.freedesktop.monado.ipc.Client.markAsDiscardedByNative().
|
inline |
Set the flag to indicate that native code is using this.
Only call this once, probably in your constructor unless you have a good reason to call it elsewhere.
Referenced by org.freedesktop.monado.ipc.Client.Client(), and org.freedesktop.monado.auxiliary.MonadoView.waitGetSurfaceHolder().