VRPlatformManagerOpenVR.cpp [plain text]
#include "config.h"
#include "VRPlatformManagerOpenVR.h"
#include "VRPlatformDisplayOpenVR.h"
#if USE(OPENVR)
#include "JSVRDisplay.h"
#include "VRDisplay.h"
namespace WebCore {
std::unique_ptr<VRPlatformManagerOpenVR> VRPlatformManagerOpenVR::create()
{
if (!vr::VR_IsRuntimeInstalled())
return nullptr;
return std::make_unique<VRPlatformManagerOpenVR>();
}
VRPlatformManagerOpenVR::~VRPlatformManagerOpenVR()
{
vr::VR_Shutdown();
}
bool VRPlatformManagerOpenVR::initOpenVR()
{
vr::HmdError error;
m_system = vr::VR_Init(&error, vr::VRApplication_Scene);
if (error)
return false;
return true;
}
Vector<WeakPtr<VRPlatformDisplay>> VRPlatformManagerOpenVR::getVRDisplays()
{
if (!vr::VR_IsHmdPresent()) {
m_system = nullptr;
return { };
}
if (!m_system && !initOpenVR()) {
m_system = nullptr;
vr::VR_Shutdown();
return { };
}
vr::HmdError error;
vr::IVRChaperone* chaperone = static_cast<vr::IVRChaperone*>(vr::VR_GetGenericInterface(vr::IVRChaperone_Version, &error));
if (error || !chaperone)
return { };
vr::IVRCompositor* compositor = static_cast<vr::IVRCompositor*>(vr::VR_GetGenericInterface(vr::IVRCompositor_Version, &error));
if (error || !compositor)
return { };
Vector<WeakPtr<VRPlatformDisplay>> displays;
if (!m_display)
m_display = std::make_unique<VRPlatformDisplayOpenVR>(m_system, chaperone, compositor);
displays.append(makeWeakPtr(*m_display));
return displays;
}
};
#endif // USE(OPENVR)