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" |
| 11 #include "core/dom/Fullscreen.h" | 11 #include "core/dom/Fullscreen.h" |
| 12 #include "core/dom/ScriptedAnimationController.h" | 12 #include "core/dom/ScriptedAnimationController.h" |
| 13 #include "core/dom/TaskRunnerHelper.h" | 13 #include "core/dom/TaskRunnerHelper.h" |
| 14 #include "core/frame/UseCounter.h" | 14 #include "core/frame/UseCounter.h" |
| 15 #include "core/inspector/ConsoleMessage.h" | 15 #include "core/inspector/ConsoleMessage.h" |
| 16 #include "core/loader/DocumentLoader.h" | 16 #include "core/loader/DocumentLoader.h" |
| 17 #include "gpu/command_buffer/client/gles2_interface.h" | 17 #include "gpu/command_buffer/client/gles2_interface.h" |
| 18 #include "modules/EventTargetModules.h" | 18 #include "modules/EventTargetModules.h" |
| 19 #include "modules/vr/NavigatorVR.h" | 19 #include "modules/vr/NavigatorVR.h" |
| 20 #include "modules/vr/VRController.h" | 20 #include "modules/vr/VRController.h" |
| 21 #include "modules/vr/VRDisplayCapabilities.h" | 21 #include "modules/vr/VRDisplayCapabilities.h" |
| 22 #include "modules/vr/VREyeParameters.h" | 22 #include "modules/vr/VREyeParameters.h" |
| 23 #include "modules/vr/VRFrameData.h" | 23 #include "modules/vr/VRFrameData.h" |
| 24 #include "modules/vr/VRLayer.h" | 24 #include "modules/vr/VRLayer.h" |
| 25 #include "modules/vr/VRPose.h" | 25 #include "modules/vr/VRPose.h" |
| 26 #include "modules/vr/VRStageParameters.h" | 26 #include "modules/vr/VRStageParameters.h" |
| 27 #include "modules/webgl/WebGLRenderingContextBase.h" | 27 #include "modules/webgl/WebGLRenderingContextBase.h" |
| 28 #include "platform/Histogram.h" | 28 #include "platform/Histogram.h" |
| 29 #include "platform/UserGestureIndicator.h" | 29 #include "platform/UserGestureIndicator.h" |
| 30 #include "platform/instrumentation/tracing/TraceEvent.h" | |
| 30 #include "public/platform/Platform.h" | 31 #include "public/platform/Platform.h" |
| 31 #include "wtf/AutoReset.h" | 32 #include "wtf/AutoReset.h" |
| 32 #include "wtf/Time.h" | 33 #include "wtf/Time.h" |
| 33 | 34 |
| 34 #include <array> | 35 #include <array> |
| 35 | 36 |
| 36 namespace blink { | 37 namespace blink { |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 m_navigatorVR->dispatchVRGestureEvent(VRDisplayEvent::create( | 670 m_navigatorVR->dispatchVRGestureEvent(VRDisplayEvent::create( |
| 670 EventTypeNames::vrdisplayactivate, true, false, this, reason)); | 671 EventTypeNames::vrdisplayactivate, true, false, this, reason)); |
| 671 } | 672 } |
| 672 | 673 |
| 673 void VRDisplay::OnDeactivate( | 674 void VRDisplay::OnDeactivate( |
| 674 device::mojom::blink::VRDisplayEventReason reason) { | 675 device::mojom::blink::VRDisplayEventReason reason) { |
| 675 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( | 676 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
| 676 EventTypeNames::vrdisplaydeactivate, true, false, this, reason)); | 677 EventTypeNames::vrdisplaydeactivate, true, false, this, reason)); |
| 677 } | 678 } |
| 678 | 679 |
| 680 void VRDisplay::processScheduledAnimations(double timestamp) { | |
| 681 TRACE_EVENT1("gpu", "VRDisplay::OnVSync", "frame", m_vrFrameId); | |
| 682 | |
| 683 AutoReset<bool> animating(&m_inAnimationFrame, true); | |
| 684 m_pendingRaf = false; | |
| 685 m_scriptedAnimationController->serviceScriptedAnimations(timestamp); | |
| 686 } | |
| 687 | |
| 679 void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, | 688 void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, |
| 680 mojo::common::mojom::blink::TimeDeltaPtr time, | 689 mojo::common::mojom::blink::TimeDeltaPtr time, |
| 681 int16_t frameId, | 690 int16_t frameId, |
| 682 device::mojom::blink::VRVSyncProvider::Status error) { | 691 device::mojom::blink::VRVSyncProvider::Status error) { |
| 683 switch (error) { | 692 switch (error) { |
| 684 case device::mojom::blink::VRVSyncProvider::Status::SUCCESS: | 693 case device::mojom::blink::VRVSyncProvider::Status::SUCCESS: |
| 685 break; | 694 break; |
| 686 case device::mojom::blink::VRVSyncProvider::Status::RETRY: | 695 case device::mojom::blink::VRVSyncProvider::Status::RETRY: |
| 687 m_vrVSyncProvider->GetVSync(convertToBaseCallback( | 696 m_vrVSyncProvider->GetVSync(convertToBaseCallback( |
| 688 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); | 697 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); |
| 689 return; | 698 return; |
| 690 } | 699 } |
| 691 m_pendingVsync = false; | 700 m_pendingVsync = false; |
| 692 if (m_displayBlurred) | 701 if (m_displayBlurred) |
| 693 return; | 702 return; |
| 694 if (!m_scriptedAnimationController) | 703 if (!m_scriptedAnimationController) |
| 695 return; | 704 return; |
| 696 Document* doc = this->document(); | 705 Document* doc = this->document(); |
| 697 if (!doc) | 706 if (!doc) |
| 698 return; | 707 return; |
| 699 | 708 |
| 700 WTF::TimeDelta timeDelta = | 709 WTF::TimeDelta timeDelta = |
| 701 WTF::TimeDelta::FromMicroseconds(time->microseconds); | 710 WTF::TimeDelta::FromMicroseconds(time->microseconds); |
| 702 // Ensure a consistent timebase with document rAF. | 711 // Ensure a consistent timebase with document rAF. |
| 703 if (m_timebase < 0) { | 712 if (m_timebase < 0) { |
| 704 m_timebase = WTF::monotonicallyIncreasingTime() - timeDelta.InSecondsF(); | 713 m_timebase = WTF::monotonicallyIncreasingTime() - timeDelta.InSecondsF(); |
| 705 } | 714 } |
| 706 | 715 |
| 707 AutoReset<bool> animating(&m_inAnimationFrame, true); | |
| 708 m_framePose = std::move(pose); | 716 m_framePose = std::move(pose); |
| 709 m_vrFrameId = frameId; | 717 m_vrFrameId = frameId; |
| 710 m_pendingRaf = false; | 718 |
| 711 m_scriptedAnimationController->serviceScriptedAnimations( | 719 // Post a task to handle scheduled animations after the current |
| 712 m_timebase + timeDelta.InSecondsF()); | 720 // execution context finishes, so that we yield to non-mojo tasks in |
| 721 // between frames. Executing mojo tasks back to back within the same | |
| 722 // execution context caused extreme input delay due to processing | |
| 723 // multiple frames without yielding, see crbug.com/701444. I suspect | |
| 724 // this is due to WaitForIncomingMethodCall receiving the OnVSync | |
| 725 // but queueing it for immediate execution since it doesn't match | |
| 726 // the interface being waited on. | |
| 727 Platform::current()->currentThread()->getWebTaskRunner()->postTask( | |
|
haraken
2017/03/24 01:16:06
The default task runner is going to be deprecated.
| |
| 728 BLINK_FROM_HERE, | |
| 729 WTF::bind(&VRDisplay::processScheduledAnimations, | |
| 730 wrapWeakPersistent(this), m_timebase + timeDelta.InSecondsF())); | |
| 713 } | 731 } |
| 714 | 732 |
| 715 void VRDisplay::ConnectVSyncProvider() { | 733 void VRDisplay::ConnectVSyncProvider() { |
| 716 if (!m_navigatorVR->isFocused() || m_vrVSyncProvider.is_bound()) | 734 if (!m_navigatorVR->isFocused() || m_vrVSyncProvider.is_bound()) |
| 717 return; | 735 return; |
| 718 m_display->GetVRVSyncProvider(mojo::MakeRequest(&m_vrVSyncProvider)); | 736 m_display->GetVRVSyncProvider(mojo::MakeRequest(&m_vrVSyncProvider)); |
| 719 if (m_pendingRaf && !m_displayBlurred) { | 737 if (m_pendingRaf && !m_displayBlurred) { |
| 720 m_pendingVsync = true; | 738 m_pendingVsync = true; |
| 721 m_vrVSyncProvider->GetVSync(convertToBaseCallback( | 739 m_vrVSyncProvider->GetVSync(convertToBaseCallback( |
| 722 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); | 740 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 807 visitor->trace(m_stageParameters); | 825 visitor->trace(m_stageParameters); |
| 808 visitor->trace(m_eyeParametersLeft); | 826 visitor->trace(m_eyeParametersLeft); |
| 809 visitor->trace(m_eyeParametersRight); | 827 visitor->trace(m_eyeParametersRight); |
| 810 visitor->trace(m_layer); | 828 visitor->trace(m_layer); |
| 811 visitor->trace(m_renderingContext); | 829 visitor->trace(m_renderingContext); |
| 812 visitor->trace(m_scriptedAnimationController); | 830 visitor->trace(m_scriptedAnimationController); |
| 813 visitor->trace(m_pendingPresentResolvers); | 831 visitor->trace(m_pendingPresentResolvers); |
| 814 } | 832 } |
| 815 | 833 |
| 816 } // namespace blink | 834 } // namespace blink |
| OLD | NEW |