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

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

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

Powered by Google App Engine
This is Rietveld 408576698