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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 } else { | 98 } else { |
99 stage_parameters_ = nullptr; | 99 stage_parameters_ = nullptr; |
100 } | 100 } |
101 | 101 |
102 if (need_on_present_change) { | 102 if (need_on_present_change) { |
103 OnPresentChange(); | 103 OnPresentChange(); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 bool VRDisplay::getFrameData(VRFrameData* frame_data) { | 107 bool VRDisplay::getFrameData(VRFrameData* frame_data) { |
108 if (!navigator_vr_->IsFocused() || !frame_pose_ || display_blurred_) | 108 if (!FocusedOrPresenting() || !frame_pose_ || display_blurred_) |
109 return false; | 109 return false; |
110 | 110 |
111 if (!frame_data) | 111 if (!frame_data) |
112 return false; | 112 return false; |
113 | 113 |
114 if (depth_near_ == depth_far_) | 114 if (depth_near_ == depth_far_) |
115 return false; | 115 return false; |
116 | 116 |
117 return frame_data->Update(frame_pose_, eye_parameters_left_, | 117 return frame_data->Update(frame_pose_, eye_parameters_left_, |
118 eye_parameters_right_, depth_near_, depth_far_); | 118 eye_parameters_right_, depth_near_, depth_far_); |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 } | 552 } |
553 } | 553 } |
554 | 554 |
555 RefPtr<Image> image_ref = rendering_context_->GetImage( | 555 RefPtr<Image> image_ref = rendering_context_->GetImage( |
556 kPreferAcceleration, kSnapshotReasonCreateImageBitmap); | 556 kPreferAcceleration, kSnapshotReasonCreateImageBitmap); |
557 | 557 |
558 // Hardware-accelerated rendering should always be texture backed, | 558 // Hardware-accelerated rendering should always be texture backed, |
559 // as implemented by AcceleratedStaticBitmapImage. Ensure this is | 559 // as implemented by AcceleratedStaticBitmapImage. Ensure this is |
560 // the case, don't attempt to render if using an unexpected drawing | 560 // the case, don't attempt to render if using an unexpected drawing |
561 // path. | 561 // path. |
562 if (!image_ref->IsTextureBacked()) { | 562 if (!image_ref.Get() || !image_ref->IsTextureBacked()) { |
klausw
2017/05/03 16:20:42
Is this out of paranoia, or have you run into case
mthiesse
2017/05/04 17:29:01
I was running into this occasionally when using th
| |
563 NOTREACHED() << "WebVR requires hardware-accelerated rendering to texture"; | 563 NOTREACHED() << "WebVR requires hardware-accelerated rendering to texture"; |
564 return; | 564 return; |
565 } | 565 } |
566 | 566 |
567 // The AcceleratedStaticBitmapImage must be kept alive until the | 567 // The AcceleratedStaticBitmapImage must be kept alive until the |
568 // mailbox is used via createAndConsumeTextureCHROMIUM, the mailbox | 568 // mailbox is used via createAndConsumeTextureCHROMIUM, the mailbox |
569 // itself does not keep it alive. We must keep a reference to the | 569 // itself does not keep it alive. We must keep a reference to the |
570 // image until the mailbox was consumed. | 570 // image until the mailbox was consumed. |
571 StaticBitmapImage* static_image = | 571 StaticBitmapImage* static_image = |
572 static_cast<StaticBitmapImage*>(image_ref.Get()); | 572 static_cast<StaticBitmapImage*>(image_ref.Get()); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 // this is due to WaitForIncomingMethodCall receiving the OnVSync | 787 // this is due to WaitForIncomingMethodCall receiving the OnVSync |
788 // but queueing it for immediate execution since it doesn't match | 788 // but queueing it for immediate execution since it doesn't match |
789 // the interface being waited on. | 789 // the interface being waited on. |
790 Platform::Current()->CurrentThread()->GetWebTaskRunner()->PostTask( | 790 Platform::Current()->CurrentThread()->GetWebTaskRunner()->PostTask( |
791 BLINK_FROM_HERE, | 791 BLINK_FROM_HERE, |
792 WTF::Bind(&VRDisplay::ProcessScheduledAnimations, | 792 WTF::Bind(&VRDisplay::ProcessScheduledAnimations, |
793 WrapWeakPersistent(this), timebase_ + time_delta.InSecondsF())); | 793 WrapWeakPersistent(this), timebase_ + time_delta.InSecondsF())); |
794 } | 794 } |
795 | 795 |
796 void VRDisplay::ConnectVSyncProvider() { | 796 void VRDisplay::ConnectVSyncProvider() { |
797 if (!navigator_vr_->IsFocused() || vr_v_sync_provider_.is_bound()) | 797 if (!FocusedOrPresenting() || vr_v_sync_provider_.is_bound()) |
798 return; | 798 return; |
799 display_->GetVRVSyncProvider(mojo::MakeRequest(&vr_v_sync_provider_)); | 799 display_->GetVRVSyncProvider(mojo::MakeRequest(&vr_v_sync_provider_)); |
800 vr_v_sync_provider_.set_connection_error_handler(ConvertToBaseCallback( | 800 vr_v_sync_provider_.set_connection_error_handler(ConvertToBaseCallback( |
801 WTF::Bind(&VRDisplay::OnVSyncConnectionError, WrapWeakPersistent(this)))); | 801 WTF::Bind(&VRDisplay::OnVSyncConnectionError, WrapWeakPersistent(this)))); |
802 if (pending_vrdisplay_raf_ && !display_blurred_) { | 802 if (pending_vrdisplay_raf_ && !display_blurred_) { |
803 pending_vsync_ = true; | 803 pending_vsync_ = true; |
804 vr_v_sync_provider_->GetVSync(ConvertToBaseCallback( | 804 vr_v_sync_provider_->GetVSync(ConvertToBaseCallback( |
805 WTF::Bind(&VRDisplay::OnVSync, WrapWeakPersistent(this)))); | 805 WTF::Bind(&VRDisplay::OnVSync, WrapWeakPersistent(this)))); |
806 } | 806 } |
807 } | 807 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
846 return GetExecutionContext() && HasEventListeners(); | 846 return GetExecutionContext() && HasEventListeners(); |
847 } | 847 } |
848 | 848 |
849 void VRDisplay::FocusChanged() { | 849 void VRDisplay::FocusChanged() { |
850 // TODO(mthiesse): Blur/focus the display. | 850 // TODO(mthiesse): Blur/focus the display. |
851 DVLOG(1) << __FUNCTION__; | 851 DVLOG(1) << __FUNCTION__; |
852 vr_v_sync_provider_.reset(); | 852 vr_v_sync_provider_.reset(); |
853 ConnectVSyncProvider(); | 853 ConnectVSyncProvider(); |
854 } | 854 } |
855 | 855 |
856 bool VRDisplay::FocusedOrPresenting() { | |
857 // TODO(mthiesse, crbug.com/687411): Focused state should be determined | |
858 // browser-side to correctly track which display should be receiving input. | |
859 return navigator_vr_->IsFocused() || is_presenting_; | |
860 } | |
861 | |
856 DEFINE_TRACE(VRDisplay) { | 862 DEFINE_TRACE(VRDisplay) { |
857 EventTargetWithInlineData::Trace(visitor); | 863 EventTargetWithInlineData::Trace(visitor); |
858 ContextLifecycleObserver::Trace(visitor); | 864 ContextLifecycleObserver::Trace(visitor); |
859 visitor->Trace(navigator_vr_); | 865 visitor->Trace(navigator_vr_); |
860 visitor->Trace(capabilities_); | 866 visitor->Trace(capabilities_); |
861 visitor->Trace(stage_parameters_); | 867 visitor->Trace(stage_parameters_); |
862 visitor->Trace(eye_parameters_left_); | 868 visitor->Trace(eye_parameters_left_); |
863 visitor->Trace(eye_parameters_right_); | 869 visitor->Trace(eye_parameters_right_); |
864 visitor->Trace(layer_); | 870 visitor->Trace(layer_); |
865 visitor->Trace(rendering_context_); | 871 visitor->Trace(rendering_context_); |
866 visitor->Trace(scripted_animation_controller_); | 872 visitor->Trace(scripted_animation_controller_); |
867 visitor->Trace(pending_present_resolvers_); | 873 visitor->Trace(pending_present_resolvers_); |
868 } | 874 } |
869 | 875 |
870 } // namespace blink | 876 } // namespace blink |
OLD | NEW |