Open AlessandroBorges opened 8 years ago
WSI interface may placed in Vulkan.java.
I have a look at GLSurfaceView and your VulkanSurfaceView , I confused that there is just one rendering thread in GLSurfaceView or VulkanSurafceView ,but why it needs wait() and notify() methods ?
Can I get SurfaceHolder from SurfaceView and then pass it to native code to create ANativeWindow , and then to create VkSurfaceKHR instead of creating every java file for every Vulkan handle or struct ?
for example ... `class MyView extends SurfaceView implements SurfaceHolder.Callback{
// other code....
@Override
public void surfaceCreated(SurfaceHolder holder) {
MyThread thread = new MyThread(this.getHolder());
}
// other code....
}
class MyThread extends Thread{
public MyThread(SurfaceHolder holder){
}
@Override
public void run(){
passHolderToNative(holder);
// may be wait before.
// Loop draw..
while(...){
// darw in native code .
// other code....
}
}
}`
Hi ! Thanks for your contribution !
We need a rendering thread to deal with external events, mostly coming from GUI thread, like pause, closing, screen rotate, screen resize, etc. Those events must wait current frame rendering process finish before we apply it. Imagine the mess caused by a surface resize in the middle of a drawn... In other moments, we must force thread to wait until we finish a resource acquisition/release operation.
About creating SurfaceKHR for drawing, bor.vulkan.VK10.java class implements several methods for this. But my favorite one is vkCreateWindowSurface() - around line 10.359 - , which creates the correct surface for Android, Win32 or Linux.
There are several ways to implement a rendering loop, but I really like the way it is done at GLSurfaceView / VulkanSurfaceView: using an implementation of Rendering interface. This interface define core operations: onSurfaceCreated(); onSurfaceChange(int width, int height) and onDrawFrame();
The GLThread / VulkanThread will call the Rendering methods in proper manner, inside its main loop. See implementation of run() and guardedRun() in GLThread / VulkanThread.
Any comments are welcome.
As you said , we need android::android_view_Surface_getNativeWindow(_env, win)
to get a ANativeWindow
, because this method come from android_runtime/android_view_Surface.h
, so I include these header files in my .cpp
file :
`
`
But the compiler can't find these two header files and android::android_view_Surface_getNativeWindow(_env, win) method
.
my cmake file :
cmake_minimum_required(VERSION 3.4.1)
add_library(native-lib SHARED src/main/cpp/native-lib.cpp )
target_link_libraries( native-lib log android_runtime )
So , I want to konw : how do you use android::android_view_Surface_getNativeWindow(_env, win)
in your bor.vulkan.Vk10.cpp
?
Thanks.
Sorry for this issue.
That code snippet example were draft considering internal NDK stuff. But today I realise that developers should use ANativeWindow
API instead.
Just replace those includes by
#include <android/native_window_jni.h>
and replace the old call for Surface's native window:
` ANativeWindow* window = android::android_view_Surface_getNativeWindow(_env, win);`
by this one:
// ANativeWindow* window = ANativeWindow_fromSurface(JNIEnv* env, jobject surface);
ANativeWindow* window = ANativeWindow_fromSurface( _env, win);
I'll commit those changes to my repo.
Now , it works, thanks for your help.
On Android platform, we must subclass android.view.SurfaceView class in order to draw 3D content. OpenGL ES does it by implementing GLSurfaceView. To implement our VulkanSurfaceView.java, it must be a SurfaceView subclass. Another requirements is to implement binding to Vulkan's WSI. It means:
GLSurfaceView does the binding this way: (a) Create window surface
(b) EGL createWindowSurface select the Surface properly, and pass the object to native side:
(c) EGL's eglCreateWindowSurface native method is this one:
(d) The native implementation of eglCreateWindowSurface get ANativeWindow* pointer from passed Surface:
This way we have essential info to implement VulkanSurfaceView on Android. Some JNI code is necessary to call
android::android_view_Surface_getNativeWindow(_env, win);ANativeWindow_fromSurface(_env, win); and get ANativeWindow pointer. Must use this include:#include <android/native_window_jni.h>
On Bor_Vulkan we wrap the pointer with ANativeWindow.java handle and then setup VkAndroidSurfaceCreateInfoKHR.java struct and call VK10.vkCreateAndroidSurfaceKHR()
Those JNI codes must be at VK10.java, using JNIgen.