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

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

Issue 2488273002: Revert of mojo VR interface simplified (Closed)
Patch Set: Created 4 years, 1 month 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
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/dom/DOMException.h" 7 #include "core/dom/DOMException.h"
8 #include "core/dom/FrameRequestCallback.h" 8 #include "core/dom/FrameRequestCallback.h"
9 #include "core/dom/Fullscreen.h" 9 #include "core/dom/Fullscreen.h"
10 #include "core/dom/ScriptedAnimationController.h" 10 #include "core/dom/ScriptedAnimationController.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 visitor->trace(m_vrDisplay); 50 visitor->trace(m_vrDisplay);
51 51
52 FrameRequestCallback::trace(visitor); 52 FrameRequestCallback::trace(visitor);
53 } 53 }
54 54
55 Member<VRDisplay> m_vrDisplay; 55 Member<VRDisplay> m_vrDisplay;
56 }; 56 };
57 57
58 } // namespace 58 } // namespace
59 59
60 VRDisplay::VRDisplay(NavigatorVR* navigatorVR, 60 VRDisplay::VRDisplay(NavigatorVR* navigatorVR)
61 device::mojom::blink::VRDisplayPtr display,
62 device::mojom::blink::VRDisplayClientRequest request)
63 : m_navigatorVR(navigatorVR), 61 : m_navigatorVR(navigatorVR),
62 m_displayId(0),
64 m_isConnected(false), 63 m_isConnected(false),
65 m_isPresenting(false), 64 m_isPresenting(false),
66 m_canUpdateFramePose(true), 65 m_canUpdateFramePose(true),
67 m_capabilities(new VRDisplayCapabilities()), 66 m_capabilities(new VRDisplayCapabilities()),
68 m_eyeParametersLeft(new VREyeParameters()), 67 m_eyeParametersLeft(new VREyeParameters()),
69 m_eyeParametersRight(new VREyeParameters()), 68 m_eyeParametersRight(new VREyeParameters()),
70 m_depthNear(0.01), 69 m_depthNear(0.01),
71 m_depthFar(10000.0), 70 m_depthFar(10000.0),
72 m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck), 71 m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck),
73 m_animationCallbackRequested(false), 72 m_animationCallbackRequested(false),
74 m_inAnimationFrame(false), 73 m_inAnimationFrame(false) {}
75 m_display(std::move(display)),
76 m_binding(this, std::move(request)) {
77 ThreadState::current()->registerPreFinalizer(this);
78 }
79 74
80 VRDisplay::~VRDisplay() {} 75 VRDisplay::~VRDisplay() {}
81 76
82 VRController* VRDisplay::controller() { 77 VRController* VRDisplay::controller() {
83 return m_navigatorVR->controller(); 78 return m_navigatorVR->controller();
84 } 79 }
85 80
86 void VRDisplay::update(const device::mojom::blink::VRDisplayInfoPtr& display) { 81 void VRDisplay::update(const device::blink::VRDisplayPtr& display) {
87 m_displayId = display->index; 82 m_displayId = display->index;
88 m_displayName = display->displayName; 83 m_displayName = display->displayName;
89 m_isConnected = true; 84 m_isConnected = true;
90 85
91 m_capabilities->setHasOrientation(display->capabilities->hasOrientation); 86 m_capabilities->setHasOrientation(display->capabilities->hasOrientation);
92 m_capabilities->setHasPosition(display->capabilities->hasPosition); 87 m_capabilities->setHasPosition(display->capabilities->hasPosition);
93 m_capabilities->setHasExternalDisplay( 88 m_capabilities->setHasExternalDisplay(
94 display->capabilities->hasExternalDisplay); 89 display->capabilities->hasExternalDisplay);
95 m_capabilities->setCanPresent(display->capabilities->canPresent); 90 m_capabilities->setCanPresent(display->capabilities->canPresent);
96 m_capabilities->setMaxLayers(display->capabilities->canPresent ? 1 : 0); 91 m_capabilities->setMaxLayers(display->capabilities->canPresent ? 1 : 0);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (!m_framePose) 126 if (!m_framePose)
132 return nullptr; 127 return nullptr;
133 128
134 VRPose* pose = VRPose::create(); 129 VRPose* pose = VRPose::create();
135 pose->setPose(m_framePose); 130 pose->setPose(m_framePose);
136 return pose; 131 return pose;
137 } 132 }
138 133
139 void VRDisplay::updatePose() { 134 void VRDisplay::updatePose() {
140 if (m_canUpdateFramePose) { 135 if (m_canUpdateFramePose) {
141 if (!m_display) 136 m_framePose = controller()->getPose(m_displayId);
142 return;
143 device::mojom::blink::VRPosePtr pose;
144 m_display->GetPose(&pose);
145 m_framePose = std::move(pose);
146 if (m_isPresenting) 137 if (m_isPresenting)
147 m_canUpdateFramePose = false; 138 m_canUpdateFramePose = false;
148 } 139 }
149 } 140 }
150 141
151 void VRDisplay::resetPose() { 142 void VRDisplay::resetPose() {
152 if (!m_display) 143 controller()->resetPose(m_displayId);
153 return;
154
155 m_display->ResetPose();
156 } 144 }
157 145
158 VREyeParameters* VRDisplay::getEyeParameters(const String& whichEye) { 146 VREyeParameters* VRDisplay::getEyeParameters(const String& whichEye) {
159 switch (stringToVREye(whichEye)) { 147 switch (stringToVREye(whichEye)) {
160 case VREyeLeft: 148 case VREyeLeft:
161 return m_eyeParametersLeft; 149 return m_eyeParametersLeft;
162 case VREyeRight: 150 case VREyeRight:
163 return m_eyeParametersRight; 151 return m_eyeParametersRight;
164 default: 152 default:
165 return nullptr; 153 return nullptr;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 Fullscreen::requestFullscreen(*m_layer.source(), 292 Fullscreen::requestFullscreen(*m_layer.source(),
305 Fullscreen::UnprefixedRequest); 293 Fullscreen::UnprefixedRequest);
306 294
307 // Check to see if the canvas is still the current fullscreen 295 // Check to see if the canvas is still the current fullscreen
308 // element once per second. 296 // element once per second.
309 m_fullscreenCheckTimer.startRepeating(1.0, BLINK_FROM_HERE); 297 m_fullscreenCheckTimer.startRepeating(1.0, BLINK_FROM_HERE);
310 } 298 }
311 299
312 if (firstPresent) { 300 if (firstPresent) {
313 bool secureContext = scriptState->getExecutionContext()->isSecureContext(); 301 bool secureContext = scriptState->getExecutionContext()->isSecureContext();
314 if (!m_display) { 302 controller()->requestPresent(resolver, m_displayId, secureContext);
315 DOMException* exception = DOMException::create(
316 InvalidStateError, "The service is no longer active.");
317 resolver->reject(exception);
318 return promise;
319 }
320 m_display->RequestPresent(
321 secureContext, convertToBaseCallback(WTF::bind(
322 &VRDisplay::onPresentComplete, wrapPersistent(this),
323 wrapPersistent(resolver))));
324 } else { 303 } else {
325 updateLayerBounds(); 304 updateLayerBounds();
326 resolver->resolve(); 305 resolver->resolve();
327 ReportPresentationResult(PresentationResult::SuccessAlreadyPresenting); 306 ReportPresentationResult(PresentationResult::SuccessAlreadyPresenting);
328 } 307 }
329 308
330 return promise; 309 return promise;
331 } 310 }
332 311
333 void VRDisplay::onPresentComplete(ScriptPromiseResolver* resolver,
334 bool success) {
335 if (success) {
336 this->beginPresent(resolver);
337 } else {
338 this->forceExitPresent();
339 DOMException* exception = DOMException::create(
340 NotAllowedError, "Presentation request was denied.");
341 resolver->reject(exception);
342 }
343 }
344
345 ScriptPromise VRDisplay::exitPresent(ScriptState* scriptState) { 312 ScriptPromise VRDisplay::exitPresent(ScriptState* scriptState) {
346 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 313 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
347 ScriptPromise promise = resolver->promise(); 314 ScriptPromise promise = resolver->promise();
348 315
349 if (!m_isPresenting) { 316 if (!m_isPresenting) {
350 // Can't stop presenting if we're not presenting. 317 // Can't stop presenting if we're not presenting.
351 DOMException* exception = 318 DOMException* exception =
352 DOMException::create(InvalidStateError, "VRDisplay is not presenting."); 319 DOMException::create(InvalidStateError, "VRDisplay is not presenting.");
353 resolver->reject(exception); 320 resolver->reject(exception);
354 return promise; 321 return promise;
355 } 322 }
356 323
357 if (!m_display) { 324 controller()->exitPresent(m_displayId);
358 DOMException* exception =
359 DOMException::create(InvalidStateError, "VRService is not available.");
360 resolver->reject(exception);
361 return promise;
362 }
363 m_display->ExitPresent();
364 325
365 resolver->resolve(); 326 resolver->resolve();
366 327
367 forceExitPresent(); 328 forceExitPresent();
368 329
369 return promise; 330 return promise;
370 } 331 }
371 332
372 void VRDisplay::beginPresent(ScriptPromiseResolver* resolver) { 333 void VRDisplay::beginPresent(ScriptPromiseResolver* resolver) {
373 if (m_capabilities->hasExternalDisplay()) { 334 if (m_capabilities->hasExternalDisplay()) {
(...skipping 26 matching lines...) Expand all
400 } 361 }
401 m_navigatorVR->fireVRDisplayPresentChange(this); 362 m_navigatorVR->fireVRDisplayPresentChange(this);
402 } 363 }
403 364
404 m_isPresenting = false; 365 m_isPresenting = false;
405 m_renderingContext = nullptr; 366 m_renderingContext = nullptr;
406 m_contextGL = nullptr; 367 m_contextGL = nullptr;
407 } 368 }
408 369
409 void VRDisplay::updateLayerBounds() { 370 void VRDisplay::updateLayerBounds() {
410 if (!m_display)
411 return;
412
413 // Set up the texture bounds for the provided layer 371 // Set up the texture bounds for the provided layer
414 device::mojom::blink::VRLayerBoundsPtr leftBounds = 372 device::blink::VRLayerBoundsPtr leftBounds =
415 device::mojom::blink::VRLayerBounds::New(); 373 device::blink::VRLayerBounds::New();
416 device::mojom::blink::VRLayerBoundsPtr rightBounds = 374 device::blink::VRLayerBoundsPtr rightBounds =
417 device::mojom::blink::VRLayerBounds::New(); 375 device::blink::VRLayerBounds::New();
418 376
419 if (m_layer.leftBounds().size() == 4) { 377 if (m_layer.leftBounds().size() == 4) {
420 leftBounds->left = m_layer.leftBounds()[0]; 378 leftBounds->left = m_layer.leftBounds()[0];
421 leftBounds->top = m_layer.leftBounds()[1]; 379 leftBounds->top = m_layer.leftBounds()[1];
422 leftBounds->width = m_layer.leftBounds()[2]; 380 leftBounds->width = m_layer.leftBounds()[2];
423 leftBounds->height = m_layer.leftBounds()[3]; 381 leftBounds->height = m_layer.leftBounds()[3];
424 } else { 382 } else {
425 // Left eye defaults 383 // Left eye defaults
426 leftBounds->left = 0.0f; 384 leftBounds->left = 0.0f;
427 leftBounds->top = 0.0f; 385 leftBounds->top = 0.0f;
428 leftBounds->width = 0.5f; 386 leftBounds->width = 0.5f;
429 leftBounds->height = 1.0f; 387 leftBounds->height = 1.0f;
430 } 388 }
431 389
432 if (m_layer.rightBounds().size() == 4) { 390 if (m_layer.rightBounds().size() == 4) {
433 rightBounds->left = m_layer.rightBounds()[0]; 391 rightBounds->left = m_layer.rightBounds()[0];
434 rightBounds->top = m_layer.rightBounds()[1]; 392 rightBounds->top = m_layer.rightBounds()[1];
435 rightBounds->width = m_layer.rightBounds()[2]; 393 rightBounds->width = m_layer.rightBounds()[2];
436 rightBounds->height = m_layer.rightBounds()[3]; 394 rightBounds->height = m_layer.rightBounds()[3];
437 } else { 395 } else {
438 // Right eye defaults 396 // Right eye defaults
439 rightBounds->left = 0.5f; 397 rightBounds->left = 0.5f;
440 rightBounds->top = 0.0f; 398 rightBounds->top = 0.0f;
441 rightBounds->width = 0.5f; 399 rightBounds->width = 0.5f;
442 rightBounds->height = 1.0f; 400 rightBounds->height = 1.0f;
443 } 401 }
444 402
445 m_display->UpdateLayerBounds(std::move(leftBounds), std::move(rightBounds)); 403 controller()->updateLayerBounds(m_displayId, std::move(leftBounds),
404 std::move(rightBounds));
446 } 405 }
447 406
448 HeapVector<VRLayer> VRDisplay::getLayers() { 407 HeapVector<VRLayer> VRDisplay::getLayers() {
449 HeapVector<VRLayer> layers; 408 HeapVector<VRLayer> layers;
450 409
451 if (m_isPresenting) { 410 if (m_isPresenting) {
452 layers.append(m_layer); 411 layers.append(m_layer);
453 } 412 }
454 413
455 return layers; 414 return layers;
456 } 415 }
457 416
458 void VRDisplay::submitFrame() { 417 void VRDisplay::submitFrame() {
459 if (!m_display)
460 return;
461
462 Document* doc = m_navigatorVR->document(); 418 Document* doc = m_navigatorVR->document();
463 if (!m_isPresenting) { 419 if (!m_isPresenting) {
464 if (doc) { 420 if (doc) {
465 doc->addConsoleMessage(ConsoleMessage::create( 421 doc->addConsoleMessage(ConsoleMessage::create(
466 RenderingMessageSource, WarningMessageLevel, 422 RenderingMessageSource, WarningMessageLevel,
467 "submitFrame has no effect when the VRDisplay is not presenting.")); 423 "submitFrame has no effect when the VRDisplay is not presenting."));
468 } 424 }
469 return; 425 return;
470 } 426 }
471 427
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 gl->ClearColor((idx & 255) / 255.0f, ((idx >> 8) & 255) / 255.0f, 461 gl->ClearColor((idx & 255) / 255.0f, ((idx >> 8) & 255) / 255.0f,
506 ((idx >> 16) & 255) / 255.0f, 1.0f); 462 ((idx >> 16) & 255) / 255.0f, 1.0f);
507 gl->Clear(GL_COLOR_BUFFER_BIT); 463 gl->Clear(GL_COLOR_BUFFER_BIT);
508 464
509 // Set the GL state back to what was set by the WebVR application. 465 // Set the GL state back to what was set by the WebVR application.
510 m_renderingContext->restoreScissorEnabled(); 466 m_renderingContext->restoreScissorEnabled();
511 m_renderingContext->restoreScissorBox(); 467 m_renderingContext->restoreScissorBox();
512 m_renderingContext->restoreColorMask(); 468 m_renderingContext->restoreColorMask();
513 m_renderingContext->restoreClearColor(); 469 m_renderingContext->restoreClearColor();
514 470
515 m_display->SubmitFrame(m_framePose.Clone()); 471 controller()->submitFrame(m_displayId, m_framePose.Clone());
516 m_canUpdateFramePose = true; 472 m_canUpdateFramePose = true;
517 } 473 }
518 474
519 void VRDisplay::OnDisplayChanged(
520 device::mojom::blink::VRDisplayInfoPtr display) {
521 update(display);
522 }
523
524 void VRDisplay::OnExitPresent() {
525 forceExitPresent();
526 }
527
528 void VRDisplay::onDisplayConnected() {
529 m_navigatorVR->fireVREvent(VRDisplayEvent::create(
530 EventTypeNames::vrdisplayconnect, true, false, this, "connect"));
531 }
532
533 void VRDisplay::onDisplayDisconnected() {
534 m_navigatorVR->fireVREvent(VRDisplayEvent::create(
535 EventTypeNames::vrdisplaydisconnect, true, false, this, "disconnect"));
536 }
537
538 void VRDisplay::onFullscreenCheck(TimerBase*) { 475 void VRDisplay::onFullscreenCheck(TimerBase*) {
539 // TODO: This is a temporary measure to track if fullscreen mode has been 476 // TODO: This is a temporary measure to track if fullscreen mode has been
540 // exited by the UA. If so we need to end VR presentation. Soon we won't 477 // exited by the UA. If so we need to end VR presentation. Soon we won't
541 // depend on the Fullscreen API to fake VR presentation, so this will 478 // depend on the Fullscreen API to fake VR presentation, so this will
542 // become unnessecary. Until that point, though, this seems preferable to 479 // become unnessecary. Until that point, though, this seems preferable to
543 // adding a bunch of notification plumbing to Fullscreen. 480 // adding a bunch of notification plumbing to Fullscreen.
544 if (!Fullscreen::isCurrentFullScreenElement(*m_layer.source())) { 481 if (!Fullscreen::isCurrentFullScreenElement(*m_layer.source())) {
545 m_isPresenting = false; 482 m_isPresenting = false;
546 m_navigatorVR->fireVRDisplayPresentChange(this); 483 m_navigatorVR->fireVRDisplayPresentChange(this);
547 m_fullscreenCheckTimer.stop(); 484 m_fullscreenCheckTimer.stop();
548 if (!m_display) 485 controller()->exitPresent(m_displayId);
549 return;
550 m_display->ExitPresent();
551 } 486 }
552 } 487 }
553 488
554 ScriptedAnimationController& VRDisplay::ensureScriptedAnimationController( 489 ScriptedAnimationController& VRDisplay::ensureScriptedAnimationController(
555 Document* doc) { 490 Document* doc) {
556 if (!m_scriptedAnimationController) 491 if (!m_scriptedAnimationController)
557 m_scriptedAnimationController = ScriptedAnimationController::create(doc); 492 m_scriptedAnimationController = ScriptedAnimationController::create(doc);
558 493
559 return *m_scriptedAnimationController; 494 return *m_scriptedAnimationController;
560 } 495 }
561 496
562 void VRDisplay::dispose() {
563 m_binding.Close();
564 }
565
566 DEFINE_TRACE(VRDisplay) { 497 DEFINE_TRACE(VRDisplay) {
567 visitor->trace(m_navigatorVR); 498 visitor->trace(m_navigatorVR);
568 visitor->trace(m_capabilities); 499 visitor->trace(m_capabilities);
569 visitor->trace(m_stageParameters); 500 visitor->trace(m_stageParameters);
570 visitor->trace(m_eyeParametersLeft); 501 visitor->trace(m_eyeParametersLeft);
571 visitor->trace(m_eyeParametersRight); 502 visitor->trace(m_eyeParametersRight);
572 visitor->trace(m_layer); 503 visitor->trace(m_layer);
573 visitor->trace(m_renderingContext); 504 visitor->trace(m_renderingContext);
574 visitor->trace(m_scriptedAnimationController); 505 visitor->trace(m_scriptedAnimationController);
575 } 506 }
576 507
577 } // namespace blink 508 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/vr/VRDisplay.h ('k') | third_party/WebKit/Source/modules/vr/VREyeParameters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698