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