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