Chromium Code Reviews| Index: third_party/WebKit/Source/platform/vr/vr_dispatcher.cc |
| diff --git a/third_party/WebKit/Source/platform/vr/vr_dispatcher.cc b/third_party/WebKit/Source/platform/vr/vr_dispatcher.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b3e0cc4513c2db82d7854443e77d3faa5f68cd8f |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/vr/vr_dispatcher.cc |
| @@ -0,0 +1,73 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "platform/vr/vr_dispatcher.h" |
| + |
| +#include "platform/threading/BindForMojo.h" |
| +#include "platform/vr/vr_type_converters.h" |
| +#include "public/platform/Platform.h" |
| + |
| +namespace blink { |
| + |
| +WebVRClient* VRDispatcher::create() |
|
haraken
2016/03/19 00:45:18
VRDispatcher is not GarbageCollected, so you canno
RaviKasibhatla
2016/03/21 15:12:01
PTAL at my current approach. Since WebVRClient is
|
| +{ |
| + return new VRDispatcher(); |
| +} |
| + |
| +VRDispatcher::VRDispatcher() { |
| +} |
| + |
| +VRDispatcher::~VRDispatcher() { |
| +} |
| + |
| +content::VRServicePtr& VRDispatcher::GetVRServicePtr() { |
| + if (!vr_service_) |
| + Platform::current()->connectToRemoteService(mojo::GetProxy(&vr_service_)); |
| + return vr_service_; |
| +} |
| + |
| +void VRDispatcher::getDevices(WebVRGetDevicesCallback* callback) { |
| + int request_id = pending_requests_.Add(callback); |
| + GetVRServicePtr()->GetDevices( |
| + sameThreadBindForMojoWithBoundArgs(&VRDispatcher::OnGetDevices, this, &request_id)); |
| +} |
| + |
| +void VRDispatcher::getSensorState(unsigned int index, |
| + WebHMDSensorState& state) { |
| + GetVRServicePtr()->GetSensorState( |
| + index, |
| + sameThreadBindForMojoWithBoundArgs(&VRDispatcher::OnGetSensorState, this, &state)); |
| + |
| + // This call needs to return results synchronously in order to be useful and |
| + // provide the lowest latency results possible. |
| + GetVRServicePtr().WaitForIncomingResponse(); |
| +} |
| + |
| +void VRDispatcher::resetSensor(unsigned int index) { |
| + GetVRServicePtr()->ResetSensor(index); |
| +} |
| + |
| +void VRDispatcher::OnGetDevices(int* request_id, |
| + const mojo::Array<content::VRDeviceInfoPtr>& devices) { |
| + WebVector<WebVRDevice> web_devices(devices.size()); |
| + |
| + WebVRGetDevicesCallback* callback = |
| + pending_requests_.Lookup(*request_id); |
| + if (!callback) |
| + return; |
| + |
| + for (size_t i = 0; i < devices.size(); ++i) { |
| + web_devices[i] = devices[i].To<WebVRDevice>(); |
| + } |
| + |
| + callback->onSuccess(web_devices); |
| + pending_requests_.Remove(*request_id); |
| +} |
| + |
| +void VRDispatcher::OnGetSensorState(WebHMDSensorState* state, |
| + const content::VRSensorStatePtr& mojo_state) { |
| + *state = mojo_state.To<WebHMDSensorState>(); |
| +} |
| + |
| +} // namespace blink |