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/FrameRequestCallback.h" | 8 #include "core/dom/FrameRequestCallback.h" |
9 #include "core/dom/Fullscreen.h" | 9 #include "core/dom/Fullscreen.h" |
10 #include "core/dom/ScriptedAnimationController.h" | 10 #include "core/dom/ScriptedAnimationController.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 callback->m_useLegacyTimeBase = false; | 188 callback->m_useLegacyTimeBase = false; |
189 return ensureScriptedAnimationController(doc).registerCallback(callback); | 189 return ensureScriptedAnimationController(doc).registerCallback(callback); |
190 } | 190 } |
191 | 191 |
192 void VRDisplay::cancelAnimationFrame(int id) { | 192 void VRDisplay::cancelAnimationFrame(int id) { |
193 if (!m_scriptedAnimationController) | 193 if (!m_scriptedAnimationController) |
194 return; | 194 return; |
195 m_scriptedAnimationController->cancelCallback(id); | 195 m_scriptedAnimationController->cancelCallback(id); |
196 } | 196 } |
197 | 197 |
198 void VRDisplay::OnDisplayBlur() { | 198 void VRDisplay::OnBlur() { |
199 m_displayBlurred = true; | 199 m_displayBlurred = true; |
200 m_navigatorVR->fireVrDisplayOnBlur(this); | 200 |
| 201 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
| 202 EventTypeNames::vrdisplayblur, true, false, this, "")); |
201 } | 203 } |
202 | 204 |
203 void VRDisplay::OnDisplayFocus() { | 205 void VRDisplay::OnFocus() { |
204 m_displayBlurred = false; | 206 m_displayBlurred = false; |
205 // Restart our internal doc requestAnimationFrame callback, if it fired while | 207 // Restart our internal doc requestAnimationFrame callback, if it fired while |
206 // the display was blurred. | 208 // the display was blurred. |
207 // TODO(bajones): Don't use doc->requestAnimationFrame() at all. Animation | 209 // TODO(bajones): Don't use doc->requestAnimationFrame() at all. Animation |
208 // frames should be tied to the presenting VR display (e.g. should be serviced | 210 // frames should be tied to the presenting VR display (e.g. should be serviced |
209 // by GVR library callbacks on Android), and not the doc frame rate. | 211 // by GVR library callbacks on Android), and not the doc frame rate. |
210 if (!m_animationCallbackRequested) { | 212 if (!m_animationCallbackRequested) { |
211 Document* doc = m_navigatorVR->document(); | 213 Document* doc = m_navigatorVR->document(); |
212 if (!doc) | 214 if (!doc) |
213 return; | 215 return; |
214 doc->requestAnimationFrame(new VRDisplayFrameRequestCallback(this)); | 216 doc->requestAnimationFrame(new VRDisplayFrameRequestCallback(this)); |
215 } | 217 } |
216 m_navigatorVR->fireVrDisplayOnFocus(this); | 218 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
| 219 EventTypeNames::vrdisplayfocus, true, false, this, "")); |
217 } | 220 } |
218 | 221 |
219 void VRDisplay::serviceScriptedAnimations(double monotonicAnimationStartTime) { | 222 void VRDisplay::serviceScriptedAnimations(double monotonicAnimationStartTime) { |
220 if (!m_scriptedAnimationController) | 223 if (!m_scriptedAnimationController) |
221 return; | 224 return; |
222 AutoReset<bool> animating(&m_inAnimationFrame, true); | 225 AutoReset<bool> animating(&m_inAnimationFrame, true); |
223 m_animationCallbackRequested = false; | 226 m_animationCallbackRequested = false; |
224 | 227 |
225 // We use an internal rAF callback to run the animation loop at the display | 228 // We use an internal rAF callback to run the animation loop at the display |
226 // speed, and run the user's callback after our internal callback fires. | 229 // speed, and run the user's callback after our internal callback fires. |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 Platform::current()->recordRapporURL("VR.WebVR.PresentSuccess", | 425 Platform::current()->recordRapporURL("VR.WebVR.PresentSuccess", |
423 WebURL(doc->url())); | 426 WebURL(doc->url())); |
424 } | 427 } |
425 | 428 |
426 m_isPresenting = true; | 429 m_isPresenting = true; |
427 ReportPresentationResult(PresentationResult::Success); | 430 ReportPresentationResult(PresentationResult::Success); |
428 | 431 |
429 updateLayerBounds(); | 432 updateLayerBounds(); |
430 | 433 |
431 resolver->resolve(); | 434 resolver->resolve(); |
432 m_navigatorVR->fireVRDisplayPresentChange(this); | 435 OnPresentChange(); |
433 } | 436 } |
434 | 437 |
435 void VRDisplay::forceExitPresent() { | 438 void VRDisplay::forceExitPresent() { |
436 if (m_isPresenting) { | 439 if (m_isPresenting) { |
437 if (!m_capabilities->hasExternalDisplay()) { | 440 if (!m_capabilities->hasExternalDisplay()) { |
438 Fullscreen::fullyExitFullscreen(m_layer.source()->document()); | 441 Fullscreen::fullyExitFullscreen(m_layer.source()->document()); |
439 m_fullscreenCheckTimer.stop(); | 442 m_fullscreenCheckTimer.stop(); |
440 } else { | 443 } else { |
441 // Can't get into this presentation mode, so nothing to do here. | 444 // Can't get into this presentation mode, so nothing to do here. |
442 } | 445 } |
443 m_navigatorVR->fireVRDisplayPresentChange(this); | 446 OnPresentChange(); |
444 } | 447 } |
445 | 448 |
446 m_isPresenting = false; | 449 m_isPresenting = false; |
447 m_renderingContext = nullptr; | 450 m_renderingContext = nullptr; |
448 m_contextGL = nullptr; | 451 m_contextGL = nullptr; |
449 } | 452 } |
450 | 453 |
451 void VRDisplay::updateLayerBounds() { | 454 void VRDisplay::updateLayerBounds() { |
452 if (!m_display) | 455 if (!m_display) |
453 return; | 456 return; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 // Set the GL state back to what was set by the WebVR application. | 554 // Set the GL state back to what was set by the WebVR application. |
552 m_renderingContext->restoreScissorEnabled(); | 555 m_renderingContext->restoreScissorEnabled(); |
553 m_renderingContext->restoreScissorBox(); | 556 m_renderingContext->restoreScissorBox(); |
554 m_renderingContext->restoreColorMask(); | 557 m_renderingContext->restoreColorMask(); |
555 m_renderingContext->restoreClearColor(); | 558 m_renderingContext->restoreClearColor(); |
556 | 559 |
557 m_display->SubmitFrame(m_framePose.Clone()); | 560 m_display->SubmitFrame(m_framePose.Clone()); |
558 m_canUpdateFramePose = true; | 561 m_canUpdateFramePose = true; |
559 } | 562 } |
560 | 563 |
561 void VRDisplay::OnDisplayChanged( | 564 void VRDisplay::OnPresentChange() { |
562 device::mojom::blink::VRDisplayInfoPtr display) { | 565 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
| 566 EventTypeNames::vrdisplaypresentchange, true, false, this, "")); |
| 567 } |
| 568 |
| 569 void VRDisplay::OnChanged(device::mojom::blink::VRDisplayInfoPtr display) { |
563 update(display); | 570 update(display); |
564 } | 571 } |
565 | 572 |
566 void VRDisplay::OnExitPresent() { | 573 void VRDisplay::OnExitPresent() { |
567 forceExitPresent(); | 574 forceExitPresent(); |
568 } | 575 } |
569 | 576 |
570 void VRDisplay::onDisplayConnected() { | 577 void VRDisplay::onConnected() { |
571 m_navigatorVR->fireVREvent(VRDisplayEvent::create( | 578 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
572 EventTypeNames::vrdisplayconnect, true, false, this, "connect")); | 579 EventTypeNames::vrdisplayconnect, true, false, this, "connect")); |
573 } | 580 } |
574 | 581 |
575 void VRDisplay::onDisplayDisconnected() { | 582 void VRDisplay::onDisconnected() { |
576 m_navigatorVR->fireVREvent(VRDisplayEvent::create( | 583 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
577 EventTypeNames::vrdisplaydisconnect, true, false, this, "disconnect")); | 584 EventTypeNames::vrdisplaydisconnect, true, false, this, "disconnect")); |
578 } | 585 } |
579 | 586 |
| 587 void VRDisplay::OnActivate(device::mojom::blink::VRDisplayEventReason reason) { |
| 588 m_navigatorVR->dispatchVRGestureEvent(VRDisplayEvent::create( |
| 589 EventTypeNames::vrdisplayactivate, true, false, this, reason)); |
| 590 } |
| 591 |
| 592 void VRDisplay::OnDeactivate( |
| 593 device::mojom::blink::VRDisplayEventReason reason) { |
| 594 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
| 595 EventTypeNames::vrdisplaydeactivate, true, false, this, reason)); |
| 596 } |
| 597 |
580 void VRDisplay::onFullscreenCheck(TimerBase*) { | 598 void VRDisplay::onFullscreenCheck(TimerBase*) { |
581 // TODO: This is a temporary measure to track if fullscreen mode has been | 599 // TODO: This is a temporary measure to track if fullscreen mode has been |
582 // exited by the UA. If so we need to end VR presentation. Soon we won't | 600 // exited by the UA. If so we need to end VR presentation. Soon we won't |
583 // depend on the Fullscreen API to fake VR presentation, so this will | 601 // depend on the Fullscreen API to fake VR presentation, so this will |
584 // become unnessecary. Until that point, though, this seems preferable to | 602 // become unnessecary. Until that point, though, this seems preferable to |
585 // adding a bunch of notification plumbing to Fullscreen. | 603 // adding a bunch of notification plumbing to Fullscreen. |
586 if (!Fullscreen::isCurrentFullScreenElement(*m_layer.source())) { | 604 if (!Fullscreen::isCurrentFullScreenElement(*m_layer.source())) { |
587 m_isPresenting = false; | 605 m_isPresenting = false; |
588 m_navigatorVR->fireVRDisplayPresentChange(this); | 606 OnPresentChange(); |
589 m_fullscreenCheckTimer.stop(); | 607 m_fullscreenCheckTimer.stop(); |
590 if (!m_display) | 608 if (!m_display) |
591 return; | 609 return; |
592 m_display->ExitPresent(); | 610 m_display->ExitPresent(); |
593 } | 611 } |
594 } | 612 } |
595 | 613 |
596 ScriptedAnimationController& VRDisplay::ensureScriptedAnimationController( | 614 ScriptedAnimationController& VRDisplay::ensureScriptedAnimationController( |
597 Document* doc) { | 615 Document* doc) { |
598 if (!m_scriptedAnimationController) | 616 if (!m_scriptedAnimationController) |
(...skipping 11 matching lines...) Expand all Loading... |
610 visitor->trace(m_capabilities); | 628 visitor->trace(m_capabilities); |
611 visitor->trace(m_stageParameters); | 629 visitor->trace(m_stageParameters); |
612 visitor->trace(m_eyeParametersLeft); | 630 visitor->trace(m_eyeParametersLeft); |
613 visitor->trace(m_eyeParametersRight); | 631 visitor->trace(m_eyeParametersRight); |
614 visitor->trace(m_layer); | 632 visitor->trace(m_layer); |
615 visitor->trace(m_renderingContext); | 633 visitor->trace(m_renderingContext); |
616 visitor->trace(m_scriptedAnimationController); | 634 visitor->trace(m_scriptedAnimationController); |
617 } | 635 } |
618 | 636 |
619 } // namespace blink | 637 } // namespace blink |
OLD | NEW |