Chromium Code Reviews| 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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 // We're expecting a frame, but it's not here yet. Retry in OnVsync. | 416 // We're expecting a frame, but it's not here yet. Retry in OnVsync. |
| 417 ++premature_received_frames_; | 417 ++premature_received_frames_; |
| 418 return; | 418 return; |
| 419 } | 419 } |
| 420 | 420 |
| 421 webvr_surface_texture_->UpdateTexImage(); | 421 webvr_surface_texture_->UpdateTexImage(); |
| 422 int frame_index = pending_frames_.front(); | 422 int frame_index = pending_frames_.front(); |
| 423 TRACE_EVENT1("gpu", "VrShellGl::OnWebVRFrameAvailable", "frame", frame_index); | 423 TRACE_EVENT1("gpu", "VrShellGl::OnWebVRFrameAvailable", "frame", frame_index); |
| 424 pending_frames_.pop(); | 424 pending_frames_.pop(); |
| 425 | 425 |
| 426 // It is legal for the WebVR client to submit a new frame now, since | |
| 427 // we've consumed the image. TODO(klausw): would timing be better if | |
| 428 // we move the "rendered" notification after draw, or suppress | |
| 429 // the next vsync until that's done? | |
| 430 | |
| 431 if (submit_client_) { | |
| 432 submit_client_->OnSubmitFrameRendered(); | |
| 433 } | |
| 434 | |
| 435 DrawFrame(frame_index); | 426 DrawFrame(frame_index); |
| 436 } | 427 } |
| 437 | 428 |
| 438 void VrShellGl::GvrInit(gvr_context* gvr_api) { | 429 void VrShellGl::GvrInit(gvr_context* gvr_api) { |
| 439 gvr_api_ = gvr::GvrApi::WrapNonOwned(gvr_api); | 430 gvr_api_ = gvr::GvrApi::WrapNonOwned(gvr_api); |
| 440 controller_.reset(new VrController(gvr_api)); | 431 controller_.reset(new VrController(gvr_api)); |
| 441 | 432 |
| 442 ViewerType viewerType; | 433 ViewerType viewerType; |
| 443 switch (gvr_api_->GetViewerType()) { | 434 switch (gvr_api_->GetViewerType()) { |
| 444 case gvr::ViewerType::GVR_VIEWER_TYPE_DAYDREAM: | 435 case gvr::ViewerType::GVR_VIEWER_TYPE_DAYDREAM: |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1059 frame.Submit(*buffer_viewport_list_, mat); | 1050 frame.Submit(*buffer_viewport_list_, mat); |
| 1060 } | 1051 } |
| 1061 | 1052 |
| 1062 // No need to swap buffers for surfaceless rendering. | 1053 // No need to swap buffers for surfaceless rendering. |
| 1063 if (!surfaceless_rendering_) { | 1054 if (!surfaceless_rendering_) { |
| 1064 // TODO(mthiesse): Support asynchronous SwapBuffers. | 1055 // TODO(mthiesse): Support asynchronous SwapBuffers. |
| 1065 TRACE_EVENT0("gpu", "VrShellGl::SwapBuffers"); | 1056 TRACE_EVENT0("gpu", "VrShellGl::SwapBuffers"); |
| 1066 surface_->SwapBuffers(); | 1057 surface_->SwapBuffers(); |
| 1067 } | 1058 } |
| 1068 | 1059 |
| 1060 // Report rendering completion to WebVR so that it's permitted to submit | |
| 1061 // a fresh frame. We could do this earlier, as soon as the frame got pulled | |
| 1062 // off the transfer surface, but that appears to result in overstuffed | |
| 1063 // buffers. | |
| 1064 if (submit_client_) { | |
| 1065 submit_client_->OnSubmitFrameRendered(); | |
| 1066 } | |
| 1067 | |
| 1069 #if DCHECK_IS_ON() | 1068 #if DCHECK_IS_ON() |
| 1070 // After saving the timestamp, fps will be available via GetFPS(). | 1069 // After saving the timestamp, fps will be available via GetFPS(). |
| 1071 // TODO(vollick): enable rendering of this framerate in a HUD. | 1070 // TODO(vollick): enable rendering of this framerate in a HUD. |
| 1072 fps_meter_->AddFrame(current_time); | 1071 fps_meter_->AddFrame(current_time); |
| 1073 DVLOG(1) << "fps: " << fps_meter_->GetFPS(); | 1072 DVLOG(1) << "fps: " << fps_meter_->GetFPS(); |
| 1074 #endif | 1073 #endif |
| 1075 } | 1074 } |
| 1076 | 1075 |
| 1077 void VrShellGl::DrawWorldElements(const vr::Mat4f& head_pose) { | 1076 void VrShellGl::DrawWorldElements(const vr::Mat4f& head_pose) { |
| 1078 TRACE_EVENT0("gpu", "VrShellGl::DrawWorldElements"); | 1077 TRACE_EVENT0("gpu", "VrShellGl::DrawWorldElements"); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1459 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; | 1458 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; |
| 1460 target = vsync_timebase_ + intervals * vsync_interval_; | 1459 target = vsync_timebase_ + intervals * vsync_interval_; |
| 1461 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(), | 1460 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(), |
| 1462 target - now); | 1461 target - now); |
| 1463 | 1462 |
| 1464 base::TimeDelta time = intervals * vsync_interval_; | 1463 base::TimeDelta time = intervals * vsync_interval_; |
| 1465 if (!callback_.is_null()) { | 1464 if (!callback_.is_null()) { |
| 1466 SendVSync(time, base::ResetAndReturn(&callback_)); | 1465 SendVSync(time, base::ResetAndReturn(&callback_)); |
| 1467 } else { | 1466 } else { |
| 1468 pending_vsync_ = true; | 1467 pending_vsync_ = true; |
| 1469 pending_time_ = time; | |
| 1470 } | 1468 } |
| 1471 if (!ShouldDrawWebVr()) { | 1469 if (!ShouldDrawWebVr()) { |
| 1472 DrawFrame(-1); | 1470 DrawFrame(-1); |
| 1473 } | 1471 } |
| 1474 } | 1472 } |
| 1475 | 1473 |
| 1476 void VrShellGl::OnRequest(device::mojom::VRVSyncProviderRequest request) { | 1474 void VrShellGl::OnRequest(device::mojom::VRVSyncProviderRequest request) { |
| 1477 binding_.Close(); | 1475 binding_.Close(); |
| 1478 binding_.Bind(std::move(request)); | 1476 binding_.Bind(std::move(request)); |
| 1479 } | 1477 } |
| 1480 | 1478 |
| 1481 void VrShellGl::GetVSync(const GetVSyncCallback& callback) { | 1479 void VrShellGl::GetVSync(const GetVSyncCallback& callback) { |
| 1482 if (!pending_vsync_) { | 1480 if (!pending_vsync_) { |
| 1483 if (!callback_.is_null()) { | 1481 if (!callback_.is_null()) { |
| 1484 mojo::ReportBadMessage( | 1482 mojo::ReportBadMessage( |
| 1485 "Requested VSync before waiting for response to previous request."); | 1483 "Requested VSync before waiting for response to previous request."); |
| 1486 binding_.Close(); | 1484 binding_.Close(); |
| 1487 return; | 1485 return; |
| 1488 } | 1486 } |
| 1489 callback_ = callback; | 1487 callback_ = callback; |
| 1490 return; | 1488 return; |
| 1491 } | 1489 } |
| 1492 pending_vsync_ = false; | 1490 pending_vsync_ = false; |
| 1493 SendVSync(pending_time_, callback); | 1491 base::TimeDelta time = base::TimeTicks::Now() - vsync_timebase_; |
|
mthiesse
2017/05/23 00:14:17
I don't think we want to do this with the timestam
| |
| 1492 SendVSync(time, callback); | |
| 1494 } | 1493 } |
| 1495 | 1494 |
| 1496 void VrShellGl::UpdateVSyncInterval(int64_t timebase_nanos, | 1495 void VrShellGl::UpdateVSyncInterval(int64_t timebase_nanos, |
| 1497 double interval_seconds) { | 1496 double interval_seconds) { |
| 1498 vsync_timebase_ = base::TimeTicks(); | 1497 vsync_timebase_ = base::TimeTicks(); |
| 1499 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000); | 1498 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000); |
| 1500 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); | 1499 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); |
| 1501 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); | 1500 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); |
| 1502 OnVSync(); | 1501 OnVSync(); |
| 1503 } | 1502 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1528 // This assumes that the initial webvr_surface_size_ was set to the | 1527 // This assumes that the initial webvr_surface_size_ was set to the |
| 1529 // appropriate recommended render resolution as the default size during | 1528 // appropriate recommended render resolution as the default size during |
| 1530 // InitializeGl. Revisit if the initialization order changes. | 1529 // InitializeGl. Revisit if the initialization order changes. |
| 1531 device::mojom::VRDisplayInfoPtr info = | 1530 device::mojom::VRDisplayInfoPtr info = |
| 1532 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), | 1531 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), |
| 1533 webvr_surface_size_, device_id); | 1532 webvr_surface_size_, device_id); |
| 1534 browser_->RunVRDisplayInfoCallback(callback, &info); | 1533 browser_->RunVRDisplayInfoCallback(callback, &info); |
| 1535 } | 1534 } |
| 1536 | 1535 |
| 1537 } // namespace vr_shell | 1536 } // namespace vr_shell |
| OLD | NEW |