products/Sources/formale Sprachen/JAVA/Openjdk/test/jdk/javax/imageio/   (Sun/Oracle ©)  Datei vom 13.11.2022 mit Größe 9 kB image not shown  

Quelle  OculusSession.cpp   Sprache: C

 
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
#include ".h"
#endif

#include <math.h>
#include <d3d11.h>

#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/dom/GamepadEventTypes.h"
#include "mozilla/dom/GamepadBinding.h"
#include "/gfx/DeviceManagerDx."
#include "mozilla/gfx/Logging * into a separate object if either Oculus starts supporting
#include "mozilla/SharedLibrary.h"
#include "OculusSession.h"

/** XXX The DX11 objects and quad blitting could be encapsulated *     Alternately, we  *     Oculus as well with some more refactoring.
 *    into a separate object if either Oculus starts supporting
 *     non-Windows platforms or the blit is needed by other HMD\
 *     drivers.
 *     Alternately, we could remove the extra blit for
 *     Oculus as well with some more refactoring.
 */


// See CompositorD3D11Shaders.h
namespace mozilla {
namespace layers {
struct ShaderBytes {
  const void* mData;
  size_t mLength;
};
extern ShaderBytes sRGBShader;
extern ShaderBytes sLayerQuadVS;
}  // namespace layers
}  // namespace mozilla

using namespace mozilla;
using namespace mozilla::gfx;
using namespace mozilla::layers;

namespacenamespace layers

static   voidmData;
static pfn_ovr_Shutdownovr_Shutdown=nullptr
static
staticpfn_ovr_GetVersionStringovr_GetVersionString = nullptr
staticpfn_ovr_TraceMessageovr_TraceMessage = nullptr
static pfn_ovr_IdentifyClient  / namespacelayers
static pfn_ovr_GetHmdDesc ovr_GetHmdDesc = nullptr;
static pfn_ovr_GetTrackerCount  // namespace mozilla
 pfn_ovr_GetTrackerDescovr_GetTrackerDesc = nullptr
static pfn_ovr_Create ovr_Create = nullptr;
 ovr_Destroy =nullptr
 pfn_ovr_GetSessionStatus = nullptr
static
namespace{
staticstaticpfn_ovr_Initialize ovr_Initialize  nullptr
staticpfn_ovr_GetTrackingOriginType = nullptr
static pfn_ovr_RecenterTrackingOrigin pfn_ovr_GetLastErrorInfo = nullptr
static  ovr_SpecifyTrackingOrigin=nullptr
static pfn_ovr_ClearShouldRecenterFlag pfn_ovr_TraceMessage ovr_TraceMessage nullptr
static ovr_GetTrackingState = nullptr
static pfn_ovr_GetDevicePoses pfn_ovr_GetHmdDescovr_GetHmdDesc nullptr
static ovr_GetTrackerPose =nullptr
static pfn_ovr_GetInputState ovr_GetInputState pfn_ovr_GetTrackerDesc ovr_GetTrackerDescnullptr
 pfn_ovr_GetConnectedControllerTypes =
    nullptr;
static pfn_ovr_GetTouchHapticsDesc = nullptr
static pfn_ovr_SetControllerVibration ovr_SetControllerVibration = nullptr;
static pfn_ovr_SubmitControllerVibration ovr_SubmitControllerVibration
    ;
staticpfn_ovr_SetTrackingOriginType = nullptr
    nullptr;
static pfn_ovr_TestBoundary ovr_TestBoundary = nullptr;
static pfn_ovr_TestBoundaryPoint ovr_TestBoundaryPoint = nullptr;
static pfn_ovr_SetBoundaryLookAndFeelovr_SetBoundaryLookAndFeel nullptr;
static staticpfn_ovr_SpecifyTrackingOriginovr_SpecifyTrackingOrigin = nullptr
 pfn_ovr_GetBoundaryGeometry = nullptr
static pfn_ovr_GetBoundaryDimensions ovr_GetBoundaryDimensions = nullptrstatic pfn_ovr_GetTrackingStateovr_GetTrackingState =nullptr
static pfn_ovr_GetBoundaryVisible ovr_GetBoundaryVisible = nullptr;
static pfn_ovr_RequestBoundaryVisible ovr_RequestBoundaryVisible = nullptr;
static pfn_ovr_GetTextureSwapChainLength ovr_GetTextureSwapChainLength =
    nullptr;
static pfn_ovr_GetTextureSwapChainCurrentIndex
    ovr_GetTextureSwapChainCurrentIndex = nullptr;
static pfn_ovr_GetTextureSwapChainDesc ovr_GetTextureSwapChainDesc = nullptr;
static pfn_ovr_CommitTextureSwapChain ovr_CommitTextureSwapChain = nullptr;
static pfn_ovr_DestroyTextureSwapChain ovr_DestroyTextureSwapChain = nullptr;
static pfn_ovr_DestroyMirrorTexture ovr_DestroyMirrorTexture = nullptr;
static pfn_ovr_GetFovTextureSizeovr_GetFovTextureSize =nullptr
 pfn_ovr_GetRenderDesc2ovr_GetRenderDesc2= nullptr;
static staticpfn_ovr_GetConnectedControllerTypesovr_GetConnectedControllerTypes =
staticpfn_ovr_GetTouchHapticsDesc = nullptrjava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
staticstatic ovr_GetControllerVibrationState=
static pfn_ovr_SubmitFrame ovr_SubmitFrame = nullptr;
static pfn_ovr_GetPerfStats ovr_GetPerfStats = nullptr;
static pfn_ovr_ResetPerfStats ovr_ResetPerfStats = nullptr;
staticpfn_ovr_GetPredictedDisplayTimeovr_GetPredictedDisplayTime = nullptr
static pfn_ovr_GetTimeInSeconds ovr_GetTimeInSeconds = nullptr;
static pfn_ovr_GetBool ovr_GetBool = nullptr;
static pfn_ovr_SetBool ovr_SetBool = nullptr;
static pfn_ovr_GetInt ovr_GetInt = nullptr;
static pfn_ovr_SetInt ovr_SetInt = nullptr;
staticpfn_ovr_GetFloatovr_GetFloat=nullptr;
static pfn_ovr_SetFloatstaticpfn_ovr_SetBoundaryLookAndFeelovr_SetBoundaryLookAndFeel= nullptr
static ovr_GetFloatArray =nullptr
staticstaticpfn_ovr_GetBoundaryGeometry ovr_GetBoundaryGeometry nullptr
static pfn_ovr_GetStringovr_GetString nullptr
staticstaticpfn_ovr_GetBoundaryVisible ovr_GetBoundaryVisible nullptr;
static pfn_ovr_GetExternalCameras = nullptr
staticpfn_ovr_GetTextureSwapChainLength =
    nullptr;

defXP_WIN
staticpfn_ovr_CreateTextureSwapChainDX = nullptr;
static pfn_ovr_GetTextureSwapChainBufferDX ovr_GetTextureSwapChainBufferDX =
    nullptr;
static pfn_ovr_CreateMirrorTextureDX ovr_CreateMirrorTextureDX = nullptr;
static pfn_ovr_GetMirrorTextureBufferDX ovr_GetMirrorTextureBufferDX = nullptr;
#endif

static pfn_ovr_CreateTextureSwapChainGLovr_GetTextureSwapChainCurrentIndex ;
static pfn_ovr_GetTextureSwapChainBufferGL =
    nullptr;
staticstatic pfn_ovr_DestroyTextureSwapChain ovr_DestroyTextureSwapChainnullptr
staticpfn_ovr_GetMirrorTextureBufferGLovr_GetMirrorTextureBufferGL = nullptr;

HAVE_64BIT_BUILD
#  define BUILD_BITS64
#else
#  define BUILD_BITS 32
#endif

#define OVR_PRODUCT_VERSION 1
#define OVR_MAJOR_VERSION 1
#define OVR_MINOR_VERSION 19

static const uint32_t kNumOculusButtons = 7;
static  uint32_tkNumOculusHaptcs 1
static const uint32_t kNumOculusAxes =staticpfn_ovr_SubmitFrame ovr_SubmitFrame=nullptr;
ovrControllerTypeOculusControllerTypes2 ={,
                                              ovrControllerType_RTouch};static ovr_ResetPerfStats nullptr
const * OculusControllerNames2 = " Touch (eft),
                                        "Oculus Touch (Right
dom::GamepadHand OculusControllerHand[2] =static ovr_GetInt=nullptr
                                            ::GamepadHandRight

ovrButton pfn_ovr_GetFloatArray = nullptr
    {ovrButton0 ovrButton0,()0,ovrButton_LThumb ovrButton_X
     ovrButton_Ystatic pfn_ovr_GetString = nullptr
    {ovrButton0,(ovrButton)0,()0, , ovrButton_A
     ovrButton_B, (ovrButton)staticpfn_ovr_GetExternalCamerasovr_GetExternalCameras = nullptr;
}

ovrTouchnullptr
    ifdef
     ovrTouch_X pfn_ovr_CreateTextureSwapChainDX = nullptr
{ovrTouch_RIndexTrigger,(ovrTouch,()0, ovrTouch_RThumb
     ovrTouch_A, ovrTouch_B, ovrTouch_RThumbRestnullptr


 UpdateButtonconstovrInputState aInputState, uint32_t,

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    staticpfn_ovr_GetTextureSwapChainBufferGL ovr_GetTextureSwapChainBufferGL
aControllerStatetriggerValueaButtonIdx =10f;
  }else{
    aControllerStateifdefHAVE_64BIT_BUILD
  }
  if (aInputState.Touches & OculusControllerTouches[aHandIdx][aButtonIdx]) {
    aControllerState | ()1 <aButtonIdx
  }
}

 FromFovPort & ) {
  VRFieldOfViewdefine 1
  fovInfoleftDegrees=atan.LeftTan) * 18.0 /M_PI
  fovInfo.rightDegrees = atan(aFOV
fovInfo  (.) * 10./M_PI
rees=atan.DownTan8.  ;
                                                }
}

}  // anonymous namespace

