| 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 mailbox_bridge_ = base::MakeUnique<MailboxToSurfaceBridge>(); | 373 mailbox_bridge_ = base::MakeUnique<MailboxToSurfaceBridge>(); |
| 374 mailbox_bridge_->CreateSurface(webvr_surface_texture_.get()); | 374 mailbox_bridge_->CreateSurface(webvr_surface_texture_.get()); |
| 375 } | 375 } |
| 376 } | 376 } |
| 377 | 377 |
| 378 void VrShellGl::SubmitWebVRFrame(int16_t frame_index, | 378 void VrShellGl::SubmitWebVRFrame(int16_t frame_index, |
| 379 const gpu::MailboxHolder& mailbox) { | 379 const gpu::MailboxHolder& mailbox) { |
| 380 DCHECK(submit_client_.get()); | 380 DCHECK(submit_client_.get()); |
| 381 TRACE_EVENT0("gpu", "VrShellGl::SubmitWebVRFrame"); | 381 TRACE_EVENT0("gpu", "VrShellGl::SubmitWebVRFrame"); |
| 382 | 382 |
| 383 webvr_time_js_submit_[frame_index % kPoseRingBufferSize] = |
| 384 base::TimeTicks::Now(); |
| 385 |
| 383 // Swapping twice on a Surface without calling updateTexImage in | 386 // Swapping twice on a Surface without calling updateTexImage in |
| 384 // between can lose frames, so don't draw+swap if we already have | 387 // between can lose frames, so don't draw+swap if we already have |
| 385 // a pending frame we haven't consumed yet. | 388 // a pending frame we haven't consumed yet. |
| 386 bool swapped = false; | 389 bool swapped = false; |
| 387 if (pending_frames_.empty()) { | 390 if (pending_frames_.empty()) { |
| 388 swapped = mailbox_bridge_->CopyMailboxToSurfaceAndSwap(mailbox); | 391 swapped = mailbox_bridge_->CopyMailboxToSurfaceAndSwap(mailbox); |
| 389 if (swapped) { | 392 if (swapped) { |
| 390 // Tell OnWebVRFrameAvailable to expect a new frame to arrive on | 393 // Tell OnWebVRFrameAvailable to expect a new frame to arrive on |
| 391 // the SurfaceTexture, and save the associated frame index. | 394 // the SurfaceTexture, and save the associated frame index. |
| 392 pending_frames_.emplace(frame_index); | 395 pending_frames_.emplace(frame_index); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 if (cardboard_ && web_vr_mode_) { | 446 if (cardboard_ && web_vr_mode_) { |
| 444 browser_->ToggleCardboardGamepad(true); | 447 browser_->ToggleCardboardGamepad(true); |
| 445 } | 448 } |
| 446 } | 449 } |
| 447 | 450 |
| 448 void VrShellGl::InitializeRenderer() { | 451 void VrShellGl::InitializeRenderer() { |
| 449 gvr_api_->InitializeGl(); | 452 gvr_api_->InitializeGl(); |
| 450 vr::Mat4f head_pose; | 453 vr::Mat4f head_pose; |
| 451 device::GvrDelegate::GetGvrPoseWithNeckModel(gvr_api_.get(), &head_pose); | 454 device::GvrDelegate::GetGvrPoseWithNeckModel(gvr_api_.get(), &head_pose); |
| 452 webvr_head_pose_.assign(kPoseRingBufferSize, head_pose); | 455 webvr_head_pose_.assign(kPoseRingBufferSize, head_pose); |
| 456 webvr_time_pose_.assign(kPoseRingBufferSize, base::TimeTicks()); |
| 457 webvr_time_js_submit_.assign(kPoseRingBufferSize, base::TimeTicks()); |
| 453 | 458 |
| 454 std::vector<gvr::BufferSpec> specs; | 459 std::vector<gvr::BufferSpec> specs; |
| 455 // For kFramePrimaryBuffer (primary VrShell and WebVR content) | 460 // For kFramePrimaryBuffer (primary VrShell and WebVR content) |
| 456 specs.push_back(gvr_api_->CreateBufferSpec()); | 461 specs.push_back(gvr_api_->CreateBufferSpec()); |
| 457 gvr::Sizei render_size_primary = specs[kFramePrimaryBuffer].GetSize(); | 462 gvr::Sizei render_size_primary = specs[kFramePrimaryBuffer].GetSize(); |
| 458 render_size_primary_ = {render_size_primary.width, | 463 render_size_primary_ = {render_size_primary.width, |
| 459 render_size_primary.height}; | 464 render_size_primary.height}; |
| 460 render_size_vrshell_ = render_size_primary_; | 465 render_size_vrshell_ = render_size_primary_; |
| 461 | 466 |
| 462 // For kFrameHeadlockedBuffer (for WebVR insecure content warning). | 467 // For kFrameHeadlockedBuffer (for WebVR insecure content warning). |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 } | 1103 } |
| 1099 | 1104 |
| 1100 // Report rendering completion to WebVR so that it's permitted to submit | 1105 // Report rendering completion to WebVR so that it's permitted to submit |
| 1101 // a fresh frame. We could do this earlier, as soon as the frame got pulled | 1106 // a fresh frame. We could do this earlier, as soon as the frame got pulled |
| 1102 // off the transfer surface, but that appears to result in overstuffed | 1107 // off the transfer surface, but that appears to result in overstuffed |
| 1103 // buffers. | 1108 // buffers. |
| 1104 if (submit_client_) { | 1109 if (submit_client_) { |
| 1105 submit_client_->OnSubmitFrameRendered(); | 1110 submit_client_->OnSubmitFrameRendered(); |
| 1106 } | 1111 } |
| 1107 | 1112 |
| 1113 if (ShouldDrawWebVr()) { |
| 1114 base::TimeTicks now = base::TimeTicks::Now(); |
| 1115 base::TimeTicks pose_time = |
| 1116 webvr_time_pose_[frame_index % kPoseRingBufferSize]; |
| 1117 base::TimeTicks js_submit_time = |
| 1118 webvr_time_js_submit_[frame_index % kPoseRingBufferSize]; |
| 1119 int64_t pose_to_js_submit_us = |
| 1120 (js_submit_time - pose_time).InMicroseconds(); |
| 1121 webvr_js_time_->AddSample(pose_to_js_submit_us); |
| 1122 int64_t js_submit_to_gvr_submit_us = |
| 1123 (now - js_submit_time).InMicroseconds(); |
| 1124 webvr_render_time_->AddSample(js_submit_to_gvr_submit_us); |
| 1125 } |
| 1126 |
| 1108 // After saving the timestamp, fps will be available via GetFPS(). | 1127 // After saving the timestamp, fps will be available via GetFPS(). |
| 1109 // TODO(vollick): enable rendering of this framerate in a HUD. | 1128 // TODO(vollick): enable rendering of this framerate in a HUD. |
| 1110 fps_meter_->AddFrame(base::TimeTicks::Now()); | 1129 fps_meter_->AddFrame(base::TimeTicks::Now()); |
| 1111 DVLOG(1) << "fps: " << fps_meter_->GetFPS(); | 1130 DVLOG(1) << "fps: " << fps_meter_->GetFPS(); |
| 1112 TRACE_COUNTER1("gpu", "WebVR FPS", fps_meter_->GetFPS()); | 1131 TRACE_COUNTER1("gpu", "WebVR FPS", fps_meter_->GetFPS()); |
| 1113 } | 1132 } |
| 1114 | 1133 |
| 1115 void VrShellGl::DrawWorldElements(const vr::Mat4f& head_pose) { | 1134 void VrShellGl::DrawWorldElements(const vr::Mat4f& head_pose) { |
| 1116 TRACE_EVENT0("gpu", "VrShellGl::DrawWorldElements"); | 1135 TRACE_EVENT0("gpu", "VrShellGl::DrawWorldElements"); |
| 1117 | 1136 |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1578 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); | 1597 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); |
| 1579 | 1598 |
| 1580 int64_t prediction_nanos = GetPredictedFrameTimeNanos(); | 1599 int64_t prediction_nanos = GetPredictedFrameTimeNanos(); |
| 1581 | 1600 |
| 1582 vr::Mat4f head_mat; | 1601 vr::Mat4f head_mat; |
| 1583 device::mojom::VRPosePtr pose = | 1602 device::mojom::VRPosePtr pose = |
| 1584 device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), &head_mat, | 1603 device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), &head_mat, |
| 1585 prediction_nanos); | 1604 prediction_nanos); |
| 1586 | 1605 |
| 1587 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; | 1606 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; |
| 1607 webvr_time_pose_[frame_index % kPoseRingBufferSize] = base::TimeTicks::Now(); |
| 1588 | 1608 |
| 1589 std::move(callback).Run(std::move(pose), time, frame_index, | 1609 std::move(callback).Run(std::move(pose), time, frame_index, |
| 1590 device::mojom::VRVSyncProvider::Status::SUCCESS); | 1610 device::mojom::VRVSyncProvider::Status::SUCCESS); |
| 1591 } | 1611 } |
| 1592 | 1612 |
| 1593 void VrShellGl::CreateVRDisplayInfo( | 1613 void VrShellGl::CreateVRDisplayInfo( |
| 1594 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, | 1614 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 1595 uint32_t device_id) { | 1615 uint32_t device_id) { |
| 1596 // This assumes that the initial webvr_surface_size_ was set to the | 1616 // This assumes that the initial webvr_surface_size_ was set to the |
| 1597 // appropriate recommended render resolution as the default size during | 1617 // appropriate recommended render resolution as the default size during |
| 1598 // InitializeGl. Revisit if the initialization order changes. | 1618 // InitializeGl. Revisit if the initialization order changes. |
| 1599 device::mojom::VRDisplayInfoPtr info = | 1619 device::mojom::VRDisplayInfoPtr info = |
| 1600 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), | 1620 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), |
| 1601 webvr_surface_size_, device_id); | 1621 webvr_surface_size_, device_id); |
| 1602 browser_->RunVRDisplayInfoCallback(callback, &info); | 1622 browser_->RunVRDisplayInfoCallback(callback, &info); |
| 1603 } | 1623 } |
| 1604 | 1624 |
| 1605 } // namespace vr_shell | 1625 } // namespace vr_shell |
| OLD | NEW |