add support for properly providing the Android Activity to the runtime#217
Conversation
|
clippy failure in CI is due to a new Rust version and not related to the changes of this PR |
|
If the activity context is still global state, why bother plumbing it through rather than fetching it internally the way we did before? I'm not a huge fan of the API special-case required. |
|
There is no API to fetch the Activity internally. It's also not strictly global, as multiple activities can exist at the same time. The current activity could also get destroyed on configuration change, which would require re-creating the OpenXR instance with a new activity. With the current implementation and |
|
You have updated the example to use |
|
That's because the library doesn't depend on |
|
Does android-activity have an equivalent call? Could we use it internally? |
|
It's AndroidApp::activity_as_ptr, but that requires the |
|
Thanks for clarifying; that's a good reason to plumb it through (assuming they have a good reason for structuring it that way, anyway). I'm still not a fan of having different platform-specific entry points that must be cfg-gated by the caller, though it's not immediately obvious to me what we should do instead. Maybe some sort of instance builder? That would be a much more robust pattern for arbitrary extension support in general, at the cost of being a much larger change... |
|
I looked at how others deal with this:
I think the reasonable options are:
I prefer option 3. |
37949bd to
e43d990
Compare
|
@Ralith I moved the passing of the That means multiple/restarting activities are not supported, but I think that's fine for an XR application. |
Good idea; that matches what we're doing for graphics APIs. For clarity and forwards-compat, we could use empty structs for platforms that don't (yet) need anything. I guess this could basically be seen as builders with platform-specific types.
Hmm, I strongly prefer not to have hidden global state. Could this be a mutex-guarded field in In retrospect, I wonder why we have |
e43d990 to
5037ca8
Compare
Ok, i've implemented that now.
The original PR mentions this was to not change the error type for |
I don't think there's anything wrong with that, so long as the safety invariants are clear. Preventing a sufficiently determined user from blowing their foot off is not a priority. |
Perhaps we could do it in |
eee9c7f to
f1fa17a
Compare
The context provided by `ndk-context` is not guaranteed to be an `Activity` context. The `create_instance` function now requires the user to pass in an `impl PlatformInfo`. This is `AndroidPlatformInfo` on Android, which is constructed with the `Activity` reference.
f1fa17a to
61df8ac
Compare
No, it has to precede all other calls to OpenXR, including |
Yeah, reviewing the spec I think you're right. It was nice having |
The context provided by
ndk-contextis not guaranteed to be anActivitycontext.The
android-activitycrate has recently changed to providing anApplicationcontext tondk-contextinstead (rust-mobile/android-activity#229), butXR_KHR_android_create_instancerequires a reference to theActivity.The new
create_instance_androidfunction requires the user to pass in theActivityreference themselves.Trying to use the normal
create_instancefunction will produce the following error, which points users to the correct function:The
vulkanexample didn't compile for Android anymore, because thendk_glue::mainproc-macro doesn't parse c string literals.ndk-gluewas deprecated some time ago (rust-mobile/ndk#372), and should probably be replaced withandroid-activity.