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" |
11 #include "core/dom/TaskRunnerHelper.h" | 11 #include "core/dom/TaskRunnerHelper.h" |
| 12 #include "core/frame/Frame.h" |
12 #include "core/frame/FrameView.h" | 13 #include "core/frame/FrameView.h" |
13 #include "core/frame/ImageBitmap.h" | 14 #include "core/frame/ImageBitmap.h" |
14 #include "core/frame/UseCounter.h" | 15 #include "core/frame/UseCounter.h" |
15 #include "core/inspector/ConsoleMessage.h" | 16 #include "core/inspector/ConsoleMessage.h" |
16 #include "core/layout/LayoutView.h" | 17 #include "core/layout/LayoutView.h" |
17 #include "core/layout/compositing/PaintLayerCompositor.h" | 18 #include "core/layout/compositing/PaintLayerCompositor.h" |
18 #include "core/loader/DocumentLoader.h" | 19 #include "core/loader/DocumentLoader.h" |
| 20 #include "core/page/FocusController.h" |
19 #include "gpu/command_buffer/client/gles2_interface.h" | 21 #include "gpu/command_buffer/client/gles2_interface.h" |
20 #include "gpu/command_buffer/common/mailbox_holder.h" | 22 #include "gpu/command_buffer/common/mailbox_holder.h" |
21 #include "modules/EventTargetModules.h" | 23 #include "modules/EventTargetModules.h" |
22 #include "modules/vr/NavigatorVR.h" | 24 #include "modules/vr/NavigatorVR.h" |
23 #include "modules/vr/VRController.h" | 25 #include "modules/vr/VRController.h" |
24 #include "modules/vr/VRDisplayCapabilities.h" | 26 #include "modules/vr/VRDisplayCapabilities.h" |
25 #include "modules/vr/VREyeParameters.h" | 27 #include "modules/vr/VREyeParameters.h" |
26 #include "modules/vr/VRFrameData.h" | 28 #include "modules/vr/VRFrameData.h" |
27 #include "modules/vr/VRLayer.h" | 29 #include "modules/vr/VRLayer.h" |
28 #include "modules/vr/VRPose.h" | 30 #include "modules/vr/VRPose.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 stage_parameters_->Update(display->stageParameters); | 99 stage_parameters_->Update(display->stageParameters); |
98 } else { | 100 } else { |
99 stage_parameters_ = nullptr; | 101 stage_parameters_ = nullptr; |
100 } | 102 } |
101 | 103 |
102 if (need_on_present_change) { | 104 if (need_on_present_change) { |
103 OnPresentChange(); | 105 OnPresentChange(); |
104 } | 106 } |
105 } | 107 } |
106 | 108 |
| 109 bool VRDisplay::IsPresentationFocused() { |
| 110 if (!navigator_vr_) |
| 111 return false; |
| 112 |
| 113 if (navigator_vr_->IsFocused()) |
| 114 return true; |
| 115 |
| 116 auto doc = navigator_vr_->GetDocument(); |
| 117 if (!doc) |
| 118 return false; |
| 119 |
| 120 // Check if this is an embedded iframe without focus. If a local parent is |
| 121 // focused, continue presenting. |
| 122 |
| 123 Frame* frame = doc->GetFrame(); |
| 124 for (; frame; frame = frame->Tree().Parent()) { |
| 125 if (!frame->IsLocalFrame()) |
| 126 break; |
| 127 auto frame_doc = ToLocalFrame(frame)->GetDocument(); |
| 128 if (frame_doc && frame_doc->hasFocus()) { |
| 129 DVLOG(3) << __FUNCTION__ << ": a parent frame is focused"; |
| 130 return true; |
| 131 } |
| 132 } |
| 133 |
| 134 return false; |
| 135 } |
| 136 |
107 bool VRDisplay::getFrameData(VRFrameData* frame_data) { | 137 bool VRDisplay::getFrameData(VRFrameData* frame_data) { |
108 if (!navigator_vr_->IsFocused() || !frame_pose_ || display_blurred_) | 138 if (!IsPresentationFocused() || !frame_pose_ || display_blurred_) |
109 return false; | 139 return false; |
110 | 140 |
111 if (!frame_data) | 141 if (!frame_data) |
112 return false; | 142 return false; |
113 | 143 |
114 if (depth_near_ == depth_far_) | 144 if (depth_near_ == depth_far_) |
115 return false; | 145 return false; |
116 | 146 |
117 return frame_data->Update(frame_pose_, eye_parameters_left_, | 147 return frame_data->Update(frame_pose_, eye_parameters_left_, |
118 eye_parameters_right_, depth_near_, depth_far_); | 148 eye_parameters_right_, depth_near_, depth_far_); |
119 } | 149 } |
120 | 150 |
121 VREyeParameters* VRDisplay::getEyeParameters(const String& which_eye) { | 151 VREyeParameters* VRDisplay::getEyeParameters(const String& which_eye) { |
122 switch (StringToVREye(which_eye)) { | 152 switch (StringToVREye(which_eye)) { |
123 case kVREyeLeft: | 153 case kVREyeLeft: |
124 return eye_parameters_left_; | 154 return eye_parameters_left_; |
125 case kVREyeRight: | 155 case kVREyeRight: |
126 return eye_parameters_right_; | 156 return eye_parameters_right_; |
127 default: | 157 default: |
128 return nullptr; | 158 return nullptr; |
129 } | 159 } |
130 } | 160 } |
131 | 161 |
132 int VRDisplay::requestAnimationFrame(FrameRequestCallback* callback) { | 162 int VRDisplay::requestAnimationFrame(FrameRequestCallback* callback) { |
| 163 DVLOG(2) << __FUNCTION__; |
133 Document* doc = this->GetDocument(); | 164 Document* doc = this->GetDocument(); |
134 if (!doc) | 165 if (!doc) |
135 return 0; | 166 return 0; |
136 pending_raf_ = true; | 167 pending_vrdisplay_raf_ = true; |
137 if (!vr_v_sync_provider_.is_bound()) { | 168 if (!vr_v_sync_provider_.is_bound()) { |
138 ConnectVSyncProvider(); | 169 ConnectVSyncProvider(); |
139 } else if (!display_blurred_ && !pending_vsync_) { | 170 } else if (!display_blurred_ && !pending_vsync_) { |
140 pending_vsync_ = true; | 171 pending_vsync_ = true; |
141 vr_v_sync_provider_->GetVSync(ConvertToBaseCallback( | 172 vr_v_sync_provider_->GetVSync(ConvertToBaseCallback( |
142 WTF::Bind(&VRDisplay::OnVSync, WrapWeakPersistent(this)))); | 173 WTF::Bind(&VRDisplay::OnVSync, WrapWeakPersistent(this)))); |
143 } | 174 } |
144 callback->use_legacy_time_base_ = false; | 175 callback->use_legacy_time_base_ = false; |
145 return EnsureScriptedAnimationController(doc).RegisterCallback(callback); | 176 return EnsureScriptedAnimationController(doc).RegisterCallback(callback); |
146 } | 177 } |
147 | 178 |
148 void VRDisplay::cancelAnimationFrame(int id) { | 179 void VRDisplay::cancelAnimationFrame(int id) { |
| 180 DVLOG(2) << __FUNCTION__; |
149 if (!scripted_animation_controller_) | 181 if (!scripted_animation_controller_) |
150 return; | 182 return; |
151 scripted_animation_controller_->CancelCallback(id); | 183 scripted_animation_controller_->CancelCallback(id); |
152 } | 184 } |
153 | 185 |
154 void VRDisplay::OnBlur() { | 186 void VRDisplay::OnBlur() { |
| 187 DVLOG(1) << __FUNCTION__; |
155 display_blurred_ = true; | 188 display_blurred_ = true; |
156 vr_v_sync_provider_.reset(); | 189 vr_v_sync_provider_.reset(); |
157 navigator_vr_->EnqueueVREvent(VRDisplayEvent::Create( | 190 navigator_vr_->EnqueueVREvent(VRDisplayEvent::Create( |
158 EventTypeNames::vrdisplayblur, true, false, this, "")); | 191 EventTypeNames::vrdisplayblur, true, false, this, "")); |
159 } | 192 } |
160 | 193 |
161 void VRDisplay::OnFocus() { | 194 void VRDisplay::OnFocus() { |
| 195 DVLOG(1) << __FUNCTION__; |
162 display_blurred_ = false; | 196 display_blurred_ = false; |
163 ConnectVSyncProvider(); | 197 ConnectVSyncProvider(); |
164 navigator_vr_->EnqueueVREvent(VRDisplayEvent::Create( | 198 navigator_vr_->EnqueueVREvent(VRDisplayEvent::Create( |
165 EventTypeNames::vrdisplayfocus, true, false, this, "")); | 199 EventTypeNames::vrdisplayfocus, true, false, this, "")); |
166 } | 200 } |
167 | 201 |
168 void ReportPresentationResult(PresentationResult result) { | 202 void ReportPresentationResult(PresentationResult result) { |
169 // Note that this is called twice for each call to requestPresent - | 203 // Note that this is called twice for each call to requestPresent - |
170 // one to declare that requestPresent was called, and one for the | 204 // one to declare that requestPresent was called, and one for the |
171 // result. | 205 // result. |
172 DEFINE_STATIC_LOCAL( | 206 DEFINE_STATIC_LOCAL( |
173 EnumerationHistogram, vr_presentation_result_histogram, | 207 EnumerationHistogram, vr_presentation_result_histogram, |
174 ("VRDisplayPresentResult", | 208 ("VRDisplayPresentResult", |
175 static_cast<int>(PresentationResult::kPresentationResultMax))); | 209 static_cast<int>(PresentationResult::kPresentationResultMax))); |
176 vr_presentation_result_histogram.Count(static_cast<int>(result)); | 210 vr_presentation_result_histogram.Count(static_cast<int>(result)); |
177 } | 211 } |
178 | 212 |
179 ScriptPromise VRDisplay::requestPresent(ScriptState* script_state, | 213 ScriptPromise VRDisplay::requestPresent(ScriptState* script_state, |
180 const HeapVector<VRLayer>& layers) { | 214 const HeapVector<VRLayer>& layers) { |
| 215 DVLOG(1) << __FUNCTION__; |
181 ExecutionContext* execution_context = ExecutionContext::From(script_state); | 216 ExecutionContext* execution_context = ExecutionContext::From(script_state); |
182 UseCounter::Count(execution_context, UseCounter::kVRRequestPresent); | 217 UseCounter::Count(execution_context, UseCounter::kVRRequestPresent); |
183 if (!execution_context->IsSecureContext()) { | 218 if (!execution_context->IsSecureContext()) { |
184 UseCounter::Count(execution_context, | 219 UseCounter::Count(execution_context, |
185 UseCounter::kVRRequestPresentInsecureOrigin); | 220 UseCounter::kVRRequestPresentInsecureOrigin); |
186 } | 221 } |
187 | 222 |
188 ReportPresentationResult(PresentationResult::kRequested); | 223 ReportPresentationResult(PresentationResult::kRequested); |
189 | 224 |
190 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 225 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 kNotAllowedError, "Presentation request was denied."); | 348 kNotAllowedError, "Presentation request was denied."); |
314 | 349 |
315 while (!pending_present_resolvers_.IsEmpty()) { | 350 while (!pending_present_resolvers_.IsEmpty()) { |
316 ScriptPromiseResolver* resolver = pending_present_resolvers_.TakeFirst(); | 351 ScriptPromiseResolver* resolver = pending_present_resolvers_.TakeFirst(); |
317 resolver->Reject(exception); | 352 resolver->Reject(exception); |
318 } | 353 } |
319 } | 354 } |
320 } | 355 } |
321 | 356 |
322 ScriptPromise VRDisplay::exitPresent(ScriptState* script_state) { | 357 ScriptPromise VRDisplay::exitPresent(ScriptState* script_state) { |
| 358 DVLOG(1) << __FUNCTION__; |
323 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 359 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
324 ScriptPromise promise = resolver->Promise(); | 360 ScriptPromise promise = resolver->Promise(); |
325 | 361 |
326 if (!is_presenting_) { | 362 if (!is_presenting_) { |
327 // Can't stop presenting if we're not presenting. | 363 // Can't stop presenting if we're not presenting. |
328 DOMException* exception = DOMException::Create( | 364 DOMException* exception = DOMException::Create( |
329 kInvalidStateError, "VRDisplay is not presenting."); | 365 kInvalidStateError, "VRDisplay is not presenting."); |
330 resolver->Reject(exception); | 366 resolver->Reject(exception); |
331 return promise; | 367 return promise; |
332 } | 368 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 is_presenting_ = true; | 426 is_presenting_ = true; |
391 ReportPresentationResult(PresentationResult::kSuccess); | 427 ReportPresentationResult(PresentationResult::kSuccess); |
392 | 428 |
393 UpdateLayerBounds(); | 429 UpdateLayerBounds(); |
394 | 430 |
395 while (!pending_present_resolvers_.IsEmpty()) { | 431 while (!pending_present_resolvers_.IsEmpty()) { |
396 ScriptPromiseResolver* resolver = pending_present_resolvers_.TakeFirst(); | 432 ScriptPromiseResolver* resolver = pending_present_resolvers_.TakeFirst(); |
397 resolver->Resolve(); | 433 resolver->Resolve(); |
398 } | 434 } |
399 OnPresentChange(); | 435 OnPresentChange(); |
| 436 |
| 437 // TODO(klausw,crbug.com/710863): there appear to be cases where an embedded |
| 438 // iframe has started presenting but isn't focused. To fix this, would need |
| 439 // to switch focus here. |
| 440 |
| 441 // Ensure that we get at least one vsync. It's possible that a page may |
| 442 // have started presentation but not used vrDisplay.rAF yet, i.e. if it |
| 443 // uses window.rAF while not yet presenting. It needs to get a chance |
| 444 // to run its animation loop to avoid getting stuck, and to do so we |
| 445 // need a vsync where we can run pending window.rAF callbacks. |
| 446 if (!vr_v_sync_provider_.is_bound()) { |
| 447 ConnectVSyncProvider(); |
| 448 } else if (!display_blurred_ && !pending_vsync_) { |
| 449 pending_vsync_ = true; |
| 450 vr_v_sync_provider_->GetVSync(ConvertToBaseCallback( |
| 451 WTF::Bind(&VRDisplay::OnVSync, WrapWeakPersistent(this)))); |
| 452 } |
| 453 if (!pending_vsync_) { |
| 454 if (doc) { |
| 455 doc->AddConsoleMessage( |
| 456 ConsoleMessage::Create(kRenderingMessageSource, kWarningMessageLevel, |
| 457 "Scheduling missing vsync.")); |
| 458 } |
| 459 if (vr_v_sync_provider_.is_bound()) { |
| 460 pending_vsync_ = true; |
| 461 vr_v_sync_provider_->GetVSync(ConvertToBaseCallback( |
| 462 WTF::Bind(&VRDisplay::OnVSync, WrapWeakPersistent(this)))); |
| 463 } else { |
| 464 if (doc) { |
| 465 doc->AddConsoleMessage(ConsoleMessage::Create( |
| 466 kRenderingMessageSource, kWarningMessageLevel, |
| 467 "Failed to schedule missing vsync. Not focused?")); |
| 468 } |
| 469 } |
| 470 } |
400 } | 471 } |
401 | 472 |
402 // Need to close service if exists and then free rendering context. | 473 // Need to close service if exists and then free rendering context. |
403 void VRDisplay::ForceExitPresent() { | 474 void VRDisplay::ForceExitPresent() { |
404 if (display_) { | 475 if (display_) { |
405 display_->ExitPresent(); | 476 display_->ExitPresent(); |
406 } | 477 } |
407 StopPresenting(); | 478 StopPresenting(); |
408 } | 479 } |
409 | 480 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 677 |
607 void VRDisplay::OnSubmitFrameRendered() { | 678 void VRDisplay::OnSubmitFrameRendered() { |
608 pending_previous_frame_render_ = false; | 679 pending_previous_frame_render_ = false; |
609 } | 680 } |
610 | 681 |
611 Document* VRDisplay::GetDocument() { | 682 Document* VRDisplay::GetDocument() { |
612 return navigator_vr_->GetDocument(); | 683 return navigator_vr_->GetDocument(); |
613 } | 684 } |
614 | 685 |
615 void VRDisplay::OnPresentChange() { | 686 void VRDisplay::OnPresentChange() { |
| 687 DVLOG(1) << __FUNCTION__ << ": is_presenting_=" << is_presenting_; |
616 if (is_presenting_ && !is_valid_device_for_presenting_) { | 688 if (is_presenting_ && !is_valid_device_for_presenting_) { |
617 DVLOG(1) << __FUNCTION__ << ": device not valid, not sending event"; | 689 DVLOG(1) << __FUNCTION__ << ": device not valid, not sending event"; |
618 return; | 690 return; |
619 } | 691 } |
620 navigator_vr_->EnqueueVREvent(VRDisplayEvent::Create( | 692 navigator_vr_->EnqueueVREvent(VRDisplayEvent::Create( |
621 EventTypeNames::vrdisplaypresentchange, true, false, this, "")); | 693 EventTypeNames::vrdisplaypresentchange, true, false, this, "")); |
622 } | 694 } |
623 | 695 |
624 void VRDisplay::OnChanged(device::mojom::blink::VRDisplayInfoPtr display) { | 696 void VRDisplay::OnChanged(device::mojom::blink::VRDisplayInfoPtr display) { |
625 Update(display); | 697 Update(display); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 } | 746 } |
675 | 747 |
676 void VRDisplay::ProcessScheduledWindowAnimations(double timestamp) { | 748 void VRDisplay::ProcessScheduledWindowAnimations(double timestamp) { |
677 TRACE_EVENT1("gpu", "VRDisplay::window.rAF", "frame", vr_frame_id_); | 749 TRACE_EVENT1("gpu", "VRDisplay::window.rAF", "frame", vr_frame_id_); |
678 auto doc = navigator_vr_->GetDocument(); | 750 auto doc = navigator_vr_->GetDocument(); |
679 if (!doc) | 751 if (!doc) |
680 return; | 752 return; |
681 auto page = doc->GetPage(); | 753 auto page = doc->GetPage(); |
682 if (!page) | 754 if (!page) |
683 return; | 755 return; |
| 756 |
| 757 bool had_pending_vrdisplay_raf = pending_vrdisplay_raf_; |
684 // TODO(klausw): update timestamp based on scheduling delay? | 758 // TODO(klausw): update timestamp based on scheduling delay? |
685 page->Animator().ServiceScriptedAnimations(timestamp); | 759 page->Animator().ServiceScriptedAnimations(timestamp); |
| 760 |
| 761 if (had_pending_vrdisplay_raf != pending_vrdisplay_raf_) { |
| 762 LOG(INFO) << __FUNCTION__ << ": rAF fallback saved us! FIXME FIXME"; |
| 763 } |
| 764 |
| 765 if (!pending_vrdisplay_raf_) { |
| 766 // There wasn't any call to vrDisplay.rAF, so we won't be getting new |
| 767 // frames from now on. TODO(klausw,crbug.com/716087): do something more |
| 768 // useful here. |
| 769 doc->AddConsoleMessage(ConsoleMessage::Create( |
| 770 kRenderingMessageSource, kWarningMessageLevel, |
| 771 "VRDisplay.requestAnimationFrame not called, presentation is broken.")); |
| 772 } |
686 } | 773 } |
687 | 774 |
688 void VRDisplay::ProcessScheduledAnimations(double timestamp) { | 775 void VRDisplay::ProcessScheduledAnimations(double timestamp) { |
| 776 DVLOG(2) << __FUNCTION__; |
689 // Check if we still have a valid context, the animation controller | 777 // Check if we still have a valid context, the animation controller |
690 // or document may have disappeared since we scheduled this. | 778 // or document may have disappeared since we scheduled this. |
691 Document* doc = this->GetDocument(); | 779 Document* doc = this->GetDocument(); |
692 if (!doc || display_blurred_ || !scripted_animation_controller_) | 780 if (!doc || display_blurred_) { |
| 781 DVLOG(2) << __FUNCTION__ << ": early exit, doc=" << doc |
| 782 << " display_blurred_=" << display_blurred_; |
693 return; | 783 return; |
| 784 } |
694 | 785 |
695 TRACE_EVENT1("gpu", "VRDisplay::OnVSync", "frame", vr_frame_id_); | 786 TRACE_EVENT1("gpu", "VRDisplay::OnVSync", "frame", vr_frame_id_); |
696 | 787 |
697 AutoReset<bool> animating(&in_animation_frame_, true); | 788 if (pending_vrdisplay_raf_ && scripted_animation_controller_) { |
698 pending_raf_ = false; | 789 // Run the callback, making sure that in_animation_frame_ is only |
699 | 790 // true for the vrDisplay rAF and not for a legacy window rAF |
700 scripted_animation_controller_->ServiceScriptedAnimations(timestamp); | 791 // that may be called later. |
| 792 AutoReset<bool> animating(&in_animation_frame_, true); |
| 793 pending_vrdisplay_raf_ = false; |
| 794 scripted_animation_controller_->ServiceScriptedAnimations(timestamp); |
| 795 } |
701 | 796 |
702 // For GVR, we shut down normal vsync processing during VR presentation. | 797 // For GVR, we shut down normal vsync processing during VR presentation. |
703 // Trigger any callbacks on window.rAF manually so that they run after | 798 // Trigger any callbacks on window.rAF manually so that they run after |
704 // completing the vrDisplay.rAF processing. | 799 // completing the vrDisplay.rAF processing. |
705 if (is_presenting_ && !capabilities_->hasExternalDisplay()) { | 800 if (is_presenting_ && !capabilities_->hasExternalDisplay()) { |
706 Platform::Current()->CurrentThread()->GetWebTaskRunner()->PostTask( | 801 Platform::Current()->CurrentThread()->GetWebTaskRunner()->PostTask( |
707 BLINK_FROM_HERE, WTF::Bind(&VRDisplay::ProcessScheduledWindowAnimations, | 802 BLINK_FROM_HERE, WTF::Bind(&VRDisplay::ProcessScheduledWindowAnimations, |
708 WrapWeakPersistent(this), timestamp)); | 803 WrapWeakPersistent(this), timestamp)); |
709 } | 804 } |
710 } | 805 } |
711 | 806 |
712 void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, | 807 void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, |
713 mojo::common::mojom::blink::TimeDeltaPtr time, | 808 mojo::common::mojom::blink::TimeDeltaPtr time, |
714 int16_t frame_id, | 809 int16_t frame_id, |
715 device::mojom::blink::VRVSyncProvider::Status error) { | 810 device::mojom::blink::VRVSyncProvider::Status error) { |
| 811 DVLOG(2) << __FUNCTION__; |
716 v_sync_connection_failed_ = false; | 812 v_sync_connection_failed_ = false; |
717 switch (error) { | 813 switch (error) { |
718 case device::mojom::blink::VRVSyncProvider::Status::SUCCESS: | 814 case device::mojom::blink::VRVSyncProvider::Status::SUCCESS: |
719 break; | 815 break; |
720 case device::mojom::blink::VRVSyncProvider::Status::CLOSING: | 816 case device::mojom::blink::VRVSyncProvider::Status::CLOSING: |
721 return; | 817 return; |
722 } | 818 } |
723 pending_vsync_ = false; | 819 pending_vsync_ = false; |
724 | 820 |
725 WTF::TimeDelta time_delta = | 821 WTF::TimeDelta time_delta = |
(...skipping 14 matching lines...) Expand all Loading... |
740 // this is due to WaitForIncomingMethodCall receiving the OnVSync | 836 // this is due to WaitForIncomingMethodCall receiving the OnVSync |
741 // but queueing it for immediate execution since it doesn't match | 837 // but queueing it for immediate execution since it doesn't match |
742 // the interface being waited on. | 838 // the interface being waited on. |
743 Platform::Current()->CurrentThread()->GetWebTaskRunner()->PostTask( | 839 Platform::Current()->CurrentThread()->GetWebTaskRunner()->PostTask( |
744 BLINK_FROM_HERE, | 840 BLINK_FROM_HERE, |
745 WTF::Bind(&VRDisplay::ProcessScheduledAnimations, | 841 WTF::Bind(&VRDisplay::ProcessScheduledAnimations, |
746 WrapWeakPersistent(this), timebase_ + time_delta.InSecondsF())); | 842 WrapWeakPersistent(this), timebase_ + time_delta.InSecondsF())); |
747 } | 843 } |
748 | 844 |
749 void VRDisplay::ConnectVSyncProvider() { | 845 void VRDisplay::ConnectVSyncProvider() { |
750 if (!navigator_vr_->IsFocused() || vr_v_sync_provider_.is_bound()) | 846 DVLOG(1) << __FUNCTION__ |
| 847 << ": IsPresentationFocused()=" << IsPresentationFocused() |
| 848 << " vr_v_sync_provider_.is_bound()=" |
| 849 << vr_v_sync_provider_.is_bound(); |
| 850 if (!IsPresentationFocused() || vr_v_sync_provider_.is_bound()) |
751 return; | 851 return; |
752 display_->GetVRVSyncProvider(mojo::MakeRequest(&vr_v_sync_provider_)); | 852 display_->GetVRVSyncProvider(mojo::MakeRequest(&vr_v_sync_provider_)); |
753 vr_v_sync_provider_.set_connection_error_handler(ConvertToBaseCallback( | 853 vr_v_sync_provider_.set_connection_error_handler(ConvertToBaseCallback( |
754 WTF::Bind(&VRDisplay::OnVSyncConnectionError, WrapWeakPersistent(this)))); | 854 WTF::Bind(&VRDisplay::OnVSyncConnectionError, WrapWeakPersistent(this)))); |
755 if (pending_raf_ && !display_blurred_) { | 855 if (pending_vrdisplay_raf_ && !display_blurred_) { |
756 pending_vsync_ = true; | 856 pending_vsync_ = true; |
757 vr_v_sync_provider_->GetVSync(ConvertToBaseCallback( | 857 vr_v_sync_provider_->GetVSync(ConvertToBaseCallback( |
758 WTF::Bind(&VRDisplay::OnVSync, WrapWeakPersistent(this)))); | 858 WTF::Bind(&VRDisplay::OnVSync, WrapWeakPersistent(this)))); |
759 } | 859 } |
760 } | 860 } |
761 | 861 |
762 void VRDisplay::OnVSyncConnectionError() { | 862 void VRDisplay::OnVSyncConnectionError() { |
763 vr_v_sync_provider_.reset(); | 863 vr_v_sync_provider_.reset(); |
764 if (v_sync_connection_failed_) | 864 if (v_sync_connection_failed_) |
765 return; | 865 return; |
(...skipping 28 matching lines...) Expand all Loading... |
794 } | 894 } |
795 | 895 |
796 bool VRDisplay::HasPendingActivity() const { | 896 bool VRDisplay::HasPendingActivity() const { |
797 // Prevent V8 from garbage collecting the wrapper object if there are | 897 // Prevent V8 from garbage collecting the wrapper object if there are |
798 // event listeners attached to it. | 898 // event listeners attached to it. |
799 return GetExecutionContext() && HasEventListeners(); | 899 return GetExecutionContext() && HasEventListeners(); |
800 } | 900 } |
801 | 901 |
802 void VRDisplay::FocusChanged() { | 902 void VRDisplay::FocusChanged() { |
803 // TODO(mthiesse): Blur/focus the display. | 903 // TODO(mthiesse): Blur/focus the display. |
| 904 DVLOG(1) << __FUNCTION__; |
804 vr_v_sync_provider_.reset(); | 905 vr_v_sync_provider_.reset(); |
805 ConnectVSyncProvider(); | 906 ConnectVSyncProvider(); |
806 } | 907 } |
807 | 908 |
808 DEFINE_TRACE(VRDisplay) { | 909 DEFINE_TRACE(VRDisplay) { |
809 EventTargetWithInlineData::Trace(visitor); | 910 EventTargetWithInlineData::Trace(visitor); |
810 ContextLifecycleObserver::Trace(visitor); | 911 ContextLifecycleObserver::Trace(visitor); |
811 visitor->Trace(navigator_vr_); | 912 visitor->Trace(navigator_vr_); |
812 visitor->Trace(capabilities_); | 913 visitor->Trace(capabilities_); |
813 visitor->Trace(stage_parameters_); | 914 visitor->Trace(stage_parameters_); |
814 visitor->Trace(eye_parameters_left_); | 915 visitor->Trace(eye_parameters_left_); |
815 visitor->Trace(eye_parameters_right_); | 916 visitor->Trace(eye_parameters_right_); |
816 visitor->Trace(layer_); | 917 visitor->Trace(layer_); |
817 visitor->Trace(rendering_context_); | 918 visitor->Trace(rendering_context_); |
818 visitor->Trace(scripted_animation_controller_); | 919 visitor->Trace(scripted_animation_controller_); |
819 visitor->Trace(pending_present_resolvers_); | 920 visitor->Trace(pending_present_resolvers_); |
820 } | 921 } |
821 | 922 |
822 } // namespace blink | 923 } // namespace blink |
OLD | NEW |