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

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

Issue 2748293002: WebVR: process animations from posted task to yield for other events (Closed)
Patch Set: Throw shade at WaitForIncomingMethodCall in comment. Created 3 years, 9 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
« no previous file with comments | « third_party/WebKit/Source/modules/vr/VRDisplay.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, so that we yield to non-mojo tasks in
727 // between frames. Executing mojo tasks back to back within the same
728 // execution context caused extreme input delay due to processing
729 // multiple frames without yielding, see crbug.com/701444. I suspect
730 // this is due to WaitForIncomingMethodCall receiving the OnVSync
731 // but queueing it for immediate execution since it doesn't match
732 // the interface being waited on.
733 Platform::current()->currentThread()->getWebTaskRunner()->postTask(
billorr 2017/03/15 18:35:45 Does this measurably have a negative effect on lat
klausw 2017/03/15 19:00:17 I don't think so, if I understand it right it's ju
734 BLINK_FROM_HERE,
735 WTF::bind(&VRDisplay::processScheduledAnimations,
736 wrapWeakPersistent(this), m_timebase + timeDelta.InSecondsF()));
720 } 737 }
721 738
722 void VRDisplay::ConnectVSyncProvider() { 739 void VRDisplay::ConnectVSyncProvider() {
723 if (!m_navigatorVR->isFocused() || m_vrVSyncProvider.is_bound()) 740 if (!m_navigatorVR->isFocused() || m_vrVSyncProvider.is_bound())
724 return; 741 return;
725 m_display->GetVRVSyncProvider(mojo::MakeRequest(&m_vrVSyncProvider)); 742 m_display->GetVRVSyncProvider(mojo::MakeRequest(&m_vrVSyncProvider));
726 m_vrVSyncProvider.set_connection_error_handler(convertToBaseCallback( 743 m_vrVSyncProvider.set_connection_error_handler(convertToBaseCallback(
727 WTF::bind(&VRDisplay::OnVSyncConnectionError, wrapWeakPersistent(this)))); 744 WTF::bind(&VRDisplay::OnVSyncConnectionError, wrapWeakPersistent(this))));
728 if (m_pendingRaf && !m_displayBlurred) { 745 if (m_pendingRaf && !m_displayBlurred) {
729 m_pendingVsync = true; 746 m_pendingVsync = true;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 visitor->trace(m_stageParameters); 800 visitor->trace(m_stageParameters);
784 visitor->trace(m_eyeParametersLeft); 801 visitor->trace(m_eyeParametersLeft);
785 visitor->trace(m_eyeParametersRight); 802 visitor->trace(m_eyeParametersRight);
786 visitor->trace(m_layer); 803 visitor->trace(m_layer);
787 visitor->trace(m_renderingContext); 804 visitor->trace(m_renderingContext);
788 visitor->trace(m_scriptedAnimationController); 805 visitor->trace(m_scriptedAnimationController);
789 visitor->trace(m_pendingPresentResolvers); 806 visitor->trace(m_pendingPresentResolvers);
790 } 807 }
791 808
792 } // namespace blink 809 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/vr/VRDisplay.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698