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/DocumentUserGestureToken.h" | 9 #include "core/dom/DocumentUserGestureToken.h" |
10 #include "core/dom/FrameRequestCallback.h" | 10 #include "core/dom/FrameRequestCallback.h" |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 rightBounds->height = m_layer.rightBounds()[3]; | 493 rightBounds->height = m_layer.rightBounds()[3]; |
494 } else { | 494 } else { |
495 // Right eye defaults | 495 // Right eye defaults |
496 rightBounds->left = 0.5f; | 496 rightBounds->left = 0.5f; |
497 rightBounds->top = 0.0f; | 497 rightBounds->top = 0.0f; |
498 rightBounds->width = 0.5f; | 498 rightBounds->width = 0.5f; |
499 rightBounds->height = 1.0f; | 499 rightBounds->height = 1.0f; |
500 m_layer.setRightBounds({0.5f, 0.0f, 0.5f, 1.0f}); | 500 m_layer.setRightBounds({0.5f, 0.0f, 0.5f, 1.0f}); |
501 } | 501 } |
502 | 502 |
503 m_display->UpdateLayerBounds(std::move(leftBounds), std::move(rightBounds)); | 503 m_display->UpdateLayerBounds(m_frameId, std::move(leftBounds), |
| 504 std::move(rightBounds)); |
504 } | 505 } |
505 | 506 |
506 HeapVector<VRLayer> VRDisplay::getLayers() { | 507 HeapVector<VRLayer> VRDisplay::getLayers() { |
507 HeapVector<VRLayer> layers; | 508 HeapVector<VRLayer> layers; |
508 | 509 |
509 if (m_isPresenting) { | 510 if (m_isPresenting) { |
510 layers.push_back(m_layer); | 511 layers.push_back(m_layer); |
511 } | 512 } |
512 | 513 |
513 return layers; | 514 return layers; |
(...skipping 21 matching lines...) Expand all Loading... |
535 "VRDisplay.requestAnimationFrame callback.")); | 536 "VRDisplay.requestAnimationFrame callback.")); |
536 } | 537 } |
537 return; | 538 return; |
538 } | 539 } |
539 | 540 |
540 if (!m_contextGL) { | 541 if (!m_contextGL) { |
541 // Something got confused, we can't submit frames without a GL context. | 542 // Something got confused, we can't submit frames without a GL context. |
542 return; | 543 return; |
543 } | 544 } |
544 | 545 |
| 546 // No frame Id to write before submitting the frame. |
| 547 if (m_frameId < 0) { |
| 548 m_display->SubmitFrame(m_framePose.Clone()); |
| 549 return; |
| 550 } |
| 551 |
545 // Write the frame number for the pose used into a bottom left pixel block. | 552 // Write the frame number for the pose used into a bottom left pixel block. |
546 // It is read by chrome/browser/android/vr_shell/vr_shell.cc to associate | 553 // It is read by chrome/browser/android/vr_shell/vr_shell.cc to associate |
547 // the correct corresponding pose for submission. | 554 // the correct corresponding pose for submission. |
548 auto gl = m_contextGL; | 555 auto gl = m_contextGL; |
549 | 556 |
550 // We must ensure that the WebGL app's GL state is preserved. We do this by | 557 // We must ensure that the WebGL app's GL state is preserved. We do this by |
551 // calling low-level GL commands directly so that the rendering context's | 558 // calling low-level GL commands directly so that the rendering context's |
552 // saved parameters don't get overwritten. | 559 // saved parameters don't get overwritten. |
553 | 560 |
554 gl->Enable(GL_SCISSOR_TEST); | 561 gl->Enable(GL_SCISSOR_TEST); |
555 // Use a few pixels to ensure we get a clean color. The resolution for the | 562 // Use a few pixels to ensure we get a clean color. The resolution for the |
556 // WebGL buffer may not match the final rendered destination size, and | 563 // WebGL buffer may not match the final rendered destination size, and |
557 // texture filtering could interfere for single pixels. This isn't visible | 564 // texture filtering could interfere for single pixels. This isn't visible |
558 // since the final rendering hides the edges via a vignette effect. | 565 // since the final rendering hides the edges via a vignette effect. |
559 gl->Scissor(0, 0, 4, 4); | 566 gl->Scissor(0, 0, 4, 4); |
560 gl->ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 567 gl->ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
561 int idx = m_framePose->poseIndex; | |
562 // Careful with the arithmetic here. Float color 1.f is equivalent to int 255. | 568 // Careful with the arithmetic here. Float color 1.f is equivalent to int 255. |
563 // Use the low byte of the index as the red component, and store an arbitrary | 569 // Use the low byte of the index as the red component, and store an arbitrary |
564 // magic number in green/blue. This number must match the reading code in | 570 // magic number in green/blue. This number must match the reading code in |
565 // vr_shell.cc. Avoid all-black/all-white. | 571 // vr_shell.cc. Avoid all-black/all-white. |
566 gl->ClearColor((idx & 255) / 255.0f, kWebVrPosePixelMagicNumbers[0] / 255.0f, | 572 gl->ClearColor((m_frameId & 255) / 255.0f, |
| 573 kWebVrPosePixelMagicNumbers[0] / 255.0f, |
567 kWebVrPosePixelMagicNumbers[1] / 255.0f, 1.0f); | 574 kWebVrPosePixelMagicNumbers[1] / 255.0f, 1.0f); |
568 gl->Clear(GL_COLOR_BUFFER_BIT); | 575 gl->Clear(GL_COLOR_BUFFER_BIT); |
569 | 576 |
570 // Set the GL state back to what was set by the WebVR application. | 577 // Set the GL state back to what was set by the WebVR application. |
571 m_renderingContext->restoreScissorEnabled(); | 578 m_renderingContext->restoreScissorEnabled(); |
572 m_renderingContext->restoreScissorBox(); | 579 m_renderingContext->restoreScissorBox(); |
573 m_renderingContext->restoreColorMask(); | 580 m_renderingContext->restoreColorMask(); |
574 m_renderingContext->restoreClearColor(); | 581 m_renderingContext->restoreClearColor(); |
575 | 582 |
576 m_display->SubmitFrame(m_framePose.Clone()); | 583 m_display->SubmitFrame(m_framePose.Clone()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 EventTypeNames::vrdisplayactivate, true, false, this, reason)); | 619 EventTypeNames::vrdisplayactivate, true, false, this, reason)); |
613 } | 620 } |
614 | 621 |
615 void VRDisplay::OnDeactivate( | 622 void VRDisplay::OnDeactivate( |
616 device::mojom::blink::VRDisplayEventReason reason) { | 623 device::mojom::blink::VRDisplayEventReason reason) { |
617 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( | 624 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
618 EventTypeNames::vrdisplaydeactivate, true, false, this, reason)); | 625 EventTypeNames::vrdisplaydeactivate, true, false, this, reason)); |
619 } | 626 } |
620 | 627 |
621 void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, | 628 void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, |
622 mojo::common::mojom::blink::TimeDeltaPtr time) { | 629 mojo::common::mojom::blink::TimeDeltaPtr time, |
| 630 int16_t frameId) { |
623 WTF::TimeDelta timeDelta = | 631 WTF::TimeDelta timeDelta = |
624 WTF::TimeDelta::FromMicroseconds(time->microseconds); | 632 WTF::TimeDelta::FromMicroseconds(time->microseconds); |
625 // The VSync provider cannot shut down before replying to pending callbacks, | 633 // The VSync provider cannot shut down before replying to pending callbacks, |
626 // so it will send a null pose with no timestamp to be ignored. | 634 // so it will send a null pose with no timestamp to be ignored. |
627 if (pose.is_null() && timeDelta.is_zero()) { | 635 if (pose.is_null() && timeDelta.is_zero()) { |
628 // We need to keep the VSync loop going because we haven't responded to the | 636 // We need to keep the VSync loop going because we haven't responded to the |
629 // previous rAF yet. | 637 // previous rAF yet. |
630 m_vrVSyncProvider->GetVSync(convertToBaseCallback( | 638 m_vrVSyncProvider->GetVSync(convertToBaseCallback( |
631 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); | 639 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); |
632 return; | 640 return; |
633 } | 641 } |
634 if (m_displayBlurred) | 642 if (m_displayBlurred) |
635 return; | 643 return; |
636 if (!m_scriptedAnimationController) | 644 if (!m_scriptedAnimationController) |
637 return; | 645 return; |
638 Document* doc = this->document(); | 646 Document* doc = this->document(); |
639 if (!doc) | 647 if (!doc) |
640 return; | 648 return; |
641 | 649 |
642 // Ensure a consistent timebase with document rAF. | 650 // Ensure a consistent timebase with document rAF. |
643 if (m_timebase < 0) { | 651 if (m_timebase < 0) { |
644 m_timebase = WTF::monotonicallyIncreasingTime() - timeDelta.InSecondsF(); | 652 m_timebase = WTF::monotonicallyIncreasingTime() - timeDelta.InSecondsF(); |
645 } | 653 } |
646 | 654 |
647 AutoReset<bool> animating(&m_inAnimationFrame, true); | 655 AutoReset<bool> animating(&m_inAnimationFrame, true); |
648 m_framePose = std::move(pose); | 656 m_framePose = std::move(pose); |
| 657 m_frameId = frameId; |
649 m_pendingRaf = false; | 658 m_pendingRaf = false; |
650 m_scriptedAnimationController->serviceScriptedAnimations( | 659 m_scriptedAnimationController->serviceScriptedAnimations( |
651 m_timebase + timeDelta.InSecondsF()); | 660 m_timebase + timeDelta.InSecondsF()); |
652 } | 661 } |
653 | 662 |
654 void VRDisplay::ConnectVSyncProvider() { | 663 void VRDisplay::ConnectVSyncProvider() { |
655 m_display->GetVRVSyncProvider(mojo::MakeRequest(&m_vrVSyncProvider)); | 664 m_display->GetVRVSyncProvider(mojo::MakeRequest(&m_vrVSyncProvider)); |
656 if (m_pendingRaf && !m_displayBlurred) { | 665 if (m_pendingRaf && !m_displayBlurred) { |
657 m_vrVSyncProvider->GetVSync(convertToBaseCallback( | 666 m_vrVSyncProvider->GetVSync(convertToBaseCallback( |
658 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); | 667 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 visitor->trace(m_stageParameters); | 744 visitor->trace(m_stageParameters); |
736 visitor->trace(m_eyeParametersLeft); | 745 visitor->trace(m_eyeParametersLeft); |
737 visitor->trace(m_eyeParametersRight); | 746 visitor->trace(m_eyeParametersRight); |
738 visitor->trace(m_layer); | 747 visitor->trace(m_layer); |
739 visitor->trace(m_renderingContext); | 748 visitor->trace(m_renderingContext); |
740 visitor->trace(m_scriptedAnimationController); | 749 visitor->trace(m_scriptedAnimationController); |
741 visitor->trace(m_pendingPresentResolvers); | 750 visitor->trace(m_pendingPresentResolvers); |
742 } | 751 } |
743 | 752 |
744 } // namespace blink | 753 } // namespace blink |
OLD | NEW |