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 "platform/vr/vr_dispatcher.h" | |
6 | |
7 #include "platform/threading/BindForMojo.h" | |
8 #include "platform/vr/vr_type_converters.h" | |
9 #include "public/platform/Platform.h" | |
10 | |
11 namespace blink { | |
12 | |
13 VRGetDevicesRequest::VRGetDevicesRequest(WebVRGetDevicesCallback* callback) | |
14 : get_devices_callback_(callback) { | |
15 } | |
16 | |
17 VRGetDevicesRequest::~VRGetDevicesRequest() { | |
18 get_devices_callback_ = nullptr; | |
19 } | |
20 | |
21 WebVRGetDevicesCallback* | |
22 VRGetDevicesRequest::get_devices_callback() const { | |
23 return get_devices_callback_; | |
24 } | |
25 | |
26 // static | |
27 WebVRClient* VRDispatcher::create() | |
28 { | |
29 return new VRDispatcher(); | |
30 } | |
31 | |
32 VRDispatcher::VRDispatcher() { | |
33 } | |
34 | |
35 VRDispatcher::~VRDispatcher() { | |
36 } | |
37 | |
38 mojom::VRServicePtr& VRDispatcher::GetVRServicePtr() { | |
39 if (!vr_service_) | |
40 Platform::current()->connectToRemoteService(mojo::GetProxy(&vr_service_)); | |
41 return vr_service_; | |
42 } | |
43 | |
44 void VRDispatcher::getDevices(WebVRGetDevicesCallback* callback) { | |
45 VRGetDevicesRequest* device_request = new VRGetDevicesRequest(callback); | |
46 GetVRServicePtr()->GetDevices( | |
47 sameThreadBindForMojoWithBoundArgs(&VRDispatcher::OnGetDevices, | |
48 this, device_request)); | |
49 } | |
50 | |
51 void VRDispatcher::getSensorState(unsigned int index, | |
52 WebHMDSensorState& state) { | |
53 GetVRServicePtr()->GetSensorState( | |
54 index, | |
55 sameThreadBindForMojoWithBoundArgs(&VRDispatcher::OnGetSensorState, | |
56 this, &state)); | |
57 | |
58 // This call needs to return results synchronously in order to be useful and | |
59 // provide the lowest latency results possible. | |
60 GetVRServicePtr().WaitForIncomingResponse(); | |
61 } | |
62 | |
63 void VRDispatcher::resetSensor(unsigned int index) { | |
64 GetVRServicePtr()->ResetSensor(index); | |
65 } | |
66 | |
67 void VRDispatcher::OnGetDevices(VRGetDevicesRequest* device_request, | |
68 const mojo::Array<mojom::VRDeviceInfoPtr>& devic es) { | |
69 WebVector<WebVRDevice> web_devices(devices.size()); | |
70 | |
71 WebVRGetDevicesCallback* callback = device_request->get_devices_callback(); | |
72 if (!callback) | |
73 return; | |
74 | |
75 for (size_t i = 0; i < devices.size(); ++i) { | |
76 web_devices[i] = devices[i].To<WebVRDevice>(); | |
77 } | |
78 | |
79 callback->onSuccess(web_devices); | |
80 delete device_request; | |
haraken
2016/03/22 02:39:20
We really want to avoid calling manual delete. Can
RaviKasibhatla
2016/03/23 15:20:50
Done.
| |
81 } | |
82 | |
83 void VRDispatcher::OnGetSensorState(WebHMDSensorState* state, | |
84 const mojom::VRSensorStatePtr& mojo_state) { | |
85 *state = mojo_state.To<WebHMDSensorState>(); | |
86 } | |
87 | |
88 } // namespace blink | |
OLD | NEW |