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

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

Issue 2329893002: Isolate a presenting VR device from pages other than the one presenting. (Closed)
Patch Set: Unit tests Created 4 years, 3 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/dom/DOMException.h" 7 #include "core/dom/DOMException.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/frame/LocalFrame.h" 9 #include "core/frame/LocalFrame.h"
10 #include "modules/vr/NavigatorVR.h" 10 #include "modules/vr/NavigatorVR.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 void VRController::resetPose(unsigned index) 53 void VRController::resetPose(unsigned index)
54 { 54 {
55 if (!m_service) 55 if (!m_service)
56 return; 56 return;
57 57
58 m_service->ResetPose(index); 58 m_service->ResetPose(index);
59 } 59 }
60 60
61 void VRController::requestPresent(unsigned index) 61 void VRController::requestPresent(ScriptPromiseResolver* resolver, unsigned inde x)
62 { 62 {
63 if (!m_service) 63 if (!m_service) {
64 DOMException* exception = DOMException::create(InvalidStateError, "The s ervice is no longer active.");
65 resolver->reject(exception);
64 return; 66 return;
67 }
65 68
66 m_service->RequestPresent(index); 69 m_service->RequestPresent(index, convertToBaseCallback(WTF::bind(&VRControll er::onPresentComplete, wrapPersistent(this), wrapPersistent(resolver), index)));
67 } 70 }
68 71
69 void VRController::exitPresent(unsigned index) 72 void VRController::exitPresent(unsigned index)
70 { 73 {
71 if (!m_service) 74 if (!m_service)
72 return; 75 return;
73 76
74 m_service->ExitPresent(index); 77 m_service->ExitPresent(index);
75 } 78 }
76 79
77 void VRController::submitFrame(unsigned index) 80 void VRController::submitFrame(unsigned index, device::blink::VRPosePtr pose)
78 { 81 {
79 if (!m_service) 82 if (!m_service)
80 return; 83 return;
81 84
82 m_service->SubmitFrame(index); 85 m_service->SubmitFrame(index, std::move(pose));
83 } 86 }
84 87
85 void VRController::updateLayerBounds(unsigned index, 88 void VRController::updateLayerBounds(unsigned index,
86 device::blink::VRLayerBoundsPtr leftBounds, 89 device::blink::VRLayerBoundsPtr leftBounds,
87 device::blink::VRLayerBoundsPtr rightBounds) 90 device::blink::VRLayerBoundsPtr rightBounds)
88 { 91 {
89 if (!m_service) 92 if (!m_service)
90 return; 93 return;
91 94
92 m_service->UpdateLayerBounds(index, std::move(leftBounds), std::move(rightBo unds)); 95 m_service->UpdateLayerBounds(index, std::move(leftBounds), std::move(rightBo unds));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 { 136 {
134 VRDisplayVector outDisplays = updateDisplays(std::move(displays)); 137 VRDisplayVector outDisplays = updateDisplays(std::move(displays));
135 138
136 std::unique_ptr<VRGetDevicesCallback> callback = m_pendingGetDevicesCallback s.takeFirst(); 139 std::unique_ptr<VRGetDevicesCallback> callback = m_pendingGetDevicesCallback s.takeFirst();
137 if (!callback) 140 if (!callback)
138 return; 141 return;
139 142
140 callback->onSuccess(outDisplays); 143 callback->onSuccess(outDisplays);
141 } 144 }
142 145
146 void VRController::onPresentComplete(ScriptPromiseResolver* resolver, unsigned i ndex, bool success)
147 {
148 VRDisplay* vrDisplay = getDisplayForIndex(index);
149 if (!vrDisplay) {
150 DOMException* exception = DOMException::create(InvalidStateError, "VRDis play not found.");
151 resolver->reject(exception);
152 return;
153 }
154
155 if (success) {
156 vrDisplay->beginPresent(resolver);
157 } else {
158 vrDisplay->forceExitPresent();
159 DOMException* exception = DOMException::create(NotAllowedError, "Present ation request was denied.");
160 resolver->reject(exception);
161 }
162 }
163
143 void VRController::OnDisplayChanged(device::blink::VRDisplayPtr display) 164 void VRController::OnDisplayChanged(device::blink::VRDisplayPtr display)
144 { 165 {
145 VRDisplay* vrDisplay = getDisplayForIndex(display->index); 166 VRDisplay* vrDisplay = getDisplayForIndex(display->index);
146 if (!vrDisplay) 167 if (!vrDisplay)
147 return; 168 return;
148 169
149 vrDisplay->update(display); 170 vrDisplay->update(display);
150 } 171 }
151 172
173 void VRController::OnExitPresent(unsigned index)
174 {
175 VRDisplay* vrDisplay = getDisplayForIndex(index);
176 if (vrDisplay)
177 vrDisplay->forceExitPresent();
178 }
179
152 void VRController::contextDestroyed() 180 void VRController::contextDestroyed()
153 { 181 {
154 // If the document context was destroyed, shut down the client connection 182 // If the document context was destroyed, shut down the client connection
155 // and never call the mojo service again. 183 // and never call the mojo service again.
156 m_binding.Close(); 184 m_binding.Close();
157 m_service.reset(); 185 m_service.reset();
158 186
159 // The context is not automatically cleared, so do it manually. 187 // The context is not automatically cleared, so do it manually.
160 ContextLifecycleObserver::clearContext(); 188 ContextLifecycleObserver::clearContext();
161 } 189 }
162 190
163 DEFINE_TRACE(VRController) 191 DEFINE_TRACE(VRController)
164 { 192 {
165 visitor->trace(m_navigatorVR); 193 visitor->trace(m_navigatorVR);
166 visitor->trace(m_displays); 194 visitor->trace(m_displays);
167 195
168 ContextLifecycleObserver::trace(visitor); 196 ContextLifecycleObserver::trace(visitor);
169 } 197 }
170 198
171 } // namespace blink 199 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/vr/VRController.h ('k') | third_party/WebKit/Source/modules/vr/VRDisplay.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698