Chromium Code Reviews| 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/css/StylePropertySet.h" | 7 #include "core/css/StylePropertySet.h" |
| 8 #include "core/dom/DOMException.h" | 8 #include "core/dom/DOMException.h" |
| 9 #include "core/dom/DocumentUserGestureToken.h" | 9 #include "core/dom/DocumentUserGestureToken.h" |
| 10 #include "core/dom/FrameRequestCallback.h" | 10 #include "core/dom/FrameRequestCallback.h" |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 m_navigatorVR->dispatchVRGestureEvent(VRDisplayEvent::create( | 682 m_navigatorVR->dispatchVRGestureEvent(VRDisplayEvent::create( |
| 683 EventTypeNames::vrdisplayactivate, true, false, this, reason)); | 683 EventTypeNames::vrdisplayactivate, true, false, this, reason)); |
| 684 } | 684 } |
| 685 | 685 |
| 686 void VRDisplay::OnDeactivate( | 686 void VRDisplay::OnDeactivate( |
| 687 device::mojom::blink::VRDisplayEventReason reason) { | 687 device::mojom::blink::VRDisplayEventReason reason) { |
| 688 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( | 688 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
| 689 EventTypeNames::vrdisplaydeactivate, true, false, this, reason)); | 689 EventTypeNames::vrdisplaydeactivate, true, false, this, reason)); |
| 690 } | 690 } |
| 691 | 691 |
| 692 void VRDisplay::processScheduledAnimations(double timestamp) { | |
| 693 TRACE_EVENT1("gpu", "VRDisplay::OnVSync", "frame", m_vrFrameId); | |
| 694 | |
| 695 AutoReset<bool> animating(&m_inAnimationFrame, true); | |
| 696 m_pendingRaf = false; | |
| 697 m_scriptedAnimationController->serviceScriptedAnimations(timestamp); | |
| 698 } | |
| 699 | |
| 692 void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, | 700 void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, |
| 693 mojo::common::mojom::blink::TimeDeltaPtr time, | 701 mojo::common::mojom::blink::TimeDeltaPtr time, |
| 694 int16_t frameId, | 702 int16_t frameId, |
| 695 device::mojom::blink::VRVSyncProvider::Status error) { | 703 device::mojom::blink::VRVSyncProvider::Status error) { |
| 696 switch (error) { | 704 switch (error) { |
| 697 case device::mojom::blink::VRVSyncProvider::Status::SUCCESS: | 705 case device::mojom::blink::VRVSyncProvider::Status::SUCCESS: |
| 698 break; | 706 break; |
| 699 case device::mojom::blink::VRVSyncProvider::Status::CLOSING: | 707 case device::mojom::blink::VRVSyncProvider::Status::CLOSING: |
| 700 return; | 708 return; |
| 701 } | 709 } |
| 702 m_pendingVsync = false; | 710 m_pendingVsync = false; |
| 703 Document* doc = this->document(); | 711 Document* doc = this->document(); |
| 704 if (!doc || m_displayBlurred || !m_scriptedAnimationController) | 712 if (!doc || m_displayBlurred || !m_scriptedAnimationController) |
| 705 return; | 713 return; |
| 706 | 714 |
| 707 WTF::TimeDelta timeDelta = | 715 WTF::TimeDelta timeDelta = |
| 708 WTF::TimeDelta::FromMicroseconds(time->microseconds); | 716 WTF::TimeDelta::FromMicroseconds(time->microseconds); |
| 709 // Ensure a consistent timebase with document rAF. | 717 // Ensure a consistent timebase with document rAF. |
| 710 if (m_timebase < 0) { | 718 if (m_timebase < 0) { |
| 711 m_timebase = WTF::monotonicallyIncreasingTime() - timeDelta.InSecondsF(); | 719 m_timebase = WTF::monotonicallyIncreasingTime() - timeDelta.InSecondsF(); |
| 712 } | 720 } |
| 713 | 721 |
| 714 AutoReset<bool> animating(&m_inAnimationFrame, true); | |
| 715 m_framePose = std::move(pose); | 722 m_framePose = std::move(pose); |
| 716 m_vrFrameId = frameId; | 723 m_vrFrameId = frameId; |
| 717 m_pendingRaf = false; | 724 |
| 718 m_scriptedAnimationController->serviceScriptedAnimations( | 725 // Post a task to handle scheduled animations after the current |
| 719 m_timebase + timeDelta.InSecondsF()); | 726 // execution context finishes. If we call GetVSync inline here via |
|
mthiesse
2017/03/15 17:43:51
Comment needs to be updated.
klausw
2017/03/15 17:55:40
The comment is accurate, but I'll rephrase it to b
mthiesse
2017/03/15 18:05:03
The problem is the comment says "If we call GetVSy
klausw
2017/03/15 18:14:26
No, we don't call GetVSync inline here. It's now c
mthiesse
2017/03/15 18:19:01
We should at least mention in this comment that th
klausw
2017/03/15 18:21:00
Done.
| |
| 727 // serviceScriptedAnimations calling rAF, we can end up with the | |
| 728 // next VSync already being ready and scheduled when we exit, and | |
| 729 // then we'll process several frames in a row without ever yielding | |
| 730 // back to the main event loop. This causes extreme input delay, see | |
| 731 // crbug.com/701444. | |
| 732 Platform::current()->currentThread()->getWebTaskRunner()->postTask( | |
| 733 BLINK_FROM_HERE, | |
| 734 WTF::bind(&VRDisplay::processScheduledAnimations, | |
| 735 wrapWeakPersistent(this), m_timebase + timeDelta.InSecondsF())); | |
| 720 } | 736 } |
| 721 | 737 |
| 722 void VRDisplay::ConnectVSyncProvider() { | 738 void VRDisplay::ConnectVSyncProvider() { |
| 723 if (!m_navigatorVR->isFocused() || m_vrVSyncProvider.is_bound()) | 739 if (!m_navigatorVR->isFocused() || m_vrVSyncProvider.is_bound()) |
| 724 return; | 740 return; |
| 725 m_display->GetVRVSyncProvider(mojo::MakeRequest(&m_vrVSyncProvider)); | 741 m_display->GetVRVSyncProvider(mojo::MakeRequest(&m_vrVSyncProvider)); |
| 726 m_vrVSyncProvider.set_connection_error_handler(convertToBaseCallback( | 742 m_vrVSyncProvider.set_connection_error_handler(convertToBaseCallback( |
| 727 WTF::bind(&VRDisplay::OnVSyncConnectionError, wrapWeakPersistent(this)))); | 743 WTF::bind(&VRDisplay::OnVSyncConnectionError, wrapWeakPersistent(this)))); |
| 728 if (m_pendingRaf && !m_displayBlurred) { | 744 if (m_pendingRaf && !m_displayBlurred) { |
| 729 m_pendingVsync = true; | 745 m_pendingVsync = true; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 visitor->trace(m_stageParameters); | 799 visitor->trace(m_stageParameters); |
| 784 visitor->trace(m_eyeParametersLeft); | 800 visitor->trace(m_eyeParametersLeft); |
| 785 visitor->trace(m_eyeParametersRight); | 801 visitor->trace(m_eyeParametersRight); |
| 786 visitor->trace(m_layer); | 802 visitor->trace(m_layer); |
| 787 visitor->trace(m_renderingContext); | 803 visitor->trace(m_renderingContext); |
| 788 visitor->trace(m_scriptedAnimationController); | 804 visitor->trace(m_scriptedAnimationController); |
| 789 visitor->trace(m_pendingPresentResolvers); | 805 visitor->trace(m_pendingPresentResolvers); |
| 790 } | 806 } |
| 791 | 807 |
| 792 } // namespace blink | 808 } // namespace blink |
| OLD | NEW |