Chromium Code Reviews| Index: chrome/browser/android/vr_shell/vr_shell.cc |
| diff --git a/chrome/browser/android/vr_shell/vr_shell.cc b/chrome/browser/android/vr_shell/vr_shell.cc |
| index c32e477f7b76dcd5eecf5d42f5a2828e2f32c90f..8f0a250a9935cd3125b24855606056ea51d0a7fb 100644 |
| --- a/chrome/browser/android/vr_shell/vr_shell.cc |
| +++ b/chrome/browser/android/vr_shell/vr_shell.cc |
| @@ -219,10 +219,17 @@ VrShell::~VrShell() { |
| g_instance = nullptr; |
| } |
| -void VrShell::PostToGlThreadWhenReady(const base::Closure& task) { |
| +void VrShell::WaitForGlThread() { |
| + if (thread_started_) |
| + return; |
| + gl_thread_->WaitUntilThreadStarted(); |
| + thread_started_ = true; |
| +} |
| + |
| +void VrShell::PostToGlThread(const base::Closure& task) { |
| + DCHECK(thread_started_); |
| // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't |
| // finished starting? |
| - gl_thread_->WaitUntilThreadStarted(); |
| gl_thread_->task_runner()->PostTask(FROM_HERE, task); |
| } |
| @@ -247,14 +254,14 @@ void VrShell::NavigateBack() { |
| } |
| void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| - gl_thread_->task_runner()->PostTask( |
| - FROM_HERE, |
| + WaitForGlThread(); |
| + PostToGlThread( |
|
Ian Vollick
2017/05/17 15:27:58
With this helper, won't the FROM_HERE in PostToGlT
mthiesse
2017/05/17 15:37:08
Can't do as you ask, but as discussed offline, I'v
|
| base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl())); |
| } |
| void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| - gl_thread_->task_runner()->PostTask( |
| - FROM_HERE, base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl())); |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl())); |
| // exit vr session |
| if (metrics_helper_) |
| @@ -263,8 +270,8 @@ void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| } |
| void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| - gl_thread_->task_runner()->PostTask( |
| - FROM_HERE, base::Bind(&VrShellGl::OnResume, gl_thread_->GetVrShellGl())); |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::OnResume, gl_thread_->GetVrShellGl())); |
| if (metrics_helper_) |
| metrics_helper_->SetVRActive(true); |
| @@ -277,9 +284,10 @@ void VrShell::SetSurface(JNIEnv* env, |
| CHECK(!reprojected_rendering_); |
| gfx::AcceleratedWidget window = |
| ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface); |
| - PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl, |
| - gl_thread_->GetVrShellGl(), |
| - base::Unretained(window))); |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::InitializeGl, |
| + gl_thread_->GetVrShellGl(), |
| + base::Unretained(window))); |
| } |
| void VrShell::SetWebVrMode(JNIEnv* env, |
| @@ -288,8 +296,9 @@ void VrShell::SetWebVrMode(JNIEnv* env, |
| webvr_mode_ = enabled; |
| if (metrics_helper_) |
| metrics_helper_->SetWebVREnabled(enabled); |
| - PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode, |
| - gl_thread_->GetVrShellGl(), enabled)); |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::SetWebVrMode, |
| + gl_thread_->GetVrShellGl(), enabled)); |
| ui_->SetWebVrMode(enabled); |
| } |
| @@ -352,40 +361,41 @@ void VrShell::SetWebVRSecureOrigin(bool secure_origin) { |
| void VrShell::SubmitWebVRFrame(int16_t frame_index, |
| const gpu::MailboxHolder& mailbox) { |
| TRACE_EVENT1("gpu", "SubmitWebVRFrame", "frame", frame_index); |
| - |
| - PostToGlThreadWhenReady(base::Bind(&VrShellGl::SubmitWebVRFrame, |
| - gl_thread_->GetVrShellGl(), frame_index, |
| - mailbox)); |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::SubmitWebVRFrame, |
| + gl_thread_->GetVrShellGl(), frame_index, mailbox)); |
| } |
| void VrShell::SubmitControllerModel(std::unique_ptr<VrControllerModel> model) { |
| - PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetControllerModel, |
| - gl_thread_->GetVrShellGl(), |
| - base::Passed(&model))); |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::SetControllerModel, |
| + gl_thread_->GetVrShellGl(), base::Passed(&model))); |
| } |
| void VrShell::UpdateWebVRTextureBounds(int16_t frame_index, |
| const gfx::RectF& left_bounds, |
| const gfx::RectF& right_bounds, |
| const gfx::Size& source_size) { |
| - PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds, |
| - gl_thread_->GetVrShellGl(), frame_index, |
| - left_bounds, right_bounds, source_size)); |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::UpdateWebVRTextureBounds, |
| + gl_thread_->GetVrShellGl(), frame_index, |
| + left_bounds, right_bounds, source_size)); |
| } |
| void VrShell::CreateVRDisplayInfo( |
| const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| uint32_t device_id) { |
| - PostToGlThreadWhenReady(base::Bind(&VrShellGl::CreateVRDisplayInfo, |
| - gl_thread_->GetVrShellGl(), callback, |
| - device_id)); |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::CreateVRDisplayInfo, |
| + gl_thread_->GetVrShellGl(), callback, device_id)); |
| } |
| void VrShell::SetSubmitClient( |
| device::mojom::VRSubmitFrameClientPtr submit_client) { |
| - PostToGlThreadWhenReady( |
| - base::Bind(&VrShellGl::SetSubmitClient, gl_thread_->GetVrShellGl(), |
| - base::Passed(submit_client.PassInterface()))); |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::SetSubmitClient, |
| + gl_thread_->GetVrShellGl(), |
| + base::Passed(submit_client.PassInterface()))); |
| } |
| base::android::ScopedJavaGlobalRef<jobject> VrShell::TakeContentSurface( |
| @@ -399,7 +409,8 @@ base::android::ScopedJavaGlobalRef<jobject> VrShell::TakeContentSurface( |
| void VrShell::RestoreContentSurface(JNIEnv* env, |
| const JavaParamRef<jobject>& obj) { |
| - PostToGlThreadWhenReady( |
| + WaitForGlThread(); |
| + PostToGlThread( |
| base::Bind(&VrShellGl::CreateContentSurface, gl_thread_->GetVrShellGl())); |
| } |
| @@ -439,11 +450,11 @@ void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, |
| jint height, |
| jfloat dpr) { |
| TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged"); |
| + WaitForGlThread(); |
| // TODO(acondor): Set the device scale factor for font rendering on the |
| // VR Shell textures. |
| - PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged, |
| - gl_thread_->GetVrShellGl(), width, |
| - height)); |
| + PostToGlThread(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged, |
| + gl_thread_->GetVrShellGl(), width, height)); |
| compositor_->SetWindowBounds(gfx::Size(width, height)); |
| } |
| @@ -485,9 +496,10 @@ void VrShell::DoUiAction(const UiAction action, |
| void VrShell::ContentFrameWasResized(bool width_changed) { |
| display::Display display = |
| display::Screen::GetScreen()->GetDisplayNearestWindow(window_); |
| - PostToGlThreadWhenReady( |
| - base::Bind(&VrShellGl::ContentBoundsChanged, gl_thread_->GetVrShellGl(), |
| - display.size().width(), display.size().height())); |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::ContentBoundsChanged, |
| + gl_thread_->GetVrShellGl(), display.size().width(), |
| + display.size().height())); |
| } |
| void VrShell::ContentWebContentsDestroyed() { |
| @@ -524,17 +536,18 @@ void VrShell::ExitFullscreen() { |
| void VrShell::OnVRVsyncProviderRequest( |
| device::mojom::VRVSyncProviderRequest request) { |
| - PostToGlThreadWhenReady(base::Bind(&VrShellGl::OnRequest, |
| - gl_thread_->GetVrShellGl(), |
| - base::Passed(&request))); |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::OnRequest, gl_thread_->GetVrShellGl(), |
| + base::Passed(&request))); |
| } |
| void VrShell::UpdateVSyncInterval(int64_t timebase_nanos, |
| double interval_seconds) { |
| PollMediaAccessFlag(); |
| - PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateVSyncInterval, |
| - gl_thread_->GetVrShellGl(), timebase_nanos, |
| - interval_seconds)); |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::UpdateVSyncInterval, |
| + gl_thread_->GetVrShellGl(), timebase_nanos, |
| + interval_seconds)); |
| } |
| void VrShell::PollMediaAccessFlag() { |
| @@ -550,24 +563,27 @@ void VrShell::PollMediaAccessFlag() { |
| MediaCaptureDevicesDispatcher::GetInstance() |
| ->GetMediaStreamCaptureIndicator(); |
| bool is_capturing_audio = indicator->IsCapturingAudio(web_contents_); |
| - if (is_capturing_audio != is_capturing_audio_) |
| - PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetAudioCapturingWarning, |
| - gl_thread_->GetVrShellGl(), |
| - is_capturing_audio)); |
| + if (is_capturing_audio != is_capturing_audio_) { |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::SetAudioCapturingWarning, |
| + gl_thread_->GetVrShellGl(), is_capturing_audio)); |
| + } |
| is_capturing_audio_ = is_capturing_audio; |
| bool is_capturing_video = indicator->IsCapturingVideo(web_contents_); |
| - if (is_capturing_video != is_capturing_video_) |
| - PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetVideoCapturingWarning, |
| - gl_thread_->GetVrShellGl(), |
| - is_capturing_video)); |
| + if (is_capturing_video != is_capturing_video_) { |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::SetVideoCapturingWarning, |
| + gl_thread_->GetVrShellGl(), is_capturing_video)); |
| + } |
| is_capturing_video_ = is_capturing_video; |
| bool is_capturing_screen = indicator->IsBeingMirrored(web_contents_); |
| - if (is_capturing_screen != is_capturing_screen_) |
| - PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetScreenCapturingWarning, |
| - gl_thread_->GetVrShellGl(), |
| - is_capturing_screen)); |
| + if (is_capturing_screen != is_capturing_screen_) { |
| + WaitForGlThread(); |
| + PostToGlThread(base::Bind(&VrShellGl::SetScreenCapturingWarning, |
| + gl_thread_->GetVrShellGl(), is_capturing_screen)); |
| + } |
| is_capturing_screen_ = is_capturing_screen; |
| } |