Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Side by Side Diff: content/renderer/vr/vr_dispatcher.cc

Issue 829803003: Adding Chrome-side WebVR interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed one cardboard reference Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/vr/vr_dispatcher.h ('k') | content/renderer/vr/vr_type_converters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "content/public/common/service_registry.h"
8 #include "content/renderer/vr/vr_type_converters.h"
9
10 namespace content {
11
12 VRDispatcher::VRDispatcher(ServiceRegistry* service_registry)
13 : service_registry_(service_registry) {
14 }
15
16 VRDispatcher::~VRDispatcher() {
17 }
18
19 VRServicePtr& VRDispatcher::GetVRServicePtr() {
20 if (!vr_service_) {
21 service_registry_->ConnectToRemoteService(mojo::GetProxy(&vr_service_));
22 }
23 return vr_service_;
24 }
25
26 void VRDispatcher::getDevices(blink::WebVRGetDevicesCallback* callback) {
27 int request_id = pending_requests_.Add(callback);
28 GetVRServicePtr()->GetDevices(base::Bind(&VRDispatcher::OnGetDevices,
29 base::Unretained(this), request_id));
30 }
31
32 void VRDispatcher::getSensorState(unsigned int index,
33 blink::WebHMDSensorState& state) {
34 GetVRServicePtr()->GetSensorState(
35 index,
36 base::Bind(&VRDispatcher::OnGetSensorState, base::Unretained(&state)));
37
38 // This call needs to return results synchronously in order to be useful and
39 // provide the lowest latency results possible.
40 GetVRServicePtr().WaitForIncomingResponse();
41 }
42
43 void VRDispatcher::resetSensor(unsigned int index) {
44 GetVRServicePtr()->ResetSensor(index);
45 }
46
47 void VRDispatcher::OnGetDevices(int request_id,
48 const mojo::Array<VRDeviceInfoPtr>& devices) {
49 blink::WebVector<blink::WebVRDevice> web_devices(devices.size());
50
51 blink::WebVRGetDevicesCallback* callback =
52 pending_requests_.Lookup(request_id);
53 if (!callback)
54 return;
55
56 for (size_t i = 0; i < devices.size(); ++i) {
57 web_devices[i] = devices[i].To<blink::WebVRDevice>();
58 }
59
60 callback->onSuccess(&web_devices);
61 pending_requests_.Remove(request_id);
62 }
63
64 void VRDispatcher::OnGetSensorState(blink::WebHMDSensorState* state,
65 const VRSensorStatePtr& mojo_state) {
66 *state = mojo_state.To<blink::WebHMDSensorState>();
67 }
68
69 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/vr/vr_dispatcher.h ('k') | content/renderer/vr/vr_type_converters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698