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 "chrome/browser/android/vr_shell/vr_shell_gl.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
6 | 6 |
7 #include <chrono> | 7 #include <chrono> |
8 #include <limits> | 8 #include <limits> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 case gvr::ViewerType::GVR_VIEWER_TYPE_CARDBOARD: | 423 case gvr::ViewerType::GVR_VIEWER_TYPE_CARDBOARD: |
424 viewerType = ViewerType::CARDBOARD; | 424 viewerType = ViewerType::CARDBOARD; |
425 break; | 425 break; |
426 default: | 426 default: |
427 NOTREACHED(); | 427 NOTREACHED(); |
428 viewerType = ViewerType::UNKNOWN_TYPE; | 428 viewerType = ViewerType::UNKNOWN_TYPE; |
429 break; | 429 break; |
430 } | 430 } |
431 UMA_HISTOGRAM_ENUMERATION("VRViewerType", static_cast<int>(viewerType), | 431 UMA_HISTOGRAM_ENUMERATION("VRViewerType", static_cast<int>(viewerType), |
432 static_cast<int>(ViewerType::VIEWER_TYPE_MAX)); | 432 static_cast<int>(ViewerType::VIEWER_TYPE_MAX)); |
| 433 |
| 434 cardboard_ = (viewerType == ViewerType::CARDBOARD); |
| 435 if (cardboard_ && web_vr_mode_) { |
| 436 browser_->ToggleCardboardGamepad(true); |
| 437 } |
433 } | 438 } |
434 | 439 |
435 void VrShellGl::InitializeRenderer() { | 440 void VrShellGl::InitializeRenderer() { |
436 gvr_api_->InitializeGl(); | 441 gvr_api_->InitializeGl(); |
437 vr::Mat4f head_pose; | 442 vr::Mat4f head_pose; |
438 device::GvrDelegate::GetGvrPoseWithNeckModel(gvr_api_.get(), &head_pose); | 443 device::GvrDelegate::GetGvrPoseWithNeckModel(gvr_api_.get(), &head_pose); |
439 webvr_head_pose_.assign(kPoseRingBufferSize, head_pose); | 444 webvr_head_pose_.assign(kPoseRingBufferSize, head_pose); |
440 | 445 |
441 std::vector<gvr::BufferSpec> specs; | 446 std::vector<gvr::BufferSpec> specs; |
442 // For kFramePrimaryBuffer (primary VrShell and WebVR content) | 447 // For kFramePrimaryBuffer (primary VrShell and WebVR content) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 webvr_right_viewport_.get()); | 511 webvr_right_viewport_.get()); |
507 webvr_right_viewport_->SetSourceBufferIndex(kFramePrimaryBuffer); | 512 webvr_right_viewport_->SetSourceBufferIndex(kFramePrimaryBuffer); |
508 | 513 |
509 browser_->GvrDelegateReady(); | 514 browser_->GvrDelegateReady(); |
510 } | 515 } |
511 | 516 |
512 void VrShellGl::UpdateController(const gfx::Vector3dF& head_direction) { | 517 void VrShellGl::UpdateController(const gfx::Vector3dF& head_direction) { |
513 controller_->UpdateState(head_direction); | 518 controller_->UpdateState(head_direction); |
514 pointer_start_ = controller_->GetPointerStart(); | 519 pointer_start_ = controller_->GetPointerStart(); |
515 | 520 |
516 browser_->UpdateGamepadData(controller_->GetGamepadData()); | 521 device::GvrGamepadData controller_data = controller_->GetGamepadData(); |
| 522 browser_->UpdateGamepadData(controller_data); |
517 } | 523 } |
518 | 524 |
519 void VrShellGl::HandleControllerInput(const gfx::Vector3dF& head_direction) { | 525 void VrShellGl::HandleControllerInput(const gfx::Vector3dF& head_direction) { |
520 HandleWebVrCompatibilityClick(); | 526 HandleWebVrCompatibilityClick(); |
521 | 527 |
522 gfx::Vector3dF ergo_neutral_pose; | 528 gfx::Vector3dF ergo_neutral_pose; |
523 if (!controller_->IsConnected()) { | 529 if (!controller_->IsConnected()) { |
524 // No controller detected, set up a gaze cursor that tracks the | 530 // No controller detected, set up a gaze cursor that tracks the |
525 // forward direction. | 531 // forward direction. |
526 ergo_neutral_pose = {0.0f, 0.0f, -1.0f}; | 532 ergo_neutral_pose = {0.0f, 0.0f, -1.0f}; |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 gvr_api_->ResumeTracking(); | 1337 gvr_api_->ResumeTracking(); |
1332 controller_->OnResume(); | 1338 controller_->OnResume(); |
1333 if (ready_to_draw_) { | 1339 if (ready_to_draw_) { |
1334 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); | 1340 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); |
1335 OnVSync(); | 1341 OnVSync(); |
1336 } | 1342 } |
1337 } | 1343 } |
1338 | 1344 |
1339 void VrShellGl::SetWebVrMode(bool enabled) { | 1345 void VrShellGl::SetWebVrMode(bool enabled) { |
1340 web_vr_mode_ = enabled; | 1346 web_vr_mode_ = enabled; |
| 1347 |
| 1348 if (cardboard_) { |
| 1349 browser_->ToggleCardboardGamepad(enabled); |
| 1350 } |
| 1351 |
1341 if (!enabled) { | 1352 if (!enabled) { |
1342 submit_client_.reset(); | 1353 submit_client_.reset(); |
1343 } | 1354 } |
1344 } | 1355 } |
1345 | 1356 |
1346 void VrShellGl::UpdateWebVRTextureBounds(int16_t frame_index, | 1357 void VrShellGl::UpdateWebVRTextureBounds(int16_t frame_index, |
1347 const gfx::RectF& left_bounds, | 1358 const gfx::RectF& left_bounds, |
1348 const gfx::RectF& right_bounds, | 1359 const gfx::RectF& right_bounds, |
1349 const gfx::Size& source_size) { | 1360 const gfx::Size& source_size) { |
1350 if (frame_index < 0) { | 1361 if (frame_index < 0) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 // This assumes that the initial webvr_surface_size_ was set to the | 1487 // This assumes that the initial webvr_surface_size_ was set to the |
1477 // appropriate recommended render resolution as the default size during | 1488 // appropriate recommended render resolution as the default size during |
1478 // InitializeGl. Revisit if the initialization order changes. | 1489 // InitializeGl. Revisit if the initialization order changes. |
1479 device::mojom::VRDisplayInfoPtr info = | 1490 device::mojom::VRDisplayInfoPtr info = |
1480 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), | 1491 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), |
1481 webvr_surface_size_, device_id); | 1492 webvr_surface_size_, device_id); |
1482 browser_->RunVRDisplayInfoCallback(callback, &info); | 1493 browser_->RunVRDisplayInfoCallback(callback, &info); |
1483 } | 1494 } |
1484 | 1495 |
1485 } // namespace vr_shell | 1496 } // namespace vr_shell |
OLD | NEW |