| 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" | |
| 10 #include "core/dom/FrameRequestCallback.h" | 9 #include "core/dom/FrameRequestCallback.h" |
| 11 #include "core/dom/ScriptedAnimationController.h" | 10 #include "core/dom/ScriptedAnimationController.h" |
| 12 #include "core/dom/TaskRunnerHelper.h" | 11 #include "core/dom/TaskRunnerHelper.h" |
| 13 #include "core/frame/FrameView.h" | 12 #include "core/frame/FrameView.h" |
| 14 #include "core/frame/ImageBitmap.h" | 13 #include "core/frame/ImageBitmap.h" |
| 15 #include "core/frame/UseCounter.h" | 14 #include "core/frame/UseCounter.h" |
| 16 #include "core/inspector/ConsoleMessage.h" | 15 #include "core/inspector/ConsoleMessage.h" |
| 17 #include "core/layout/LayoutView.h" | 16 #include "core/layout/LayoutView.h" |
| 18 #include "core/layout/compositing/PaintLayerCompositor.h" | 17 #include "core/layout/compositing/PaintLayerCompositor.h" |
| 19 #include "core/loader/DocumentLoader.h" | 18 #include "core/loader/DocumentLoader.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 ReportPresentationResult(PresentationResult::VRDisplayCannotPresent); | 220 ReportPresentationResult(PresentationResult::VRDisplayCannotPresent); |
| 222 return promise; | 221 return promise; |
| 223 } | 222 } |
| 224 | 223 |
| 225 bool firstPresent = !m_isPresenting; | 224 bool firstPresent = !m_isPresenting; |
| 226 | 225 |
| 227 // Initiating VR presentation is only allowed in response to a user gesture. | 226 // Initiating VR presentation is only allowed in response to a user gesture. |
| 228 // If the VRDisplay is already presenting, however, repeated calls are | 227 // If the VRDisplay is already presenting, however, repeated calls are |
| 229 // allowed outside a user gesture so that the presented content may be | 228 // allowed outside a user gesture so that the presented content may be |
| 230 // updated. | 229 // updated. |
| 231 if (firstPresent && !UserGestureIndicator::utilizeUserGesture()) { | 230 if (firstPresent && !UserGestureIndicator::utilizeUserGesture() && |
| 231 !m_inDisplayActivate) { |
| 232 DOMException* exception = DOMException::create( | 232 DOMException* exception = DOMException::create( |
| 233 InvalidStateError, "API can only be initiated by a user gesture."); | 233 InvalidStateError, "API can only be initiated by a user gesture."); |
| 234 resolver->reject(exception); | 234 resolver->reject(exception); |
| 235 ReportPresentationResult(PresentationResult::NotInitiatedByUserGesture); | 235 ReportPresentationResult(PresentationResult::NotInitiatedByUserGesture); |
| 236 return promise; | 236 return promise; |
| 237 } | 237 } |
| 238 | 238 |
| 239 // A valid number of layers must be provided in order to present. | 239 // A valid number of layers must be provided in order to present. |
| 240 if (layers.size() == 0 || layers.size() > m_capabilities->maxLayers()) { | 240 if (layers.size() == 0 || layers.size() > m_capabilities->maxLayers()) { |
| 241 forceExitPresent(); | 241 forceExitPresent(); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 362 |
| 363 resolver->resolve(); | 363 resolver->resolve(); |
| 364 | 364 |
| 365 stopPresenting(); | 365 stopPresenting(); |
| 366 | 366 |
| 367 return promise; | 367 return promise; |
| 368 } | 368 } |
| 369 | 369 |
| 370 void VRDisplay::beginPresent() { | 370 void VRDisplay::beginPresent() { |
| 371 Document* doc = this->document(); | 371 Document* doc = this->document(); |
| 372 std::unique_ptr<UserGestureIndicator> gestureIndicator; | |
| 373 if (m_capabilities->hasExternalDisplay()) { | 372 if (m_capabilities->hasExternalDisplay()) { |
| 374 forceExitPresent(); | 373 forceExitPresent(); |
| 375 DOMException* exception = DOMException::create( | 374 DOMException* exception = DOMException::create( |
| 376 InvalidStateError, | 375 InvalidStateError, |
| 377 "VR Presentation not implemented for this VRDisplay."); | 376 "VR Presentation not implemented for this VRDisplay."); |
| 378 while (!m_pendingPresentResolvers.isEmpty()) { | 377 while (!m_pendingPresentResolvers.isEmpty()) { |
| 379 ScriptPromiseResolver* resolver = m_pendingPresentResolvers.takeFirst(); | 378 ScriptPromiseResolver* resolver = m_pendingPresentResolvers.takeFirst(); |
| 380 resolver->reject(exception); | 379 resolver->reject(exception); |
| 381 } | 380 } |
| 382 ReportPresentationResult( | 381 ReportPresentationResult( |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 671 |
| 673 m_renderingContext = nullptr; | 672 m_renderingContext = nullptr; |
| 674 m_contextGL = nullptr; | 673 m_contextGL = nullptr; |
| 675 m_pendingSubmitFrame = false; | 674 m_pendingSubmitFrame = false; |
| 676 m_pendingPreviousFrameRender = false; | 675 m_pendingPreviousFrameRender = false; |
| 677 } | 676 } |
| 678 | 677 |
| 679 void VRDisplay::OnActivate(device::mojom::blink::VRDisplayEventReason reason) { | 678 void VRDisplay::OnActivate(device::mojom::blink::VRDisplayEventReason reason) { |
| 680 if (!m_navigatorVR->isFocused() || m_displayBlurred) | 679 if (!m_navigatorVR->isFocused() || m_displayBlurred) |
| 681 return; | 680 return; |
| 682 m_navigatorVR->dispatchVRGestureEvent(VRDisplayEvent::create( | 681 AutoReset<bool> activating(&m_inDisplayActivate, true); |
| 682 m_navigatorVR->dispatchVREvent(VRDisplayEvent::create( |
| 683 EventTypeNames::vrdisplayactivate, true, false, this, reason)); | 683 EventTypeNames::vrdisplayactivate, true, false, this, reason)); |
| 684 } | 684 } |
| 685 | 685 |
| 686 void VRDisplay::OnDeactivate( | 686 void VRDisplay::OnDeactivate( |
| 687 device::mojom::blink::VRDisplayEventReason reason) { | 687 device::mojom::blink::VRDisplayEventReason reason) { |
| 688 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( | 688 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
| 689 EventTypeNames::vrdisplaydeactivate, true, false, this, reason)); | 689 EventTypeNames::vrdisplaydeactivate, true, false, this, reason)); |
| 690 } | 690 } |
| 691 | 691 |
| 692 void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, | 692 void VRDisplay::OnVSync(device::mojom::blink::VRPosePtr pose, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 visitor->trace(m_stageParameters); | 783 visitor->trace(m_stageParameters); |
| 784 visitor->trace(m_eyeParametersLeft); | 784 visitor->trace(m_eyeParametersLeft); |
| 785 visitor->trace(m_eyeParametersRight); | 785 visitor->trace(m_eyeParametersRight); |
| 786 visitor->trace(m_layer); | 786 visitor->trace(m_layer); |
| 787 visitor->trace(m_renderingContext); | 787 visitor->trace(m_renderingContext); |
| 788 visitor->trace(m_scriptedAnimationController); | 788 visitor->trace(m_scriptedAnimationController); |
| 789 visitor->trace(m_pendingPresentResolvers); | 789 visitor->trace(m_pendingPresentResolvers); |
| 790 } | 790 } |
| 791 | 791 |
| 792 } // namespace blink | 792 } // namespace blink |
| OLD | NEW |