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/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 suspended_. | |
| 67 } | |
| 66 | 68 |
| 67 VRDisplay::~VRDisplay() {} | 69 VRDisplay::~VRDisplay() {} |
| 68 | 70 |
| 71 void VRDisplay::Suspend() { | |
| 72 suspended_ = true; | |
| 73 } | |
| 74 | |
| 75 void VRDisplay::Resume() { | |
| 76 suspended_ = false; | |
| 77 if (request_vsync_on_resume_) { | |
|
mthiesse
2017/06/08 03:26:30
No need for this boolean. RequestVSync() is always
billorr
2017/06/08 04:20:21
Done.
| |
| 78 RequestVSync(); | |
| 79 } | |
| 80 } | |
| 81 | |
| 69 VRController* VRDisplay::Controller() { | 82 VRController* VRDisplay::Controller() { |
| 70 return navigator_vr_->Controller(); | 83 return navigator_vr_->Controller(); |
| 71 } | 84 } |
| 72 | 85 |
| 73 void VRDisplay::Update(const device::mojom::blink::VRDisplayInfoPtr& display) { | 86 void VRDisplay::Update(const device::mojom::blink::VRDisplayInfoPtr& display) { |
| 74 display_id_ = display->index; | 87 display_id_ = display->index; |
| 75 display_name_ = display->displayName; | 88 display_name_ = display->displayName; |
| 76 is_connected_ = true; | 89 is_connected_ = true; |
| 77 | 90 |
| 78 capabilities_->SetHasPosition(display->capabilities->hasPosition); | 91 capabilities_->SetHasPosition(display->capabilities->hasPosition); |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 DVLOG(2) << __FUNCTION__; | 807 DVLOG(2) << __FUNCTION__; |
| 795 // Check if we still have a valid context, the animation controller | 808 // Check if we still have a valid context, the animation controller |
| 796 // or document may have disappeared since we scheduled this. | 809 // or document may have disappeared since we scheduled this. |
| 797 Document* doc = this->GetDocument(); | 810 Document* doc = this->GetDocument(); |
| 798 if (!doc || display_blurred_) { | 811 if (!doc || display_blurred_) { |
| 799 DVLOG(2) << __FUNCTION__ << ": early exit, doc=" << doc | 812 DVLOG(2) << __FUNCTION__ << ": early exit, doc=" << doc |
| 800 << " display_blurred_=" << display_blurred_; | 813 << " display_blurred_=" << display_blurred_; |
| 801 return; | 814 return; |
| 802 } | 815 } |
| 803 | 816 |
| 817 if (suspended_) { | |
| 818 // We are currently suspended - try ProcessScheduledAnimations again later | |
| 819 // when we resume. | |
| 820 request_vsync_on_resume_ = true; | |
| 821 return; | |
| 822 } | |
| 823 | |
| 804 TRACE_EVENT1("gpu", "VRDisplay::OnVSync", "frame", vr_frame_id_); | 824 TRACE_EVENT1("gpu", "VRDisplay::OnVSync", "frame", vr_frame_id_); |
| 805 | 825 |
| 806 if (pending_vrdisplay_raf_ && scripted_animation_controller_) { | 826 if (pending_vrdisplay_raf_ && scripted_animation_controller_) { |
| 807 // Run the callback, making sure that in_animation_frame_ is only | 827 // Run the callback, making sure that in_animation_frame_ is only |
| 808 // true for the vrDisplay rAF and not for a legacy window rAF | 828 // true for the vrDisplay rAF and not for a legacy window rAF |
| 809 // that may be called later. | 829 // that may be called later. |
| 810 AutoReset<bool> animating(&in_animation_frame_, true); | 830 AutoReset<bool> animating(&in_animation_frame_, true); |
| 811 pending_vrdisplay_raf_ = false; | 831 pending_vrdisplay_raf_ = false; |
| 812 did_submit_this_frame_ = false; | 832 did_submit_this_frame_ = false; |
| 813 scripted_animation_controller_->ServiceScriptedAnimations(timestamp); | 833 scripted_animation_controller_->ServiceScriptedAnimations(timestamp); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 903 } | 923 } |
| 904 | 924 |
| 905 ExecutionContext* VRDisplay::GetExecutionContext() const { | 925 ExecutionContext* VRDisplay::GetExecutionContext() const { |
| 906 return ContextLifecycleObserver::GetExecutionContext(); | 926 return ContextLifecycleObserver::GetExecutionContext(); |
| 907 } | 927 } |
| 908 | 928 |
| 909 const AtomicString& VRDisplay::InterfaceName() const { | 929 const AtomicString& VRDisplay::InterfaceName() const { |
| 910 return EventTargetNames::VRDisplay; | 930 return EventTargetNames::VRDisplay; |
| 911 } | 931 } |
| 912 | 932 |
| 913 void VRDisplay::ContextDestroyed(ExecutionContext*) { | 933 void VRDisplay::ContextDestroyed(ExecutionContext* context) { |
| 934 SuspendableObject::ContextDestroyed(context); | |
| 914 ForceExitPresent(); | 935 ForceExitPresent(); |
| 915 scripted_animation_controller_.Clear(); | 936 scripted_animation_controller_.Clear(); |
| 916 } | 937 } |
| 917 | 938 |
| 918 bool VRDisplay::HasPendingActivity() const { | 939 bool VRDisplay::HasPendingActivity() const { |
| 919 // Prevent V8 from garbage collecting the wrapper object if there are | 940 // Prevent V8 from garbage collecting the wrapper object if there are |
| 920 // event listeners attached to it. | 941 // event listeners attached to it. |
| 921 return GetExecutionContext() && HasEventListeners(); | 942 return GetExecutionContext() && HasEventListeners(); |
| 922 } | 943 } |
| 923 | 944 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 942 visitor->Trace(stage_parameters_); | 963 visitor->Trace(stage_parameters_); |
| 943 visitor->Trace(eye_parameters_left_); | 964 visitor->Trace(eye_parameters_left_); |
| 944 visitor->Trace(eye_parameters_right_); | 965 visitor->Trace(eye_parameters_right_); |
| 945 visitor->Trace(layer_); | 966 visitor->Trace(layer_); |
| 946 visitor->Trace(rendering_context_); | 967 visitor->Trace(rendering_context_); |
| 947 visitor->Trace(scripted_animation_controller_); | 968 visitor->Trace(scripted_animation_controller_); |
| 948 visitor->Trace(pending_present_resolvers_); | 969 visitor->Trace(pending_present_resolvers_); |
| 949 } | 970 } |
| 950 | 971 |
| 951 } // namespace blink | 972 } // namespace blink |
| OLD | NEW |