diff --git a/cmake/modules/FindLibOVR.cmake b/cmake/modules/FindLibOVR.cmake index d26ac70a59..62d8313d63 100644 --- a/cmake/modules/FindLibOVR.cmake +++ b/cmake/modules/FindLibOVR.cmake @@ -73,6 +73,7 @@ else (NOT ANDROID) find_path(JNI_DIR VrCommon.h PATH_SUFFIXES ${_VRLIB_JNI_DIR} HINTS ${LIBOVR_SEARCH_DIRS}) find_library(LIBOVR_LIBRARY_RELEASE NAMES oculus PATH_SUFFIXES ${_VRLIB_LIBS_DIR} HINTS ${LIBOVR_SEARCH_DIRS}) + find_library(TURBOJPEG_LIBRARY NAMES jpeg PATH_SUFFIXES 3rdParty/turbojpeg HINTS ${LIBOVR_SEARCH_DIRS}) endif (NOT ANDROID) select_library_configurations(LIBOVR) @@ -84,8 +85,9 @@ if (APPLE) list(APPEND LIBOVR_LIBRARIES ${IOKit} ${ApplicationServices}) list(APPEND LIBOVR_ARGS_LIST IOKit ApplicationServices) elseif (ANDROID) + list(APPEND LIBOVR_ANDROID_LIBRARIES "-lGLESv3" "-lEGL" "-landroid" "-lOpenMAXAL" "-llog" "-lz" "-lOpenSLES") - list(APPEND LIBOVR_ARGS_LIST LIBOVR_ANDROID_LIBRARIES LIBOVR_VRLIB_DIR MINIZIP_DIR JNI_DIR) + list(APPEND LIBOVR_ARGS_LIST LIBOVR_ANDROID_LIBRARIES LIBOVR_VRLIB_DIR MINIZIP_DIR JNI_DIR TURBOJPEG_LIBRARY) elseif (UNIX) list(APPEND LIBOVR_LIBRARIES "${UDEV_LIBRARY}" "${XINERAMA_LIBRARY}") list(APPEND LIBOVR_ARGS_LIST UDEV_LIBRARY XINERAMA_LIBRARY) diff --git a/gvr-interface/CMakeLists.txt b/gvr-interface/CMakeLists.txt index 6ce5c28e4e..37ac6ec050 100644 --- a/gvr-interface/CMakeLists.txt +++ b/gvr-interface/CMakeLists.txt @@ -34,7 +34,7 @@ if (ANDROID) if (LIBOVR_FOUND) add_definitions(-DHAVE_LIBOVR) - target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES} ${LIBOVR_ANDROID_LIBRARIES}) + target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES} ${LIBOVR_ANDROID_LIBRARIES} ${TURBOJPEG_LIBRARY}) include_directories(SYSTEM ${LIBOVR_INCLUDE_DIRS}) # we need VRLib, so add a project.properties to our apk build folder that says that diff --git a/gvr-interface/src/GVRInterface.cpp b/gvr-interface/src/GVRInterface.cpp index aa30a563e8..1f8cf019de 100644 --- a/gvr-interface/src/GVRInterface.cpp +++ b/gvr-interface/src/GVRInterface.cpp @@ -19,9 +19,8 @@ #ifdef HAVE_LIBOVR -#include +#include #include -#include #endif #endif @@ -37,8 +36,21 @@ static QString launchURLString = QString(); +#ifdef ANDROID + +extern "C" { + +JNIEXPORT void Java_io_highfidelity_gvrinterface_InterfaceActivity_handleHifiURL(JNIEnv *jni, jclass clazz, jstring hifiURLString) { + launchURLString = QAndroidJniObject(hifiURLString).toString(); +} + +} + +#endif + GVRInterface::GVRInterface(int argc, char* argv[]) : QApplication(argc, argv), + _mainWindow(NULL), _inVRMode(false) { if (!launchURLString.isEmpty()) { @@ -59,6 +71,11 @@ GVRInterface::GVRInterface(int argc, char* argv[]) : jobject activity = (jobject) interface->nativeResourceForIntegration("QtActivity"); ovr_RegisterHmtReceivers(&*jniEnv, activity); + + // PLATFORMACTIVITY_REMOVAL: Temp workaround for PlatformActivity being + // stripped from UnityPlugin. Alternate is to use LOCAL_WHOLE_STATIC_LIBRARIES + // but that increases the size of the plugin by ~1MiB + OVR::linkerPlatformActivity++; #endif // call our idle function whenever we can @@ -67,25 +84,13 @@ GVRInterface::GVRInterface(int argc, char* argv[]) : idleTimer->start(0); } -#ifdef ANDROID - -extern "C" { - -JNIEXPORT void Java_io_highfidelity_gvrinterface_InterfaceActivity_handleHifiURL(JNIEnv *jni, jclass clazz, jstring hifiURLString) { - launchURLString = QAndroidJniObject(hifiURLString).toString(); -} - -} - -#endif - void GVRInterface::idle() { #if defined(ANDROID) && defined(HAVE_LIBOVR) if (!_inVRMode && ovr_IsHeadsetDocked()) { qDebug() << "The headset just got docked - enter VR mode."; enterVRMode(); } else if (_inVRMode) { - + if (ovr_IsHeadsetDocked()) { static int counter = 0; @@ -113,6 +118,18 @@ void GVRInterface::idle() { leaveVRMode(); } } + + OVR::KeyState& backKeyState = _mainWindow->getBackKeyState(); + auto backEvent = backKeyState.Update(ovr_GetTimeInSeconds()); + + if (backEvent == OVR::KeyState::KEY_EVENT_LONG_PRESS) { + qDebug() << "Attemping to start the Platform UI Activity."; + ovr_StartPackageActivity(_ovr, PUI_CLASS_NAME, PUI_GLOBAL_MENU); + } else if (backEvent == OVR::KeyState::KEY_EVENT_DOUBLE_TAP || backEvent == OVR::KeyState::KEY_EVENT_SHORT_PRESS) { + qDebug() << "Got an event we should cancel for!"; + } else if (backEvent == OVR::KeyState::KEY_EVENT_DOUBLE_TAP) { + qDebug() << "The button is down!"; + } #endif } diff --git a/gvr-interface/src/GVRInterface.h b/gvr-interface/src/GVRInterface.h index c3f7d0167a..926c44da15 100644 --- a/gvr-interface/src/GVRInterface.h +++ b/gvr-interface/src/GVRInterface.h @@ -17,8 +17,19 @@ #if defined(ANDROID) && defined(HAVE_LIBOVR) class ovrMobile; class ovrHmdInfo; + +// This is set by JNI_OnLoad() when the .so is initially loaded. +// Must use to attach each thread that will use JNI: +namespace OVR { + // PLATFORMACTIVITY_REMOVAL: Temp workaround for PlatformActivity being + // stripped from UnityPlugin. Alternate is to use LOCAL_WHOLE_STATIC_LIBRARIES + // but that increases the size of the plugin by ~1MiB + extern int linkerPlatformActivity; +} + #endif +class GVRMainWindow; class RenderingClient; class QKeyEvent; @@ -33,6 +44,8 @@ public: GVRInterface(int argc, char* argv[]); RenderingClient* getClient() { return _client; } + void setMainWindow(GVRMainWindow* mainWindow) { _mainWindow = mainWindow; } + protected: void keyPressEvent(QKeyEvent* event); @@ -49,6 +62,8 @@ private: ovrHmdInfo* _hmdInfo; #endif + GVRMainWindow* _mainWindow; + RenderingClient* _client; bool _inVRMode; }; diff --git a/gvr-interface/src/GVRMainWindow.cpp b/gvr-interface/src/GVRMainWindow.cpp index fbdee20435..3496a7f1b0 100644 --- a/gvr-interface/src/GVRMainWindow.cpp +++ b/gvr-interface/src/GVRMainWindow.cpp @@ -88,8 +88,6 @@ void GVRMainWindow::keyReleaseEvent(QKeyEvent* event) { // release on the Android back key, hand off to OVR KeyState _backKeyState.HandleEvent(ovr_GetTimeInSeconds(), false, 0); _wasBackKeyDown = false; - - auto backEvent = _backKeyState.Update(ovr_GetTimeInSeconds()); } #endif QWidget::keyReleaseEvent(event); diff --git a/gvr-interface/src/GVRMainWindow.h b/gvr-interface/src/GVRMainWindow.h index 9f389d9904..1e19e6d0af 100644 --- a/gvr-interface/src/GVRMainWindow.h +++ b/gvr-interface/src/GVRMainWindow.h @@ -29,6 +29,11 @@ public: ~GVRMainWindow(); public slots: void showAddressBar(); + +#if defined(ANDROID) && defined(HAVE_LIBOVR) + OVR::KeyState& getBackKeyState() { return _backKeyState; } +#endif + protected: void keyPressEvent(QKeyEvent* event); void keyReleaseEvent(QKeyEvent* event); diff --git a/gvr-interface/src/main.cpp b/gvr-interface/src/main.cpp index fd08c4c3ad..26576393fb 100644 --- a/gvr-interface/src/main.cpp +++ b/gvr-interface/src/main.cpp @@ -22,5 +22,7 @@ int main(int argc, char* argv[]) { mainWindow.showMaximized(); #endif + app.setMainWindow(&mainWindow); + return app.exec(); } \ No newline at end of file