Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: third_party/WebKit/Source/modules/vr/VRDisplay.cpp

Issue 2888313002: WebVR: Defer GetVSync calls until the current frame is submitted. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/vr/VRDisplay.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 switch (StringToVREye(which_eye)) { 122 switch (StringToVREye(which_eye)) {
123 case kVREyeLeft: 123 case kVREyeLeft:
124 return eye_parameters_left_; 124 return eye_parameters_left_;
125 case kVREyeRight: 125 case kVREyeRight:
126 return eye_parameters_right_; 126 return eye_parameters_right_;
127 default: 127 default:
128 return nullptr; 128 return nullptr;
129 } 129 }
130 } 130 }
131 131
132 int VRDisplay::requestAnimationFrame(FrameRequestCallback* callback) { 132 void VRDisplay::RequestVSync() {
133 DVLOG(2) << __FUNCTION__; 133 if (pending_vsync_ || !pending_vrdisplay_raf_)
134 Document* doc = this->GetDocument(); 134 return;
135 if (!doc) 135
136 return 0;
137 pending_vrdisplay_raf_ = true;
138 if (!vr_v_sync_provider_.is_bound()) { 136 if (!vr_v_sync_provider_.is_bound()) {
139 ConnectVSyncProvider(); 137 ConnectVSyncProvider();
140 } else if (!display_blurred_ && !pending_vsync_) { 138 } else if (!display_blurred_ && !pending_vsync_) {
141 pending_vsync_ = true; 139 pending_vsync_ = true;
142 vr_v_sync_provider_->GetVSync(ConvertToBaseCallback( 140 vr_v_sync_provider_->GetVSync(ConvertToBaseCallback(
143 WTF::Bind(&VRDisplay::OnVSync, WrapWeakPersistent(this)))); 141 WTF::Bind(&VRDisplay::OnVSync, WrapWeakPersistent(this))));
144 } 142 }
143 }
144
145 int VRDisplay::requestAnimationFrame(FrameRequestCallback* callback) {
146 DVLOG(2) << __FUNCTION__;
147 Document* doc = this->GetDocument();
148 if (!doc)
149 return 0;
150 pending_vrdisplay_raf_ = true;
151 if (did_submit_this_frame_) {
152 RequestVSync();
153 }
bajones 2017/05/18 15:59:18 I'm not sure what this call site provides? Seems l
mthiesse 2017/05/18 16:09:01 This code is all really subtle and kind of scary.
klausw 2017/05/18 22:22:29 I've added a detailed explanation in RequestVSync,
145 callback->use_legacy_time_base_ = false; 154 callback->use_legacy_time_base_ = false;
146 return EnsureScriptedAnimationController(doc).RegisterCallback(callback); 155 return EnsureScriptedAnimationController(doc).RegisterCallback(callback);
147 } 156 }
148 157
149 void VRDisplay::cancelAnimationFrame(int id) { 158 void VRDisplay::cancelAnimationFrame(int id) {
150 DVLOG(2) << __FUNCTION__; 159 DVLOG(2) << __FUNCTION__;
151 if (!scripted_animation_controller_) 160 if (!scripted_animation_controller_)
152 return; 161 return;
153 scripted_animation_controller_->CancelCallback(id); 162 scripted_animation_controller_->CancelCallback(id);
154 } 163 }
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 } 608 }
600 } 609 }
601 } 610 }
602 611
603 pending_previous_frame_render_ = true; 612 pending_previous_frame_render_ = true;
604 pending_submit_frame_ = true; 613 pending_submit_frame_ = true;
605 display_->SubmitFrame( 614 display_->SubmitFrame(
606 vr_frame_id_, 615 vr_frame_id_,
607 gpu::MailboxHolder(static_image->GetMailbox(), 616 gpu::MailboxHolder(static_image->GetMailbox(),
608 static_image->GetSyncToken(), GL_TEXTURE_2D)); 617 static_image->GetSyncToken(), GL_TEXTURE_2D));
618 did_submit_this_frame_ = true;
619 RequestVSync();
609 620
610 // If preserveDrawingBuffer is false, must clear now. Normally this 621 // If preserveDrawingBuffer is false, must clear now. Normally this
611 // happens as part of compositing, but that's not active while 622 // happens as part of compositing, but that's not active while
612 // presenting, so run the responsible code directly. 623 // presenting, so run the responsible code directly.
613 rendering_context_->MarkCompositedAndClearBackbufferIfNeeded(); 624 rendering_context_->MarkCompositedAndClearBackbufferIfNeeded();
614 625
615 // If we're not deferring the wait for transferring the mailbox, 626 // If we're not deferring the wait for transferring the mailbox,
616 // we need to wait for it now to prevent the image going out of 627 // we need to wait for it now to prevent the image going out of
617 // scope before its mailbox is retrieved. 628 // scope before its mailbox is retrieved.
618 if (!wait_for_previous_transfer_to_finish) { 629 if (!wait_for_previous_transfer_to_finish) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 } 760 }
750 761
751 TRACE_EVENT1("gpu", "VRDisplay::OnVSync", "frame", vr_frame_id_); 762 TRACE_EVENT1("gpu", "VRDisplay::OnVSync", "frame", vr_frame_id_);
752 763
753 if (pending_vrdisplay_raf_ && scripted_animation_controller_) { 764 if (pending_vrdisplay_raf_ && scripted_animation_controller_) {
754 // Run the callback, making sure that in_animation_frame_ is only 765 // Run the callback, making sure that in_animation_frame_ is only
755 // true for the vrDisplay rAF and not for a legacy window rAF 766 // true for the vrDisplay rAF and not for a legacy window rAF
756 // that may be called later. 767 // that may be called later.
757 AutoReset<bool> animating(&in_animation_frame_, true); 768 AutoReset<bool> animating(&in_animation_frame_, true);
758 pending_vrdisplay_raf_ = false; 769 pending_vrdisplay_raf_ = false;
770 did_submit_this_frame_ = false;
759 scripted_animation_controller_->ServiceScriptedAnimations(timestamp); 771 scripted_animation_controller_->ServiceScriptedAnimations(timestamp);
772 if (!did_submit_this_frame_) {
773 DVLOG(2) << __FUNCTION__ << ": vrDisplay.rAF did not submit a frame";
774 RequestVSync();
775 }
760 } 776 }
761 777
mthiesse 2017/05/18 16:09:01 Add a DCHECK here that if pending_vrdisplay_raf_ i
klausw 2017/05/18 22:22:29 Done.
762 // For GVR, we shut down normal vsync processing during VR presentation. 778 // For GVR, we shut down normal vsync processing during VR presentation.
763 // Trigger any callbacks on window.rAF manually so that they run after 779 // Trigger any callbacks on window.rAF manually so that they run after
764 // completing the vrDisplay.rAF processing. 780 // completing the vrDisplay.rAF processing.
765 if (is_presenting_ && !capabilities_->hasExternalDisplay()) { 781 if (is_presenting_ && !capabilities_->hasExternalDisplay()) {
766 Platform::Current()->CurrentThread()->GetWebTaskRunner()->PostTask( 782 Platform::Current()->CurrentThread()->GetWebTaskRunner()->PostTask(
767 BLINK_FROM_HERE, WTF::Bind(&VRDisplay::ProcessScheduledWindowAnimations, 783 BLINK_FROM_HERE, WTF::Bind(&VRDisplay::ProcessScheduledWindowAnimations,
768 WrapWeakPersistent(this), timestamp)); 784 WrapWeakPersistent(this), timestamp));
769 } 785 }
770 } 786 }
771 787
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 visitor->Trace(stage_parameters_); 897 visitor->Trace(stage_parameters_);
882 visitor->Trace(eye_parameters_left_); 898 visitor->Trace(eye_parameters_left_);
883 visitor->Trace(eye_parameters_right_); 899 visitor->Trace(eye_parameters_right_);
884 visitor->Trace(layer_); 900 visitor->Trace(layer_);
885 visitor->Trace(rendering_context_); 901 visitor->Trace(rendering_context_);
886 visitor->Trace(scripted_animation_controller_); 902 visitor->Trace(scripted_animation_controller_);
887 visitor->Trace(pending_present_resolvers_); 903 visitor->Trace(pending_present_resolvers_);
888 } 904 }
889 905
890 } // namespace blink 906 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/vr/VRDisplay.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698