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

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: Finish implementaion 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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 rightBounds->height = m_layer.rightBounds()[3]; 482 rightBounds->height = m_layer.rightBounds()[3];
483 } else { 483 } else {
484 // Right eye defaults 484 // Right eye defaults
485 rightBounds->left = 0.5f; 485 rightBounds->left = 0.5f;
486 rightBounds->top = 0.0f; 486 rightBounds->top = 0.0f;
487 rightBounds->width = 0.5f; 487 rightBounds->width = 0.5f;
488 rightBounds->height = 1.0f; 488 rightBounds->height = 1.0f;
489 m_layer.setRightBounds({0.5f, 0.0f, 0.5f, 1.0f}); 489 m_layer.setRightBounds({0.5f, 0.0f, 0.5f, 1.0f});
490 } 490 }
491 491
492 m_display->UpdateLayerBounds(std::move(leftBounds), std::move(rightBounds)); 492 m_display->UpdateLayerBounds(m_frameId, std::move(leftBounds),
493 std::move(rightBounds));
493 } 494 }
494 495
495 HeapVector<VRLayer> VRDisplay::getLayers() { 496 HeapVector<VRLayer> VRDisplay::getLayers() {
496 HeapVector<VRLayer> layers; 497 HeapVector<VRLayer> layers;
497 498
498 if (m_isPresenting) { 499 if (m_isPresenting) {
499 layers.push_back(m_layer); 500 layers.push_back(m_layer);
500 } 501 }
501 502
502 return layers; 503 return layers;
(...skipping 21 matching lines...) Expand all
524 "VRDisplay.requestAnimationFrame callback.")); 525 "VRDisplay.requestAnimationFrame callback."));
525 } 526 }
526 return; 527 return;
527 } 528 }
528 529
529 if (!m_contextGL) { 530 if (!m_contextGL) {
530 // Something got confused, we can't submit frames without a GL context. 531 // Something got confused, we can't submit frames without a GL context.
531 return; 532 return;
532 } 533 }
533 534
535 // No frame Id to write before submitting the frame.
536 if (m_frameId < 0) {
537 m_display->SubmitFrame(m_framePose.Clone());
538 return;
539 }
540
534 // Write the frame number for the pose used into a bottom left pixel block. 541 // Write the frame number for the pose used into a bottom left pixel block.
535 // It is read by chrome/browser/android/vr_shell/vr_shell.cc to associate 542 // It is read by chrome/browser/android/vr_shell/vr_shell.cc to associate
536 // the correct corresponding pose for submission. 543 // the correct corresponding pose for submission.
537 auto gl = m_contextGL; 544 auto gl = m_contextGL;
538 545
539 // We must ensure that the WebGL app's GL state is preserved. We do this by 546 // We must ensure that the WebGL app's GL state is preserved. We do this by
540 // calling low-level GL commands directly so that the rendering context's 547 // calling low-level GL commands directly so that the rendering context's
541 // saved parameters don't get overwritten. 548 // saved parameters don't get overwritten.
542 549
543 gl->Enable(GL_SCISSOR_TEST); 550 gl->Enable(GL_SCISSOR_TEST);
544 // Use a few pixels to ensure we get a clean color. The resolution for the 551 // Use a few pixels to ensure we get a clean color. The resolution for the
545 // WebGL buffer may not match the final rendered destination size, and 552 // WebGL buffer may not match the final rendered destination size, and
546 // texture filtering could interfere for single pixels. This isn't visible 553 // texture filtering could interfere for single pixels. This isn't visible
547 // since the final rendering hides the edges via a vignette effect. 554 // since the final rendering hides the edges via a vignette effect.
548 gl->Scissor(0, 0, 4, 4); 555 gl->Scissor(0, 0, 4, 4);
549 gl->ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 556 gl->ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
550 int idx = m_framePose->poseIndex;
551 // Careful with the arithmetic here. Float color 1.f is equivalent to int 255. 557 // Careful with the arithmetic here. Float color 1.f is equivalent to int 255.
552 // Use the low byte of the index as the red component, and store an arbitrary 558 // Use the low byte of the index as the red component, and store an arbitrary
553 // magic number in green/blue. This number must match the reading code in 559 // magic number in green/blue. This number must match the reading code in
554 // vr_shell.cc. Avoid all-black/all-white. 560 // vr_shell.cc. Avoid all-black/all-white.
555 gl->ClearColor((idx & 255) / 255.0f, kWebVrPosePixelMagicNumbers[0] / 255.0f, 561 gl->ClearColor((m_frameId & 255) / 255.0f,
562 kWebVrPosePixelMagicNumbers[0] / 255.0f,
556 kWebVrPosePixelMagicNumbers[1] / 255.0f, 1.0f); 563 kWebVrPosePixelMagicNumbers[1] / 255.0f, 1.0f);
557 gl->Clear(GL_COLOR_BUFFER_BIT); 564 gl->Clear(GL_COLOR_BUFFER_BIT);
558 565
559 // Set the GL state back to what was set by the WebVR application. 566 // Set the GL state back to what was set by the WebVR application.
560 m_renderingContext->restoreScissorEnabled(); 567 m_renderingContext->restoreScissorEnabled();
561 m_renderingContext->restoreScissorBox(); 568 m_renderingContext->restoreScissorBox();
562 m_renderingContext->restoreColorMask(); 569 m_renderingContext->restoreColorMask();
563 m_renderingContext->restoreClearColor(); 570 m_renderingContext->restoreClearColor();
564 571
565 m_display->SubmitFrame(m_framePose.Clone()); 572 m_display->SubmitFrame(m_framePose.Clone());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 EventTypeNames::vrdisplayactivate, true, false, this, reason)); 608 EventTypeNames::vrdisplayactivate, true, false, this, reason));
602 } 609 }
603 610
604 void VRDisplay::OnDeactivate( 611 void VRDisplay::OnDeactivate(
605 device::mojom::blink::VRDisplayEventReason reason) { 612 device::mojom::blink::VRDisplayEventReason reason) {
606 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( 613 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create(
607 EventTypeNames::vrdisplaydeactivate, true, false, this, reason)); 614 EventTypeNames::vrdisplaydeactivate, true, false, this, reason));
608 } 615 }
609 616
610 void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, 617 void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose,
611 double timeSeconds) { 618 double timeSeconds,
619 int16_t frameId) {
612 if (m_vrVSyncProvider.is_bound()) { 620 if (m_vrVSyncProvider.is_bound()) {
613 m_vrVSyncProvider->GetVSync(convertToBaseCallback( 621 m_vrVSyncProvider->GetVSync(convertToBaseCallback(
614 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); 622 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this))));
615 } 623 }
616 // The VSync provider cannot shut down before replying to pending callbacks, 624 // The VSync provider cannot shut down before replying to pending callbacks,
617 // so it will send a null pose with no timestamp to be ignored. 625 // so it will send a null pose with no timestamp to be ignored.
618 if (pose.is_null() && timeSeconds == 0) 626 if (pose.is_null() && timeSeconds == 0)
619 return; 627 return;
620 if (m_displayBlurred) 628 if (m_displayBlurred)
621 return; 629 return;
622 if (!m_scriptedAnimationController) 630 if (!m_scriptedAnimationController)
623 return; 631 return;
624 Document* doc = this->document(); 632 Document* doc = this->document();
625 if (!doc) 633 if (!doc)
626 return; 634 return;
627 635
628 // Ensure a consistent timebase with document rAF. 636 // Ensure a consistent timebase with document rAF.
629 if (m_timebase < 0) { 637 if (m_timebase < 0) {
630 m_timebase = WTF::monotonicallyIncreasingTime() - timeSeconds; 638 m_timebase = WTF::monotonicallyIncreasingTime() - timeSeconds;
631 } 639 }
632 640
633 AutoReset<bool> animating(&m_inAnimationFrame, true); 641 AutoReset<bool> animating(&m_inAnimationFrame, true);
634 m_framePose = std::move(pose); 642 m_framePose = std::move(pose);
643 m_frameId = frameId;
635 m_scriptedAnimationController->serviceScriptedAnimations(m_timebase + 644 m_scriptedAnimationController->serviceScriptedAnimations(m_timebase +
636 timeSeconds); 645 timeSeconds);
637 } 646 }
638 647
639 void VRDisplay::OnVSyncProviderDisconnected() { 648 void VRDisplay::OnVSyncProviderDisconnected() {
640 TaskRunnerHelper::get(TaskType::UnspecedTimer, document()) 649 TaskRunnerHelper::get(TaskType::UnspecedTimer, document())
641 ->postDelayedTask( 650 ->postDelayedTask(
642 BLINK_FROM_HERE, 651 BLINK_FROM_HERE,
643 WTF::bind(&VRDisplay::ConnectVSyncProvider, wrapWeakPersistent(this)), 652 WTF::bind(&VRDisplay::ConnectVSyncProvider, wrapWeakPersistent(this)),
644 100); // Short delay to throttle requests. 653 100); // Short delay to throttle requests.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 visitor->trace(m_stageParameters); 737 visitor->trace(m_stageParameters);
729 visitor->trace(m_eyeParametersLeft); 738 visitor->trace(m_eyeParametersLeft);
730 visitor->trace(m_eyeParametersRight); 739 visitor->trace(m_eyeParametersRight);
731 visitor->trace(m_layer); 740 visitor->trace(m_layer);
732 visitor->trace(m_renderingContext); 741 visitor->trace(m_renderingContext);
733 visitor->trace(m_scriptedAnimationController); 742 visitor->trace(m_scriptedAnimationController);
734 visitor->trace(m_pendingPresentResolvers); 743 visitor->trace(m_pendingPresentResolvers);
735 } 744 }
736 745
737 } // namespace blink 746 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698