ANativeWindow* awindow = nullptr;
QPlatformNativeInterface
*nativeInterface
= QApplication::platformNativeInterface();
// the JNI black magic to get ANativeWindow*
jobject activity = (jobject)nativeInterface->nativeResourceForIntegration("QtActivity");
QAndroidJniEnvironment *qjniEnv;
JNIEnv * jniEnv;
JavaVM * jvm = qjniEnv->javaVM();
jvm->GetEnv(reinterpret_cast<void**>(&qjniEnv), JNI_VERSION_1_6);
jvm->AttachCurrentThread(&jniEnv,NULL);
jint r_id_content = QAndroidJniObject::getStaticField<jint>("android/R$id", "content");
QAndroidJniObject view = ((QAndroidJniObject) activity).callObjectMethod("findViewById", "(I)Landroid/view/View;", r_id_content);
if (view.isValid()) {
QAndroidJniObject child1 = view.callObjectMethod("getChildAt", "(I)Landroid/view/View;", 0);
if (child1.isValid()) {
jint cnt = child1.callMethod<jint>("getChildCount");
if (cnt > 0) {
QAndroidJniObject child2 = child1.callObjectMethod("getChildAt", "(I)Landroid/view/View;", 0);
if (child2.isValid()) {
QAndroidJniObject sHolder = child2.callObjectMethod("getHolder","()Landroid/view/SurfaceHolder;");
if (sHolder.isValid()) {
QAndroidJniObject theSurface = sHolder.callObjectMethod("getSurface","()Landroid/view/Surface;");
if (theSurface.isValid()) {
awindow = ANativeWindow_fromSurface(jniEnv, theSurface.object());
qDebug() <<"Got native window " << awindow;
WId wid = winId();
qDebug() << "winid returned " << wid;
}
}
}
}
}
}
if (awindow != nullptr) {
// and now try to create vulkan surface
VkAndroidSurfaceCreateInfoKHR createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
createInfo.pNext = nullptr;
createInfo.flags = 0;
createInfo.window = awindow;
VkResult res = vkInstance->vkCreateAndroidSurfaceKHR(&createInfo, NULL, &m_surface);
if (res != VK_SUCCESS) qDebug() << "Could not create Vulkan surface, err: " << res;
else qDebug() << "Vulkan surface creaated!";
}
ANativeWindow* awindow = nullptr;
QPlatformNativeInterface *nativeInterface = QApplication::platformNativeInterface();
// the JNI black magic to get ANativeWindow*
jobject activity = (jobject)nativeInterface->nativeResourceForIntegration("QtActivity");
QAndroidJniEnvironment *qjniEnv;
JNIEnv * jniEnv;
JavaVM * jvm = qjniEnv->javaVM();
jvm->GetEnv(reinterpret_cast<void**>(&qjniEnv), JNI_VERSION_1_6);
jvm->AttachCurrentThread(&jniEnv,NULL);
jint r_id_content = QAndroidJniObject::getStaticField<jint>("android/R$id", "content");
QAndroidJniObject view = ((QAndroidJniObject) activity).callObjectMethod("findViewById", "(I)Landroid/view/View;", r_id_content);
if (view.isValid()) {
QAndroidJniObject child1 = view.callObjectMethod("getChildAt", "(I)Landroid/view/View;", 0);
if (child1.isValid()) {
jint cnt = child1.callMethod<jint>("getChildCount");
if (cnt > 0) {
QAndroidJniObject child2 = child1.callObjectMethod("getChildAt", "(I)Landroid/view/View;", 0);
if (child2.isValid()) {
QAndroidJniObject sHolder = child2.callObjectMethod("getHolder","()Landroid/view/SurfaceHolder;");
if (sHolder.isValid()) {
QAndroidJniObject theSurface = sHolder.callObjectMethod("getSurface","()Landroid/view/Surface;");
if (theSurface.isValid()) {
awindow = ANativeWindow_fromSurface(jniEnv, theSurface.object());
qDebug() <<"Got native window " << awindow;
WId wid = winId();
qDebug() << "winid returned " << wid;
}
}
}
}
}
}
if (awindow != nullptr) {
// and now try to create vulkan surface
VkAndroidSurfaceCreateInfoKHR createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
createInfo.pNext = nullptr;
createInfo.flags = 0;
createInfo.window = awindow;
VkResult res = vkInstance->vkCreateAndroidSurfaceKHR(&createInfo, NULL, &m_surface);
if (res != VK_SUCCESS) qDebug() << "Could not create Vulkan surface, err: " << res;
else qDebug() << "Vulkan surface creaated!";
}
To copy to clipboard, switch view to plain text mode
D libVkWindow.
so: ..
/VkWindow
/vkwindow.
cpp:440 (virtual void QVkWindow
::keyPressEvent(QKeyEvent*)): Got native window 0x9ebf3808
D libVkWindow.
so: ..
/VkWindow
/vkwindow.
cpp:442 (virtual void QVkWindow
::keyPressEvent(QKeyEvent*)): winid returned
1E vulkan : native_window_api_connect() failed: Invalid argument (-22)
D libVkWindow.
so: ..
/VkWindow
/vkwindow.
cpp:456 (virtual void QVkWindow
::keyPressEvent(QKeyEvent*)): Could not create Vulkan surface, err
: -3
D libVkWindow.so: ../VkWindow/vkwindow.cpp:440 (virtual void QVkWindow::keyPressEvent(QKeyEvent*)): Got native window 0x9ebf3808
D libVkWindow.so: ../VkWindow/vkwindow.cpp:442 (virtual void QVkWindow::keyPressEvent(QKeyEvent*)): winid returned 1
E vulkan : native_window_api_connect() failed: Invalid argument (-22)
D libVkWindow.so: ../VkWindow/vkwindow.cpp:456 (virtual void QVkWindow::keyPressEvent(QKeyEvent*)): Could not create Vulkan surface, err: -3
To copy to clipboard, switch view to plain text mode
Bookmarks