Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/vr/VRController.h" | 5 #include "modules/vr/VRController.h" |
| 6 | 6 |
| 7 #include "core/frame/LocalFrame.h" | 7 #include "core/frame/LocalFrame.h" |
| 8 #include "modules/vr/VRGetDevicesCallback.h" | |
| 8 #include "platform/RuntimeEnabledFeatures.h" | 9 #include "platform/RuntimeEnabledFeatures.h" |
| 10 #include "platform/mojo/MojoHelper.h" | |
| 11 #include "public/platform/ServiceRegistry.h" | |
| 9 | 12 |
| 10 namespace blink { | 13 namespace blink { |
| 11 | 14 |
| 12 VRController::~VRController() | 15 VRController::~VRController() |
| 13 { | 16 { |
| 14 } | 17 } |
| 15 | 18 |
| 16 void VRController::provideTo(LocalFrame& frame, WebVRClient* client) | 19 void VRController::provideTo(LocalFrame& frame, ServiceRegistry* registry) |
| 17 { | 20 { |
| 18 ASSERT(RuntimeEnabledFeatures::webVREnabled()); | 21 ASSERT(RuntimeEnabledFeatures::webVREnabled()); |
| 19 | 22 Supplement<LocalFrame>::provideTo(frame, supplementName(), registry ? new VR Controller(frame, registry) : nullptr); |
| 20 VRController* controller = new VRController(frame, client); | |
| 21 Supplement<LocalFrame>::provideTo(frame, supplementName(), controller); | |
| 22 } | 23 } |
| 23 | 24 |
| 24 VRController* VRController::from(LocalFrame& frame) | 25 VRController* VRController::from(LocalFrame& frame) |
| 25 { | 26 { |
| 26 return static_cast<VRController*>(Supplement<LocalFrame>::from(frame, supple mentName())); | 27 return static_cast<VRController*>(Supplement<LocalFrame>::from(frame, supple mentName())); |
| 27 } | 28 } |
| 28 | 29 |
| 29 VRController::VRController(LocalFrame& frame, WebVRClient* client) | 30 VRController::VRController(LocalFrame& frame, ServiceRegistry* registry) |
| 30 : LocalFrameLifecycleObserver(&frame) | 31 : LocalFrameLifecycleObserver(&frame) |
| 31 , m_client(client) | |
| 32 { | 32 { |
| 33 ASSERT(!m_service.is_bound()); | |
| 34 registry->connectToRemoteService(mojo::GetProxy(&m_service)); | |
| 33 } | 35 } |
| 34 | 36 |
| 35 const char* VRController::supplementName() | 37 const char* VRController::supplementName() |
| 36 { | 38 { |
| 37 return "VRController"; | 39 return "VRController"; |
| 38 } | 40 } |
| 39 | 41 |
| 40 void VRController::getDevices(WebVRGetDevicesCallback* callback) | 42 void VRController::getDevices(std::unique_ptr<VRGetDevicesCallback> callback) |
| 41 { | 43 { |
| 42 // When detached, the client is no longer valid. | 44 if (!m_service) { |
| 43 if (!m_client) { | |
| 44 callback->onError(); | 45 callback->onError(); |
| 45 delete callback; | |
| 46 return; | 46 return; |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Client is expected to take ownership of the callback | 49 m_pendingGetDevicesCallbacks.append(std::move(callback)); |
| 50 m_client->getDevices(callback); | 50 m_service->GetDevices(sameThreadBindForMojo(&VRController::OnGetDevices, thi s)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void VRController::getSensorState(unsigned index, WebHMDSensorState& into) | 53 void VRController::getSensorState(unsigned index, WebHMDSensorState& into) |
| 54 { | 54 { |
| 55 // When detached, the client is no longer valid. | 55 if (!m_service) |
| 56 if (!m_client) | |
| 57 return; | 56 return; |
| 58 m_client->getSensorState(index, into); | 57 |
| 58 mojom::VRSensorStatePtr state; | |
| 59 m_service->GetSensorState(index, &state); | |
| 60 into = state.To<WebHMDSensorState>(); | |
| 59 } | 61 } |
| 60 | 62 |
| 61 void VRController::resetSensor(unsigned index) | 63 void VRController::resetSensor(unsigned index) |
| 62 { | 64 { |
| 63 // When detached, the client is no longer valid. | 65 if (!m_service) |
| 64 if (!m_client) | |
| 65 return; | 66 return; |
| 66 m_client->resetSensor(index); | 67 m_service->ResetSensor(index); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void VRController::willDetachFrameHost() | 70 void VRController::willDetachFrameHost() |
| 70 { | 71 { |
| 71 m_client = nullptr; | 72 // FIXME:: Detach from the mojo service connection. |
|
haraken
2016/05/03 15:56:31
TODO(your name)
RaviKasibhatla
2016/05/04 08:54:37
Done.
| |
| 73 } | |
| 74 | |
| 75 void VRController::OnGetDevices(const mojo::Array<mojom::VRDeviceInfoPtr>& devic es) | |
| 76 { | |
| 77 WebVector<WebVRDevice> webDevices(devices.size()); | |
| 78 | |
| 79 std::unique_ptr<VRGetDevicesCallback> callback = m_pendingGetDevicesCallback s.takeFirst(); | |
| 80 if (!callback) | |
| 81 return; | |
| 82 | |
| 83 for (size_t i = 0; i < devices.size(); ++i) | |
| 84 webDevices[i] = devices[i].To<WebVRDevice>(); | |
| 85 callback->onSuccess(webDevices); | |
| 72 } | 86 } |
| 73 | 87 |
| 74 DEFINE_TRACE(VRController) | 88 DEFINE_TRACE(VRController) |
| 75 { | 89 { |
| 76 Supplement<LocalFrame>::trace(visitor); | 90 Supplement<LocalFrame>::trace(visitor); |
| 77 LocalFrameLifecycleObserver::trace(visitor); | 91 LocalFrameLifecycleObserver::trace(visitor); |
| 78 } | 92 } |
| 79 | 93 |
| 80 } // namespace blink | 94 } // namespace blink |
| OLD | NEW |