Hemant
Hemant

Reputation: 61

how to interact Vulkan with Android Java Activity

Currently, android Vulkan only supports NativeActivity, but is there any way we can use Java Activity and SurfaceView or any other view and pass Native through JNI to get NativeWindow handler?

I tried looking around and link my surface view but it didn't work for me, any sample code or example will be appreciated.

Upvotes: 1

Views: 1092

Answers (1)

Jesse Hall
Jesse Hall

Reputation: 6787

I don't know of any sample code off-hand, but if you have a SurfaceView you want to get the Surface from it, and from that you can get (in C) the ANativeWindow for creating the VkSurfaceKHR/VkSwapchainKHR. The sequence is something like:

Java: surface = surfaceView->getHolder()->getSurface();

Pass surface to a JNI call into C as a jobject.

C: window = ANativeWindow_fromSurface(env, jsurface);

That function is declared in the NDK android/native_window_jni.h header.

You'll want to register callbacks with the SurfaceView's SurfaceHolder and manage the window lifecycle (which is tied to the Activity lifecycle) correctly.

Upvotes: 2

Related Questions