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

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

Issue 2905843003: WebVR: use optimized render path with deferred wait (Closed)
Patch Set: Created 3 years, 6 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 | « no previous file | 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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 } 582 }
583 583
584 // There's two types of synchronization needed for submitting frames: 584 // There's two types of synchronization needed for submitting frames:
585 // 585 //
586 // - Before submitting, need to wait for the previous frame to be 586 // - Before submitting, need to wait for the previous frame to be
587 // pulled off the transfer surface to avoid lost frames. This 587 // pulled off the transfer surface to avoid lost frames. This
588 // is currently a compile-time option, normally we always want 588 // is currently a compile-time option, normally we always want
589 // to defer this wait to increase parallelism. 589 // to defer this wait to increase parallelism.
590 // 590 //
591 // - After submitting, need to wait for the mailbox to be consumed, 591 // - After submitting, need to wait for the mailbox to be consumed,
592 // and must remain inside the execution context while waiting. 592 // and the image object must remain alive during this time.
593 // The waitForPreviousTransferToFinish option defers this wait 593 // We keep a reference to the image so that we can defer this
594 // until the next frame. That's more efficient, but seems to 594 // wait. Here, we wait for the previous transfer to complete.
595 // cause wobbly framerates. 595 {
596 bool wait_for_previous_transfer_to_finish =
597 RuntimeEnabledFeatures::webVRExperimentalRenderingEnabled();
598
599 if (wait_for_previous_transfer_to_finish) {
600 TRACE_EVENT0("gpu", "VRDisplay::waitForPreviousTransferToFinish"); 596 TRACE_EVENT0("gpu", "VRDisplay::waitForPreviousTransferToFinish");
601 while (pending_submit_frame_) { 597 while (pending_submit_frame_) {
602 if (!submit_frame_client_binding_.WaitForIncomingMethodCall()) { 598 if (!submit_frame_client_binding_.WaitForIncomingMethodCall()) {
603 DLOG(ERROR) << "Failed to receive SubmitFrame response"; 599 DLOG(ERROR) << "Failed to receive SubmitFrame response";
604 break; 600 break;
605 } 601 }
606 } 602 }
607 } 603 }
608 604
609 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::GetImage"); 605 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::GetImage");
(...skipping 13 matching lines...) Expand all
623 // The AcceleratedStaticBitmapImage must be kept alive until the 619 // The AcceleratedStaticBitmapImage must be kept alive until the
624 // mailbox is used via createAndConsumeTextureCHROMIUM, the mailbox 620 // mailbox is used via createAndConsumeTextureCHROMIUM, the mailbox
625 // itself does not keep it alive. We must keep a reference to the 621 // itself does not keep it alive. We must keep a reference to the
626 // image until the mailbox was consumed. 622 // image until the mailbox was consumed.
627 StaticBitmapImage* static_image = 623 StaticBitmapImage* static_image =
628 static_cast<StaticBitmapImage*>(image_ref.Get()); 624 static_cast<StaticBitmapImage*>(image_ref.Get());
629 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::EnsureMailbox"); 625 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::EnsureMailbox");
630 static_image->EnsureMailbox(); 626 static_image->EnsureMailbox();
631 TRACE_EVENT_END0("gpu", "VRDisplay::EnsureMailbox"); 627 TRACE_EVENT_END0("gpu", "VRDisplay::EnsureMailbox");
632 628
633 if (wait_for_previous_transfer_to_finish) { 629 // Save a reference to the image to keep it alive until next frame,
634 // Save a reference to the image to keep it alive until next frame, 630 // where we'll wait for the transfer to finish before overwriting
635 // where we'll wait for the transfer to finish before overwriting 631 // it.
636 // it. 632 previous_image_ = std::move(image_ref);
637 previous_image_ = std::move(image_ref);
638 }
639 633
640 // Create mailbox and sync token for transfer. 634 // Create mailbox and sync token for transfer.
641 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::GetMailbox"); 635 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::GetMailbox");
642 auto mailbox = static_image->GetMailbox(); 636 auto mailbox = static_image->GetMailbox();
643 TRACE_EVENT_END0("gpu", "VRDisplay::GetMailbox"); 637 TRACE_EVENT_END0("gpu", "VRDisplay::GetMailbox");
644 // Flush to avoid black screen flashes which appear to be related to 638 // Flush to avoid black screen flashes which appear to be related to
645 // "fence sync must be flushed before generating sync token" GL errors. 639 // "fence sync must be flushed before generating sync token" GL errors.
646 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::Flush_2"); 640 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::Flush_2");
647 context_gl_->Flush(); 641 context_gl_->Flush();
648 TRACE_EVENT_END0("gpu", "VRDisplay::Flush_2"); 642 TRACE_EVENT_END0("gpu", "VRDisplay::Flush_2");
(...skipping 24 matching lines...) Expand all
673 667
674 did_submit_this_frame_ = true; 668 did_submit_this_frame_ = true;
675 // If we were deferring a rAF-triggered vsync request, do this now. 669 // If we were deferring a rAF-triggered vsync request, do this now.
676 if (pending_vrdisplay_raf_) 670 if (pending_vrdisplay_raf_)
677 RequestVSync(); 671 RequestVSync();
678 672
679 // If preserveDrawingBuffer is false, must clear now. Normally this 673 // If preserveDrawingBuffer is false, must clear now. Normally this
680 // happens as part of compositing, but that's not active while 674 // happens as part of compositing, but that's not active while
681 // presenting, so run the responsible code directly. 675 // presenting, so run the responsible code directly.
682 rendering_context_->MarkCompositedAndClearBackbufferIfNeeded(); 676 rendering_context_->MarkCompositedAndClearBackbufferIfNeeded();
683
684 // If we're not deferring the wait for transferring the mailbox,
685 // we need to wait for it now to prevent the image going out of
686 // scope before its mailbox is retrieved.
687 if (!wait_for_previous_transfer_to_finish) {
688 TRACE_EVENT0("gpu", "waitForCurrentTransferToFinish");
689 while (pending_submit_frame_) {
690 if (!submit_frame_client_binding_.WaitForIncomingMethodCall()) {
691 DLOG(ERROR) << "Failed to receive SubmitFrame response";
692 break;
693 }
694 }
695 }
696 } 677 }
697 678
698 void VRDisplay::OnSubmitFrameTransferred() { 679 void VRDisplay::OnSubmitFrameTransferred() {
699 DVLOG(3) << __FUNCTION__; 680 DVLOG(3) << __FUNCTION__;
700 pending_submit_frame_ = false; 681 pending_submit_frame_ = false;
701 } 682 }
702 683
703 void VRDisplay::OnSubmitFrameRendered() { 684 void VRDisplay::OnSubmitFrameRendered() {
704 DVLOG(3) << __FUNCTION__; 685 DVLOG(3) << __FUNCTION__;
705 pending_previous_frame_render_ = false; 686 pending_previous_frame_render_ = false;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 visitor->Trace(stage_parameters_); 944 visitor->Trace(stage_parameters_);
964 visitor->Trace(eye_parameters_left_); 945 visitor->Trace(eye_parameters_left_);
965 visitor->Trace(eye_parameters_right_); 946 visitor->Trace(eye_parameters_right_);
966 visitor->Trace(layer_); 947 visitor->Trace(layer_);
967 visitor->Trace(rendering_context_); 948 visitor->Trace(rendering_context_);
968 visitor->Trace(scripted_animation_controller_); 949 visitor->Trace(scripted_animation_controller_);
969 visitor->Trace(pending_present_resolvers_); 950 visitor->Trace(pending_present_resolvers_);
970 } 951 }
971 952
972 } // namespace blink 953 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698