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

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

Issue 2665293002: Only send vrdisplayactivate events to focused frames (Closed)
Patch Set: Rebase + add comments Created 3 years, 10 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 | « third_party/WebKit/Source/modules/vr/VRDisplay.h ('k') | 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/DocumentUserGestureToken.h" 9 #include "core/dom/DocumentUserGestureToken.h"
10 #include "core/dom/FrameRequestCallback.h" 10 #include "core/dom/FrameRequestCallback.h"
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 rightBounds->height = m_layer.rightBounds()[3]; 504 rightBounds->height = m_layer.rightBounds()[3];
505 } else { 505 } else {
506 // Right eye defaults 506 // Right eye defaults
507 rightBounds->left = 0.5f; 507 rightBounds->left = 0.5f;
508 rightBounds->top = 0.0f; 508 rightBounds->top = 0.0f;
509 rightBounds->width = 0.5f; 509 rightBounds->width = 0.5f;
510 rightBounds->height = 1.0f; 510 rightBounds->height = 1.0f;
511 m_layer.setRightBounds({0.5f, 0.0f, 0.5f, 1.0f}); 511 m_layer.setRightBounds({0.5f, 0.0f, 0.5f, 1.0f});
512 } 512 }
513 513
514 m_display->UpdateLayerBounds(m_frameId, std::move(leftBounds), 514 m_display->UpdateLayerBounds(m_vrFrameId, std::move(leftBounds),
515 std::move(rightBounds)); 515 std::move(rightBounds));
516 } 516 }
517 517
518 HeapVector<VRLayer> VRDisplay::getLayers() { 518 HeapVector<VRLayer> VRDisplay::getLayers() {
519 HeapVector<VRLayer> layers; 519 HeapVector<VRLayer> layers;
520 520
521 if (m_isPresenting) { 521 if (m_isPresenting) {
522 layers.push_back(m_layer); 522 layers.push_back(m_layer);
523 } 523 }
524 524
(...skipping 23 matching lines...) Expand all
548 } 548 }
549 return; 549 return;
550 } 550 }
551 551
552 if (!m_contextGL) { 552 if (!m_contextGL) {
553 // Something got confused, we can't submit frames without a GL context. 553 // Something got confused, we can't submit frames without a GL context.
554 return; 554 return;
555 } 555 }
556 556
557 // No frame Id to write before submitting the frame. 557 // No frame Id to write before submitting the frame.
558 if (m_frameId < 0) { 558 if (m_vrFrameId < 0) {
559 m_display->SubmitFrame(m_framePose.Clone()); 559 m_display->SubmitFrame(m_framePose.Clone());
560 return; 560 return;
561 } 561 }
562 562
563 // Write the frame number for the pose used into a bottom left pixel block. 563 // Write the frame number for the pose used into a bottom left pixel block.
564 // It is read by chrome/browser/android/vr_shell/vr_shell.cc to associate 564 // It is read by chrome/browser/android/vr_shell/vr_shell.cc to associate
565 // the correct corresponding pose for submission. 565 // the correct corresponding pose for submission.
566 auto gl = m_contextGL; 566 auto gl = m_contextGL;
567 567
568 // We must ensure that the WebGL app's GL state is preserved. We do this by 568 // We must ensure that the WebGL app's GL state is preserved. We do this by
569 // calling low-level GL commands directly so that the rendering context's 569 // calling low-level GL commands directly so that the rendering context's
570 // saved parameters don't get overwritten. 570 // saved parameters don't get overwritten.
571 571
572 gl->Enable(GL_SCISSOR_TEST); 572 gl->Enable(GL_SCISSOR_TEST);
573 // Use a few pixels to ensure we get a clean color. The resolution for the 573 // Use a few pixels to ensure we get a clean color. The resolution for the
574 // WebGL buffer may not match the final rendered destination size, and 574 // WebGL buffer may not match the final rendered destination size, and
575 // texture filtering could interfere for single pixels. This isn't visible 575 // texture filtering could interfere for single pixels. This isn't visible
576 // since the final rendering hides the edges via a vignette effect. 576 // since the final rendering hides the edges via a vignette effect.
577 gl->Scissor(0, 0, 4, 4); 577 gl->Scissor(0, 0, 4, 4);
578 gl->ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 578 gl->ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
579 // Careful with the arithmetic here. Float color 1.f is equivalent to int 255. 579 // Careful with the arithmetic here. Float color 1.f is equivalent to int 255.
580 // Use the low byte of the index as the red component, and store an arbitrary 580 // Use the low byte of the index as the red component, and store an arbitrary
581 // magic number in green/blue. This number must match the reading code in 581 // magic number in green/blue. This number must match the reading code in
582 // vr_shell.cc. Avoid all-black/all-white. 582 // vr_shell.cc. Avoid all-black/all-white.
583 gl->ClearColor((m_frameId & 255) / 255.0f, 583 gl->ClearColor((m_vrFrameId & 255) / 255.0f,
584 kWebVrPosePixelMagicNumbers[0] / 255.0f, 584 kWebVrPosePixelMagicNumbers[0] / 255.0f,
585 kWebVrPosePixelMagicNumbers[1] / 255.0f, 1.0f); 585 kWebVrPosePixelMagicNumbers[1] / 255.0f, 1.0f);
586 gl->Clear(GL_COLOR_BUFFER_BIT); 586 gl->Clear(GL_COLOR_BUFFER_BIT);
587 587
588 // Set the GL state back to what was set by the WebVR application. 588 // Set the GL state back to what was set by the WebVR application.
589 m_renderingContext->restoreScissorEnabled(); 589 m_renderingContext->restoreScissorEnabled();
590 m_renderingContext->restoreScissorBox(); 590 m_renderingContext->restoreScissorBox();
591 m_renderingContext->restoreColorMask(); 591 m_renderingContext->restoreColorMask();
592 m_renderingContext->restoreClearColor(); 592 m_renderingContext->restoreClearColor();
593 593
(...skipping 25 matching lines...) Expand all
619 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( 619 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create(
620 EventTypeNames::vrdisplayconnect, true, false, this, "connect")); 620 EventTypeNames::vrdisplayconnect, true, false, this, "connect"));
621 } 621 }
622 622
623 void VRDisplay::onDisconnected() { 623 void VRDisplay::onDisconnected() {
624 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( 624 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create(
625 EventTypeNames::vrdisplaydisconnect, true, false, this, "disconnect")); 625 EventTypeNames::vrdisplaydisconnect, true, false, this, "disconnect"));
626 } 626 }
627 627
628 void VRDisplay::OnActivate(device::mojom::blink::VRDisplayEventReason reason) { 628 void VRDisplay::OnActivate(device::mojom::blink::VRDisplayEventReason reason) {
629 if (!m_navigatorVR->isFocused() || m_displayBlurred)
630 return;
629 m_navigatorVR->dispatchVRGestureEvent(VRDisplayEvent::create( 631 m_navigatorVR->dispatchVRGestureEvent(VRDisplayEvent::create(
630 EventTypeNames::vrdisplayactivate, true, false, this, reason)); 632 EventTypeNames::vrdisplayactivate, true, false, this, reason));
631 } 633 }
632 634
633 void VRDisplay::OnDeactivate( 635 void VRDisplay::OnDeactivate(
634 device::mojom::blink::VRDisplayEventReason reason) { 636 device::mojom::blink::VRDisplayEventReason reason) {
635 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( 637 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create(
636 EventTypeNames::vrdisplaydeactivate, true, false, this, reason)); 638 EventTypeNames::vrdisplaydeactivate, true, false, this, reason));
637 } 639 }
638 640
(...skipping 19 matching lines...) Expand all
658 if (!doc) 660 if (!doc)
659 return; 661 return;
660 662
661 // Ensure a consistent timebase with document rAF. 663 // Ensure a consistent timebase with document rAF.
662 if (m_timebase < 0) { 664 if (m_timebase < 0) {
663 m_timebase = WTF::monotonicallyIncreasingTime() - timeDelta.InSecondsF(); 665 m_timebase = WTF::monotonicallyIncreasingTime() - timeDelta.InSecondsF();
664 } 666 }
665 667
666 AutoReset<bool> animating(&m_inAnimationFrame, true); 668 AutoReset<bool> animating(&m_inAnimationFrame, true);
667 m_framePose = std::move(pose); 669 m_framePose = std::move(pose);
668 m_frameId = frameId; 670 m_vrFrameId = frameId;
669 m_pendingRaf = false; 671 m_pendingRaf = false;
670 m_scriptedAnimationController->serviceScriptedAnimations( 672 m_scriptedAnimationController->serviceScriptedAnimations(
671 m_timebase + timeDelta.InSecondsF()); 673 m_timebase + timeDelta.InSecondsF());
672 } 674 }
673 675
674 void VRDisplay::ConnectVSyncProvider() { 676 void VRDisplay::ConnectVSyncProvider() {
675 if (!m_navigatorVR->isFocused()) 677 if (!m_navigatorVR->isFocused())
676 return; 678 return;
677 m_display->GetVRVSyncProvider(mojo::MakeRequest(&m_vrVSyncProvider)); 679 m_display->GetVRVSyncProvider(mojo::MakeRequest(&m_vrVSyncProvider));
678 if (m_pendingRaf && !m_displayBlurred) { 680 if (m_pendingRaf && !m_displayBlurred) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 visitor->trace(m_stageParameters); 765 visitor->trace(m_stageParameters);
764 visitor->trace(m_eyeParametersLeft); 766 visitor->trace(m_eyeParametersLeft);
765 visitor->trace(m_eyeParametersRight); 767 visitor->trace(m_eyeParametersRight);
766 visitor->trace(m_layer); 768 visitor->trace(m_layer);
767 visitor->trace(m_renderingContext); 769 visitor->trace(m_renderingContext);
768 visitor->trace(m_scriptedAnimationController); 770 visitor->trace(m_scriptedAnimationController);
769 visitor->trace(m_pendingPresentResolvers); 771 visitor->trace(m_pendingPresentResolvers);
770 } 772 }
771 773
772 } // namespace blink 774 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/vr/VRDisplay.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698