diff --git a/src/android/app/src/main/jni/vr/layers/UILayer.cpp b/src/android/app/src/main/jni/vr/layers/UILayer.cpp index d87282950..967521985 100644 --- a/src/android/app/src/main/jni/vr/layers/UILayer.cpp +++ b/src/android/app/src/main/jni/vr/layers/UILayer.cpp @@ -254,29 +254,29 @@ void UILayer::Shutdown() { } int UILayer::CreateSwapchain() { - { - AndroidWindowBounds viewBounds; - if (mEnv->ExceptionCheck()) { mEnv->ExceptionClear(); } - const jint ret = - mEnv->CallIntMethod(mVrUILayerObject, mGetBoundsMethodID, BoundsHandle(&viewBounds).l); - // Check for exceptions (and log them). - if (mEnv->ExceptionCheck()) { - mEnv->ExceptionDescribe(); - mEnv->ExceptionClear(); - FAIL("Exception in getBoundsForView()"); - } - if (ret < 0) { - ALOGE("{}() returned error {}", __FUNCTION__, ret); - return -1; - } - if (viewBounds.Width() == 0 || viewBounds.Height() == 0) { - ALOGE("{}() returned invalid bounds {} x {}", __FUNCTION__, viewBounds.Width(), - viewBounds.Height()); - return -2; + { + AndroidWindowBounds viewBounds; + if (mEnv->ExceptionCheck()) { mEnv->ExceptionClear(); } + const jint ret = + mEnv->CallIntMethod(mVrUILayerObject, mGetBoundsMethodID, BoundsHandle(&viewBounds).l); + // Check for exceptions (and log them). + if (mEnv->ExceptionCheck()) { + mEnv->ExceptionDescribe(); + mEnv->ExceptionClear(); + FAIL("Exception in getBoundsForView()"); + } + if (ret < 0) { + ALOGE("{}() returned error {}", __FUNCTION__, ret); + return -1; + } + if (viewBounds.Width() == 0 || viewBounds.Height() == 0) { + ALOGE("{}() returned invalid bounds {} x {}", __FUNCTION__, viewBounds.Width(), + viewBounds.Height()); + return -2; + } + mSwapchain.mWidth = viewBounds.Width(); + mSwapchain.mHeight = viewBounds.Height(); } - mSwapchain.mWidth = viewBounds.Width(); - mSwapchain.mHeight = viewBounds.Height(); - } // Initialize swapchain. { XrSwapchainCreateInfo swapchainCreateInfo; @@ -287,7 +287,7 @@ int UILayer::CreateSwapchain() { XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT; swapchainCreateInfo.format = 0; swapchainCreateInfo.sampleCount = 0; - swapchainCreateInfo.width = mSwapchain.mWidth; + swapchainCreateInfo.width = mSwapchain.mWidth; swapchainCreateInfo.height = mSwapchain.mHeight; swapchainCreateInfo.faceCount = 0; swapchainCreateInfo.arraySize = 0; @@ -308,8 +308,8 @@ int UILayer::CreateSwapchain() { ALOGD("UILayer: created swapchain {}x{}", mSwapchain.mWidth, mSwapchain.mHeight); - mEnv->CallIntMethod(mVrUILayerObject, mSetSurfaceMethodId, mSurface, - (int)mSwapchain.mWidth, (int)mSwapchain.mHeight); + mEnv->CallIntMethod(mVrUILayerObject, mSetSurfaceMethodId, mSurface, (int)mSwapchain.mWidth, + (int)mSwapchain.mHeight); if (mEnv->ExceptionCheck()) { mEnv->ExceptionDescribe(); mEnv->ExceptionClear(); diff --git a/src/android/app/src/main/jni/vr/vr_main.cpp b/src/android/app/src/main/jni/vr/vr_main.cpp index ca587ab0b..1aad850f9 100644 --- a/src/android/app/src/main/jni/vr/vr_main.cpp +++ b/src/android/app/src/main/jni/vr/vr_main.cpp @@ -539,80 +539,82 @@ class VRApp { mErrorMessageLayer->SendClickToUI(cursorPos2d, triggerState.currentState); } - } else if (mIsKeyboardActive) { - shouldRenderCursor = mKeyboardLayer->GetRayIntersectionWithPanel( - start, end, cursorPos2d, cursorPose3d); - if (triggerState.changedSinceLastSync) { - mKeyboardLayer->SendClickToUI(cursorPos2d, - triggerState.currentState); - } - } else { - shouldRenderCursor = mGameSurfaceLayer->GetRayIntersectionWithPanel( - start, end, cursorPos2d, cursorPose3d); - ALOG_INPUT_VERBOSE("Cursor 2D coords: {} {}", cursorPos2d.x, - cursorPos2d.y); - if (triggerState.currentState == 0 && - triggerState.changedSinceLastSync) { - jni->CallVoidMethod(mActivityObject, mSendClickToWindowMethodID, - cursorPos2d.x, cursorPos2d.y, 0); - } else if (triggerState.changedSinceLastSync && - triggerState.currentState == 1) { - jni->CallVoidMethod(mActivityObject, mSendClickToWindowMethodID, - cursorPos2d.x, cursorPos2d.y, 1); - } else if (triggerState.currentState == 1 && - !triggerState.changedSinceLastSync) { - - jni->CallVoidMethod(mActivityObject, mSendClickToWindowMethodID, - cursorPos2d.x, cursorPos2d.y, 2); - } - if (!shouldRenderCursor) { - // Handling this here means L2/R2 are liable to - // be slightly out of sync with the other - // buttons (which are handled before - // WaitFrame()). We'll see if that ends up being - // a problem for any games. - ForwardButtonStateIfNeeded( - jni, mActivityObject, mForwardVRInputMethodID, - 104 /* BUTTON_L2 */, - mInputStateFrame - .mIndexTriggerState[InputStateFrame::LEFT_CONTROLLER], - "l2"); - ForwardButtonStateIfNeeded( - jni, mActivityObject, mForwardVRInputMethodID, - 105 /* BUTTON_R2 */, - mInputStateFrame - .mIndexTriggerState[InputStateFrame::RIGHT_CONTROLLER], - "r2"); - } - } - - // Hit test the top panel - if (!shouldRenderCursor) { - shouldRenderCursor = - mGameSurfaceLayer->GetRayIntersectionWithPanelTopPanel( + } else { // Don't test for cursor intersection if error message is shown + if (mIsKeyboardActive) { + shouldRenderCursor = mKeyboardLayer->GetRayIntersectionWithPanel( start, end, cursorPos2d, cursorPose3d); - // If top panel is hit, trigger controls the - // position/rotation - if (shouldRenderCursor && triggerState.currentState) { - // null out X component -- screen should stay - // center - mGameSurfaceLayer->SetTopPanelFromController(XrVector3f{ - 0, cursorPose3d.position.y, cursorPose3d.position.z}); - // If trigger is pressed, thumbstick controls - // the depth - const XrActionStateVector2f& thumbstickState = - mInputStateFrame - .mThumbStickState[mInputStateFrame.mPreferredHand]; - - static constexpr float kThumbStickDirectionThreshold = 0.5f; - if (std::abs(thumbstickState.currentState.y) > - kThumbStickDirectionThreshold) { - mGameSurfaceLayer->SetTopPanelFromThumbstick( - thumbstickState.currentState.y); + if (triggerState.changedSinceLastSync) { + mKeyboardLayer->SendClickToUI(cursorPos2d, + triggerState.currentState); + } + } else { + shouldRenderCursor = mGameSurfaceLayer->GetRayIntersectionWithPanel( + start, end, cursorPos2d, cursorPose3d); + ALOG_INPUT_VERBOSE("Cursor 2D coords: {} {}", cursorPos2d.x, + cursorPos2d.y); + if (triggerState.currentState == 0 && + triggerState.changedSinceLastSync) { + jni->CallVoidMethod(mActivityObject, mSendClickToWindowMethodID, + cursorPos2d.x, cursorPos2d.y, 0); + } else if (triggerState.changedSinceLastSync && + triggerState.currentState == 1) { + jni->CallVoidMethod(mActivityObject, mSendClickToWindowMethodID, + cursorPos2d.x, cursorPos2d.y, 1); + } else if (triggerState.currentState == 1 && + !triggerState.changedSinceLastSync) { + + jni->CallVoidMethod(mActivityObject, mSendClickToWindowMethodID, + cursorPos2d.x, cursorPos2d.y, 2); + } + if (!shouldRenderCursor) { + // Handling this here means L2/R2 are liable to + // be slightly out of sync with the other + // buttons (which are handled before + // WaitFrame()). We'll see if that ends up being + // a problem for any games. + ForwardButtonStateIfNeeded( + jni, mActivityObject, mForwardVRInputMethodID, + 104 /* BUTTON_L2 */, + mInputStateFrame + .mIndexTriggerState[InputStateFrame::LEFT_CONTROLLER], + "l2"); + ForwardButtonStateIfNeeded( + jni, mActivityObject, mForwardVRInputMethodID, + 105 /* BUTTON_R2 */, + mInputStateFrame + .mIndexTriggerState[InputStateFrame::RIGHT_CONTROLLER], + "r2"); } } - if (shouldRenderCursor) { - cursorType = CursorLayer::CursorType::CURSOR_TYPE_TOP_PANEL; + + // Hit test the top panel + if (!shouldRenderCursor) { + shouldRenderCursor = + mGameSurfaceLayer->GetRayIntersectionWithPanelTopPanel( + start, end, cursorPos2d, cursorPose3d); + // If top panel is hit, trigger controls the + // position/rotation + if (shouldRenderCursor && triggerState.currentState) { + // null out X component -- screen should stay + // center + mGameSurfaceLayer->SetTopPanelFromController(XrVector3f{ + 0, cursorPose3d.position.y, cursorPose3d.position.z}); + // If trigger is pressed, thumbstick controls + // the depth + const XrActionStateVector2f& thumbstickState = + mInputStateFrame + .mThumbStickState[mInputStateFrame.mPreferredHand]; + + static constexpr float kThumbStickDirectionThreshold = 0.5f; + if (std::abs(thumbstickState.currentState.y) > + kThumbStickDirectionThreshold) { + mGameSurfaceLayer->SetTopPanelFromThumbstick( + thumbstickState.currentState.y); + } + } + if (shouldRenderCursor) { + cursorType = CursorLayer::CursorType::CURSOR_TYPE_TOP_PANEL; + } } } // Add a scale factor so the cursor doesn't scale as