OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/VRDisplay.h" | 5 #include "modules/vr/VRDisplay.h" |
6 | 6 |
7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
8 #include "core/dom/Fullscreen.h" | 8 #include "core/dom/Fullscreen.h" |
9 #include "core/inspector/ConsoleMessage.h" | 9 #include "core/inspector/ConsoleMessage.h" |
10 #include "modules/vr/NavigatorVR.h" | 10 #include "modules/vr/NavigatorVR.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 m_isPresenting = true; | 175 m_isPresenting = true; |
176 | 176 |
177 resolver->resolve(); | 177 resolver->resolve(); |
178 | 178 |
179 m_navigatorVR->fireVRDisplayPresentChange(this); | 179 m_navigatorVR->fireVRDisplayPresentChange(this); |
180 | 180 |
181 // Check to see if the canvas is still the current fullscreen | 181 // Check to see if the canvas is still the current fullscreen |
182 // element once per second. | 182 // element once per second. |
183 m_fullscreenCheckTimer.startRepeating(1.0, BLINK_FROM_HERE); | 183 m_fullscreenCheckTimer.startRepeating(1.0, BLINK_FROM_HERE); |
| 184 |
| 185 controller()->requestPresent(m_displayId); |
184 } else { | 186 } else { |
185 DOMException* exception = DOMException::create(InvalidStateError, "V
R Presentation not implemented for this VRDisplay."); | 187 DOMException* exception = DOMException::create(InvalidStateError, "V
R Presentation not implemented for this VRDisplay."); |
186 resolver->reject(exception); | 188 resolver->reject(exception); |
187 } | 189 } |
| 190 |
| 191 // Set up the texture bounds for the provided layer |
| 192 device::blink::VRLayerBoundsPtr leftBounds = device::blink::VRLayerBound
s::New(); |
| 193 device::blink::VRLayerBoundsPtr rightBounds = device::blink::VRLayerBoun
ds::New(); |
| 194 |
| 195 if (m_layer.hasLeftBounds()) { |
| 196 leftBounds->left = m_layer.leftBounds()[0]; |
| 197 leftBounds->top = m_layer.leftBounds()[1]; |
| 198 leftBounds->width = m_layer.leftBounds()[2]; |
| 199 leftBounds->height = m_layer.leftBounds()[3]; |
| 200 } else { |
| 201 // Left eye defaults |
| 202 leftBounds->left = 0.0f; |
| 203 leftBounds->top = 0.0f; |
| 204 leftBounds->width = 0.5f; |
| 205 leftBounds->height = 1.0f; |
| 206 } |
| 207 |
| 208 if (m_layer.hasRightBounds()) { |
| 209 rightBounds->left = m_layer.rightBounds()[0]; |
| 210 rightBounds->top = m_layer.rightBounds()[1]; |
| 211 rightBounds->width = m_layer.rightBounds()[2]; |
| 212 rightBounds->height = m_layer.rightBounds()[3]; |
| 213 } else { |
| 214 // Right eye defaults |
| 215 rightBounds->left = 0.5f; |
| 216 rightBounds->top = 0.0f; |
| 217 rightBounds->width = 0.5f; |
| 218 rightBounds->height = 1.0f; |
| 219 } |
| 220 |
| 221 controller()->updateLayerBounds(m_displayId, std::move(leftBounds), std:
:move(rightBounds)); |
188 } else { | 222 } else { |
189 DOMException* exception = DOMException::create(InvalidStateError, "Inval
id layer source."); | 223 DOMException* exception = DOMException::create(InvalidStateError, "Inval
id layer source."); |
190 resolver->reject(exception); | 224 resolver->reject(exception); |
191 } | 225 } |
192 | 226 |
193 return promise; | 227 return promise; |
194 } | 228 } |
195 | 229 |
196 ScriptPromise VRDisplay::exitPresent(ScriptState* scriptState) | 230 ScriptPromise VRDisplay::exitPresent(ScriptState* scriptState) |
197 { | 231 { |
198 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 232 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
199 ScriptPromise promise = resolver->promise(); | 233 ScriptPromise promise = resolver->promise(); |
200 | 234 |
201 if (!m_isPresenting) { | 235 if (!m_isPresenting) { |
202 // Can't stop presenting if we're not presenting. | 236 // Can't stop presenting if we're not presenting. |
203 DOMException* exception = DOMException::create(InvalidStateError, "VRDis
play is not presenting."); | 237 DOMException* exception = DOMException::create(InvalidStateError, "VRDis
play is not presenting."); |
204 resolver->reject(exception); | 238 resolver->reject(exception); |
205 return promise; | 239 return promise; |
206 } | 240 } |
207 | 241 |
208 if (!m_capabilities->hasExternalDisplay()) { | 242 if (!m_capabilities->hasExternalDisplay()) { |
209 Fullscreen::fullyExitFullscreen(m_layer.source()->document()); | 243 Fullscreen::fullyExitFullscreen(m_layer.source()->document()); |
210 m_fullscreenCheckTimer.stop(); | 244 m_fullscreenCheckTimer.stop(); |
| 245 controller()->exitPresent(m_displayId); |
211 } else { | 246 } else { |
212 // Can't get into this presentation mode, so nothing to do here. | 247 // Can't get into this presentation mode, so nothing to do here. |
213 } | 248 } |
214 | 249 |
215 m_isPresenting = false; | 250 m_isPresenting = false; |
216 | 251 |
217 // TODO: Resolve when exit is confirmed | 252 // TODO: Resolve when exit is confirmed |
218 resolver->resolve(); | 253 resolver->resolve(); |
219 | 254 |
220 m_navigatorVR->fireVRDisplayPresentChange(this); | 255 m_navigatorVR->fireVRDisplayPresentChange(this); |
221 | 256 |
222 return promise; | 257 return promise; |
223 } | 258 } |
224 | 259 |
225 HeapVector<VRLayer> VRDisplay::getLayers() | 260 HeapVector<VRLayer> VRDisplay::getLayers() |
226 { | 261 { |
227 HeapVector<VRLayer> layers; | 262 HeapVector<VRLayer> layers; |
228 | 263 |
229 if (m_isPresenting) { | 264 if (m_isPresenting) { |
230 layers.append(m_layer); | 265 layers.append(m_layer); |
231 } | 266 } |
232 | 267 |
233 return layers; | 268 return layers; |
234 } | 269 } |
235 | 270 |
236 void VRDisplay::submitFrame(VRPose* pose) | 271 void VRDisplay::submitFrame(VRPose* pose) |
237 { | 272 { |
| 273 controller()->submitFrame(m_displayId); |
238 } | 274 } |
239 | 275 |
240 void VRDisplay::didProcessTask() | 276 void VRDisplay::didProcessTask() |
241 { | 277 { |
242 // Pose should be stable until control is returned to the user agent. | 278 // Pose should be stable until control is returned to the user agent. |
243 if (!m_canUpdateFramePose) { | 279 if (!m_canUpdateFramePose) { |
244 Platform::current()->currentThread()->removeTaskObserver(this); | 280 Platform::current()->currentThread()->removeTaskObserver(this); |
245 m_canUpdateFramePose = true; | 281 m_canUpdateFramePose = true; |
246 } | 282 } |
247 } | 283 } |
248 | 284 |
249 void VRDisplay::onFullscreenCheck(TimerBase*) | 285 void VRDisplay::onFullscreenCheck(TimerBase*) |
250 { | 286 { |
251 // TODO: This is a temporary measure to track if fullscreen mode has been | 287 // TODO: This is a temporary measure to track if fullscreen mode has been |
252 // exited by the UA. If so we need to end VR presentation. Soon we won't | 288 // exited by the UA. If so we need to end VR presentation. Soon we won't |
253 // depend on the Fullscreen API to fake VR presentation, so this will | 289 // depend on the Fullscreen API to fake VR presentation, so this will |
254 // become unnessecary. Until that point, though, this seems preferable to | 290 // become unnessecary. Until that point, though, this seems preferable to |
255 // adding a bunch of notification plumbing to Fullscreen. | 291 // adding a bunch of notification plumbing to Fullscreen. |
256 if (!Fullscreen::isCurrentFullScreenElement(*m_layer.source())) { | 292 if (!Fullscreen::isCurrentFullScreenElement(*m_layer.source())) { |
257 m_isPresenting = false; | 293 m_isPresenting = false; |
258 m_navigatorVR->fireVRDisplayPresentChange(this); | 294 m_navigatorVR->fireVRDisplayPresentChange(this); |
259 m_fullscreenCheckTimer.stop(); | 295 m_fullscreenCheckTimer.stop(); |
| 296 controller()->exitPresent(m_displayId); |
260 } | 297 } |
261 } | 298 } |
262 | 299 |
263 DEFINE_TRACE(VRDisplay) | 300 DEFINE_TRACE(VRDisplay) |
264 { | 301 { |
265 visitor->trace(m_navigatorVR); | 302 visitor->trace(m_navigatorVR); |
266 visitor->trace(m_capabilities); | 303 visitor->trace(m_capabilities); |
267 visitor->trace(m_stageParameters); | 304 visitor->trace(m_stageParameters); |
268 visitor->trace(m_eyeParametersLeft); | 305 visitor->trace(m_eyeParametersLeft); |
269 visitor->trace(m_eyeParametersRight); | 306 visitor->trace(m_eyeParametersRight); |
270 visitor->trace(m_framePose); | 307 visitor->trace(m_framePose); |
271 visitor->trace(m_layer); | 308 visitor->trace(m_layer); |
272 } | 309 } |
273 | 310 |
274 } // namespace blink | 311 } // namespace blink |
OLD | NEW |