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

Side by Side Diff: third_party/WebKit/Source/modules/vr/VRController.cpp

Issue 1808203005: [OnionSoup] Moving VR service from content to Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased to ToT and fixed the crash in webkit_unit_tests! Created 4 years, 7 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
OLDNEW
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(PassOwnPtr<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 m_pendingSensorStateRequest = &into;
59 m_service->GetSensorState(index, sameThreadBindForMojo(&VRController::OnGetS ensorState, this));
60
61 // This call needs to return results synchronously in order to be useful and
62 // provide the lowest latency results possible.
63 m_service.WaitForIncomingResponse();
59 } 64 }
60 65
61 void VRController::resetSensor(unsigned index) 66 void VRController::resetSensor(unsigned index)
62 { 67 {
63 // When detached, the client is no longer valid. 68 if (!m_service)
64 if (!m_client)
65 return; 69 return;
66 m_client->resetSensor(index); 70 m_service->ResetSensor(index);
67 } 71 }
68 72
69 void VRController::willDetachFrameHost() 73 void VRController::willDetachFrameHost()
70 { 74 {
71 m_client = nullptr; 75 resetSensor(0);
dcheng 2016/04/28 19:59:44 Why is this always 0?
bajones 2016/04/28 20:21:51 I don't see a reason for the call to be there at a
RaviKasibhatla 2016/04/29 14:49:05 Agree. I have removed the resetSensor(0). However,
RaviKasibhatla 2016/05/03 14:34:21 @bajones: Can we take the detaching of service in
76 }
77
78 void VRController::OnGetDevices(const mojo::Array<mojom::VRDeviceInfoPtr>& devic es)
79 {
80 WebVector<WebVRDevice> webDevices(devices.size());
81
82 VRGetDevicesCallback* callback = m_pendingGetDevicesCallbacks.takeFirst().ge t();
haraken 2016/04/28 14:50:03 OwnPtr<VRGetDevicesCallback> callback = m_pendingG
RaviKasibhatla 2016/04/28 18:08:33 Done. Will make the change.
RaviKasibhatla 2016/04/29 14:49:05 Done.
83 if (!callback)
84 return;
85
86 for (size_t i = 0; i < devices.size(); ++i) {
87 webDevices[i] = devices[i].To<WebVRDevice>();
88 }
89
90 callback->onSuccess(webDevices);
91 }
92
93 void VRController::OnGetSensorState(const mojom::VRSensorStatePtr& mojoState)
94 {
95 *m_pendingSensorStateRequest = mojoState.To<WebHMDSensorState>();
72 } 96 }
73 97
74 DEFINE_TRACE(VRController) 98 DEFINE_TRACE(VRController)
75 { 99 {
76 Supplement<LocalFrame>::trace(visitor); 100 Supplement<LocalFrame>::trace(visitor);
77 LocalFrameLifecycleObserver::trace(visitor); 101 LocalFrameLifecycleObserver::trace(visitor);
78 } 102 }
79 103
80 } // namespace blink 104 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698