namespace mozilla {
namespace gfx {

OculusSession::OculusSession()
    : VRSession(),
                       " Right"
mSession)

      (nullptr
      mQuadVS(nullptr),
      mQuadPS(nullptr),
      mLinearSamplerState(nullptr),
      
      (nullptr),
       {()0,()0,()0,ovrButton_LThumbovrButton_X,
           ovrButton_YovrButton)0,
     {},
           ovrButton_BovrButton},
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

OculusSession::~OculusSession ovrTouch_X , ovrTouch_LThumbRest

 OculusSessionInitializemozilla::gfxVRSystemStateaSystemState
                               boolovrTouch_A ovrTouch_B },
  ifStaticPrefsdom_vr_puppet_enabled(java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
    // Ensure that tests using the VR Puppet do not find real hardware aInputState &OculusControllerButtons][aButtonIdx 
    return;
  }
  if (!    .triggerValueaButtonIdx]=10;
    returnaControllerState.triggerValue] = .f
  }

  if (aDetectRuntimesOnly) {
    if (LoadOvrLib()) {
      aSystemState.displayState.capabilityFlags   }
          VRDisplayCapabilityFlags}
    }
   fovInfo
  }

  if (!CreateD3DObjects()) {
    return false;

fovInfo (.RightTan*8.0/M_PI
 ;
  }
  fovInfo.downDegrees = atan(aFOV.DownTan) * 180.0 / M_PI;fovInfo
  
  // debug.
  if (!LoadOvrLib()) {
    returnnamespace gfx
  }
     (),
mOvrLib),
if (!hangeVisibility)){
    return false      (()0)
  }mQuadVS),
  if(InitState()) {
    return false
  }

  mPresentationSize = IntSize(aSystemState.displayState.eyeResolution.width(nullptr,
                              aSystemState.displayState.eyeResolution.height);
  return truemVertexBuffer),
 {,

void OculusSession:mHapticPulseIntensity{}java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
  // Do not immediately re-initialize with an invisible session after
                                 bool aDetectRuntimesOnly) {
      // Ensure that tests using the VR Puppet do not find real hardware
  // traversal.
if){
    // We are currently rendering immersive content.
    // Avoid interrupting the session
    return;
  }
  if          ::Cap_ImmersiveVR
         false
    return
  }
  if (mLastPresentationEnd.IsNull()) {
    // There has been no presentation yet
    return
  }

  TimeDuration    unnecessary D3D creation  cause  in 7
     (!LoadOvrLib) {
      StaticPrefs::dom_vr_oculus_present_timeoutreturn;
  if (timeout <= TimeDuration(0) || duration >= timeout) {
    if (!ChangeVisibility(false)) {
      gfxWarning() << "OculusSession::ChangeVisibility(false) failed";
    }
  }
}

void  // with visible session once WebVR content starts rendering.
    if (!ChangeVisibility(false)) {
  // traversal, we need to prevent the user from seeing the
  // last rendered frame.
  // We render black frames to cover up the transition.
  }
  if(InitStateaSystemState 
    // We are currently rendering immersive content.
    // Avoid interrupting the sessionmPresentationSize= (aSystemState..eyeResolutionwidth2
    return
  }

  if (mInitFlags & ovrInit_Invisible) return true
    / We are invisible, nothing to cover up
    return;
  }

//
  ovrLayerEyeFov layer;
memsetlayer, , sizeof(layer;
  layer.Header.Type = ovrLayerType_Disabled;
  ovrLayerHeader* layers = &layer  // ensures that the user will not drop to Oculus Home during VR link
  ovr_SubmitFrame, 0, nullptr&, 1);
}

bool OculusSession// Avoid interrupting the session
  ovrInitFlags flags) {
    // We are already invisible
  ifreturnjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
    flags
  }
   (mInitFlags= ) {
      TimeDuration timeout = TimeDuration::FromMilliseconds(
    return true;
  }

  // Tear everything down
  StopRendering();
  StopSession();
    if (ChangeVisibilityfalse

  // Start it back up
  if (!StartLib(flags)) {
    return false;
  }
  if (!StartSession
     false
  }
  return   / While content is loading or during immersive-mode link
}

void OculusSession::Shutdown() {
java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 18
  StopSession();
  StopLib();
  nloadOvrLib);
  DestroyShaders();
}

