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

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: 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 switch (stringToVREye(whichEye)) { 144 switch (stringToVREye(whichEye)) {
145 case VREyeLeft: 145 case VREyeLeft:
146 return m_eyeParametersLeft; 146 return m_eyeParametersLeft;
147 case VREyeRight: 147 case VREyeRight:
148 return m_eyeParametersRight; 148 return m_eyeParametersRight;
149 default: 149 default:
150 return nullptr; 150 return nullptr;
151 } 151 }
152 } 152 }
153 153
154 void VRDisplay::doGetVSync() {
155 if (!m_displayBlurred && !m_pendingVsync) {
156 m_pendingVsync = true;
157 m_vrVSyncProvider->GetVSync(convertToBaseCallback(
158 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this))));
159 }
160 }
161
154 int VRDisplay::requestAnimationFrame(FrameRequestCallback* callback) { 162 int VRDisplay::requestAnimationFrame(FrameRequestCallback* callback) {
155 Document* doc = this->document(); 163 Document* doc = this->document();
156 if (!doc) 164 if (!doc)
157 return 0; 165 return 0;
158 m_pendingRaf = true; 166 m_pendingRaf = true;
159 if (!m_vrVSyncProvider.is_bound()) { 167 if (!m_vrVSyncProvider.is_bound()) {
160 ConnectVSyncProvider(); 168 ConnectVSyncProvider();
161 } else if (!m_displayBlurred && !m_pendingVsync) { 169 } else if (!m_displayBlurred && !m_pendingVsync) {
162 m_pendingVsync = true; 170 // Schedule a task to fetch a new VSync after the current
163 m_vrVSyncProvider->GetVSync(convertToBaseCallback( 171 // execution context finishes. If we call GetVSync inline here, we
164 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); 172 // can end up with the next VSync already being ready and
173 // scheduled when we exit, and then we'll process several frames
174 // in a row without ever yielding back to the main event loop,
175 // causing extreme input delay. See crbug.com/701444.
176 Platform::current()->currentThread()->getWebTaskRunner()->postTask(
mthiesse 2017/03/15 15:17:35 Two comments: 1. This shouldn't be necessary, this
klausw 2017/03/15 15:42:39 Yes, this was unexpected. It's not just starving I
klausw 2017/03/15 15:50:59 To clarify, I think that executing the next GetVSy
klausw 2017/03/15 17:39:25 The deferred serviceScriptedAnimations works, goin
177 BLINK_FROM_HERE,
178 WTF::bind(&VRDisplay::doGetVSync, wrapWeakPersistent(this)));
165 } 179 }
166 callback->m_useLegacyTimeBase = false; 180 callback->m_useLegacyTimeBase = false;
167 return ensureScriptedAnimationController(doc).registerCallback(callback); 181 return ensureScriptedAnimationController(doc).registerCallback(callback);
168 } 182 }
169 183
170 void VRDisplay::cancelAnimationFrame(int id) { 184 void VRDisplay::cancelAnimationFrame(int id) {
171 if (!m_scriptedAnimationController) 185 if (!m_scriptedAnimationController)
172 return; 186 return;
173 m_scriptedAnimationController->cancelCallback(id); 187 m_scriptedAnimationController->cancelCallback(id);
174 } 188 }
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 WTF::TimeDelta::FromMicroseconds(time->microseconds); 722 WTF::TimeDelta::FromMicroseconds(time->microseconds);
709 // Ensure a consistent timebase with document rAF. 723 // Ensure a consistent timebase with document rAF.
710 if (m_timebase < 0) { 724 if (m_timebase < 0) {
711 m_timebase = WTF::monotonicallyIncreasingTime() - timeDelta.InSecondsF(); 725 m_timebase = WTF::monotonicallyIncreasingTime() - timeDelta.InSecondsF();
712 } 726 }
713 727
714 AutoReset<bool> animating(&m_inAnimationFrame, true); 728 AutoReset<bool> animating(&m_inAnimationFrame, true);
715 m_framePose = std::move(pose); 729 m_framePose = std::move(pose);
716 m_vrFrameId = frameId; 730 m_vrFrameId = frameId;
717 m_pendingRaf = false; 731 m_pendingRaf = false;
732 TRACE_EVENT1("gpu", "VRDisplay::OnVSync", "frame", frameId);
733
718 m_scriptedAnimationController->serviceScriptedAnimations( 734 m_scriptedAnimationController->serviceScriptedAnimations(
719 m_timebase + timeDelta.InSecondsF()); 735 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))));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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