blob: c10611cb1437f5b76f74fd8154ac0324fa6d528f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/vr/openxr/openxr_statics.h"
#include "device/vr/openxr/openxr_util.h"
namespace device {
OpenXrStatics::OpenXrStatics() : instance_(XR_NULL_HANDLE) {}
OpenXrStatics::~OpenXrStatics() {
if (instance_ != XR_NULL_HANDLE) {
xrDestroyInstance(instance_);
instance_ = XR_NULL_HANDLE;
}
}
bool OpenXrStatics::IsHardwareAvailable() {
if (instance_ == XR_NULL_HANDLE && XR_FAILED(CreateInstance(&instance_))) {
return false;
}
XrSystemId system;
return XR_SUCCEEDED(GetSystem(instance_, &system));
}
bool OpenXrStatics::IsApiAvailable() {
return instance_ != XR_NULL_HANDLE ||
XR_SUCCEEDED(CreateInstance(&instance_));
}
#if defined(OS_WIN)
// Returns the LUID of the adapter the OpenXR runtime is on. Returns {0, 0} if
// the LUID could not be determined.
LUID OpenXrStatics::GetLuid() {
if (!IsApiAvailable())
return {0, 0};
XrSystemId system;
if (XR_FAILED(GetSystem(instance_, &system)))
return {0, 0};
XrGraphicsRequirementsD3D11KHR graphics_requirements = {
XR_TYPE_GRAPHICS_REQUIREMENTS_D3D11_KHR};
if (XR_FAILED(xrGetD3D11GraphicsRequirementsKHR(instance_, system,
&graphics_requirements)))
return {0, 0};
return graphics_requirements.adapterLuid;
}
#endif
} // namespace device
|