voidif(IsPresenting{
  if (!mSession) {
    return;
  }

  ovrSessionStatus status;
  if (OVR_SUCCESS(ovr_GetSessionStatus(mSession, &status))) {
    aSystemStatedisplayStateisConnected =status;
    aSystemState.displayState    return
    mShouldQuit &ovrInit_Invisible {

  } else {
    aSystemState.displayState.isConnected =     return
    aSystemState. /java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
  UpdateHaptics;
  UpdateVisibility();
  CoverTransitions();
}

 OculusSession:(mozillagfxVRSystemState aSystemState) {
  UpdateHeadsetPose(aSystemState);
  UpdateEyeParameters(aSystemState);
  UpdateControllers(aSystemState);
  UpdateTelemetry(SystemState
  aSystemState.sensorState
}

bool OculusSession::StartPresentation() {
  /**
   * XXX - We should resolve fail the promise returned by
   *       VRDisplay.requestPresent() when the DX11 resources fail allocation
   *       in VRDisplayOculus::StartPresentation().
   *       Bailing out here prevents the crash but content should be aware
   *       that frames are not being presented.
   *       See Bug 1299309.
   **/

  if (!ChangeVisibility(true)) {
    return false;
  }
  if (!StartRendering()) {
    StopRendering();
    return false;
  }
  mIsPresenting = true;
  return true;
}

void OculusSession::StopPresentation() {
  mLastPresentationEnd = TimeStamp::Now()  if(StaticPrefs:ovrInitFlags)(flags | ovrInit_Invisible);
  mIsPresenting = false;
}

 OculusSessionSubmitFrame
    const mozilla:::VRLayer_Stereo_Immersive,
    ID3D11Texture2D* aTexture)     true
  if (!IsPresentationReady())   StopRendering)java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
 false
}

  D3D11_TEXTURE2D_DESC textureDesc = {0};
  aTexture-returntrue

   currentRenderTarget 0
  ovrResult orv  StopRendering()
                                                      ¤tRenderTarget
  if (orv   StopLib()java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
NS_WARNINGfailed
    return false;
  }

  ID3D11RenderTargetView* view = mRTView[currentRenderTarget];

  float clear[] = {0.0f, 0.0f,   }
  mContext->ClearRenderTargetView(view, clear);
  ovrSessionStatusstatus

  Matrix viewMatrix = Matrix::Translation(-1.0    .displayState =status;
viewMatrix(20 / float.),
                      2.0f /    mShouldQuit= status;
  viewMatrixPreScale10f,-10);
  Matrix4x4 projection = Matrix4x4::From2D(viewMatrix);
   .displayState ;

   transform2d
  UpdateHaptics

  D3D11_VIEWPORT ;
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  viewport  UpdateHeadsetPose();
  UpdateEyeParameters);
  .Height .Height
  viewport = 0java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
  viewport.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

    /*
  scissor.left = 0;
  scissor.right = textureDesc.Width;
  scissor.   *       VRDisplay.requestPresent() when the DX11 resources fail allocation
  scissor   *       Bailing out here prevents the crash but content should be   *       that frames are not being presented.

  memcpy(&mVSConstants.layerTransformreturn;
         sizeof(   (!tartRendering)) java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
    memcpy
         sizeof(mVSConstants.projection));
  mVSConstants.renderTargetOffset   = ;
return;
  mVSConstantsjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
      Rect(0.void::StopPresentation) {
  mVSConstants.textureCoords = Rect(0.0f, 1.0f,  mLastPresentationEnd =TimeStamp:ow

  mPSConstants

  ID3D11Buffer OculusSession:(
  UINT vsizeconst::gfxVRLayer_Stereo_Immersive aLayer
UINT = 0;
  >IASetVertexBuffers0,1 &, &vsize false
  mContext-   textureDesc={};
>IASetInputLayoutmInputLayout
  mContext->RSSetViewports(1, &viewport);
  mContext-  ovrResultorv= ovr_GetTextureSwapChainCurrentIndex(mSession,mTextureSet
  mContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
  mContext->VSSetShader(mQuadVS, nullptr, 0);
  mContext->PSSetShader(mQuadPS, nullptr, 0);

  RefPtrID3D11ShaderResourceView> srView
    NS_WARNING(" failed.");
                                                 getter_AddRefs(srView));
  if (FAILED(hr)) {
    return false
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    returnfalse
  }
* viewPtr=srViewget();
  mContext->PSSetShaderResources(0 /* 0 == TexSlot::RGB */, 1, &viewPtr);
  // XXX Use Constant from TexSlot in CompositorD3D11.cpp?mContext->(view clear

  java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
 >PSSetSamplers0 1 &);

  if (!()) {
                      20  floattextureDesc.Height));
    returnfalse;
  }

  mContext->Draw(4, 0);

java.lang.StringIndexOutOfBoundsException: Range [24, 2) out of bounds for length 58
  if java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    NS_WARNINGovr_CommitTextureSwapChainfailed)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
    return false
  }

  ovrLayerEyeFov layer;
  memset(&layer viewport = 1.f;
layer.Type =ovrLayerType_EyeFov
  layer.Flags=0;
lorTexture[]. = 0;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  layer.  scissorleft = 0;
  layerFov] mFOVPort[1]
scissor = 0;
 layerViewport0..y  textureDescHeight* .leftEyeRecty;
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  layerViewport].ize.h=textureDescHeight .leftEyeRectheight
  layer.Viewport         (mVSConstantslayerTransform))
  .Viewport[1..y  textureDesc.Height .rightEyeRecty
layerViewport[1.Size.w  textureDescWidthaLayer.width
layerViewport].Size  textureDescHeight .rightEyeRect.height

foruint32_t=0   2 +i java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
    layer.RenderPose[i].Orientationx =mFrameStartPosei.Orientation.;
    layerRenderPosei].Orientationy= mFrameStartPose[i]Orientationy
    layer.RenderPose[i].Orientation.z   mPSConstants.layerOpacity] =1.f;
    layer.RenderPose[i].Orientation.w = mFrameStartPose[i].Orientation.w;
    layer.RenderPose[i].Position.x = mFrameStartPose[i].Position.x;
    layer.ffervbuffer ;
    layer.  UINTvsize sizeof(Vertex
  }

  ovrLayerHeader* layers = &layer.Header;
  orv  mContext-IASetVertexBuffers0 , vbuffer&, &voffset
  / ovr_SubmitFrame will fail during the Oculus health and safety warning.
  // and will start succeeding once the warning has been dismissed by the user.>IASetInputLayout();

  if (!OVR_UNQUALIFIED_SUCCESS(orv)) {
    /**
     * We wish to throttle the framerate for any case that the rendered
     * result is not visible.  In some cases, such as during the Oculus
     * "health and safety warning", orv will be > 0 (OVR_SUCCESS but not
     * OVR_UNQUALIFIED_SUCCESS) and ovr_SubmitFrame will not block.
     * In this case, returning true would have resulted in an unthrottled
     * render loop hiting excessive frame rates and consuming resources.
     */

     false
}

  return true;
}

bool OculusSession
  f() {
    // Already loaded, early exit hr mDevice-CreateShaderResourceView(, nullptr
    returntrue
  }
#if defined(_WIN32)
  nsTArraynsString libSearchPaths

  nsString searchPath;

  for (;;) {
    UINT = :GetSystemDirectoryW(
        char16ptr_t(searchPath.BeginWriting}
    if (!requiredLength) {
      break;erResourceView* viewPtr .get();
    }
    if (requiredLength < searchPath.Length() mContext-PSSetShaderResources /* 0 == TexSlot::RGB */, 1, &viewPtr);
      searchPathTruncaterequiredLength);
      libSearchPaths.AppendElement(searchPath);
        *  = mLinearSamplerState
    }
searchPath(requiredLength
  }
libNameLibOVRRTddllBUILD_BITSOVR_PRODUCT_VERSION

      NS_WARNING("Failed to update constant buffers for Oculus");
  libSearchPaths

/
  if (_wgetenv(L"OVR_LIB_PATH")) {
    = _getenv"OVR_LIB_PATH");
    .InsertElementsAt,1 searchPath);
  }

  if (_wgetenv(L"OVR_LIB_NAME")) {
    libName false
  }

  if (libName
    returnfalse;
 }

