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 mojom::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( | |
50 int request_id, | |
51 const mojo::Array<mojom::VRDeviceInfoPtr>& devices) { | |
52 blink::WebVector<blink::WebVRDevice> web_devices(devices.size()); | |
53 | |
54 blink::WebVRGetDevicesCallback* callback = | |
55 pending_requests_.Lookup(request_id); | |
56 if (!callback) | |
57 return; | |
58 | |
59 for (size_t i = 0; i < devices.size(); ++i) { | |
60 web_devices[i] = devices[i].To<blink::WebVRDevice>(); | |
61 } | |
62 | |
63 callback->onSuccess(web_devices); | |
64 pending_requests_.Remove(request_id); | |
65 } | |
66 | |
67 void VRDispatcher::OnGetSensorState(blink::WebHMDSensorState* state, | |
68 const mojom::VRSensorStatePtr& mojo_state) { | |
69 *state = mojo_state.To<blink::WebHMDSensorState>(); | |
70 } | |
71 | |
72 } // namespace content | |
OLD | NEW |