Chromium Code Reviews| Index: device/vr/openvr/openvr_device.cc |
| diff --git a/device/vr/openvr/openvr_device.cc b/device/vr/openvr/openvr_device.cc |
| index f129d977e0a77510ee14f763cf9f171dcea8b523..68d02db48ff3b3b410dc5a200e8cccdbc762076f 100644 |
| --- a/device/vr/openvr/openvr_device.cc |
| +++ b/device/vr/openvr/openvr_device.cc |
| @@ -76,7 +76,7 @@ std::vector<float> HmdMatrix34ToWebVRTransformMatrix( |
| namespace device { |
| -OpenVRDevice::OpenVRDevice() {} |
| +OpenVRDevice::OpenVRDevice() : weak_ptr_factory_(this) {} |
| OpenVRDevice::~OpenVRDevice() {} |
| void OpenVRDevice::CreateVRDisplayInfo( |
| @@ -149,6 +149,9 @@ void OpenVRDevice::CreateVRDisplayInfo( |
| render_loop_ = std::make_unique<OpenVRRenderLoop>(vr_system); |
| + render_loop_->RegistPollingEventCallback(base::Bind( |
| + &OpenVRDevice::OnPollingEvent, weak_ptr_factory_.GetWeakPtr())); |
| + |
| on_created.Run(std::move(device)); |
| } |
| @@ -179,6 +182,23 @@ void OpenVRDevice::UpdateLayerBounds(int16_t frame_index, |
| // We don't support presentation currently, so don't do anything. |
| } |
| +// TODO(shaobo): OnConnect and OnDisconnect need to be added to VrDisplayClient |
| +// in vr_service.mojom |
| +void OpenVRDevice::OnPollingEvent(OpenVRDevice::VREvent event) { |
| + switch (event) { |
| + case OpenVRDevice::VREvent::CONNECTED: |
| + case OpenVRDevice::VREvent::DISCONNECTED: |
| + break; |
| + |
| + case OpenVRDevice::VREvent::CHANGED: |
| + OnChanged(); |
|
shaobo.yan
2017/04/24 02:27:27
I just find that this will cause vr_system created
|
| + break; |
| + |
| + default: |
| + break; |
| + } |
| +} |
| + |
| void OpenVRDevice::GetVRVSyncProvider(mojom::VRVSyncProviderRequest request) { |
| render_loop_->Bind(std::move(request)); |
| } |
| @@ -238,11 +258,67 @@ device::mojom::VRPosePtr OpenVRDevice::OpenVRRenderLoop::getPose() { |
| return std::move(pose); |
| } |
| +// Only deal with event which will cause displayInfo changed now. |
| +void OpenVRDevice::OpenVRRenderLoop::PollEvent() { |
| + if (!vr_system_ || on_polling_event_.is_null()) |
| + return; |
| + |
| + vr::VREvent_t event; |
| + bool is_changed = false; |
| + while (vr_system_->PollNextEvent(&event, sizeof(event))) { |
| + if (event.trackedDeviceIndex != vr::k_unTrackedDeviceIndex_Hmd && |
| + event.trackedDeviceIndex != vr::k_unTrackedDeviceIndexInvalid) { |
| + continue; |
| + } |
| + |
| + switch (event.eventType) { |
| + case vr::VREvent_TrackedDeviceActivated: |
| + on_polling_event_.Run(OpenVRDevice::VREvent::CONNECTED); |
| + break; |
| + |
| + case vr::VREvent_TrackedDeviceDeactivated: |
| + on_polling_event_.Run(OpenVRDevice::VREvent::DISCONNECTED); |
| + break; |
| + |
| + case vr::VREvent_TrackedDeviceUpdated: |
| + case vr::VREvent_IpdChanged: |
| + case vr::VREvent_ChaperoneDataHasChanged: |
| + case vr::VREvent_ChaperoneSettingsHaveChanged: |
| + case vr::VREvent_ChaperoneUniverseHasChanged: |
| + is_changed = true; |
|
nhu
2017/04/24 01:47:06
If there is the only one place to trigger Changed
shaobo.yan
2017/04/24 02:27:27
I introduce this bool variable here for the situat
|
| + break; |
| + |
| + default: |
| + break; |
| + } |
| + } |
| + |
| + if (is_changed) { |
| + on_polling_event_.Run(OpenVRDevice::VREvent::CHANGED); |
| + } |
| +} |
| + |
| +// Regist a callback function to deal with system event. |
| +void OpenVRDevice::OpenVRRenderLoop::RegistPollingEventCallback( |
| + const base::Callback<void(OpenVRDevice::VREvent)>& onPollingEvent) { |
| + if (onPollingEvent.is_null()) |
| + return; |
| + |
| + on_polling_event_ = onPollingEvent; |
| +} |
| + |
| +void OpenVRDevice::OpenVRRenderLoop::UnregistPollingEventCallback() { |
| + on_polling_event_.Reset(); |
| +} |
| + |
| void OpenVRDevice::OpenVRRenderLoop::GetVSync( |
| const mojom::VRVSyncProvider::GetVSyncCallback& callback) { |
| static int16_t next_frame = 0; |
| int16_t frame = next_frame++; |
| + // VSync could be used as a signal to poll event. |
| + PollEvent(); |
| + |
| // TODO(BillOrr): Give real values when VSync loop is hooked up. This is the |
| // presentation time for the frame. Just returning a default value for now |
| // since we don't have VSync hooked up. |