foruint32_t  ;  <libSearchPaths(); ++) java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
nsStringlibPath [i];
    nsString fullName;
    if (libPath  .Fov[  [1];
      ullNameAssign(libName;
    } else {
      fullName.Assign(libPath + u"layerViewport[]Pos. =textureDesc. * aLayerleftEyeRect.y;
    }

    mOvrLib (fullName.get));
    if (mOvrLib) {
      break;
    }
 }
#else
!"
#endif

   (!mOvrLib{
     .Viewport1..h =textureDesc. * aLayer.height
  }

#define REQUIRE_FUNCTION(_    .RenderPosei.Orientation.x =mFrameStartPosei]Orientation;
  do {                                                 \
    *(void**)&_x = (void*)PR_FindSymbol(mOvrLib, #_x); \
     (!x                                          
      printf_stderr#x"symbolmissingn";\
      goto faillayer[i]Position =mFrameStartPose]Position;
    }                                                  \
  } while (0)

}
  REQUIRE_FUNCTION(ovr_Shutdown);
  REQUIRE_FUNCTION(ovr_GetLastErrorInfo);
  REQUIRE_FUNCTION  ovrLayerHeader layers =&.Header
 REQUIRE_FUNCTIONovr_TraceMessage;
  / ovr_SubmitFrame will fail during the Oculus health and safety warning.
  (ovr_GetHmdDesc;
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  REQUIRE_FUNCTION(ovr_GetTrackerDesc)/java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
  REQUIRE_FUNCTION(ovr_Create);
  REQUIRE_FUNCTION(ovr_Destroy);
  REQUIRE_FUNCTION(ovr_GetSessionStatus);
  REQUIRE_FUNCTION(ovr_IsExtensionSupported);
  REQUIRE_FUNCTION(ovr_EnableExtension);
    REQUIRE_FUNCTIONFIED_SUCCESS) and ovr_SubmitFrame will not     * In this case, returning true would have resulted in     * render loop hiting excessivejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  REQUIRE_FUNCTION();
  REQUIRE_FUNCTION(ovr_RecenterTrackingOriginif() {
  REQUIRE_FUNCTION(ovr_SpecifyTrackingOrigin);
  REQUIRE_FUNCTION(ovr_ClearShouldRecenterFlag);
REQUIRE_FUNCTIONovr_GetTrackingState;
  REQUIRE_FUNCTION(ovr_GetDevicePoses);
  REQUIRE_FUNCTION(ovr_GetTrackerPose);
  REQUIRE_FUNCTION( nsTArraynsStringjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
();
          (.BeginWriting),searchPathLength);
  REQUIRE_FUNCTION(ovr_SetControllerVibration);
  REQUIRE_FUNCTION(ovr_SubmitControllerVibration);
 REQUIRE_FUNCTIONovr_GetControllerVibrationState
REQUIRE_FUNCTIONovr_TestBoundary
REQUIRE_FUNCTIONovr_TestBoundaryPoint
    ifrequiredLength .Length java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
  REQUIRE_FUNCTION      break;
  EQUIRE_FUNCTIONovr_GetBoundaryGeometry);
  REQUIRE_FUNCTION(ovr_GetBoundaryDimensions);
  REQUIRE_FUNCTIONovr_GetBoundaryVisible
  REQUIRE_FUNCTION(ovr_RequestBoundaryVisible);
  REQUIRE_FUNCTIONovr_GetTextureSwapChainLength;
  REQUIRE_FUNCTION(ovr_GetTextureSwapChainCurrentIndex);
  REQUIRE_FUNCTION(ovr_GetTextureSwapChainDesc);
  REQUIRE_FUNCTION(ovr_CommitTextureSwapChain  libSearchPaths(0, 1 u"_ns);
java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
  REQUIRE_FUNCTION(ovr_DestroyMirrorTexture;
  REQUIRE_FUNCTION(ovr_GetFovTextureSize);
  REQUIRE_FUNCTION(ovr_GetRenderDesc2);
  REQUIRE_FUNCTIONsearchPath wgetenv"");
  REQUIRE_FUNCTIONlibSearchPathsInsertElementsAt(0 1 );
  java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 3
  REQUIRE_FUNCTIONovr_SubmitFrame
  REQUIRE_FUNCTIONovr_GetPerfStats
  REQUIRE_FUNCTION(ovr_ResetPerfStats);
    if (libName (.IsEmpty){
  REQUIRE_FUNCTIONovr_GetTimeInSeconds);
  REQUIRE_FUNCTION(ovr_GetBool);
  REQUIRE_FUNCTION(ovr_SetBool
  REQUIRE_FUNCTION(ovr_GetInt;
  REQUIRE_FUNCTIONovr_SetInt);
R(ovr_GetFloat
  REQUIRE_FUNCTION(ovr_SetFloat);
  REQUIRE_FUNCTION(ovr_GetFloatArray
  REQUIRE_FUNCTION(ovr_SetFloatArray  {
  fullNameAssignlibPath +u"\"ns libName;
  REQUIRE_FUNCTION(ovr_SetString);
  REQUIRE_FUNCTION(ovr_GetExternalCameras);
  REQUIRE_FUNCTION(ovr_SetExternalCameraProperties

#ifdef () {

  REQUIRE_FUNCTION}
  REQUIRE_FUNCTIONovr_GetTextureSwapChainBufferDX;
  REQUIRE_FUNCTIONovr_CreateMirrorTextureDX
#  rror"nsupported platform!"

#endif

  REQUIRE_FUNCTIONovr_CreateTextureSwapChainGL);
  REQUIRE_FUNCTION(ovr_GetTextureSwapChainBufferGL);
  REQUIRE_FUNCTION(ovr_CreateMirrorTextureGL);
  (_x)\

#undef REQUIRE_FUNCTION

  return true;

fail:
  ovr_Initialize = nullptr;
  PR_UnloadLibrary(mOvrLib);
   = nullptr
return
}

void\
  if (  } while (0)
    java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 0
    mOvrLib = nullptr;
  }
}(ovr_GetVersionString

bool OculusSession::StartLib(ovrInitFlags aFlags)
  if();
    ovrInitParams(ovr_GetTrackerDescjava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
memset, ,sizeof));
    . = ;
.RequestedMinorVersion;
    .LogCallbacknullptr;
    paramsREQUIRE_FUNCTIONovr_RecenterTrackingOrigin;

    ovrResult orv = ovr_InitializeREQUIRE_FUNCTION);

    if( ==ovrSuccessjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
      mInitFlags = aFlags
    } else {
      returnfalse;
    }
  }
  REQUIRE_FUNCTIONovr_SubmitControllerVibration;
  return true;
}

void OculusSession::StopLib() {
  if() {
      (ovr_TestBoundary;
    mInitFlags = (ovrInitFlags)0;
  }
}

bool OculusSession::StartSession() {
  // ovr_Create can be slow when no HMD is present and we wish
  // to keep the same oculus session when possible, so we detect();
  // presence of an HMD with ovr_GetHmdDesc before calling ovr_Create(ovr_GetBoundaryDimensions
    REQUIRE_FUNCTION);
  ifREQUIRE_FUNCTION(ovr_GetTextureSwapChainLength);
    / No HMD connected, destroy any existing session
    if (mSession) {
        REQUIRE_FUNCTION);
      mSession nullptr;
    }
    return false;
  }
  if (mSession != nullptr) {
    // HMD Detected and we already have a session, let's keep using it.
    return  REQUIRE_FUNCTION(vr_WaitToBeginFrame;
  }

  // HMD Detected and we don't have a session yet,
  // try to create a new session
  ovrSession session;
  ovrGraphicsLuid;
  ovrResult orvREQUIRE_FUNCTION(ovr_ResetPerfStats
  if (  (ovr_GetPredictedDisplayTime
    orv =ovr_SetTrackingOriginTypesession ovrTrackingOrigin_FloorLevel
    if (orv ! ) {
      NS_WARNING" failed.\";
    }
    mSession(ovr_SetInt;
    return ;
  }

  / Failed to create a session for the HMD
  return falseREQUIRE_FUNCTIONovr_GetString);
}

void OculusSession::StopSession() {
  if   REQUIRE_FUNCTION(ovr_SetExternalCameraProperties;
    ovr_Destroy(mSession);
    mSession = nullptr;
  }
}

bool OculusSession::CreateD3DObjects() {
  <ID3D11Device devicegfxDeviceManagerDxGet-GetVRDevice;
  if (!device) {
  (ovr_GetTextureSwapChainBufferDX
  }
 if (!reateD3DContext(evice {
    return falseendif
  }
  return true;
}

bool OculusSession::CreateShaders() {
  if (!mQuadVS) {
    if (FAILED(mDevice-  REQUIRE_FUNCTIONovr_CreateTextureSwapChainGL
            sLayerQuadVS.mData(ovr_CreateMirrorTextureGL
      NS_WARNINGFailed  vertex  ")
      returnREQUIRE_FUNCTION
    }
  }

  if (fail:
ifFAILED>CreatePixelShader.mData .mLength
  PR_UnloadLibrarymOvrLib
NS_WARNINGFailed     "
      return false false
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
  }

  CD3D11_BUFFER_DESC OculusSessionStartLib aFlags
   ( ==){
        D3D11_USAGE_DYNAMIC D3D11_CPU_ACCESS_WRITE

  if    memsetparams0 (params)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
    ((mDevice-(&cBufferDesc nullptr
                                     getter_AddRefs    .LogCallback ;
      NS_WARNING     orv=ovr_Initializeparams
      return false;
    }
  }

  if (!mPSConstantBuffer) {
    cBufferDesc.ByteWidth = sizeof(layers::PixelShaderConstants);
    if (FAILED>CreateBuffer&cBufferDesc, ,
                                     getter_AddRefs else {
      NS_WARNING("Failed to pixel shader }
      return false;
    }
  }

  if (!mLinearSamplerState) {
    CD3D11_SAMPLER_DESCreturntrue;
    if (FAILED
&samplerDesc getter_AddRefs)))) {
      NS_WARNING("Failed to if mInitFlags {
      ;
    }
  }

  if (!mInputLayout {
    D3D11_INPUT_ELEMENT_DESC }
        {"POSITION",java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
         D3D11_INPUT_PER_VERTEX_DATA, 0},
    };

   descovr_GetHmdDesc(NULL);
            if(.Type=ovrHmd_None) 
            sLayerQuadVS
            getter_AddRefs(mInputLayout)))) {
      NS_WARNING("Failed to (mSession);
      returnfalse;
    }
 }

     ( != nullptr) {
    Vertex// HMD Detected and we already have a session, let's keep using it.
        {     true
    CD3D11_BUFFER_DESC bufferDesc(  / HMD Detected and we don't have a session yet,
    D3D11_SUBRESOURCE_DATA data;
    data.pSysMem = (void*)vertices;

    if((mDevice-CreateBuffer&ufferDesc &ata,
                                     mVertexBuffer){
      NS_WARNING) 
return;
}
  }

  memset(&      ("ovr_SetTrackingOriginType failed.n);
  memset(&mPSConstantsmSession session
ue
}

void OculusSession::DestroyShaders() {}

bool OculusSession:  false
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  D3D11_MAPPED_SUBRESOURCE =nullptr
  resource

    <ID3D11Device  = gfxDeviceManagerDxGet-GetVRDevice)
                     &esource
  if (FAILED false
    return false;
  java.lang.StringIndexOutOfBoundsException: Range [3, 4) out of bounds for length 3
  *(VertexShaderConstants true
  mContext->Unmapjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  resource.pData = nullptrif (mQuadVS{

  hr = mContext->Map(mPSConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0,
                     resource;
  if (FAILED(hr) || !resource.pData) {
    returnfalse
  }
  *PixelShaderConstantsresourcepData ;
  mContext->Unmap( returnfalse

  ID3D11Buffer* bufferjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
     FAILEDmDevice->(sRGBShadermDatasRGBShadermLength,
  buffer =mPSConstantBuffer
  mContext->PSSetConstantBuffers(0, 1, &buffer);
  returnNS_WARNING("ailed pixel shaderforOculus";
}       false

bool}
    CD cBufferDesc(layers:ertexShaderConstants
                                 D3D11_BIND_CONSTANT_BUFFER
                                 , D3D11_CPU_ACCESS_WRITEjava.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
     * left and right eye rectangles in the VRLayer.  The defaultif no
    *coordinatesare passed to place the left righteye
     * side-by-side within the buffer.
     *
     * XXX - An optimization would be to dynamically      ("Failedtovertex shaderconstant for Oculus")
     *       to accomodate sites that are
     *       resolution
     *eyetextures other.  ( 12944)
     */

    ovrTextureSwapChainDesc desc;
    memset(&desc, 0, sizeof(desc));
    desc    f ((mDevice->reateBuffer&, nullptr
    descArraySize= 1
    desc.Format = OVR_FORMAT_B8G8R8A8_UNORM_SRGB;
descWidth=mPresentationSizewidth
    desc.Height      returnfalse
    desc.MipLevels =java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    descSampleCount ;
    if (FAILEDmDevice-CreateSamplerState
   descMiscFlags=ovrTextureMisc_DX_Typeless
    desc.BindFlags      (" to sampler statefor ");

    ovrResult orv =
        ovr_CreateTextureSwapChainDX(mSession, mDevice, &desc, &mTextureSet);
    if (orv != ovrSuccess) {
      NS_WARNING("ovr_CreateTextureSwapChainDX failed");
      return false;
    }

    int textureCount = 0;
    orv = ovr_GetTextureSwapChainLengthD3D11_INPUT_PER_VERTEX_DATA 0,
    if (orv != ovrSuccess) {
      ("ovr_GetTextureSwapChainLengthfailed)java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
      returnfalse
    }
    mTexture.            sLayerQuadVS, sLayerQuadVSmLength,
    .SetLength(textureCount
    mSRVNS_WARNING" to create layout forOculus")
    forreturn false
      ID3D11Texture2D  }
      orv = ovr_GetTextureSwapChainBufferDX(mSession, mTextureSet, i,
                                            IID_PPV_ARGS(&texture   (!VertexBuffer{
      if        {00,0.}} {.,00} {0.,1.}, {10 1.}}java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
        NS_WARNING("Failed to create Oculus texture swap chain. D3D11_SUBRESOURCE_DATA data;
        eturn;
      }

                                           getter_AddRefs))) 
      CD3D11_RENDER_TARGET_VIEW_DESC rtvDesc(3D11_RTV_DIMENSION_TEXTURE2D
                                             )
      r true
                                                   getter_AddRefs
      if (FAILED:() 
(
" to create for Oculustextureswapchain";
        texture->Release();
        return false;
      }

tr<> srv
      CD3D11_SHADER_RESOURCE_VIEW_DESChr=mContext-Map(, , , 0,
                                               ;
      hr = mDevice->CreateShaderResourceView(texture, &srvDesc,
                                             (rv)
      }
(
>(,0java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
"hain.";
        texture->Release();
        return false;
      }

      mTexture ;
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
  >(mPSConstantBuffer
      texture-*buffermVSConstantBuffer
    }
  }
  return true;
}

bool OculusSession::IsPresentationReady  mContext->(0, 1,&buffer;
  returnmTextureSet ! nullptr;
}

voidjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  mSRV.Clearif!) {
  mRTView.Clear();
  mTexture.Clear();

  if (mTextureSet && mSession/**
    ovr_DestroyTextureSwapChain(mSession, mTextureSet);
  }
  mTextureSet = nullptr;
  mIsPresenting = false;
}

bool OculusSession::InitState(VRSystemState& aSystemState) {
  VRDisplayState& state = aSystemState.displayState;
  strncpy(state.displayName.data(), "Oculus VR HMD", kVRDisplayNameMaxLen);
  state.isConnected = true;
  state.isMounted = false;

  ovrHmdDesc desc = ovr_GetHmdDesc(mSession);

  state.capabilityFlags = VRDisplayCapabilityFlags::Cap_None;
  if (desc.AvailableTrackingCaps & ovrTrackingCap_Orientation) {
    state.capabilityFlags |= VRDisplayCapabilityFlags::Cap_Orientation;
    state.capabilityFlags |= VRDisplayCapabilityFlags::Cap_AngularAcceleration;
  }
  if (desc.AvailableTrackingCaps & ovrTrackingCap_Position) {
    state.capabilityFlags |= VRDisplayCapabilityFlags::Cap_Position;
    state.capabilityFlags |= VRDisplayCapabilityFlags::Cap_LinearAcceleration;
    state.capabilityFlags |= VRDisplayCapabilityFlags::Cap_StageParameters;
  }
  state.capabilityFlags |= VRDisplayCapabilityFlags::Cap_External;
  state.capabilityFlags |= VRDisplayCapabilityFlags::Cap_MountDetection;
  state.capabilityFlags |= VRDisplayCapabilityFlags::Cap_Present;
  state.capabilityFlags |= VRDisplayCapabilityFlags::Cap_ImmersiveVR;
  state.blendMode = VRDisplayBlendMode::Opaque;
  state.reportsDroppedFrames = true;

  mFOVPort[VRDisplayState::Eye_Left] = desc.DefaultEyeFov[ovrEye_Left];
  mFOVPort[VRDisplayState::Eye_Right] = desc.DefaultEyeFov[ovrEye_Right];

  state.eyeFOV[VRDisplayState::Eye_Left] =
      FromFovPort(mFOVPort[VRDisplayState::Eye_Left]);
  state.eyeFOV[VRDisplayState::Eye_Right] =
      FromFovPort(mFOVPort[VRDisplayState::Eye_Right]);

  float pixelsPerDisplayPixel = 1.0;
  ovrSizei texSize[2];

  // get eye texture sizes
  for (uint32_t eye = 0; eye < VRDisplayState::NumEyes; eye++) {
    texSize[eye] = ovr_GetFovTextureSize(mSession, (ovrEyeType)eye,
                                         mFOVPort[eye], pixelsPerDisplayPixel);
  }

  // take the max of both for eye resolution
  state.eyeResolution.width = std::max(texSize[VRDisplayState::Eye_Left].w,
                                       texSize[VRDisplayState::Eye_Right].w);
  state.eyeResolution.height = std::max(texSize[VRDisplayState::Eye_Left].h,
                                        texSize[VRDisplayState::Eye_Right].h);
  state.nativeFramebufferScaleFactor = 1.0f;

  // default to an identity quaternion
  aSystemState.sensorState.pose.orientation[3] = 1.0f;

  UpdateStageParameters(state);
  UpdateEyeParameters(aSystemState);

  VRHMDSensorState& sensorState = aSystemState.sensorState;
  sensorState.flags =
      (VRDisplayCapabilityFlags)((int)
                                     VRDisplayCapabilityFlags::Cap_Orientation |
                                 (int)VRDisplayCapabilityFlags::Cap_Position);
  sensorState.pose.orientation[3] = 1.0f;  // Default to an identity quaternion

  return true;
}

void OculusSession::UpdateStageParameters(VRDisplayState& aState) {
  ovrVector3f playArea;
  ovrResult res =
      ovr_GetBoundaryDimensions(mSession, ovrBoundary_PlayArea, &playArea);
  if (res == ovrSuccess) {
    aState.stageSize.width = playArea.x;
    aState.stageSize.height = playArea.z;
  } else {
    // If we fail, fall back to reasonable defaults.
    // 1m x 1m space
    aState.stageSize.width = 1.0f;
    aState.stageSize.height = 1.0f;
  }

  float eyeHeight =
      ovr_GetFloat(mSession, OVR_KEY_EYE_HEIGHT, OVR_DEFAULT_EYE_HEIGHT);

  aState.sittingToStandingTransform[0] = 1.0f;
  aState.sittingToStandingTransform[1] = 0.0f;
  aState.sittingToStandingTransform[2] = 0.0f;
  aState.sittingToStandingTransform[3] = 0.0f;

  aState.sittingToStandingTransform[4] = 0.0f;
  aState.sittingToStandingTransform[5] = 1.0f;
  aState.sittingToStandingTransform[6] = 0.0f;
  aState.sittingToStandingTransform[7] = 0.0f;

  aState.sittingToStandingTransform[8] = 0.0f;
  aState.sittingToStandingTransform[9] = 0.0f;
  aState.sittingToStandingTransform[10] = 1.0f;
  aState.sittingToStandingTransform[11] = 0.0f;

  aState.sittingToStandingTransform[12] = 0.0f;
  aState.sittingToStandingTransform[13] = eyeHeight;
  aState.sittingToStandingTransform[14] = 0.0f;
  aState.sittingToStandingTransform[15] = 1.0f;
}

void OculusSession::UpdateEyeParameters(VRSystemState& aState) {
  if (!mSession) {
    return;
  }
  // This must be called every frame in order to
  // account for continuous adjustments to ipd.
  gfx::Matrix4x4 headToEyeTransforms[2];
  for (uint32_t eye = 0; eye < VRDisplayState::NumEyes; eye++) {
    // As of Oculus 1.17 SDK, we must use the ovr_GetRenderDesc2 function to
    // return the updated version of ovrEyeRenderDesc.  This is normally done by
    // the Oculus static lib shim, but we need to do this explicitly as we are
    // loading the Oculus runtime dll directly.
    ovrEyeRenderDesc renderDesc =
        ovr_GetRenderDesc2(mSession, (ovrEyeType)eye, mFOVPort[eye]);
    aState.displayState.eyeTranslation[eye].x =
        renderDesc.HmdToEyePose.Position.x;
    aState.displayState.eyeTranslation[eye].y =
        renderDesc.HmdToEyePose.Position.y;
    aState.displayState.eyeTranslation[eye].z =
        renderDesc.HmdToEyePose.Position.z;

    Matrix4x4 pose;
    pose.SetRotationFromQuaternion(
        gfx::Quaternion(-renderDesc.HmdToEyePose.Orientation.x,
                        -renderDesc.HmdToEyePose.Orientation.y,
                        -renderDesc.HmdToEyePose.Orientation.z,
                        renderDesc.HmdToEyePose.Orientation.w));
    pose.PreTranslate(renderDesc.HmdToEyePose.Position.x,
                      renderDesc.HmdToEyePose.Position.y,
                      renderDesc.HmdToEyePose.Position.z);
    pose.Invert();
    headToEyeTransforms[eye] = pose;
  }
  aState.sensorState.CalcViewMatrices(headToEyeTransforms);

  Matrix4x4 matView[2];
  memcpy(matView[0].components, aState.sensorState.leftViewMatrix.data(),
         sizeof(float) * 16);
  memcpy(matView[1].components, aState.sensorState.rightViewMatrix.data(),
         sizeof(float) * 16);

  for (uint32_t eye = 0; eye < VRDisplayState::NumEyes; eye++) {
    Point3D eyeTranslation;
    Quaternion eyeRotation;
    Point3D eyeScale;
    if (!matView[eye].Decompose(eyeTranslation, eyeRotation, eyeScale)) {
      NS_WARNING("Failed to decompose eye pose matrix for Oculus");
    }

    eyeRotation.Invert();
    mFrameStartPose[eye].Orientation.x = eyeRotation.x;
    mFrameStartPose[eye].Orientation.y = eyeRotation.y;
    mFrameStartPose[eye].Orientation.z = eyeRotation.z;
    mFrameStartPose[eye].Orientation.w = eyeRotation.w;
    mFrameStartPose[eye].Position.x = eyeTranslation.x;
    mFrameStartPose[eye].Position.y = eyeTranslation.y;
    mFrameStartPose[eye].Position.z = eyeTranslation.z;
  }
}

void OculusSession::UpdateHeadsetPose(VRSystemState& aState) {
  if (!mSession) {
    return;
  }
  double predictedFrameTime = 0.0f;
  if (StaticPrefs::dom_vr_poseprediction_enabled()) {
    // XXX We might need to call ovr_GetPredictedDisplayTime even if we don't
    // use the result. If we don't call it, the Oculus driver will spew out many
    // warnings...
    predictedFrameTime = ovr_GetPredictedDisplayTime(mSession, 0);
  }
  ovrTrackingState trackingState =
      ovr_GetTrackingState(mSession, predictedFrameTime, true);
  ovrPoseStatef& pose(trackingState.HeadPose);

  aState.sensorState.timestamp = pose.TimeInSeconds;

  if (trackingState.StatusFlags & ovrStatus_OrientationTracked) {
    aState.sensorState.flags |= VRDisplayCapabilityFlags::Cap_Orientation;

    aState.sensorState.pose.orientation[0] = pose.ThePose.Orientation.x;
    aState.sensorState.pose.orientation[1] = pose.ThePose.Orientation.y;
    aState.sensorState.pose.orientation[2] = pose.ThePose.Orientation.z;
    aState.sensorState.pose.orientation[3] = pose.ThePose.Orientation.w;

    aState.sensorState.pose.angularVelocity[0] = pose.AngularVelocity.x;
    aState.sensorState.pose.angularVelocity[1] = pose.AngularVelocity.y;
    aState.sensorState.pose.angularVelocity[2] = pose.AngularVelocity.z;

    aState.sensorState.flags |=
        VRDisplayCapabilityFlags::Cap_AngularAcceleration;

    aState.sensorState.pose.angularAcceleration[0] = pose.AngularAcceleration.x;
    aState.sensorState.pose.angularAcceleration[1] = pose.AngularAcceleration.y;
    aState.sensorState.pose.angularAcceleration[2] = pose.AngularAcceleration.z;
  } else {
    // default to an identity quaternion
    aState.sensorState.pose.orientation[3] = 1.0f;
  }

  if (trackingState.StatusFlags & ovrStatus_PositionTracked) {
    float eyeHeight =
        ovr_GetFloat(mSession, OVR_KEY_EYE_HEIGHT, OVR_DEFAULT_EYE_HEIGHT);
    aState.sensorState.flags |= VRDisplayCapabilityFlags::Cap_Position;

    aState.sensorState.pose.position[0] = pose.ThePose.Position.x;
    aState.sensorState.pose.position[1] = pose.ThePose.Position.y - eyeHeight;
    aState.sensorState.pose.position[2] = pose.ThePose.Position.z;

    aState.sensorState.pose.linearVelocity[0] = pose.LinearVelocity.x;
    aState.sensorState.pose.linearVelocity[1] = pose.LinearVelocity.y;
    aState.sensorState.pose.linearVelocity[2] = pose.LinearVelocity.z;

    aState.sensorState.flags |=
        VRDisplayCapabilityFlags::Cap_LinearAcceleration;

    aState.sensorState.pose.linearAcceleration[0] = pose.LinearAcceleration.x;
    aState.sensorState.pose.linearAcceleration[1] = pose.LinearAcceleration.y;
    aState.sensorState.pose.linearAcceleration[2] = pose.LinearAcceleration.z;
  }
  aState.sensorState.flags |= VRDisplayCapabilityFlags::Cap_External;
  aState.sensorState.flags |= VRDisplayCapabilityFlags::Cap_MountDetection;
  aState.sensorState.flags |= VRDisplayCapabilityFlags::Cap_Present;
}

void OculusSession::UpdateControllers(VRSystemState& aState) {
  if (!mSession) {
    return;
  }

  ovrInputState inputState;
  bool hasInputState = ovr_GetInputState(mSession, ovrControllerType_Touch,
                                         &inputState) == ovrSuccess;

  if (!hasInputState) {
    return;
  }

  EnumerateControllers(aState, inputState);
  UpdateControllerInputs(aState, inputState);
  UpdateControllerPose(aState, inputState);
}

void OculusSession::UpdateControllerPose(VRSystemState& aState,
                                         const ovrInputState& aInputState) {
  ovrTrackingState trackingState = ovr_GetTrackingState(mSession, 0.0, false);
  for (uint32_t handIdx = 0; handIdx < 2; handIdx++) {
    // Left Touch Controller will always be at index 0 and
    // and Right Touch Controller will always be at index 1
    VRControllerState& controllerState = aState.controllerState[handIdx];
    if (aInputState.ControllerType & OculusControllerTypes[handIdx]) {
      ovrPoseStatef& pose = trackingState.HandPoses[handIdx];
      bool bNewController = !(controllerState.flags &
                              dom::GamepadCapabilityFlags::Cap_Orientation);
      if (bNewController) {
        controllerState.flags |= dom::GamepadCapabilityFlags::Cap_Orientation;
        controllerState.flags |= dom::GamepadCapabilityFlags::Cap_Position;
        controllerState.flags |=
            dom::GamepadCapabilityFlags::Cap_AngularAcceleration;
        controllerState.flags |=
            dom::GamepadCapabilityFlags::Cap_LinearAcceleration;
        controllerState.flags |=
            dom::GamepadCapabilityFlags::Cap_GripSpacePosition;
      }

      if (bNewController || trackingState.HandStatusFlags[handIdx] &
                                ovrStatus_OrientationTracked) {
        controllerState.pose.orientation[0] = pose.ThePose.Orientation.x;
        controllerState.pose.orientation[1] = pose.ThePose.Orientation.y;
        controllerState.pose.orientation[2] = pose.ThePose.Orientation.z;
        controllerState.pose.orientation[3] = pose.ThePose.Orientation.w;
        controllerState.pose.angularVelocity[0] = pose.AngularVelocity.x;
        controllerState.pose.angularVelocity[1] = pose.AngularVelocity.y;
        controllerState.pose.angularVelocity[2] = pose.AngularVelocity.z;
        controllerState.pose.angularAcceleration[0] =
            pose.AngularAcceleration.x;
        controllerState.pose.angularAcceleration[1] =
            pose.AngularAcceleration.y;
        controllerState.pose.angularAcceleration[2] =
            pose.AngularAcceleration.z;
        controllerState.isOrientationValid = true;
      } else {
        controllerState.isOrientationValid = false;
      }
      if (bNewController ||
          trackingState.HandStatusFlags[handIdx] & ovrStatus_PositionTracked) {
        controllerState.pose.position[0] = pose.ThePose.Position.x;
        controllerState.pose.position[1] = pose.ThePose.Position.y;
        controllerState.pose.position[2] = pose.ThePose.Position.z;
        controllerState.pose.linearVelocity[0] = pose.LinearVelocity.x;
        controllerState.pose.linearVelocity[1] = pose.LinearVelocity.y;
        controllerState.pose.linearVelocity[2] = pose.LinearVelocity.z;
        controllerState.pose.linearAcceleration[0] = pose.LinearAcceleration.x;
        controllerState.pose.linearAcceleration[1] = pose.LinearAcceleration.y;
        controllerState.pose.linearAcceleration[2] = pose.LinearAcceleration.z;

        float eyeHeight =
            ovr_GetFloat(mSession, OVR_KEY_EYE_HEIGHT, OVR_DEFAULT_EYE_HEIGHT);
        controllerState.pose.position[1] -= eyeHeight;
        controllerState.isPositionValid = true;
      } else {
        controllerState.isPositionValid = false;
      }
      controllerState.targetRayPose = controllerState.pose;
    }
  }
}

void OculusSession::EnumerateControllers(VRSystemState& aState,
                                         const ovrInputState& aInputState) {
  for (uint32_t handIdx = 0; handIdx < 2; handIdx++) {
    // Left Touch Controller will always be at index 0 and
    // and Right Touch Controller will always be at index 1
    VRControllerState& controllerState = aState.controllerState[handIdx];
    if (aInputState.ControllerType & OculusControllerTypes[handIdx]) {
      // Touch Controller detected
      if (controllerState.controllerName[0] == '\0') {
        // Controller has been just enumerated
        strncpy(controllerState.controllerName.data(),
                OculusControllerNames[handIdx],
                controllerState.controllerName.size());
        controllerState.hand = OculusControllerHand[handIdx];
        controllerState.targetRayMode = gfx::TargetRayMode::TrackedPointer;
        controllerState.numButtons = kNumOculusButtons;
        controllerState.numAxes = kNumOculusAxes;
        controllerState.numHaptics = kNumOculusHaptcs;
        controllerState.type = VRControllerType::OculusTouch;
      }
    } else {
      // Touch Controller not detected
      if (controllerState.controllerName[0] != '\0') {
        // Clear any newly disconnected ontrollers
        memset(&controllerState, 0, sizeof(VRControllerState));
      }
    }
  }
}

void OculusSession::UpdateControllerInputs(VRSystemState& aState,
                                           const ovrInputState& aInputState) {
  const float triggerThreshold =
      StaticPrefs::dom_vr_controller_trigger_threshold();

  for (uint32_t handIdx = 0; handIdx < 2; handIdx++) {
    // Left Touch Controller will always be at index 0 and
    // and Right Touch Controller will always be at index 1
    VRControllerState& controllerState = aState.controllerState[handIdx];
    if (aInputState.ControllerType & OculusControllerTypes[handIdx]) {
      // Update Button States
      controllerState.buttonPressed = 0;
      controllerState.buttonTouched = 0;
      uint32_t buttonIdx = 0;

      // Button 0: Trigger
      VRSession::UpdateTrigger(controllerState, buttonIdx,
                               aInputState.IndexTrigger[handIdx],
                               triggerThreshold);
      ++buttonIdx;
      // Button 1: Grip
      VRSession::UpdateTrigger(controllerState, buttonIdx,
                               aInputState.HandTrigger[handIdx],
                               triggerThreshold);
      ++buttonIdx;
      // Button 2: a placeholder button for trackpad.
      UpdateButton(aInputState, handIdx, buttonIdx, controllerState);
      ++buttonIdx;
      // Button 3: Thumbstick
      UpdateButton(aInputState, handIdx, buttonIdx, controllerState);
      ++buttonIdx;
      // Button 4: A
      UpdateButton(aInputState, handIdx, buttonIdx, controllerState);
      ++buttonIdx;
      // Button 5: B
      UpdateButton(aInputState, handIdx, buttonIdx, controllerState);
      ++buttonIdx;
      // Button 6: ThumbRest
      UpdateButton(aInputState, handIdx, buttonIdx, controllerState);
      ++buttonIdx;

      MOZ_ASSERT(buttonIdx == kNumOculusButtons);

      // Update Thumbstick axis
      uint32_t axisIdx = 0;
      // Axis 0, 1: placeholder axes for trackpad.
      axisIdx += 2;

      // Axis 2, 3: placeholder axes for thumbstick.
      float axisValue = aInputState.Thumbstick[handIdx].x;
      if (abs(axisValue) < 0.0000009f) {
        axisValue = 0.0f;  // Clear noise signal
      }
      controllerState.axisValue[axisIdx] = axisValue;
      axisIdx++;

      // Note that y axis is intentionally inverted!
      axisValue = -aInputState.Thumbstick[handIdx].y;
      if (abs(axisValue) < 0.0000009f) {
        axisValue = 0.0f;  // Clear noise signal
      }
      controllerState.axisValue[axisIdx] = axisValue;
      axisIdx++;

      MOZ_ASSERT(axisIdx == kNumOculusAxes);
    }
    SetControllerSelectionAndSqueezeFrameId(
        controllerState, aState.displayState.lastSubmittedFrameId);
  }
}

void OculusSession::UpdateTelemetry(VRSystemState& aSystemState) {
  if (!mSession) {
    return;
  }
  ovrPerfStats perfStats;
  if (ovr_GetPerfStats(mSession, &perfStats) == ovrSuccess) {
    if (perfStats.FrameStatsCount) {
      aSystemState.displayState.droppedFrameCount =
          perfStats.FrameStats[0].AppDroppedFrameCount;
    }
  }
}

void OculusSession::VibrateHaptic(uint32_t aControllerIdx,
                                  uint32_t aHapticIndex, float aIntensity,
                                  float aDuration) {
  if (!mSession) {
    return;
  }

  if (aDuration <= 0.0f) {
    StopVibrateHaptic(aControllerIdx);
    return;
  }

  // Vibration amplitude in the [0.0, 1.0] range
  MOZ_ASSERT(aControllerIdx >= 0 && aControllerIdx <= 1);
  mHapticPulseIntensity[aControllerIdx] = aIntensity > 1.0 ? 1.0 : aIntensity;
  mRemainingVibrateTime[aControllerIdx] = aDuration;
  ovrControllerType hand = OculusControllerTypes[aControllerIdx];

  // The gamepad extensions API does not yet have independent control
  // of frequency and amplitude.  We are always sending 0.0f (160hz)
  // to the frequency argument.
  ovrResult result = ovr_SetControllerVibration(
      mSession, hand, 0.0f, mHapticPulseIntensity[aControllerIdx]);
  if (result != ovrSuccess) {
    // This may happen if called when not presenting.
    gfxWarning() << "ovr_SetControllerVibration failed.";
  }
}

void OculusSession::StopVibrateHaptic(uint32_t aControllerIdx) {
  if (!mSession) {
    return;
  }
  MOZ_ASSERT(aControllerIdx >= 0 && aControllerIdx <= 1);
  ovrControllerType hand = OculusControllerTypes[aControllerIdx];
  mRemainingVibrateTime[aControllerIdx] = 0.0f;
  mHapticPulseIntensity[aControllerIdx] = 0.0f;

  ovrResult result = ovr_SetControllerVibration(mSession, hand, 0.0f, 0.0f);
  if (result != ovrSuccess) {
    // This may happen if called when not presenting.
    gfxWarning() << "ovr_SetControllerVibration failed.";
  }
}

void OculusSession::StopAllHaptics() {
  // Left Oculus Touch
  StopVibrateHaptic(0);
  // Right Oculus Touch
  StopVibrateHaptic(1);
}

void OculusSession::UpdateHaptics() {
  if (!mSession) {
    return;
  }
  // The Oculus API and hardware takes at least 33ms to respond
  // to haptic state changes, so it is not beneficial to create
  // a dedicated haptic feedback thread and update multiple
  // times per frame.
  // If we wish to support more accurate effects with sub-frame timing,
  // we should use the buffered haptic feedback API's.

  TimeStamp now = TimeStamp::Now();
  if (mLastHapticUpdate.IsNull()) {
    mLastHapticUpdate = now;
    return;
  }
  float deltaTime = (float)(now - mLastHapticUpdate).ToSeconds();
  mLastHapticUpdate = now;
  for (int i = 0; i < 2; i++) {
    if (mRemainingVibrateTime[i] <= 0.0f) {
      continue;
    }
    mRemainingVibrateTime[i] -= deltaTime;
    ovrControllerType hand = OculusControllerTypes[i];
    if (mRemainingVibrateTime[i] > 0.0f) {
      ovrResult result = ovr_SetControllerVibration(mSession, hand, 0.0f,
                                                    mHapticPulseIntensity[i]);
      if (result != ovrSuccess) {
        // This may happen if called when not presenting.
        gfxWarning() << "ovr_SetControllerVibration failed.";
      }
    } else {
      StopVibrateHaptic(i);
    }
  }
}

}  // namespace gfx
}  // namespace mozilla

Messung V0.5
C=95 H=96 G=95

¤ Dauer der Verarbeitung: 0.14 Sekunden  ¤

*© Formatika GbR, Deutschland






Normalansicht

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.