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" |
11 #include "core/dom/Fullscreen.h" | |
12 #include "core/dom/ScriptedAnimationController.h" | 11 #include "core/dom/ScriptedAnimationController.h" |
13 #include "core/dom/TaskRunnerHelper.h" | 12 #include "core/dom/TaskRunnerHelper.h" |
| 13 #include "core/frame/FrameView.h" |
| 14 #include "core/frame/ImageBitmap.h" |
14 #include "core/frame/UseCounter.h" | 15 #include "core/frame/UseCounter.h" |
15 #include "core/inspector/ConsoleMessage.h" | 16 #include "core/inspector/ConsoleMessage.h" |
| 17 #include "core/layout/LayoutView.h" |
| 18 #include "core/layout/compositing/PaintLayerCompositor.h" |
16 #include "core/loader/DocumentLoader.h" | 19 #include "core/loader/DocumentLoader.h" |
17 #include "gpu/command_buffer/client/gles2_interface.h" | 20 #include "gpu/command_buffer/client/gles2_interface.h" |
| 21 #include "gpu/command_buffer/common/mailbox_holder.h" |
18 #include "modules/EventTargetModules.h" | 22 #include "modules/EventTargetModules.h" |
19 #include "modules/vr/NavigatorVR.h" | 23 #include "modules/vr/NavigatorVR.h" |
20 #include "modules/vr/VRController.h" | 24 #include "modules/vr/VRController.h" |
21 #include "modules/vr/VRDisplayCapabilities.h" | 25 #include "modules/vr/VRDisplayCapabilities.h" |
22 #include "modules/vr/VREyeParameters.h" | 26 #include "modules/vr/VREyeParameters.h" |
23 #include "modules/vr/VRFrameData.h" | 27 #include "modules/vr/VRFrameData.h" |
24 #include "modules/vr/VRLayer.h" | 28 #include "modules/vr/VRLayer.h" |
25 #include "modules/vr/VRPose.h" | 29 #include "modules/vr/VRPose.h" |
26 #include "modules/vr/VRStageParameters.h" | 30 #include "modules/vr/VRStageParameters.h" |
27 #include "modules/webgl/WebGLRenderingContextBase.h" | 31 #include "modules/webgl/WebGLRenderingContextBase.h" |
28 #include "platform/Histogram.h" | 32 #include "platform/Histogram.h" |
29 #include "platform/UserGestureIndicator.h" | 33 #include "platform/UserGestureIndicator.h" |
| 34 #include "platform/instrumentation/tracing/TraceEvent.h" |
30 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
31 #include "wtf/AutoReset.h" | 36 #include "wtf/AutoReset.h" |
32 #include "wtf/Time.h" | 37 #include "wtf/Time.h" |
33 | 38 |
34 #include <array> | 39 #include <array> |
35 | 40 |
36 namespace blink { | 41 namespace blink { |
37 | 42 |
38 namespace { | 43 namespace { |
39 | 44 |
40 // Magic numbers used to mark valid pose index values encoded in frame | |
41 // data. Must match the magic numbers used in vr_shell.cc. | |
42 static constexpr std::array<uint8_t, 2> kWebVrPosePixelMagicNumbers{{42, 142}}; | |
43 | |
44 VREye stringToVREye(const String& whichEye) { | 45 VREye stringToVREye(const String& whichEye) { |
45 if (whichEye == "left") | 46 if (whichEye == "left") |
46 return VREyeLeft; | 47 return VREyeLeft; |
47 if (whichEye == "right") | 48 if (whichEye == "right") |
48 return VREyeRight; | 49 return VREyeRight; |
49 return VREyeNone; | 50 return VREyeNone; |
50 } | 51 } |
51 | 52 |
52 } // namespace | 53 } // namespace |
53 | 54 |
54 VRDisplay::VRDisplay(NavigatorVR* navigatorVR, | 55 VRDisplay::VRDisplay(NavigatorVR* navigatorVR, |
55 device::mojom::blink::VRDisplayPtr display, | 56 device::mojom::blink::VRDisplayPtr display, |
56 device::mojom::blink::VRDisplayClientRequest request) | 57 device::mojom::blink::VRDisplayClientRequest request) |
57 : ContextLifecycleObserver(navigatorVR->document()), | 58 : ContextLifecycleObserver(navigatorVR->document()), |
58 m_navigatorVR(navigatorVR), | 59 m_navigatorVR(navigatorVR), |
59 m_capabilities(new VRDisplayCapabilities()), | 60 m_capabilities(new VRDisplayCapabilities()), |
60 m_eyeParametersLeft(new VREyeParameters()), | 61 m_eyeParametersLeft(new VREyeParameters()), |
61 m_eyeParametersRight(new VREyeParameters()), | 62 m_eyeParametersRight(new VREyeParameters()), |
62 m_fullscreenCheckTimer( | |
63 TaskRunnerHelper::get(TaskType::UnspecedTimer, | |
64 navigatorVR->document()->frame()), | |
65 this, | |
66 &VRDisplay::onFullscreenCheck), | |
67 m_display(std::move(display)), | 63 m_display(std::move(display)), |
| 64 m_submit_frame_client_binding(this), |
68 m_displayClientBinding(this, std::move(request)) {} | 65 m_displayClientBinding(this, std::move(request)) {} |
69 | 66 |
70 VRDisplay::~VRDisplay() {} | 67 VRDisplay::~VRDisplay() {} |
71 | 68 |
72 VRController* VRDisplay::controller() { | 69 VRController* VRDisplay::controller() { |
73 return m_navigatorVR->controller(); | 70 return m_navigatorVR->controller(); |
74 } | 71 } |
75 | 72 |
76 void VRDisplay::update(const device::mojom::blink::VRDisplayInfoPtr& display) { | 73 void VRDisplay::update(const device::mojom::blink::VRDisplayInfoPtr& display) { |
77 m_displayId = display->index; | 74 m_displayId = display->index; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // allowed outside a user gesture so that the presented content may be | 229 // allowed outside a user gesture so that the presented content may be |
233 // updated. | 230 // updated. |
234 if (firstPresent && !UserGestureIndicator::utilizeUserGesture()) { | 231 if (firstPresent && !UserGestureIndicator::utilizeUserGesture()) { |
235 DOMException* exception = DOMException::create( | 232 DOMException* exception = DOMException::create( |
236 InvalidStateError, "API can only be initiated by a user gesture."); | 233 InvalidStateError, "API can only be initiated by a user gesture."); |
237 resolver->reject(exception); | 234 resolver->reject(exception); |
238 ReportPresentationResult(PresentationResult::NotInitiatedByUserGesture); | 235 ReportPresentationResult(PresentationResult::NotInitiatedByUserGesture); |
239 return promise; | 236 return promise; |
240 } | 237 } |
241 | 238 |
242 // TODO(mthiesse): Remove fullscreen requirement for presentation. See | |
243 // crbug.com/687369 | |
244 Document* doc = this->document(); | |
245 if (!doc || !Fullscreen::fullscreenEnabled(*doc)) { | |
246 DOMException* exception = | |
247 DOMException::create(InvalidStateError, "Fullscreen is not enabled."); | |
248 resolver->reject(exception); | |
249 ReportPresentationResult(PresentationResult::FullscreenNotEnabled); | |
250 return promise; | |
251 } | |
252 | |
253 // 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. |
254 if (layers.size() == 0 || layers.size() > m_capabilities->maxLayers()) { | 240 if (layers.size() == 0 || layers.size() > m_capabilities->maxLayers()) { |
255 forceExitPresent(); | 241 forceExitPresent(); |
256 DOMException* exception = | 242 DOMException* exception = |
257 DOMException::create(InvalidStateError, "Invalid number of layers."); | 243 DOMException::create(InvalidStateError, "Invalid number of layers."); |
258 resolver->reject(exception); | 244 resolver->reject(exception); |
259 ReportPresentationResult(PresentationResult::InvalidNumberOfLayers); | 245 ReportPresentationResult(PresentationResult::InvalidNumberOfLayers); |
260 return promise; | 246 return promise; |
261 } | 247 } |
262 | 248 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 "VR Presentation not implemented for this VRDisplay."); | 374 "VR Presentation not implemented for this VRDisplay."); |
389 while (!m_pendingPresentResolvers.isEmpty()) { | 375 while (!m_pendingPresentResolvers.isEmpty()) { |
390 ScriptPromiseResolver* resolver = m_pendingPresentResolvers.takeFirst(); | 376 ScriptPromiseResolver* resolver = m_pendingPresentResolvers.takeFirst(); |
391 resolver->reject(exception); | 377 resolver->reject(exception); |
392 } | 378 } |
393 ReportPresentationResult( | 379 ReportPresentationResult( |
394 PresentationResult::PresentationNotSupportedByDisplay); | 380 PresentationResult::PresentationNotSupportedByDisplay); |
395 return; | 381 return; |
396 } else { | 382 } else { |
397 if (m_layer.source().isHTMLCanvasElement()) { | 383 if (m_layer.source().isHTMLCanvasElement()) { |
398 HTMLCanvasElement* canvas = m_layer.source().getAsHTMLCanvasElement(); | 384 // TODO(klausw,crbug.com/698923): suppress compositor updates |
399 // TODO(klausw,crbug.com/655722): Need a proper VR compositor, but | 385 // since they aren't needed, they do a fair amount of extra |
400 // for the moment on mobile we'll just make the canvas fullscreen | 386 // work. |
401 // so that VrShell can pick it up through the standard (high | |
402 // latency) compositing path. auto canvas = | |
403 // m_layer.source().getAsHTMLCanvasElement(); | |
404 auto inlineStyle = canvas->inlineStyle(); | |
405 if (inlineStyle) { | |
406 // THREE.js's VREffect sets explicit style.width/height on its rendering | |
407 // canvas based on the non-fullscreen window dimensions, and it keeps | |
408 // those unchanged when presenting. Unfortunately it appears that a | |
409 // fullscreened canvas just gets centered if it has explicitly set a | |
410 // size smaller than the fullscreen dimensions. Manually set size to | |
411 // 100% in this case and restore it when exiting fullscreen. This is a | |
412 // stopgap measure since THREE.js's usage appears legal according to the | |
413 // WebVR API spec. This will no longer be necessary once we can get rid | |
414 // of this fullscreen hack. | |
415 m_fullscreenOrigWidth = inlineStyle->getPropertyValue(CSSPropertyWidth); | |
416 if (!m_fullscreenOrigWidth.isNull()) { | |
417 canvas->setInlineStyleProperty(CSSPropertyWidth, "100%"); | |
418 } | |
419 m_fullscreenOrigHeight = | |
420 inlineStyle->getPropertyValue(CSSPropertyHeight); | |
421 if (!m_fullscreenOrigHeight.isNull()) { | |
422 canvas->setInlineStyleProperty(CSSPropertyHeight, "100%"); | |
423 } | |
424 } else { | |
425 m_fullscreenOrigWidth = String(); | |
426 m_fullscreenOrigHeight = String(); | |
427 } | |
428 | |
429 if (doc) { | |
430 // Since the callback for requestPresent is asynchronous, we've lost our | |
431 // UserGestureToken, and need to create a new one to enter fullscreen. | |
432 gestureIndicator = WTF::wrapUnique( | |
433 new UserGestureIndicator(DocumentUserGestureToken::create( | |
434 doc, UserGestureToken::Status::PossiblyExistingGesture))); | |
435 } | |
436 Fullscreen::requestFullscreen(*canvas); | |
437 | |
438 // Check to see if the canvas is still the current fullscreen | |
439 // element once every 2 seconds. | |
440 m_fullscreenCheckTimer.startRepeating(2.0, BLINK_FROM_HERE); | |
441 m_reenteredFullscreen = false; | |
442 } else { | 387 } else { |
443 DCHECK(m_layer.source().isOffscreenCanvas()); | 388 DCHECK(m_layer.source().isOffscreenCanvas()); |
444 // TODO(junov, crbug.com/695497): Implement OffscreenCanvas presentation | 389 // TODO(junov, crbug.com/695497): Implement OffscreenCanvas presentation |
445 forceExitPresent(); | 390 forceExitPresent(); |
446 DOMException* exception = DOMException::create( | 391 DOMException* exception = DOMException::create( |
447 InvalidStateError, "OffscreenCanvas presentation not implemented."); | 392 InvalidStateError, "OffscreenCanvas presentation not implemented."); |
448 while (!m_pendingPresentResolvers.isEmpty()) { | 393 while (!m_pendingPresentResolvers.isEmpty()) { |
449 ScriptPromiseResolver* resolver = m_pendingPresentResolvers.takeFirst(); | 394 ScriptPromiseResolver* resolver = m_pendingPresentResolvers.takeFirst(); |
450 resolver->reject(exception); | 395 resolver->reject(exception); |
451 } | 396 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 } else { | 457 } else { |
513 // Right eye defaults | 458 // Right eye defaults |
514 rightBounds->left = 0.5f; | 459 rightBounds->left = 0.5f; |
515 rightBounds->top = 0.0f; | 460 rightBounds->top = 0.0f; |
516 rightBounds->width = 0.5f; | 461 rightBounds->width = 0.5f; |
517 rightBounds->height = 1.0f; | 462 rightBounds->height = 1.0f; |
518 m_layer.setRightBounds({0.5f, 0.0f, 0.5f, 1.0f}); | 463 m_layer.setRightBounds({0.5f, 0.0f, 0.5f, 1.0f}); |
519 } | 464 } |
520 | 465 |
521 m_display->UpdateLayerBounds(m_vrFrameId, std::move(leftBounds), | 466 m_display->UpdateLayerBounds(m_vrFrameId, std::move(leftBounds), |
522 std::move(rightBounds)); | 467 std::move(rightBounds), m_sourceWidth, |
| 468 m_sourceHeight); |
523 } | 469 } |
524 | 470 |
525 HeapVector<VRLayer> VRDisplay::getLayers() { | 471 HeapVector<VRLayer> VRDisplay::getLayers() { |
526 HeapVector<VRLayer> layers; | 472 HeapVector<VRLayer> layers; |
527 | 473 |
528 if (m_isPresenting) { | 474 if (m_isPresenting) { |
529 layers.push_back(m_layer); | 475 layers.push_back(m_layer); |
530 } | 476 } |
531 | 477 |
532 return layers; | 478 return layers; |
533 } | 479 } |
534 | 480 |
535 void VRDisplay::submitFrame() { | 481 void VRDisplay::submitFrame() { |
536 if (!m_display) | 482 if (!m_display) |
537 return; | 483 return; |
| 484 TRACE_EVENT1("gpu", "submitFrame", "frame", m_vrFrameId); |
538 | 485 |
539 Document* doc = this->document(); | 486 Document* doc = this->document(); |
540 if (!m_isPresenting) { | 487 if (!m_isPresenting) { |
541 if (doc) { | 488 if (doc) { |
542 doc->addConsoleMessage(ConsoleMessage::create( | 489 doc->addConsoleMessage(ConsoleMessage::create( |
543 RenderingMessageSource, WarningMessageLevel, | 490 RenderingMessageSource, WarningMessageLevel, |
544 "submitFrame has no effect when the VRDisplay is not presenting.")); | 491 "submitFrame has no effect when the VRDisplay is not presenting.")); |
545 } | 492 } |
546 return; | 493 return; |
547 } | 494 } |
548 | 495 |
549 if (!m_inAnimationFrame) { | 496 if (!m_inAnimationFrame) { |
550 if (doc) { | 497 if (doc) { |
551 doc->addConsoleMessage( | 498 doc->addConsoleMessage( |
552 ConsoleMessage::create(RenderingMessageSource, WarningMessageLevel, | 499 ConsoleMessage::create(RenderingMessageSource, WarningMessageLevel, |
553 "submitFrame must be called within a " | 500 "submitFrame must be called within a " |
554 "VRDisplay.requestAnimationFrame callback.")); | 501 "VRDisplay.requestAnimationFrame callback.")); |
555 } | 502 } |
556 return; | 503 return; |
557 } | 504 } |
558 | 505 |
559 if (!m_contextGL) { | 506 if (!m_contextGL) { |
560 // Something got confused, we can't submit frames without a GL context. | 507 // Something got confused, we can't submit frames without a GL context. |
561 return; | 508 return; |
562 } | 509 } |
563 | 510 |
564 // No frame Id to write before submitting the frame. | 511 // No frame Id to write before submitting the frame. |
565 if (m_vrFrameId < 0) { | 512 if (m_vrFrameId < 0) { |
566 m_display->SubmitFrame(m_framePose.Clone()); | 513 // TODO(klausw): There used to be a submitFrame here, but we can't |
| 514 // submit without a frameId and associated pose data. Just drop it. |
567 return; | 515 return; |
568 } | 516 } |
569 | 517 |
570 // Write the frame number for the pose used into a bottom left pixel block. | 518 m_contextGL->Flush(); |
571 // It is read by chrome/browser/android/vr_shell/vr_shell.cc to associate | 519 auto elem = m_layer.source(); |
572 // the correct corresponding pose for submission. | |
573 auto gl = m_contextGL; | |
574 | 520 |
575 // We must ensure that the WebGL app's GL state is preserved. We do this by | 521 // Check if the canvas got resized, if yes send a bounds update. |
576 // calling low-level GL commands directly so that the rendering context's | 522 int currentWidth = m_renderingContext->drawingBufferWidth(); |
577 // saved parameters don't get overwritten. | 523 int currentHeight = m_renderingContext->drawingBufferHeight(); |
| 524 if ((currentWidth != m_sourceWidth || currentHeight != m_sourceHeight) && |
| 525 currentWidth != 0 && currentHeight != 0) { |
| 526 m_sourceWidth = currentWidth; |
| 527 m_sourceHeight = currentHeight; |
| 528 updateLayerBounds(); |
| 529 } |
578 | 530 |
579 gl->Enable(GL_SCISSOR_TEST); | 531 // There's two types of synchronization needed for submitting frames: |
580 // Use a few pixels to ensure we get a clean color. The resolution for the | 532 // |
581 // WebGL buffer may not match the final rendered destination size, and | 533 // - Before submitting, need to wait for the previous frame to be |
582 // texture filtering could interfere for single pixels. This isn't visible | 534 // pulled off the transfer surface to avoid lost frames. This |
583 // since the final rendering hides the edges via a vignette effect. | 535 // is currently a compile-time option, normally we always want |
584 gl->Scissor(0, 0, 4, 4); | 536 // to defer this wait to increase parallelism. |
585 gl->ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 537 // |
586 // Careful with the arithmetic here. Float color 1.f is equivalent to int 255. | 538 // - After submitting, need to wait for the mailbox to be consumed, |
587 // Use the low byte of the index as the red component, and store an arbitrary | 539 // and must remain inside the execution context while waiting. |
588 // magic number in green/blue. This number must match the reading code in | 540 // The waitForPreviousTransferToFinish option defers this wait |
589 // vr_shell.cc. Avoid all-black/all-white. | 541 // until the next frame. That's more efficient, but seems to |
590 gl->ClearColor((m_vrFrameId & 255) / 255.0f, | 542 // cause wobbly framerates. |
591 kWebVrPosePixelMagicNumbers[0] / 255.0f, | 543 bool waitForPreviousTransferToFinish = |
592 kWebVrPosePixelMagicNumbers[1] / 255.0f, 1.0f); | 544 RuntimeEnabledFeatures::webVRExperimentalRenderingEnabled(); |
593 gl->Clear(GL_COLOR_BUFFER_BIT); | |
594 | 545 |
595 // Set the GL state back to what was set by the WebVR application. | 546 if (waitForPreviousTransferToFinish) { |
596 m_renderingContext->restoreScissorEnabled(); | 547 TRACE_EVENT0("gpu", "waitPrevXfer"); |
597 m_renderingContext->restoreScissorBox(); | 548 while (m_pendingSubmitFrame) { |
598 m_renderingContext->restoreColorMask(); | 549 if (!m_submit_frame_client_binding.WaitForIncomingMethodCall()) { |
599 m_renderingContext->restoreClearColor(); | 550 LOG(ERROR) << "Failed to receive SubmitFrame response"; |
| 551 break; |
| 552 } |
| 553 } |
| 554 } |
600 | 555 |
601 m_display->SubmitFrame(m_framePose.Clone()); | 556 auto image_ref = m_renderingContext->getImage( |
| 557 PreferAcceleration, SnapshotReasonCreateImageBitmap); |
| 558 |
| 559 // Hardware-accelerated rendering should always be texture backed. |
| 560 // I hope nobody is trying to do WebVR with software rendering. |
| 561 DCHECK(image_ref->isTextureBacked()); |
| 562 |
| 563 // The AcceleratedStaticBitmapImage must be kept alive until the |
| 564 // mailbox is used via createAndConsumeTextureCHROMIUM, the mailbox |
| 565 // itself does not keep it alive. We must keep a reference to the |
| 566 // image until the mailbox was consumed. |
| 567 StaticBitmapImage* staticImage = |
| 568 static_cast<StaticBitmapImage*>(image_ref.get()); |
| 569 staticImage->ensureMailbox(); |
| 570 |
| 571 if (waitForPreviousTransferToFinish) { |
| 572 // Save a reference to the image to keep it alive until next frame, |
| 573 // where we'll wait for the transfer to finish before overwriting |
| 574 // it. |
| 575 m_previousImage = std::move(image_ref); |
| 576 } |
| 577 |
| 578 // Wait for the previous render to finish, to avoid losing frames in the |
| 579 // Android Surface / GLConsumer pair. TODO(klausw): make this tunable? |
| 580 // Other devices may have different preferences. |
| 581 { |
| 582 TRACE_EVENT0("gpu", "waitPrevRender"); |
| 583 while (m_pendingPreviousFrameRender) { |
| 584 if (!m_submit_frame_client_binding.WaitForIncomingMethodCall()) { |
| 585 LOG(ERROR) << "Failed to receive SubmitFrame response"; |
| 586 break; |
| 587 } |
| 588 } |
| 589 TRACE_EVENT_END0("gpu", "waitPrevRender"); |
| 590 } |
| 591 |
| 592 m_pendingPreviousFrameRender = true; |
| 593 m_pendingSubmitFrame = true; |
| 594 m_display->SubmitFrame( |
| 595 m_vrFrameId, |
| 596 gpu::MailboxHolder(staticImage->mailbox(), staticImage->syncToken(), |
| 597 GL_TEXTURE_2D), |
| 598 m_submit_frame_client_binding.CreateInterfacePtrAndBind()); |
| 599 |
| 600 // If we're not deferring the wait for transferring the mailbox, |
| 601 // we need to wait for it now to prevent the image going out of |
| 602 // scope before its mailbox is retrieved. |
| 603 if (!waitForPreviousTransferToFinish) { |
| 604 TRACE_EVENT0("gpu", "waitCurrXfer"); |
| 605 while (m_pendingSubmitFrame) { |
| 606 if (!m_submit_frame_client_binding.WaitForIncomingMethodCall()) { |
| 607 LOG(ERROR) << "Failed to receive SubmitFrame response"; |
| 608 break; |
| 609 } |
| 610 } |
| 611 } |
| 612 } |
| 613 |
| 614 void VRDisplay::OnSubmitFrameTransferred() { |
| 615 m_pendingSubmitFrame = false; |
| 616 } |
| 617 |
| 618 void VRDisplay::OnSubmitFrameRendered() { |
| 619 m_pendingPreviousFrameRender = false; |
602 } | 620 } |
603 | 621 |
604 Document* VRDisplay::document() { | 622 Document* VRDisplay::document() { |
605 return m_navigatorVR->document(); | 623 return m_navigatorVR->document(); |
606 } | 624 } |
607 | 625 |
608 void VRDisplay::OnPresentChange() { | 626 void VRDisplay::OnPresentChange() { |
609 if (m_isPresenting && !m_isValidDeviceForPresenting) { | 627 if (m_isPresenting && !m_isValidDeviceForPresenting) { |
610 VLOG(1) << __FUNCTION__ << ": device not valid, not sending event"; | 628 VLOG(1) << __FUNCTION__ << ": device not valid, not sending event"; |
611 return; | 629 return; |
(...skipping 17 matching lines...) Expand all Loading... |
629 | 647 |
630 void VRDisplay::onDisconnected() { | 648 void VRDisplay::onDisconnected() { |
631 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( | 649 m_navigatorVR->enqueueVREvent(VRDisplayEvent::create( |
632 EventTypeNames::vrdisplaydisconnect, true, false, this, "disconnect")); | 650 EventTypeNames::vrdisplaydisconnect, true, false, this, "disconnect")); |
633 } | 651 } |
634 | 652 |
635 void VRDisplay::stopPresenting() { | 653 void VRDisplay::stopPresenting() { |
636 if (m_isPresenting) { | 654 if (m_isPresenting) { |
637 if (!m_capabilities->hasExternalDisplay()) { | 655 if (!m_capabilities->hasExternalDisplay()) { |
638 if (m_layer.source().isHTMLCanvasElement()) { | 656 if (m_layer.source().isHTMLCanvasElement()) { |
639 auto canvas = m_layer.source().getAsHTMLCanvasElement(); | 657 // TODO(klausw,crbug.com/698923): If compositor updates are |
640 Fullscreen::fullyExitFullscreen(canvas->document()); | 658 // suppressed, restore them here. |
641 m_fullscreenCheckTimer.stop(); | |
642 if (!m_fullscreenOrigWidth.isNull()) { | |
643 canvas->setInlineStyleProperty(CSSPropertyWidth, | |
644 m_fullscreenOrigWidth); | |
645 m_fullscreenOrigWidth = String(); | |
646 } | |
647 if (!m_fullscreenOrigHeight.isNull()) { | |
648 canvas->setInlineStyleProperty(CSSPropertyWidth, | |
649 m_fullscreenOrigHeight); | |
650 m_fullscreenOrigHeight = String(); | |
651 } | |
652 } else { | 659 } else { |
653 // TODO(junov, crbug.com/695497): Implement for OffscreenCanvas | 660 // TODO(junov, crbug.com/695497): Implement for OffscreenCanvas |
654 } | 661 } |
655 } else { | 662 } else { |
656 // Can't get into this presentation mode, so nothing to do here. | 663 // Can't get into this presentation mode, so nothing to do here. |
657 } | 664 } |
658 m_isPresenting = false; | 665 m_isPresenting = false; |
659 OnPresentChange(); | 666 OnPresentChange(); |
660 } | 667 } |
661 | 668 |
662 m_renderingContext = nullptr; | 669 m_renderingContext = nullptr; |
663 m_contextGL = nullptr; | 670 m_contextGL = nullptr; |
| 671 m_pendingSubmitFrame = false; |
| 672 m_pendingPreviousFrameRender = false; |
664 } | 673 } |
665 | 674 |
666 void VRDisplay::OnActivate(device::mojom::blink::VRDisplayEventReason reason) { | 675 void VRDisplay::OnActivate(device::mojom::blink::VRDisplayEventReason reason) { |
667 if (!m_navigatorVR->isFocused() || m_displayBlurred) | 676 if (!m_navigatorVR->isFocused() || m_displayBlurred) |
668 return; | 677 return; |
669 m_navigatorVR->dispatchVRGestureEvent(VRDisplayEvent::create( | 678 m_navigatorVR->dispatchVRGestureEvent(VRDisplayEvent::create( |
670 EventTypeNames::vrdisplayactivate, true, false, this, reason)); | 679 EventTypeNames::vrdisplayactivate, true, false, this, reason)); |
671 } | 680 } |
672 | 681 |
673 void VRDisplay::OnDeactivate( | 682 void VRDisplay::OnDeactivate( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 if (!m_navigatorVR->isFocused() || m_vrVSyncProvider.is_bound()) | 725 if (!m_navigatorVR->isFocused() || m_vrVSyncProvider.is_bound()) |
717 return; | 726 return; |
718 m_display->GetVRVSyncProvider(mojo::MakeRequest(&m_vrVSyncProvider)); | 727 m_display->GetVRVSyncProvider(mojo::MakeRequest(&m_vrVSyncProvider)); |
719 if (m_pendingRaf && !m_displayBlurred) { | 728 if (m_pendingRaf && !m_displayBlurred) { |
720 m_pendingVsync = true; | 729 m_pendingVsync = true; |
721 m_vrVSyncProvider->GetVSync(convertToBaseCallback( | 730 m_vrVSyncProvider->GetVSync(convertToBaseCallback( |
722 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); | 731 WTF::bind(&VRDisplay::OnVSync, wrapWeakPersistent(this)))); |
723 } | 732 } |
724 } | 733 } |
725 | 734 |
726 void VRDisplay::onFullscreenCheck(TimerBase*) { | |
727 DCHECK(m_layer.source().isHTMLCanvasElement()); | |
728 if (!m_isPresenting) { | |
729 m_fullscreenCheckTimer.stop(); | |
730 return; | |
731 } | |
732 // TODO: This is a temporary measure to track if fullscreen mode has been | |
733 // exited by the UA. If so we need to end VR presentation. Soon we won't | |
734 // depend on the Fullscreen API to fake VR presentation, so this will | |
735 // become unnessecary. Until that point, though, this seems preferable to | |
736 // adding a bunch of notification plumbing to Fullscreen. | |
737 if (!Fullscreen::isCurrentFullScreenElement( | |
738 *m_layer.source().getAsHTMLCanvasElement())) { | |
739 // TODO(mthiesse): Due to asynchronous resizing, we might get kicked out of | |
740 // fullscreen when changing display parameters upon entering WebVR. So one | |
741 // time only, we reenter fullscreen after having left it; otherwise we exit | |
742 // presentation. | |
743 if (m_reenteredFullscreen) { | |
744 m_isPresenting = false; | |
745 OnPresentChange(); | |
746 m_fullscreenCheckTimer.stop(); | |
747 if (m_display) | |
748 m_display->ExitPresent(); | |
749 return; | |
750 } | |
751 m_reenteredFullscreen = true; | |
752 auto canvas = m_layer.source().getAsHTMLCanvasElement(); | |
753 Document* doc = this->document(); | |
754 std::unique_ptr<UserGestureIndicator> gestureIndicator; | |
755 if (doc) { | |
756 gestureIndicator = WTF::wrapUnique( | |
757 new UserGestureIndicator(DocumentUserGestureToken::create( | |
758 doc, UserGestureToken::Status::PossiblyExistingGesture))); | |
759 } | |
760 Fullscreen::requestFullscreen(*canvas); | |
761 } | |
762 } | |
763 | |
764 ScriptedAnimationController& VRDisplay::ensureScriptedAnimationController( | 735 ScriptedAnimationController& VRDisplay::ensureScriptedAnimationController( |
765 Document* doc) { | 736 Document* doc) { |
766 if (!m_scriptedAnimationController) | 737 if (!m_scriptedAnimationController) |
767 m_scriptedAnimationController = ScriptedAnimationController::create(doc); | 738 m_scriptedAnimationController = ScriptedAnimationController::create(doc); |
768 | 739 |
769 return *m_scriptedAnimationController; | 740 return *m_scriptedAnimationController; |
770 } | 741 } |
771 | 742 |
772 void VRDisplay::dispose() { | 743 void VRDisplay::dispose() { |
773 m_displayClientBinding.Close(); | 744 m_displayClientBinding.Close(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 visitor->trace(m_stageParameters); | 778 visitor->trace(m_stageParameters); |
808 visitor->trace(m_eyeParametersLeft); | 779 visitor->trace(m_eyeParametersLeft); |
809 visitor->trace(m_eyeParametersRight); | 780 visitor->trace(m_eyeParametersRight); |
810 visitor->trace(m_layer); | 781 visitor->trace(m_layer); |
811 visitor->trace(m_renderingContext); | 782 visitor->trace(m_renderingContext); |
812 visitor->trace(m_scriptedAnimationController); | 783 visitor->trace(m_scriptedAnimationController); |
813 visitor->trace(m_pendingPresentResolvers); | 784 visitor->trace(m_pendingPresentResolvers); |
814 } | 785 } |
815 | 786 |
816 } // namespace blink | 787 } // namespace blink |
OLD | NEW |