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/dom/DOMException.h" | 8 #include "core/dom/DOMException.h" |
8 #include "core/dom/FrameRequestCallback.h" | 9 #include "core/dom/FrameRequestCallback.h" |
9 #include "core/dom/Fullscreen.h" | 10 #include "core/dom/Fullscreen.h" |
10 #include "core/dom/ScriptedAnimationController.h" | 11 #include "core/dom/ScriptedAnimationController.h" |
11 #include "core/frame/UseCounter.h" | 12 #include "core/frame/UseCounter.h" |
12 #include "core/inspector/ConsoleMessage.h" | 13 #include "core/inspector/ConsoleMessage.h" |
13 #include "gpu/command_buffer/client/gles2_interface.h" | 14 #include "gpu/command_buffer/client/gles2_interface.h" |
14 #include "modules/vr/NavigatorVR.h" | 15 #include "modules/vr/NavigatorVR.h" |
15 #include "modules/vr/VRController.h" | 16 #include "modules/vr/VRController.h" |
16 #include "modules/vr/VRDisplayCapabilities.h" | 17 #include "modules/vr/VRDisplayCapabilities.h" |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 forceExitPresent(); | 330 forceExitPresent(); |
330 DOMException* exception = DOMException::create( | 331 DOMException* exception = DOMException::create( |
331 InvalidStateError, | 332 InvalidStateError, |
332 "Layer bounds must either be an empty array or have 4 values"); | 333 "Layer bounds must either be an empty array or have 4 values"); |
333 resolver->reject(exception); | 334 resolver->reject(exception); |
334 ReportPresentationResult(PresentationResult::InvalidLayerBounds); | 335 ReportPresentationResult(PresentationResult::InvalidLayerBounds); |
335 return promise; | 336 return promise; |
336 } | 337 } |
337 | 338 |
338 if (!m_capabilities->hasExternalDisplay()) { | 339 if (!m_capabilities->hasExternalDisplay()) { |
339 // TODO: Need a proper VR compositor, but for the moment on mobile | 340 // TODO(klausw,crbug.com/655722): Need a proper VR compositor, but |
340 // we'll just make the canvas fullscreen so that VrShell can pick it | 341 // for the moment on mobile we'll just make the canvas fullscreen |
341 // up through the standard (high latency) compositing path. | 342 // so that VrShell can pick it up through the standard (high |
342 Fullscreen::requestFullscreen(*m_layer.source(), | 343 // latency) compositing path. |
343 Fullscreen::UnprefixedRequest); | 344 auto canvas = m_layer.source(); |
| 345 auto inlineStyle = canvas->inlineStyle(); |
| 346 if (inlineStyle) { |
| 347 // THREE.js's VREffect sets explicit style.width/height on its rendering |
| 348 // canvas based on the non-fullscreen window dimensions, and it keeps |
| 349 // those unchanged when presenting. Unfortunately it appears that a |
| 350 // fullscreened canvas just gets centered if it has explicitly set a |
| 351 // size smaller than the fullscreen dimensions. Manually set size to |
| 352 // 100% in this case and restore it when exiting fullscreen. This is a |
| 353 // stopgap measure since THREE.js's usage appears legal according to the |
| 354 // WebVR API spec. This will no longer be necessary once we can get rid |
| 355 // of this fullscreen hack. |
| 356 m_fullscreenOrigWidth = inlineStyle->getPropertyValue(CSSPropertyWidth); |
| 357 if (!m_fullscreenOrigWidth.isNull()) { |
| 358 canvas->setInlineStyleProperty(CSSPropertyWidth, "100%"); |
| 359 } |
| 360 m_fullscreenOrigHeight = inlineStyle->getPropertyValue(CSSPropertyHeight); |
| 361 if (!m_fullscreenOrigHeight.isNull()) { |
| 362 canvas->setInlineStyleProperty(CSSPropertyHeight, "100%"); |
| 363 } |
| 364 } else { |
| 365 m_fullscreenOrigWidth = String(); |
| 366 m_fullscreenOrigHeight = String(); |
| 367 } |
| 368 Fullscreen::requestFullscreen(*canvas, Fullscreen::UnprefixedRequest); |
344 | 369 |
345 // Check to see if the canvas is still the current fullscreen | 370 // Check to see if the canvas is still the current fullscreen |
346 // element once per second. | 371 // element once per second. |
347 m_fullscreenCheckTimer.startRepeating(1.0, BLINK_FROM_HERE); | 372 m_fullscreenCheckTimer.startRepeating(1.0, BLINK_FROM_HERE); |
348 } | 373 } |
349 | 374 |
350 if (firstPresent) { | 375 if (firstPresent) { |
351 bool secureContext = scriptState->getExecutionContext()->isSecureContext(); | 376 bool secureContext = scriptState->getExecutionContext()->isSecureContext(); |
352 if (!m_display) { | 377 if (!m_display) { |
353 forceExitPresent(); | 378 forceExitPresent(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 | 456 |
432 updateLayerBounds(); | 457 updateLayerBounds(); |
433 | 458 |
434 resolver->resolve(); | 459 resolver->resolve(); |
435 OnPresentChange(); | 460 OnPresentChange(); |
436 } | 461 } |
437 | 462 |
438 void VRDisplay::forceExitPresent() { | 463 void VRDisplay::forceExitPresent() { |
439 if (m_isPresenting) { | 464 if (m_isPresenting) { |
440 if (!m_capabilities->hasExternalDisplay()) { | 465 if (!m_capabilities->hasExternalDisplay()) { |
441 Fullscreen::fullyExitFullscreen(m_layer.source()->document()); | 466 auto canvas = m_layer.source(); |
| 467 Fullscreen::fullyExitFullscreen(canvas->document()); |
442 m_fullscreenCheckTimer.stop(); | 468 m_fullscreenCheckTimer.stop(); |
| 469 if (!m_fullscreenOrigWidth.isNull()) { |
| 470 canvas->setInlineStyleProperty(CSSPropertyWidth, m_fullscreenOrigWidth); |
| 471 m_fullscreenOrigWidth = String(); |
| 472 } |
| 473 if (!m_fullscreenOrigHeight.isNull()) { |
| 474 canvas->setInlineStyleProperty(CSSPropertyWidth, |
| 475 m_fullscreenOrigHeight); |
| 476 m_fullscreenOrigHeight = String(); |
| 477 } |
443 } else { | 478 } else { |
444 // Can't get into this presentation mode, so nothing to do here. | 479 // Can't get into this presentation mode, so nothing to do here. |
445 } | 480 } |
446 OnPresentChange(); | 481 OnPresentChange(); |
447 } | 482 } |
448 | 483 |
449 m_isPresenting = false; | 484 m_isPresenting = false; |
450 m_renderingContext = nullptr; | 485 m_renderingContext = nullptr; |
451 m_contextGL = nullptr; | 486 m_contextGL = nullptr; |
452 } | 487 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 visitor->trace(m_capabilities); | 663 visitor->trace(m_capabilities); |
629 visitor->trace(m_stageParameters); | 664 visitor->trace(m_stageParameters); |
630 visitor->trace(m_eyeParametersLeft); | 665 visitor->trace(m_eyeParametersLeft); |
631 visitor->trace(m_eyeParametersRight); | 666 visitor->trace(m_eyeParametersRight); |
632 visitor->trace(m_layer); | 667 visitor->trace(m_layer); |
633 visitor->trace(m_renderingContext); | 668 visitor->trace(m_renderingContext); |
634 visitor->trace(m_scriptedAnimationController); | 669 visitor->trace(m_scriptedAnimationController); |
635 } | 670 } |
636 | 671 |
637 } // namespace blink | 672 } // namespace blink |
OLD | NEW |