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

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell.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
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.h" 5 #include "chrome/browser/android/vr_shell/vr_shell.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/threading/platform_thread.h" 8 #include "base/threading/platform_thread.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // regarding jank in this case, because we're switching from 3D to 2D, 171 // regarding jank in this case, because we're switching from 3D to 2D,
172 // adding/removing a bunch of Java views, and probably changing device 172 // adding/removing a bunch of Java views, and probably changing device
173 // orientation here. 173 // orientation here.
174 base::ThreadRestrictions::ScopedAllowIO allow_io; 174 base::ThreadRestrictions::ScopedAllowIO allow_io;
175 gl_thread_.reset(); 175 gl_thread_.reset();
176 } 176 }
177 delegate_->RemoveDelegate(); 177 delegate_->RemoveDelegate();
178 g_instance = nullptr; 178 g_instance = nullptr;
179 } 179 }
180 180
181 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) {
182 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
183 if (thread->GetVrShellGlUnsafe()) {
184 thread->GetVrShellGlUnsafe()->SetGvrPoseForWebVr(pose, pose_num);
185 }
186 }
187
188 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) {
189 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
190 if (thread->GetVrShellGlUnsafe()) {
191 thread->GetVrShellGlUnsafe()->SetWebVRRenderSurfaceSize(width, height);
192 }
193 }
194
195 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() {
196 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
197 if (thread->GetVrShellGlUnsafe()) {
198 return thread->GetVrShellGlUnsafe()->GetWebVRCompositorSurfaceSize();
199 }
200 return gvr::Sizei();
201 }
202
203 void VrShell::OnTriggerEvent(JNIEnv* env, 181 void VrShell::OnTriggerEvent(JNIEnv* env,
204 const JavaParamRef<jobject>& obj) { 182 const JavaParamRef<jobject>& obj) {
205 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 183 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
206 thread->task_runner()->PostTask(FROM_HERE, 184 thread->task_runner()->PostTask(FROM_HERE,
207 base::Bind(&VrShellGl::OnTriggerEvent, 185 base::Bind(&VrShellGl::OnTriggerEvent,
208 thread->GetVrShellGl())); 186 thread->GetVrShellGl()));
209 } 187 }
210 188
211 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { 189 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) {
212 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 190 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 const base::android::JavaParamRef<jobject>& obj, 230 const base::android::JavaParamRef<jobject>& obj,
253 bool enabled) { 231 bool enabled) {
254 metrics_helper_->SetWebVREnabled(enabled); 232 metrics_helper_->SetWebVREnabled(enabled);
255 if (enabled) { 233 if (enabled) {
256 html_interface_->SetMode(UiInterface::Mode::WEB_VR); 234 html_interface_->SetMode(UiInterface::Mode::WEB_VR);
257 } else { 235 } else {
258 html_interface_->SetMode(UiInterface::Mode::STANDARD); 236 html_interface_->SetMode(UiInterface::Mode::STANDARD);
259 } 237 }
260 } 238 }
261 239
240 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) {
241 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
242 thread->task_runner()->PostTask(
243 FROM_HERE, base::Bind(&VrShellGl::SetGvrPoseForWebVr,
244 thread->GetVrShellGl(), pose, pose_num));
245 }
246
247 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) {
248 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR
249 // render surface size.
250 }
251
252 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() {
253 const gfx::Size& size = content_compositor_->GetWindowBounds();
254 return {size.width(), size.height()};
255 }
256
262 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { 257 void VrShell::SetWebVRSecureOrigin(bool secure_origin) {
263 // TODO(cjgrant): Align this state with the logic that drives the omnibox. 258 // TODO(cjgrant): Align this state with the logic that drives the omnibox.
264 html_interface_->SetWebVRSecureOrigin(secure_origin); 259 html_interface_->SetWebVRSecureOrigin(secure_origin);
265 } 260 }
266 261
267 void VrShell::SubmitWebVRFrame() {} 262 void VrShell::SubmitWebVRFrame() {}
268 263
269 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, 264 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds,
270 const gvr::Rectf& right_bounds) { 265 const gvr::Rectf& right_bounds) {
271 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 266 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
272 if (thread->GetVrShellGlUnsafe()) { 267 thread->task_runner()->PostTask(
273 thread->GetVrShellGlUnsafe()->UpdateWebVRTextureBounds(left_bounds, 268 FROM_HERE, base::Bind(&VrShellGl::UpdateWebVRTextureBounds,
274 right_bounds); 269 thread->GetVrShellGl(), left_bounds, right_bounds));
275 }
276 } 270 }
277 271
278 // TODO(mthiesse): Do not expose GVR API outside of GL thread. 272 // TODO(mthiesse): Do not expose GVR API outside of GL thread.
279 // It's not thread-safe. 273 // It's not thread-safe.
280 gvr::GvrApi* VrShell::gvr_api() { 274 gvr::GvrApi* VrShell::gvr_api() {
281 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 275 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
282 if (thread->GetVrShellGlUnsafe()) { 276 if (thread->GetVrShellGlUnsafe()) {
283 return thread->GetVrShellGlUnsafe()->gvr_api(); 277 return thread->GetVrShellGlUnsafe()->gvr_api();
284 } 278 }
285 CHECK(false); 279 CHECK(false);
(...skipping 14 matching lines...) Expand all
300 jint width, jint height, jfloat dpr) { 294 jint width, jint height, jfloat dpr) {
301 TRACE_EVENT0("gpu", "VrShell::ContentBoundsChanged"); 295 TRACE_EVENT0("gpu", "VrShell::ContentBoundsChanged");
302 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 296 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
303 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't 297 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't
304 // finished starting? 298 // finished starting?
305 thread->WaitUntilThreadStarted(); 299 thread->WaitUntilThreadStarted();
306 CHECK(thread->task_runner()->PostTask( 300 CHECK(thread->task_runner()->PostTask(
307 FROM_HERE, base::Bind(&VrShellGl::ContentPhysicalBoundsChanged, 301 FROM_HERE, base::Bind(&VrShellGl::ContentPhysicalBoundsChanged,
308 thread->GetVrShellGl(), 302 thread->GetVrShellGl(),
309 width, height))); 303 width, height)));
310 content_compositor_->SetWindowBounds(width, height); 304 content_compositor_->SetWindowBounds(gfx::Size(width, height));
311 } 305 }
312 306
313 void VrShell::UIBoundsChanged(JNIEnv* env, 307 void VrShell::UIBoundsChanged(JNIEnv* env,
314 const JavaParamRef<jobject>& object, 308 const JavaParamRef<jobject>& object,
315 jint width, jint height, jfloat dpr) { 309 jint width, jint height, jfloat dpr) {
316 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 310 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
317 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't 311 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't
318 // finished starting? 312 // finished starting?
319 thread->WaitUntilThreadStarted(); 313 thread->WaitUntilThreadStarted();
320 thread->task_runner()->PostTask( 314 thread->task_runner()->PostTask(
321 FROM_HERE, base::Bind(&VrShellGl::UIPhysicalBoundsChanged, 315 FROM_HERE, base::Bind(&VrShellGl::UIPhysicalBoundsChanged,
322 thread->GetVrShellGl(), 316 thread->GetVrShellGl(),
323 width, height)); 317 width, height));
324 ui_compositor_->SetWindowBounds(width, height); 318 ui_compositor_->SetWindowBounds(gfx::Size(width, height));
325 } 319 }
326 320
327 UiScene* VrShell::GetScene() { 321 UiScene* VrShell::GetScene() {
328 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 322 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
329 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't 323 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't
330 // finished starting? 324 // finished starting?
331 thread->WaitUntilThreadStarted(); 325 thread->WaitUntilThreadStarted();
332 if (thread->GetVrShellGlUnsafe()) { 326 if (thread->GetVrShellGlUnsafe()) {
333 return thread->GetVrShellGlUnsafe()->GetScene(); 327 return thread->GetVrShellGlUnsafe()->GetScene();
334 } 328 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 thread->task_runner()->PostTask( 398 thread->task_runner()->PostTask(
405 FROM_HERE, base::Bind(&VrShellGl::ContentBoundsChanged, 399 FROM_HERE, base::Bind(&VrShellGl::ContentBoundsChanged,
406 thread->GetVrShellGl(), 400 thread->GetVrShellGl(),
407 display.size().width(), display.size().height())); 401 display.size().width(), display.size().height()));
408 } 402 }
409 403
410 void VrShell::WebContentsDestroyed() { 404 void VrShell::WebContentsDestroyed() {
411 ui_input_manager_.reset(); 405 ui_input_manager_.reset();
412 ui_contents_ = nullptr; 406 ui_contents_ = nullptr;
413 // TODO(mthiesse): Handle web contents being destroyed. 407 // TODO(mthiesse): Handle web contents being destroyed.
414 ForceExitVR(); 408 ForceExitVr();
415 } 409 }
416 410
417 void VrShell::ContentWebContentsDestroyed() { 411 void VrShell::ContentWebContentsDestroyed() {
418 content_input_manager_.reset(); 412 content_input_manager_.reset();
419 main_contents_ = nullptr; 413 main_contents_ = nullptr;
420 // TODO(mthiesse): Handle web contents being destroyed. 414 // TODO(mthiesse): Handle web contents being destroyed.
421 ForceExitVR(); 415 ForceExitVr();
422 } 416 }
423 417
424 void VrShell::ContentWasHidden() { 418 void VrShell::ContentWasHidden() {
425 // Ensure we don't continue sending input to it. 419 // Ensure we don't continue sending input to it.
426 content_input_manager_.reset(); 420 content_input_manager_.reset();
427 // TODO(mthiesse): Handle web contents being hidden. 421 // TODO(mthiesse): Handle web contents being hidden.
428 ForceExitVR(); 422 ForceExitVr();
429 } 423 }
430 424
431 void VrShell::ForceExitVR() { 425 void VrShell::ForceExitVr() {
432 delegate_->ForceExitVr(); 426 delegate_->ForceExitVr();
433 } 427 }
434 428
435 void VrShell::SetContentCssSize(float width, float height, float dpr) { 429 void VrShell::SetContentCssSize(float width, float height, float dpr) {
436 JNIEnv* env = base::android::AttachCurrentThread(); 430 JNIEnv* env = base::android::AttachCurrentThread();
437 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, 431 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height,
438 dpr); 432 dpr);
439 } 433 }
440 434
441 void VrShell::SetUiCssSize(float width, float height, float dpr) { 435 void VrShell::SetUiCssSize(float width, float height, float dpr) {
(...skipping 15 matching lines...) Expand all
457 return reinterpret_cast<intptr_t>(new VrShell( 451 return reinterpret_cast<intptr_t>(new VrShell(
458 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), 452 env, obj, content::WebContents::FromJavaWebContents(content_web_contents),
459 reinterpret_cast<ui::WindowAndroid*>(content_window_android), 453 reinterpret_cast<ui::WindowAndroid*>(content_window_android),
460 content::WebContents::FromJavaWebContents(ui_web_contents), 454 content::WebContents::FromJavaWebContents(ui_web_contents),
461 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), 455 reinterpret_cast<ui::WindowAndroid*>(ui_window_android),
462 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), 456 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate),
463 reinterpret_cast<gvr_context*>(gvr_api))); 457 reinterpret_cast<gvr_context*>(gvr_api)));
464 } 458 }
465 459
466 } // namespace vr_shell 460 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell.h ('k') | chrome/browser/android/vr_shell/vr_shell_gl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698