| 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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 return; | 516 return; |
| 517 } | 517 } |
| 518 | 518 |
| 519 // No frame Id to write before submitting the frame. | 519 // No frame Id to write before submitting the frame. |
| 520 if (vr_frame_id_ < 0) { | 520 if (vr_frame_id_ < 0) { |
| 521 // TODO(klausw): There used to be a submitFrame here, but we can't | 521 // TODO(klausw): There used to be a submitFrame here, but we can't |
| 522 // submit without a frameId and associated pose data. Just drop it. | 522 // submit without a frameId and associated pose data. Just drop it. |
| 523 return; | 523 return; |
| 524 } | 524 } |
| 525 | 525 |
| 526 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::Flush_1"); |
| 526 context_gl_->Flush(); | 527 context_gl_->Flush(); |
| 528 TRACE_EVENT_END0("gpu", "VRDisplay::Flush_1"); |
| 527 | 529 |
| 528 // Check if the canvas got resized, if yes send a bounds update. | 530 // Check if the canvas got resized, if yes send a bounds update. |
| 529 int current_width = rendering_context_->drawingBufferWidth(); | 531 int current_width = rendering_context_->drawingBufferWidth(); |
| 530 int current_height = rendering_context_->drawingBufferHeight(); | 532 int current_height = rendering_context_->drawingBufferHeight(); |
| 531 if ((current_width != source_width_ || current_height != source_height_) && | 533 if ((current_width != source_width_ || current_height != source_height_) && |
| 532 current_width != 0 && current_height != 0) { | 534 current_width != 0 && current_height != 0) { |
| 533 source_width_ = current_width; | 535 source_width_ = current_width; |
| 534 source_height_ = current_height; | 536 source_height_ = current_height; |
| 535 UpdateLayerBounds(); | 537 UpdateLayerBounds(); |
| 536 } | 538 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 553 if (wait_for_previous_transfer_to_finish) { | 555 if (wait_for_previous_transfer_to_finish) { |
| 554 TRACE_EVENT0("gpu", "VRDisplay::waitForPreviousTransferToFinish"); | 556 TRACE_EVENT0("gpu", "VRDisplay::waitForPreviousTransferToFinish"); |
| 555 while (pending_submit_frame_) { | 557 while (pending_submit_frame_) { |
| 556 if (!submit_frame_client_binding_.WaitForIncomingMethodCall()) { | 558 if (!submit_frame_client_binding_.WaitForIncomingMethodCall()) { |
| 557 DLOG(ERROR) << "Failed to receive SubmitFrame response"; | 559 DLOG(ERROR) << "Failed to receive SubmitFrame response"; |
| 558 break; | 560 break; |
| 559 } | 561 } |
| 560 } | 562 } |
| 561 } | 563 } |
| 562 | 564 |
| 565 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::GetImage"); |
| 563 RefPtr<Image> image_ref = rendering_context_->GetImage( | 566 RefPtr<Image> image_ref = rendering_context_->GetImage( |
| 564 kPreferAcceleration, kSnapshotReasonCreateImageBitmap); | 567 kPreferAcceleration, kSnapshotReasonCreateImageBitmap); |
| 568 TRACE_EVENT_END0("gpu", "VRDisplay::GetImage"); |
| 565 | 569 |
| 566 // Hardware-accelerated rendering should always be texture backed, | 570 // Hardware-accelerated rendering should always be texture backed, |
| 567 // as implemented by AcceleratedStaticBitmapImage. Ensure this is | 571 // as implemented by AcceleratedStaticBitmapImage. Ensure this is |
| 568 // the case, don't attempt to render if using an unexpected drawing | 572 // the case, don't attempt to render if using an unexpected drawing |
| 569 // path. | 573 // path. |
| 570 if (!image_ref.Get() || !image_ref->IsTextureBacked()) { | 574 if (!image_ref.Get() || !image_ref->IsTextureBacked()) { |
| 571 NOTREACHED() << "WebVR requires hardware-accelerated rendering to texture"; | 575 NOTREACHED() << "WebVR requires hardware-accelerated rendering to texture"; |
| 572 return; | 576 return; |
| 573 } | 577 } |
| 574 | 578 |
| 575 // The AcceleratedStaticBitmapImage must be kept alive until the | 579 // The AcceleratedStaticBitmapImage must be kept alive until the |
| 576 // mailbox is used via createAndConsumeTextureCHROMIUM, the mailbox | 580 // mailbox is used via createAndConsumeTextureCHROMIUM, the mailbox |
| 577 // itself does not keep it alive. We must keep a reference to the | 581 // itself does not keep it alive. We must keep a reference to the |
| 578 // image until the mailbox was consumed. | 582 // image until the mailbox was consumed. |
| 579 StaticBitmapImage* static_image = | 583 StaticBitmapImage* static_image = |
| 580 static_cast<StaticBitmapImage*>(image_ref.Get()); | 584 static_cast<StaticBitmapImage*>(image_ref.Get()); |
| 585 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::EnsureMailbox"); |
| 581 static_image->EnsureMailbox(); | 586 static_image->EnsureMailbox(); |
| 587 TRACE_EVENT_END0("gpu", "VRDisplay::EnsureMailbox"); |
| 582 | 588 |
| 583 if (wait_for_previous_transfer_to_finish) { | 589 if (wait_for_previous_transfer_to_finish) { |
| 584 // Save a reference to the image to keep it alive until next frame, | 590 // Save a reference to the image to keep it alive until next frame, |
| 585 // where we'll wait for the transfer to finish before overwriting | 591 // where we'll wait for the transfer to finish before overwriting |
| 586 // it. | 592 // it. |
| 587 previous_image_ = std::move(image_ref); | 593 previous_image_ = std::move(image_ref); |
| 588 } | 594 } |
| 589 | 595 |
| 596 // Create mailbox and sync token for transfer. |
| 597 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::GetMailbox"); |
| 598 auto mailbox = static_image->GetMailbox(); |
| 599 TRACE_EVENT_END0("gpu", "VRDisplay::GetMailbox"); |
| 600 // Flush to avoid black screen flashes which appear to be related to |
| 601 // "fence sync must be flushed before generating sync token" GL errors. |
| 602 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::Flush_2"); |
| 603 context_gl_->Flush(); |
| 604 TRACE_EVENT_END0("gpu", "VRDisplay::Flush_2"); |
| 605 auto sync_token = static_image->GetSyncToken(); |
| 606 |
| 590 // Wait for the previous render to finish, to avoid losing frames in the | 607 // Wait for the previous render to finish, to avoid losing frames in the |
| 591 // Android Surface / GLConsumer pair. TODO(klausw): make this tunable? | 608 // Android Surface / GLConsumer pair. TODO(klausw): make this tunable? |
| 592 // Other devices may have different preferences. | 609 // Other devices may have different preferences. Do this step as late |
| 610 // as possible before SubmitFrame to ensure we can do as much work as |
| 611 // possible in parallel with the previous frame's rendering. |
| 593 { | 612 { |
| 594 TRACE_EVENT0("gpu", "waitForPreviousRenderToFinish"); | 613 TRACE_EVENT0("gpu", "waitForPreviousRenderToFinish"); |
| 595 while (pending_previous_frame_render_) { | 614 while (pending_previous_frame_render_) { |
| 596 if (!submit_frame_client_binding_.WaitForIncomingMethodCall()) { | 615 if (!submit_frame_client_binding_.WaitForIncomingMethodCall()) { |
| 597 DLOG(ERROR) << "Failed to receive SubmitFrame response"; | 616 DLOG(ERROR) << "Failed to receive SubmitFrame response"; |
| 598 break; | 617 break; |
| 599 } | 618 } |
| 600 } | 619 } |
| 601 } | 620 } |
| 602 | 621 |
| 603 pending_previous_frame_render_ = true; | 622 pending_previous_frame_render_ = true; |
| 604 pending_submit_frame_ = true; | 623 pending_submit_frame_ = true; |
| 605 display_->SubmitFrame( | 624 |
| 606 vr_frame_id_, | 625 TRACE_EVENT_BEGIN0("gpu", "VRDisplay::SubmitFrame"); |
| 607 gpu::MailboxHolder(static_image->GetMailbox(), | 626 display_->SubmitFrame(vr_frame_id_, |
| 608 static_image->GetSyncToken(), GL_TEXTURE_2D)); | 627 gpu::MailboxHolder(mailbox, sync_token, GL_TEXTURE_2D)); |
| 628 TRACE_EVENT_END0("gpu", "VRDisplay::SubmitFrame"); |
| 609 | 629 |
| 610 // If preserveDrawingBuffer is false, must clear now. Normally this | 630 // If preserveDrawingBuffer is false, must clear now. Normally this |
| 611 // happens as part of compositing, but that's not active while | 631 // happens as part of compositing, but that's not active while |
| 612 // presenting, so run the responsible code directly. | 632 // presenting, so run the responsible code directly. |
| 613 rendering_context_->MarkCompositedAndClearBackbufferIfNeeded(); | 633 rendering_context_->MarkCompositedAndClearBackbufferIfNeeded(); |
| 614 | 634 |
| 615 // If we're not deferring the wait for transferring the mailbox, | 635 // 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 | 636 // we need to wait for it now to prevent the image going out of |
| 617 // scope before its mailbox is retrieved. | 637 // scope before its mailbox is retrieved. |
| 618 if (!wait_for_previous_transfer_to_finish) { | 638 if (!wait_for_previous_transfer_to_finish) { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 visitor->Trace(stage_parameters_); | 901 visitor->Trace(stage_parameters_); |
| 882 visitor->Trace(eye_parameters_left_); | 902 visitor->Trace(eye_parameters_left_); |
| 883 visitor->Trace(eye_parameters_right_); | 903 visitor->Trace(eye_parameters_right_); |
| 884 visitor->Trace(layer_); | 904 visitor->Trace(layer_); |
| 885 visitor->Trace(rendering_context_); | 905 visitor->Trace(rendering_context_); |
| 886 visitor->Trace(scripted_animation_controller_); | 906 visitor->Trace(scripted_animation_controller_); |
| 887 visitor->Trace(pending_present_resolvers_); | 907 visitor->Trace(pending_present_resolvers_); |
| 888 } | 908 } |
| 889 | 909 |
| 890 } // namespace blink | 910 } // namespace blink |
| OLD | NEW |