| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/vr/vr_dispatcher.h" | 5 #include "content/renderer/vr/vr_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "content/public/common/service_registry.h" | 9 #include "content/public/common/service_registry.h" |
| 10 #include "content/renderer/vr/vr_type_converters.h" | 10 #include "content/renderer/vr/vr_type_converters.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 VRDispatcher::VRDispatcher(ServiceRegistry* service_registry) | 14 VRDispatcher::VRDispatcher(ServiceRegistry* service_registry) |
| 15 : service_registry_(service_registry) { | 15 : service_registry_(service_registry) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 VRDispatcher::~VRDispatcher() { | 18 VRDispatcher::~VRDispatcher() { |
| 19 } | 19 } |
| 20 | 20 |
| 21 VRServicePtr& VRDispatcher::GetVRServicePtr() { | 21 mojom::VRServicePtr& VRDispatcher::GetVRServicePtr() { |
| 22 if (!vr_service_) { | 22 if (!vr_service_) { |
| 23 service_registry_->ConnectToRemoteService(mojo::GetProxy(&vr_service_)); | 23 service_registry_->ConnectToRemoteService(mojo::GetProxy(&vr_service_)); |
| 24 } | 24 } |
| 25 return vr_service_; | 25 return vr_service_; |
| 26 } | 26 } |
| 27 | 27 |
| 28 void VRDispatcher::getDevices(blink::WebVRGetDevicesCallback* callback) { | 28 void VRDispatcher::getDevices(blink::WebVRGetDevicesCallback* callback) { |
| 29 int request_id = pending_requests_.Add(callback); | 29 int request_id = pending_requests_.Add(callback); |
| 30 GetVRServicePtr()->GetDevices(base::Bind(&VRDispatcher::OnGetDevices, | 30 GetVRServicePtr()->GetDevices(base::Bind(&VRDispatcher::OnGetDevices, |
| 31 base::Unretained(this), request_id)); | 31 base::Unretained(this), request_id)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void VRDispatcher::getSensorState(unsigned int index, | 34 void VRDispatcher::getSensorState(unsigned int index, |
| 35 blink::WebHMDSensorState& state) { | 35 blink::WebHMDSensorState& state) { |
| 36 GetVRServicePtr()->GetSensorState( | 36 GetVRServicePtr()->GetSensorState( |
| 37 index, | 37 index, |
| 38 base::Bind(&VRDispatcher::OnGetSensorState, base::Unretained(&state))); | 38 base::Bind(&VRDispatcher::OnGetSensorState, base::Unretained(&state))); |
| 39 | 39 |
| 40 // This call needs to return results synchronously in order to be useful and | 40 // This call needs to return results synchronously in order to be useful and |
| 41 // provide the lowest latency results possible. | 41 // provide the lowest latency results possible. |
| 42 GetVRServicePtr().WaitForIncomingResponse(); | 42 GetVRServicePtr().WaitForIncomingResponse(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void VRDispatcher::resetSensor(unsigned int index) { | 45 void VRDispatcher::resetSensor(unsigned int index) { |
| 46 GetVRServicePtr()->ResetSensor(index); | 46 GetVRServicePtr()->ResetSensor(index); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void VRDispatcher::OnGetDevices(int request_id, | 49 void VRDispatcher::OnGetDevices( |
| 50 const mojo::Array<VRDeviceInfoPtr>& devices) { | 50 int request_id, |
| 51 const mojo::Array<mojom::VRDeviceInfoPtr>& devices) { |
| 51 blink::WebVector<blink::WebVRDevice> web_devices(devices.size()); | 52 blink::WebVector<blink::WebVRDevice> web_devices(devices.size()); |
| 52 | 53 |
| 53 blink::WebVRGetDevicesCallback* callback = | 54 blink::WebVRGetDevicesCallback* callback = |
| 54 pending_requests_.Lookup(request_id); | 55 pending_requests_.Lookup(request_id); |
| 55 if (!callback) | 56 if (!callback) |
| 56 return; | 57 return; |
| 57 | 58 |
| 58 for (size_t i = 0; i < devices.size(); ++i) { | 59 for (size_t i = 0; i < devices.size(); ++i) { |
| 59 web_devices[i] = devices[i].To<blink::WebVRDevice>(); | 60 web_devices[i] = devices[i].To<blink::WebVRDevice>(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 callback->onSuccess(web_devices); | 63 callback->onSuccess(web_devices); |
| 63 pending_requests_.Remove(request_id); | 64 pending_requests_.Remove(request_id); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void VRDispatcher::OnGetSensorState(blink::WebHMDSensorState* state, | 67 void VRDispatcher::OnGetSensorState(blink::WebHMDSensorState* state, |
| 67 const VRSensorStatePtr& mojo_state) { | 68 const mojom::VRSensorStatePtr& mojo_state) { |
| 68 *state = mojo_state.To<blink::WebHMDSensorState>(); | 69 *state = mojo_state.To<blink::WebHMDSensorState>(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 } // namespace content | 72 } // namespace content |
| OLD | NEW |