| 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 if (mailbox_bridge_) { | 323 if (mailbox_bridge_) { |
| 324 mailbox_bridge_->ResizeSurface(size.width(), size.height()); | 324 mailbox_bridge_->ResizeSurface(size.width(), size.height()); |
| 325 } else { | 325 } else { |
| 326 mailbox_bridge_ = base::MakeUnique<MailboxToSurfaceBridge>(); | 326 mailbox_bridge_ = base::MakeUnique<MailboxToSurfaceBridge>(); |
| 327 mailbox_bridge_->CreateSurface(webvr_surface_texture_.get()); | 327 mailbox_bridge_->CreateSurface(webvr_surface_texture_.get()); |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 | 330 |
| 331 void VrShellGl::SubmitWebVRFrame(int16_t frame_index, | 331 void VrShellGl::SubmitWebVRFrame(int16_t frame_index, |
| 332 const gpu::MailboxHolder& mailbox) { | 332 const gpu::MailboxHolder& mailbox) { |
| 333 DCHECK(submit_client_.get()); | |
| 334 TRACE_EVENT0("gpu", "VrShellGl::SubmitWebVRFrame"); | 333 TRACE_EVENT0("gpu", "VrShellGl::SubmitWebVRFrame"); |
| 335 | 334 |
| 336 // Swapping twice on a Surface without calling updateTexImage in | 335 // Swapping twice on a Surface without calling updateTexImage in |
| 337 // between can lose frames, so don't draw+swap if we already have | 336 // between can lose frames, so don't draw+swap if we already have |
| 338 // a pending frame we haven't consumed yet. | 337 // a pending frame we haven't consumed yet. |
| 339 bool swapped = false; | 338 bool swapped = false; |
| 340 if (pending_frames_.empty()) { | 339 if (pending_frames_.empty()) { |
| 341 swapped = mailbox_bridge_->CopyMailboxToSurfaceAndSwap(mailbox); | 340 swapped = mailbox_bridge_->CopyMailboxToSurfaceAndSwap(mailbox); |
| 342 if (swapped) { | 341 if (swapped) { |
| 343 // Tell OnWebVRFrameAvailable to expect a new frame to arrive on | 342 // Tell OnWebVRFrameAvailable to expect a new frame to arrive on |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 webvr_surface_texture_->UpdateTexImage(); | 386 webvr_surface_texture_->UpdateTexImage(); |
| 388 int frame_index = pending_frames_.front(); | 387 int frame_index = pending_frames_.front(); |
| 389 TRACE_EVENT1("gpu", "VrShellGl::OnWebVRFrameAvailable", "frame", frame_index); | 388 TRACE_EVENT1("gpu", "VrShellGl::OnWebVRFrameAvailable", "frame", frame_index); |
| 390 pending_frames_.pop(); | 389 pending_frames_.pop(); |
| 391 | 390 |
| 392 // It is legal for the WebVR client to submit a new frame now, since | 391 // It is legal for the WebVR client to submit a new frame now, since |
| 393 // we've consumed the image. TODO(klausw): would timing be better if | 392 // we've consumed the image. TODO(klausw): would timing be better if |
| 394 // we move the "rendered" notification after draw, or suppress | 393 // we move the "rendered" notification after draw, or suppress |
| 395 // the next vsync until that's done? | 394 // the next vsync until that's done? |
| 396 | 395 |
| 397 if (submit_client_) { | 396 submit_client_->OnSubmitFrameRendered(); |
| 398 submit_client_->OnSubmitFrameRendered(); | |
| 399 } | |
| 400 | 397 |
| 401 DrawFrame(frame_index); | 398 DrawFrame(frame_index); |
| 402 } | 399 } |
| 403 | 400 |
| 404 void VrShellGl::GvrInit(gvr_context* gvr_api) { | 401 void VrShellGl::GvrInit(gvr_context* gvr_api) { |
| 405 gvr_api_ = gvr::GvrApi::WrapNonOwned(gvr_api); | 402 gvr_api_ = gvr::GvrApi::WrapNonOwned(gvr_api); |
| 406 controller_.reset(new VrController(gvr_api)); | 403 controller_.reset(new VrController(gvr_api)); |
| 407 | 404 |
| 408 ViewerType viewerType; | 405 ViewerType viewerType; |
| 409 switch (gvr_api_->GetViewerType()) { | 406 switch (gvr_api_->GetViewerType()) { |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 gvr_api_->ResumeTracking(); | 1207 gvr_api_->ResumeTracking(); |
| 1211 controller_->OnResume(); | 1208 controller_->OnResume(); |
| 1212 if (ready_to_draw_) { | 1209 if (ready_to_draw_) { |
| 1213 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); | 1210 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); |
| 1214 OnVSync(); | 1211 OnVSync(); |
| 1215 } | 1212 } |
| 1216 } | 1213 } |
| 1217 | 1214 |
| 1218 void VrShellGl::SetWebVrMode(bool enabled) { | 1215 void VrShellGl::SetWebVrMode(bool enabled) { |
| 1219 web_vr_mode_ = enabled; | 1216 web_vr_mode_ = enabled; |
| 1220 if (!enabled) { | |
| 1221 submit_client_.reset(); | |
| 1222 } | |
| 1223 } | 1217 } |
| 1224 | 1218 |
| 1225 void VrShellGl::UpdateWebVRTextureBounds(int16_t frame_index, | 1219 void VrShellGl::UpdateWebVRTextureBounds(int16_t frame_index, |
| 1226 const gfx::RectF& left_bounds, | 1220 const gfx::RectF& left_bounds, |
| 1227 const gfx::RectF& right_bounds, | 1221 const gfx::RectF& right_bounds, |
| 1228 const gfx::Size& source_size) { | 1222 const gfx::Size& source_size) { |
| 1229 if (frame_index < 0) { | 1223 if (frame_index < 0) { |
| 1230 webvr_left_viewport_->SetSourceUv(UVFromGfxRect(left_bounds)); | 1224 webvr_left_viewport_->SetSourceUv(UVFromGfxRect(left_bounds)); |
| 1231 webvr_right_viewport_->SetSourceUv(UVFromGfxRect(right_bounds)); | 1225 webvr_right_viewport_->SetSourceUv(UVFromGfxRect(right_bounds)); |
| 1232 CreateOrResizeWebVRSurface(source_size); | 1226 CreateOrResizeWebVRSurface(source_size); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 // This assumes that the initial webvr_surface_size_ was set to the | 1337 // This assumes that the initial webvr_surface_size_ was set to the |
| 1344 // appropriate recommended render resolution as the default size during | 1338 // appropriate recommended render resolution as the default size during |
| 1345 // InitializeGl. Revisit if the initialization order changes. | 1339 // InitializeGl. Revisit if the initialization order changes. |
| 1346 device::mojom::VRDisplayInfoPtr info = | 1340 device::mojom::VRDisplayInfoPtr info = |
| 1347 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), | 1341 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), |
| 1348 webvr_surface_size_, device_id); | 1342 webvr_surface_size_, device_id); |
| 1349 browser_->RunVRDisplayInfoCallback(callback, &info); | 1343 browser_->RunVRDisplayInfoCallback(callback, &info); |
| 1350 } | 1344 } |
| 1351 | 1345 |
| 1352 } // namespace vr_shell | 1346 } // namespace vr_shell |
| OLD | NEW |