| 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/FrameRequestCallback.h" | 9 #include "core/dom/FrameRequestCallback.h" |
| 10 #include "core/dom/ScriptedAnimationController.h" | 10 #include "core/dom/ScriptedAnimationController.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 if (which_eye == "right") | 48 if (which_eye == "right") |
| 49 return kVREyeRight; | 49 return kVREyeRight; |
| 50 return kVREyeNone; | 50 return kVREyeNone; |
| 51 } | 51 } |
| 52 | 52 |
| 53 } // namespace | 53 } // namespace |
| 54 | 54 |
| 55 VRDisplay::VRDisplay(NavigatorVR* navigator_vr, | 55 VRDisplay::VRDisplay(NavigatorVR* navigator_vr, |
| 56 device::mojom::blink::VRDisplayPtr display, | 56 device::mojom::blink::VRDisplayPtr display, |
| 57 device::mojom::blink::VRDisplayClientRequest request) | 57 device::mojom::blink::VRDisplayClientRequest request) |
| 58 : ContextLifecycleObserver(navigator_vr->GetDocument()), | 58 : SuspendableObject(navigator_vr->GetDocument()), |
| 59 navigator_vr_(navigator_vr), | 59 navigator_vr_(navigator_vr), |
| 60 capabilities_(new VRDisplayCapabilities()), | 60 capabilities_(new VRDisplayCapabilities()), |
| 61 eye_parameters_left_(new VREyeParameters()), | 61 eye_parameters_left_(new VREyeParameters()), |
| 62 eye_parameters_right_(new VREyeParameters()), | 62 eye_parameters_right_(new VREyeParameters()), |
| 63 display_(std::move(display)), | 63 display_(std::move(display)), |
| 64 submit_frame_client_binding_(this), | 64 submit_frame_client_binding_(this), |
| 65 display_client_binding_(this, std::move(request)) {} | 65 display_client_binding_(this, std::move(request)) { |
| 66 SuspendIfNeeded(); // Initialize SuspendabaleObject. |
| 67 } |
| 66 | 68 |
| 67 VRDisplay::~VRDisplay() {} | 69 VRDisplay::~VRDisplay() {} |
| 68 | 70 |
| 71 void VRDisplay::Suspend() {} |
| 72 |
| 73 void VRDisplay::Resume() { |
| 74 RequestVSync(); |
| 75 } |
| 76 |
| 69 VRController* VRDisplay::Controller() { | 77 VRController* VRDisplay::Controller() { |
| 70 return navigator_vr_->Controller(); | 78 return navigator_vr_->Controller(); |
| 71 } | 79 } |
| 72 | 80 |
| 73 void VRDisplay::Update(const device::mojom::blink::VRDisplayInfoPtr& display) { | 81 void VRDisplay::Update(const device::mojom::blink::VRDisplayInfoPtr& display) { |
| 74 display_id_ = display->index; | 82 display_id_ = display->index; |
| 75 display_name_ = display->displayName; | 83 display_name_ = display->displayName; |
| 76 is_connected_ = true; | 84 is_connected_ = true; |
| 77 | 85 |
| 78 capabilities_->SetHasPosition(display->capabilities->hasPosition); | 86 capabilities_->SetHasPosition(display->capabilities->hasPosition); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return nullptr; | 136 return nullptr; |
| 129 } | 137 } |
| 130 } | 138 } |
| 131 | 139 |
| 132 void VRDisplay::RequestVSync() { | 140 void VRDisplay::RequestVSync() { |
| 133 DVLOG(2) << __FUNCTION__ | 141 DVLOG(2) << __FUNCTION__ |
| 134 << " start: pending_vrdisplay_raf_=" << pending_vrdisplay_raf_ | 142 << " start: pending_vrdisplay_raf_=" << pending_vrdisplay_raf_ |
| 135 << " in_animation_frame_=" << in_animation_frame_ | 143 << " in_animation_frame_=" << in_animation_frame_ |
| 136 << " did_submit_this_frame_=" << did_submit_this_frame_; | 144 << " did_submit_this_frame_=" << did_submit_this_frame_; |
| 137 | 145 |
| 146 if (!pending_vrdisplay_raf_) |
| 147 return; |
| 148 |
| 138 // The logic here is a bit subtle. We get called from one of the following | 149 // The logic here is a bit subtle. We get called from one of the following |
| 139 // four contexts: | 150 // four contexts: |
| 140 // | 151 // |
| 141 // (a) from requestAnimationFrame if outside an animating context (i.e. the | 152 // (a) from requestAnimationFrame if outside an animating context (i.e. the |
| 142 // first rAF call from inside a getVRDisplays() promise) | 153 // first rAF call from inside a getVRDisplays() promise) |
| 143 // | 154 // |
| 144 // (b) from requestAnimationFrame in an animating context if the JS code | 155 // (b) from requestAnimationFrame in an animating context if the JS code |
| 145 // calls rAF after submitFrame. | 156 // calls rAF after submitFrame. |
| 146 // | 157 // |
| 147 // (c) from submitFrame if that is called after rAF. | 158 // (c) from submitFrame if that is called after rAF. |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 DVLOG(2) << __FUNCTION__; | 805 DVLOG(2) << __FUNCTION__; |
| 795 // Check if we still have a valid context, the animation controller | 806 // Check if we still have a valid context, the animation controller |
| 796 // or document may have disappeared since we scheduled this. | 807 // or document may have disappeared since we scheduled this. |
| 797 Document* doc = this->GetDocument(); | 808 Document* doc = this->GetDocument(); |
| 798 if (!doc || display_blurred_) { | 809 if (!doc || display_blurred_) { |
| 799 DVLOG(2) << __FUNCTION__ << ": early exit, doc=" << doc | 810 DVLOG(2) << __FUNCTION__ << ": early exit, doc=" << doc |
| 800 << " display_blurred_=" << display_blurred_; | 811 << " display_blurred_=" << display_blurred_; |
| 801 return; | 812 return; |
| 802 } | 813 } |
| 803 | 814 |
| 815 if (doc->IsContextSuspended()) { |
| 816 // We are currently suspended - try ProcessScheduledAnimations again later |
| 817 // when we resume. |
| 818 return; |
| 819 } |
| 820 |
| 804 TRACE_EVENT1("gpu", "VRDisplay::OnVSync", "frame", vr_frame_id_); | 821 TRACE_EVENT1("gpu", "VRDisplay::OnVSync", "frame", vr_frame_id_); |
| 805 | 822 |
| 806 if (pending_vrdisplay_raf_ && scripted_animation_controller_) { | 823 if (pending_vrdisplay_raf_ && scripted_animation_controller_) { |
| 807 // Run the callback, making sure that in_animation_frame_ is only | 824 // Run the callback, making sure that in_animation_frame_ is only |
| 808 // true for the vrDisplay rAF and not for a legacy window rAF | 825 // true for the vrDisplay rAF and not for a legacy window rAF |
| 809 // that may be called later. | 826 // that may be called later. |
| 810 AutoReset<bool> animating(&in_animation_frame_, true); | 827 AutoReset<bool> animating(&in_animation_frame_, true); |
| 811 pending_vrdisplay_raf_ = false; | 828 pending_vrdisplay_raf_ = false; |
| 812 did_submit_this_frame_ = false; | 829 did_submit_this_frame_ = false; |
| 813 scripted_animation_controller_->ServiceScriptedAnimations(timestamp); | 830 scripted_animation_controller_->ServiceScriptedAnimations(timestamp); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 } | 920 } |
| 904 | 921 |
| 905 ExecutionContext* VRDisplay::GetExecutionContext() const { | 922 ExecutionContext* VRDisplay::GetExecutionContext() const { |
| 906 return ContextLifecycleObserver::GetExecutionContext(); | 923 return ContextLifecycleObserver::GetExecutionContext(); |
| 907 } | 924 } |
| 908 | 925 |
| 909 const AtomicString& VRDisplay::InterfaceName() const { | 926 const AtomicString& VRDisplay::InterfaceName() const { |
| 910 return EventTargetNames::VRDisplay; | 927 return EventTargetNames::VRDisplay; |
| 911 } | 928 } |
| 912 | 929 |
| 913 void VRDisplay::ContextDestroyed(ExecutionContext*) { | 930 void VRDisplay::ContextDestroyed(ExecutionContext* context) { |
| 931 SuspendableObject::ContextDestroyed(context); |
| 914 ForceExitPresent(); | 932 ForceExitPresent(); |
| 915 scripted_animation_controller_.Clear(); | 933 scripted_animation_controller_.Clear(); |
| 916 } | 934 } |
| 917 | 935 |
| 918 bool VRDisplay::HasPendingActivity() const { | 936 bool VRDisplay::HasPendingActivity() const { |
| 919 // Prevent V8 from garbage collecting the wrapper object if there are | 937 // Prevent V8 from garbage collecting the wrapper object if there are |
| 920 // event listeners attached to it. | 938 // event listeners attached to it. |
| 921 return GetExecutionContext() && HasEventListeners(); | 939 return GetExecutionContext() && HasEventListeners(); |
| 922 } | 940 } |
| 923 | 941 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 942 visitor->Trace(stage_parameters_); | 960 visitor->Trace(stage_parameters_); |
| 943 visitor->Trace(eye_parameters_left_); | 961 visitor->Trace(eye_parameters_left_); |
| 944 visitor->Trace(eye_parameters_right_); | 962 visitor->Trace(eye_parameters_right_); |
| 945 visitor->Trace(layer_); | 963 visitor->Trace(layer_); |
| 946 visitor->Trace(rendering_context_); | 964 visitor->Trace(rendering_context_); |
| 947 visitor->Trace(scripted_animation_controller_); | 965 visitor->Trace(scripted_animation_controller_); |
| 948 visitor->Trace(pending_present_resolvers_); | 966 visitor->Trace(pending_present_resolvers_); |
| 949 } | 967 } |
| 950 | 968 |
| 951 } // namespace blink | 969 } // namespace blink |
| OLD | NEW |