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

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

Issue 2550803002: WebVR: avoid race conditions for partially-initialized display (Closed)
Patch Set: Created 4 years 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 }; 68 };
69 69
70 } // namespace 70 } // namespace
71 71
72 VRDisplay::VRDisplay(NavigatorVR* navigatorVR, 72 VRDisplay::VRDisplay(NavigatorVR* navigatorVR,
73 device::mojom::blink::VRDisplayPtr display, 73 device::mojom::blink::VRDisplayPtr display,
74 device::mojom::blink::VRDisplayClientRequest request) 74 device::mojom::blink::VRDisplayClientRequest request)
75 : m_navigatorVR(navigatorVR), 75 : m_navigatorVR(navigatorVR),
76 m_isConnected(false), 76 m_isConnected(false),
77 m_isPresenting(false), 77 m_isPresenting(false),
78 m_isValidDeviceForPresenting(true),
78 m_canUpdateFramePose(true), 79 m_canUpdateFramePose(true),
79 m_capabilities(new VRDisplayCapabilities()), 80 m_capabilities(new VRDisplayCapabilities()),
80 m_eyeParametersLeft(new VREyeParameters()), 81 m_eyeParametersLeft(new VREyeParameters()),
81 m_eyeParametersRight(new VREyeParameters()), 82 m_eyeParametersRight(new VREyeParameters()),
82 m_depthNear(0.01), 83 m_depthNear(0.01),
83 m_depthFar(10000.0), 84 m_depthFar(10000.0),
84 m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck), 85 m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck),
85 m_contextGL(nullptr), 86 m_contextGL(nullptr),
86 m_animationCallbackRequested(false), 87 m_animationCallbackRequested(false),
87 m_inAnimationFrame(false), 88 m_inAnimationFrame(false),
(...skipping 13 matching lines...) Expand all
101 m_displayName = display->displayName; 102 m_displayName = display->displayName;
102 m_isConnected = true; 103 m_isConnected = true;
103 104
104 m_capabilities->setHasOrientation(display->capabilities->hasOrientation); 105 m_capabilities->setHasOrientation(display->capabilities->hasOrientation);
105 m_capabilities->setHasPosition(display->capabilities->hasPosition); 106 m_capabilities->setHasPosition(display->capabilities->hasPosition);
106 m_capabilities->setHasExternalDisplay( 107 m_capabilities->setHasExternalDisplay(
107 display->capabilities->hasExternalDisplay); 108 display->capabilities->hasExternalDisplay);
108 m_capabilities->setCanPresent(display->capabilities->canPresent); 109 m_capabilities->setCanPresent(display->capabilities->canPresent);
109 m_capabilities->setMaxLayers(display->capabilities->canPresent ? 1 : 0); 110 m_capabilities->setMaxLayers(display->capabilities->canPresent ? 1 : 0);
110 111
112 // Ignore non presenting delegate
113 bool isValid = display->leftEye->renderWidth > 0;
114 bool needOnPresentChange = false;
115 if (m_isPresenting && isValid && !m_isValidDeviceForPresenting) {
116 needOnPresentChange = true;
117 }
118 m_isValidDeviceForPresenting = isValid;
111 m_eyeParametersLeft->update(display->leftEye); 119 m_eyeParametersLeft->update(display->leftEye);
112 m_eyeParametersRight->update(display->rightEye); 120 m_eyeParametersRight->update(display->rightEye);
113 121
114 if (!display->stageParameters.is_null()) { 122 if (!display->stageParameters.is_null()) {
115 if (!m_stageParameters) 123 if (!m_stageParameters)
116 m_stageParameters = new VRStageParameters(); 124 m_stageParameters = new VRStageParameters();
117 m_stageParameters->update(display->stageParameters); 125 m_stageParameters->update(display->stageParameters);
118 } else { 126 } else {
119 m_stageParameters = nullptr; 127 m_stageParameters = nullptr;
120 } 128 }
129
130 if (needOnPresentChange) {
131 OnPresentChange();
132 }
121 } 133 }
122 134
123 void VRDisplay::disconnected() { 135 void VRDisplay::disconnected() {
124 if (m_isConnected) 136 if (m_isConnected)
125 m_isConnected = !m_isConnected; 137 m_isConnected = !m_isConnected;
126 } 138 }
127 139
128 bool VRDisplay::getFrameData(VRFrameData* frameData) { 140 bool VRDisplay::getFrameData(VRFrameData* frameData) {
129 updatePose(); 141 updatePose();
130 142
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 m_fullscreenOrigWidth = String(); 501 m_fullscreenOrigWidth = String();
490 } 502 }
491 if (!m_fullscreenOrigHeight.isNull()) { 503 if (!m_fullscreenOrigHeight.isNull()) {
492 canvas->setInlineStyleProperty(CSSPropertyWidth, 504 canvas->setInlineStyleProperty(CSSPropertyWidth,
493 m_fullscreenOrigHeight); 505 m_fullscreenOrigHeight);
494 m_fullscreenOrigHeight = String(); 506 m_fullscreenOrigHeight = String();
495 } 507 }
496 } else { 508 } else {
497 // Can't get into this presentation mode, so nothing to do here. 509 // Can't get into this presentation mode, so nothing to do here.
498 } 510 }
511 m_isPresenting = false;
499 OnPresentChange(); 512 OnPresentChange();
500 } 513 }
501 514
502 m_isPresenting = false;
503 m_renderingContext = nullptr; 515 m_renderingContext = nullptr;
504 m_contextGL = nullptr; 516 m_contextGL = nullptr;
505 } 517 }
506 518
507 void VRDisplay::updateLayerBounds() { 519 void VRDisplay::updateLayerBounds() {
508 if (!m_display) 520 if (!m_display)
509 return; 521 return;
510 522
511 // Set up the texture bounds for the provided layer 523 // Set up the texture bounds for the provided layer
512 device::mojom::blink::VRLayerBoundsPtr leftBounds = 524 device::mojom::blink::VRLayerBoundsPtr leftBounds =
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 624
613 m_display->SubmitFrame(m_framePose.Clone()); 625 m_display->SubmitFrame(m_framePose.Clone());
614 m_canUpdateFramePose = true; 626 m_canUpdateFramePose = true;
615 } 627 }
616 628
617 Document* VRDisplay::document() { 629 Document* VRDisplay::document() {
618 return m_navigatorVR->document(); 630 return m_navigatorVR->document();
619 } 631 }
620 632
621 void VRDisplay::OnPresentChange() { 633 void VRDisplay::OnPresentChange() {
634 if (m_isPresenting && !m_isValidDeviceForPresenting) {
635 VLOG(1) << __FUNCTION__ << ": device not valid, not sending event";
636 return;
637 }
622 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( 638 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create(
623 EventTypeNames::vrdisplaypresentchange, true, false, this, "")); 639 EventTypeNames::vrdisplaypresentchange, true, false, this, ""));
624 } 640 }
625 641
626 void VRDisplay::OnChanged(device::mojom::blink::VRDisplayInfoPtr display) { 642 void VRDisplay::OnChanged(device::mojom::blink::VRDisplayInfoPtr display) {
627 update(display); 643 update(display);
628 } 644 }
629 645
630 void VRDisplay::OnExitPresent() { 646 void VRDisplay::OnExitPresent() {
631 forceExitPresent(); 647 forceExitPresent();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 visitor->trace(m_capabilities); 701 visitor->trace(m_capabilities);
686 visitor->trace(m_stageParameters); 702 visitor->trace(m_stageParameters);
687 visitor->trace(m_eyeParametersLeft); 703 visitor->trace(m_eyeParametersLeft);
688 visitor->trace(m_eyeParametersRight); 704 visitor->trace(m_eyeParametersRight);
689 visitor->trace(m_layer); 705 visitor->trace(m_layer);
690 visitor->trace(m_renderingContext); 706 visitor->trace(m_renderingContext);
691 visitor->trace(m_scriptedAnimationController); 707 visitor->trace(m_scriptedAnimationController);
692 } 708 }
693 709
694 } // namespace blink 710 } // 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