Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_gl.cc

Issue 2571713006: Fix some thread safety violations in device::GvrDelegate implementation. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "chrome/browser/android/vr_shell/ui_elements.h" 10 #include "chrome/browser/android/vr_shell/ui_elements.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 InitializeRenderer(); 207 InitializeRenderer();
208 208
209 ScheduleNextDrawFrame(); 209 ScheduleNextDrawFrame();
210 return true; 210 return true;
211 } 211 }
212 212
213 bool VrShellGl::InitializeGl() { 213 bool VrShellGl::InitializeGl() {
214 if (gl::GetGLImplementation() == gl::kGLImplementationNone && 214 if (gl::GetGLImplementation() == gl::kGLImplementationNone &&
215 !gl::init::InitializeGLOneOff()) { 215 !gl::init::InitializeGLOneOff()) {
216 LOG(ERROR) << "gl::init::InitializeGLOneOff failed"; 216 LOG(ERROR) << "gl::init::InitializeGLOneOff failed";
217 ForceExitVR(); 217 ForceExitVr();
218 return false; 218 return false;
219 } 219 }
220 surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size()); 220 surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size());
221 if (!surface_.get()) { 221 if (!surface_.get()) {
222 LOG(ERROR) << "gl::init::CreateOffscreenGLSurface failed"; 222 LOG(ERROR) << "gl::init::CreateOffscreenGLSurface failed";
223 ForceExitVR(); 223 ForceExitVr();
224 return false; 224 return false;
225 } 225 }
226 context_ = gl::init::CreateGLContext(nullptr, surface_.get(), 226 context_ = gl::init::CreateGLContext(nullptr, surface_.get(),
227 gl::GLContextAttribs()); 227 gl::GLContextAttribs());
228 if (!context_.get()) { 228 if (!context_.get()) {
229 LOG(ERROR) << "gl::init::CreateGLContext failed"; 229 LOG(ERROR) << "gl::init::CreateGLContext failed";
230 ForceExitVR(); 230 ForceExitVr();
231 return false; 231 return false;
232 } 232 }
233 if (!context_->MakeCurrent(surface_.get())) { 233 if (!context_->MakeCurrent(surface_.get())) {
234 LOG(ERROR) << "gl::GLContext::MakeCurrent() failed"; 234 LOG(ERROR) << "gl::GLContext::MakeCurrent() failed";
235 ForceExitVR(); 235 ForceExitVr();
236 return false; 236 return false;
237 } 237 }
238 238
239 // TODO(mthiesse): We don't appear to have a VSync provider ever here. This is 239 // TODO(mthiesse): We don't appear to have a VSync provider ever here. This is
240 // sort of okay, because the GVR swap chain will block if we render too fast, 240 // sort of okay, because the GVR swap chain will block if we render too fast,
241 // but we should address this properly. 241 // but we should address this properly.
242 if (surface_->GetVSyncProvider()) { 242 if (surface_->GetVSyncProvider()) {
243 surface_->GetVSyncProvider()->GetVSyncParameters(base::Bind( 243 surface_->GetVSyncProvider()->GetVSyncParameters(base::Bind(
244 &VrShellGl::UpdateVSyncParameters, weak_ptr_factory_.GetWeakPtr())); 244 &VrShellGl::UpdateVSyncParameters, weak_ptr_factory_.GetWeakPtr()));
245 } else { 245 } else {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // Out of paranoia, explicitly reset the "pose valid" flags to false 310 // Out of paranoia, explicitly reset the "pose valid" flags to false
311 // from the GL thread. The constructor ran in the UI thread. 311 // from the GL thread. The constructor ran in the UI thread.
312 // TODO(klausw,crbug.com/655722): remove this. 312 // TODO(klausw,crbug.com/655722): remove this.
313 webvr_head_pose_valid_.assign(kPoseRingBufferSize, false); 313 webvr_head_pose_valid_.assign(kPoseRingBufferSize, false);
314 314
315 gvr_api_->InitializeGl(); 315 gvr_api_->InitializeGl();
316 std::vector<gvr::BufferSpec> specs; 316 std::vector<gvr::BufferSpec> specs;
317 // For kFramePrimaryBuffer (primary VrShell and WebVR content) 317 // For kFramePrimaryBuffer (primary VrShell and WebVR content)
318 specs.push_back(gvr_api_->CreateBufferSpec()); 318 specs.push_back(gvr_api_->CreateBufferSpec());
319 render_size_primary_ = specs[kFramePrimaryBuffer].GetSize(); 319 render_size_primary_ = specs[kFramePrimaryBuffer].GetSize();
320 render_size_primary_vrshell_ = render_size_primary_;
321 320
322 // For kFrameHeadlockedBuffer (for WebVR insecure content warning). 321 // For kFrameHeadlockedBuffer (for WebVR insecure content warning).
323 // Set this up at fixed resolution, the (smaller) FOV gets set below. 322 // Set this up at fixed resolution, the (smaller) FOV gets set below.
324 specs.push_back(gvr_api_->CreateBufferSpec()); 323 specs.push_back(gvr_api_->CreateBufferSpec());
325 specs.back().SetSize(kHeadlockedBufferDimensions); 324 specs.back().SetSize(kHeadlockedBufferDimensions);
326 render_size_headlocked_ = specs[kFrameHeadlockedBuffer].GetSize(); 325 render_size_headlocked_ = specs[kFrameHeadlockedBuffer].GetSize();
327 326
328 swap_chain_.reset(new gvr::SwapChain(gvr_api_->CreateSwapChain(specs))); 327 swap_chain_.reset(new gvr::SwapChain(gvr_api_->CreateSwapChain(specs)));
329 328
330 vr_shell_renderer_.reset(new VrShellRenderer()); 329 vr_shell_renderer_.reset(new VrShellRenderer());
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 return true; 602 return true;
604 } 603 }
605 604
606 void VrShellGl::DrawFrame() { 605 void VrShellGl::DrawFrame() {
607 TRACE_EVENT0("gpu", "VrShellGl::DrawFrame"); 606 TRACE_EVENT0("gpu", "VrShellGl::DrawFrame");
608 // Reset the viewport list to just the pair of viewports for the 607 // Reset the viewport list to just the pair of viewports for the
609 // primary buffer each frame. Head-locked viewports get added by 608 // primary buffer each frame. Head-locked viewports get added by
610 // DrawVrShell if needed. 609 // DrawVrShell if needed.
611 buffer_viewport_list_->SetToRecommendedBufferViewports(); 610 buffer_viewport_list_->SetToRecommendedBufferViewports();
612 611
613 // TODO(klausw): Fix this. Resizing buffers here leads to webVR mode showing
614 // nothing but a black screen.
615 // if (vr_shell_->GetUiInterface()->GetMode() == UiInterface::Mode::WEB_VR) {
616 // // If needed, resize the primary buffer for use with WebVR.
617 // if (render_size_primary_ != render_size_primary_webvr_) {
618 // if (!render_size_primary_webvr_.width) {
619 // VLOG(2) << "WebVR rendering size not known yet, dropping frame";
620 // return;
621 // }
622 // render_size_primary_ = render_size_primary_webvr_;
623 // swap_chain_->ResizeBuffer(kFramePrimaryBuffer, render_size_primary_);
624 // }
625 // } else {
626 // if (render_size_primary_ != render_size_primary_vrshell_) {
627 // render_size_primary_ = render_size_primary_vrshell_;
628 // swap_chain_->ResizeBuffer(kFramePrimaryBuffer, render_size_primary_);
629 // }
630 // }
631
632 gvr::Frame frame = swap_chain_->AcquireFrame(); 612 gvr::Frame frame = swap_chain_->AcquireFrame();
633 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); 613 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow();
634 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; 614 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos;
635 615
636 gvr::Mat4f head_pose = 616 gvr::Mat4f head_pose =
637 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); 617 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time);
638 618
639 gvr::Vec3f position = GetTranslation(head_pose); 619 gvr::Vec3f position = GetTranslation(head_pose);
640 if (position.x == 0.0f && position.y == 0.0f && position.z == 0.0f) { 620 if (position.x == 0.0f && position.y == 0.0f && position.z == 0.0f) {
641 // This appears to be a 3DOF pose without a neck model. Add one. 621 // This appears to be a 3DOF pose without a neck model. Add one.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 // TODO(mthiesse): We don't unbind this? Maybe some cleanup is in order 728 // TODO(mthiesse): We don't unbind this? Maybe some cleanup is in order
749 // here. 729 // here.
750 frame.BindBuffer(kFrameHeadlockedBuffer); 730 frame.BindBuffer(kFrameHeadlockedBuffer);
751 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 731 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
752 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 732 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
753 DrawUiView(nullptr, head_locked_elements, render_size_headlocked_, 733 DrawUiView(nullptr, head_locked_elements, render_size_headlocked_,
754 kViewportListHeadlockedOffset); 734 kViewportListHeadlockedOffset);
755 } 735 }
756 } 736 }
757 737
758 void VrShellGl::SetWebVRRenderSurfaceSize(int width, int height) {
759 render_size_primary_webvr_.width = width;
760 render_size_primary_webvr_.height = height;
761 // TODO(klausw,crbug.com/655722): set the WebVR render surface size here once
762 // we have that.
763 }
764
765 gvr::Sizei VrShellGl::GetWebVRCompositorSurfaceSize() { 738 gvr::Sizei VrShellGl::GetWebVRCompositorSurfaceSize() {
766 // This is a stopgap while we're using the WebVR compositor rendering path. 739 // This is a stopgap while we're using the WebVR compositor rendering path.
767 // TODO(klausw,crbug.com/655722): Remove this method and member once we're 740 // TODO(klausw,crbug.com/655722): Remove this method and member once we're
768 // using a separate WebVR render surface. 741 // using a separate WebVR render surface.
769 return content_tex_physical_size_; 742 return content_tex_physical_size_;
770 } 743 }
771 744
772 void VrShellGl::DrawUiView(const gvr::Mat4f* head_pose, 745 void VrShellGl::DrawUiView(const gvr::Mat4f* head_pose,
773 const std::vector<const ContentRectangle*>& elements, 746 const std::vector<const ContentRectangle*>& elements,
774 const gvr::Sizei& render_size, 747 const gvr::Sizei& render_size,
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 target = now; 971 target = now;
999 } else { 972 } else {
1000 target = now + vsync_interval_; 973 target = now + vsync_interval_;
1001 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; 974 int64_t intervals = (target - vsync_timebase_) / vsync_interval_;
1002 target = vsync_timebase_ + intervals * vsync_interval_; 975 target = vsync_timebase_ + intervals * vsync_interval_;
1003 } 976 }
1004 977
1005 task_runner_->PostDelayedTask(FROM_HERE, draw_task_.callback(), target - now); 978 task_runner_->PostDelayedTask(FROM_HERE, draw_task_.callback(), target - now);
1006 } 979 }
1007 980
1008 void VrShellGl::ForceExitVR() { 981 void VrShellGl::ForceExitVr() {
1009 main_thread_task_runner_->PostTask( 982 main_thread_task_runner_->PostTask(
1010 FROM_HERE, base::Bind(&VrShell::ForceExitVR, weak_vr_shell_)); 983 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_));
1011 } 984 }
1012 985
1013 } // namespace vr_shell 986 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698