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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 // We're expecting a frame, but it's not here yet. Retry in OnVsync. | 418 // We're expecting a frame, but it's not here yet. Retry in OnVsync. |
419 ++premature_received_frames_; | 419 ++premature_received_frames_; |
420 return; | 420 return; |
421 } | 421 } |
422 | 422 |
423 webvr_surface_texture_->UpdateTexImage(); | 423 webvr_surface_texture_->UpdateTexImage(); |
424 int frame_index = pending_frames_.front(); | 424 int frame_index = pending_frames_.front(); |
425 TRACE_EVENT1("gpu", "VrShellGl::OnWebVRFrameAvailable", "frame", frame_index); | 425 TRACE_EVENT1("gpu", "VrShellGl::OnWebVRFrameAvailable", "frame", frame_index); |
426 pending_frames_.pop(); | 426 pending_frames_.pop(); |
427 | 427 |
428 // It is legal for the WebVR client to submit a new frame now, since | |
429 // we've consumed the image. TODO(klausw): would timing be better if | |
430 // we move the "rendered" notification after draw, or suppress | |
431 // the next vsync until that's done? | |
432 | |
433 if (submit_client_) { | |
434 submit_client_->OnSubmitFrameRendered(); | |
435 } | |
436 | |
437 DrawFrame(frame_index); | 428 DrawFrame(frame_index); |
438 } | 429 } |
439 | 430 |
440 void VrShellGl::GvrInit(gvr_context* gvr_api) { | 431 void VrShellGl::GvrInit(gvr_context* gvr_api) { |
441 gvr_api_ = gvr::GvrApi::WrapNonOwned(gvr_api); | 432 gvr_api_ = gvr::GvrApi::WrapNonOwned(gvr_api); |
442 controller_.reset(new VrController(gvr_api)); | 433 controller_.reset(new VrController(gvr_api)); |
443 | 434 |
444 ViewerType viewerType; | 435 ViewerType viewerType; |
445 switch (gvr_api_->GetViewerType()) { | 436 switch (gvr_api_->GetViewerType()) { |
446 case gvr::ViewerType::GVR_VIEWER_TYPE_DAYDREAM: | 437 case gvr::ViewerType::GVR_VIEWER_TYPE_DAYDREAM: |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 frame.Submit(*buffer_viewport_list_, mat); | 1058 frame.Submit(*buffer_viewport_list_, mat); |
1068 } | 1059 } |
1069 | 1060 |
1070 // No need to swap buffers for surfaceless rendering. | 1061 // No need to swap buffers for surfaceless rendering. |
1071 if (!surfaceless_rendering_) { | 1062 if (!surfaceless_rendering_) { |
1072 // TODO(mthiesse): Support asynchronous SwapBuffers. | 1063 // TODO(mthiesse): Support asynchronous SwapBuffers. |
1073 TRACE_EVENT0("gpu", "VrShellGl::SwapBuffers"); | 1064 TRACE_EVENT0("gpu", "VrShellGl::SwapBuffers"); |
1074 surface_->SwapBuffers(); | 1065 surface_->SwapBuffers(); |
1075 } | 1066 } |
1076 | 1067 |
| 1068 // Report rendering completion to WebVR so that it's permitted to submit |
| 1069 // a fresh frame. We could do this earlier, as soon as the frame got pulled |
| 1070 // off the transfer surface, but that appears to result in overstuffed |
| 1071 // buffers. |
| 1072 if (submit_client_) { |
| 1073 submit_client_->OnSubmitFrameRendered(); |
| 1074 } |
| 1075 |
1077 #if DCHECK_IS_ON() | 1076 #if DCHECK_IS_ON() |
1078 // After saving the timestamp, fps will be available via GetFPS(). | 1077 // After saving the timestamp, fps will be available via GetFPS(). |
1079 // TODO(vollick): enable rendering of this framerate in a HUD. | 1078 // TODO(vollick): enable rendering of this framerate in a HUD. |
1080 fps_meter_->AddFrame(current_time); | 1079 fps_meter_->AddFrame(current_time); |
1081 DVLOG(1) << "fps: " << fps_meter_->GetFPS(); | 1080 DVLOG(1) << "fps: " << fps_meter_->GetFPS(); |
1082 #endif | 1081 #endif |
1083 } | 1082 } |
1084 | 1083 |
1085 void VrShellGl::DrawWorldElements(const vr::Mat4f& head_pose) { | 1084 void VrShellGl::DrawWorldElements(const vr::Mat4f& head_pose) { |
1086 TRACE_EVENT0("gpu", "VrShellGl::DrawWorldElements"); | 1085 TRACE_EVENT0("gpu", "VrShellGl::DrawWorldElements"); |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 // This assumes that the initial webvr_surface_size_ was set to the | 1540 // This assumes that the initial webvr_surface_size_ was set to the |
1542 // appropriate recommended render resolution as the default size during | 1541 // appropriate recommended render resolution as the default size during |
1543 // InitializeGl. Revisit if the initialization order changes. | 1542 // InitializeGl. Revisit if the initialization order changes. |
1544 device::mojom::VRDisplayInfoPtr info = | 1543 device::mojom::VRDisplayInfoPtr info = |
1545 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), | 1544 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), |
1546 webvr_surface_size_, device_id); | 1545 webvr_surface_size_, device_id); |
1547 browser_->RunVRDisplayInfoCallback(callback, &info); | 1546 browser_->RunVRDisplayInfoCallback(callback, &info); |
1548 } | 1547 } |
1549 | 1548 |
1550 } // namespace vr_shell | 1549 } // namespace vr_shell |
OLD | NEW |