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

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: Addressed Michael's feedback 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);
haraken 2016/09/14 00:08:20 Don't we need to add 'return' here?
bajones 2016/09/14 00:30:03 Yes, we do. Thanks! Fixed.
152 }
153
154 if (success) {
155 vrDisplay->beginPresent(resolver);
156 } else {
157 vrDisplay->forceExitPresent();
158 DOMException* exception = DOMException::create(NotAllowedError, "Present ation request was denied.");
159 resolver->reject(exception);
160 }
161 }
162
143 void VRController::OnDisplayChanged(device::blink::VRDisplayPtr display) 163 void VRController::OnDisplayChanged(device::blink::VRDisplayPtr display)
144 { 164 {
145 VRDisplay* vrDisplay = getDisplayForIndex(display->index); 165 VRDisplay* vrDisplay = getDisplayForIndex(display->index);
146 if (!vrDisplay) 166 if (!vrDisplay)
147 return; 167 return;
148 168
149 vrDisplay->update(display); 169 vrDisplay->update(display);
150 } 170 }
151 171
172 void VRController::OnExitPresent(unsigned index)
173 {
174 VRDisplay* vrDisplay = getDisplayForIndex(index);
175 if (vrDisplay)
176 vrDisplay->forceExitPresent();
177 }
178
152 void VRController::contextDestroyed() 179 void VRController::contextDestroyed()
153 { 180 {
154 // If the document context was destroyed, shut down the client connection 181 // If the document context was destroyed, shut down the client connection
155 // and never call the mojo service again. 182 // and never call the mojo service again.
156 m_binding.Close(); 183 m_binding.Close();
157 m_service.reset(); 184 m_service.reset();
158 185
159 // The context is not automatically cleared, so do it manually. 186 // The context is not automatically cleared, so do it manually.
160 ContextLifecycleObserver::clearContext(); 187 ContextLifecycleObserver::clearContext();
161 } 188 }
162 189
163 DEFINE_TRACE(VRController) 190 DEFINE_TRACE(VRController)
164 { 191 {
165 visitor->trace(m_navigatorVR); 192 visitor->trace(m_navigatorVR);
166 visitor->trace(m_displays); 193 visitor->trace(m_displays);
167 194
168 ContextLifecycleObserver::trace(visitor); 195 ContextLifecycleObserver::trace(visitor);
169 } 196 }
170 197
171 } // namespace blink 198 } // 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