| 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" | 9 #include "core/dom/DocumentUserGestureToken.h" |
| 10 #include "core/dom/FrameRequestCallback.h" | 10 #include "core/dom/FrameRequestCallback.h" |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 if (!m_display) { | 358 if (!m_display) { |
| 359 DOMException* exception = | 359 DOMException* exception = |
| 360 DOMException::create(InvalidStateError, "VRService is not available."); | 360 DOMException::create(InvalidStateError, "VRService is not available."); |
| 361 resolver->reject(exception); | 361 resolver->reject(exception); |
| 362 return promise; | 362 return promise; |
| 363 } | 363 } |
| 364 m_display->ExitPresent(); | 364 m_display->ExitPresent(); |
| 365 | 365 |
| 366 resolver->resolve(); | 366 resolver->resolve(); |
| 367 | 367 |
| 368 forceExitPresent(); | 368 stopPresenting(); |
| 369 | 369 |
| 370 return promise; | 370 return promise; |
| 371 } | 371 } |
| 372 | 372 |
| 373 void VRDisplay::beginPresent() { | 373 void VRDisplay::beginPresent() { |
| 374 Document* doc = this->document(); | 374 Document* doc = this->document(); |
| 375 std::unique_ptr<UserGestureIndicator> gestureIndicator; | 375 std::unique_ptr<UserGestureIndicator> gestureIndicator; |
| 376 if (m_capabilities->hasExternalDisplay()) { | 376 if (m_capabilities->hasExternalDisplay()) { |
| 377 forceExitPresent(); | 377 forceExitPresent(); |
| 378 DOMException* exception = DOMException::create( | 378 DOMException* exception = DOMException::create( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 440 |
| 441 updateLayerBounds(); | 441 updateLayerBounds(); |
| 442 | 442 |
| 443 while (!m_pendingPresentResolvers.isEmpty()) { | 443 while (!m_pendingPresentResolvers.isEmpty()) { |
| 444 ScriptPromiseResolver* resolver = m_pendingPresentResolvers.takeFirst(); | 444 ScriptPromiseResolver* resolver = m_pendingPresentResolvers.takeFirst(); |
| 445 resolver->resolve(); | 445 resolver->resolve(); |
| 446 } | 446 } |
| 447 OnPresentChange(); | 447 OnPresentChange(); |
| 448 } | 448 } |
| 449 | 449 |
| 450 // Need to close service if exists and then free rendering context. |
| 450 void VRDisplay::forceExitPresent() { | 451 void VRDisplay::forceExitPresent() { |
| 451 if (m_isPresenting) { | 452 if (m_display) { |
| 452 if (!m_capabilities->hasExternalDisplay()) { | 453 m_display->ExitPresent(); |
| 453 auto canvas = m_layer.source(); | |
| 454 Fullscreen::fullyExitFullscreen(canvas->document()); | |
| 455 m_fullscreenCheckTimer.stop(); | |
| 456 if (!m_fullscreenOrigWidth.isNull()) { | |
| 457 canvas->setInlineStyleProperty(CSSPropertyWidth, m_fullscreenOrigWidth); | |
| 458 m_fullscreenOrigWidth = String(); | |
| 459 } | |
| 460 if (!m_fullscreenOrigHeight.isNull()) { | |
| 461 canvas->setInlineStyleProperty(CSSPropertyWidth, | |
| 462 m_fullscreenOrigHeight); | |
| 463 m_fullscreenOrigHeight = String(); | |
| 464 } | |
| 465 } else { | |
| 466 // Can't get into this presentation mode, so nothing to do here. | |
| 467 } | |
| 468 m_isPresenting = false; | |
| 469 OnPresentChange(); | |
| 470 } | 454 } |
| 471 | 455 stopPresenting(); |
| 472 m_renderingContext = nullptr; | |
| 473 m_contextGL = nullptr; | |
| 474 } | 456 } |
| 475 | 457 |
| 476 void VRDisplay::updateLayerBounds() { | 458 void VRDisplay::updateLayerBounds() { |
| 477 if (!m_display) | 459 if (!m_display) |
| 478 return; | 460 return; |
| 479 | 461 |
| 480 // Set up the texture bounds for the provided layer | 462 // Set up the texture bounds for the provided layer |
| 481 device::mojom::blink::VRLayerBoundsPtr leftBounds = | 463 device::mojom::blink::VRLayerBoundsPtr leftBounds = |
| 482 device::mojom::blink::VRLayerBounds::New(); | 464 device::mojom::blink::VRLayerBounds::New(); |
| 483 device::mojom::blink::VRLayerBoundsPtr rightBounds = | 465 device::mojom::blink::VRLayerBoundsPtr rightBounds = |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 } | 587 } |
| 606 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( | 588 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
| 607 EventTypeNames::vrdisplaypresentchange, true, false, this, "")); | 589 EventTypeNames::vrdisplaypresentchange, true, false, this, "")); |
| 608 } | 590 } |
| 609 | 591 |
| 610 void VRDisplay::OnChanged(device::mojom::blink::VRDisplayInfoPtr display) { | 592 void VRDisplay::OnChanged(device::mojom::blink::VRDisplayInfoPtr display) { |
| 611 update(display); | 593 update(display); |
| 612 } | 594 } |
| 613 | 595 |
| 614 void VRDisplay::OnExitPresent() { | 596 void VRDisplay::OnExitPresent() { |
| 615 forceExitPresent(); | 597 stopPresenting(); |
| 616 } | 598 } |
| 617 | 599 |
| 618 void VRDisplay::onConnected() { | 600 void VRDisplay::onConnected() { |
| 619 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( | 601 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
| 620 EventTypeNames::vrdisplayconnect, true, false, this, "connect")); | 602 EventTypeNames::vrdisplayconnect, true, false, this, "connect")); |
| 621 } | 603 } |
| 622 | 604 |
| 623 void VRDisplay::onDisconnected() { | 605 void VRDisplay::onDisconnected() { |
| 624 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( | 606 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
| 625 EventTypeNames::vrdisplaydisconnect, true, false, this, "disconnect")); | 607 EventTypeNames::vrdisplaydisconnect, true, false, this, "disconnect")); |
| 626 } | 608 } |
| 627 | 609 |
| 610 void VRDisplay::stopPresenting() { |
| 611 if (m_isPresenting) { |
| 612 if (!m_capabilities->hasExternalDisplay()) { |
| 613 auto canvas = m_layer.source(); |
| 614 Fullscreen::fullyExitFullscreen(canvas->document()); |
| 615 m_fullscreenCheckTimer.stop(); |
| 616 if (!m_fullscreenOrigWidth.isNull()) { |
| 617 canvas->setInlineStyleProperty(CSSPropertyWidth, m_fullscreenOrigWidth); |
| 618 m_fullscreenOrigWidth = String(); |
| 619 } |
| 620 if (!m_fullscreenOrigHeight.isNull()) { |
| 621 canvas->setInlineStyleProperty(CSSPropertyWidth, |
| 622 m_fullscreenOrigHeight); |
| 623 m_fullscreenOrigHeight = String(); |
| 624 } |
| 625 } else { |
| 626 // Can't get into this presentation mode, so nothing to do here. |
| 627 } |
| 628 m_isPresenting = false; |
| 629 OnPresentChange(); |
| 630 } |
| 631 |
| 632 m_renderingContext = nullptr; |
| 633 m_contextGL = nullptr; |
| 634 } |
| 635 |
| 628 void VRDisplay::OnActivate(device::mojom::blink::VRDisplayEventReason reason) { | 636 void VRDisplay::OnActivate(device::mojom::blink::VRDisplayEventReason reason) { |
| 629 if (!m_navigatorVR->isFocused() || m_displayBlurred) | 637 if (!m_navigatorVR->isFocused() || m_displayBlurred) |
| 630 return; | 638 return; |
| 631 m_navigatorVR->dispatchVRGestureEvent(VRDisplayEvent::create( | 639 m_navigatorVR->dispatchVRGestureEvent(VRDisplayEvent::create( |
| 632 EventTypeNames::vrdisplayactivate, true, false, this, reason)); | 640 EventTypeNames::vrdisplayactivate, true, false, this, reason)); |
| 633 } | 641 } |
| 634 | 642 |
| 635 void VRDisplay::OnDeactivate( | 643 void VRDisplay::OnDeactivate( |
| 636 device::mojom::blink::VRDisplayEventReason reason) { | 644 device::mojom::blink::VRDisplayEventReason reason) { |
| 637 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( | 645 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 visitor->trace(m_stageParameters); | 773 visitor->trace(m_stageParameters); |
| 766 visitor->trace(m_eyeParametersLeft); | 774 visitor->trace(m_eyeParametersLeft); |
| 767 visitor->trace(m_eyeParametersRight); | 775 visitor->trace(m_eyeParametersRight); |
| 768 visitor->trace(m_layer); | 776 visitor->trace(m_layer); |
| 769 visitor->trace(m_renderingContext); | 777 visitor->trace(m_renderingContext); |
| 770 visitor->trace(m_scriptedAnimationController); | 778 visitor->trace(m_scriptedAnimationController); |
| 771 visitor->trace(m_pendingPresentResolvers); | 779 visitor->trace(m_pendingPresentResolvers); |
| 772 } | 780 } |
| 773 | 781 |
| 774 } // namespace blink | 782 } // namespace blink |
| OLD | NEW |