| 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.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell.h" |
| 6 | 6 |
| 7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 261 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
| 262 PostToGlThreadWhenReady( | 262 PostToGlThreadWhenReady( |
| 263 base::Bind(&VrShellGl::SetWebVrMode, thread->GetVrShellGl(), enabled)); | 263 base::Bind(&VrShellGl::SetWebVrMode, thread->GetVrShellGl(), enabled)); |
| 264 if (enabled) { | 264 if (enabled) { |
| 265 html_interface_->SetMode(UiInterface::Mode::WEB_VR); | 265 html_interface_->SetMode(UiInterface::Mode::WEB_VR); |
| 266 } else { | 266 } else { |
| 267 html_interface_->SetMode(UiInterface::Mode::STANDARD); | 267 html_interface_->SetMode(UiInterface::Mode::STANDARD); |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { | |
| 272 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | |
| 273 if (thread->IsRunning()) { | |
| 274 thread->task_runner()->PostTask( | |
| 275 FROM_HERE, base::Bind(&VrShellGl::SetGvrPoseForWebVr, | |
| 276 thread->GetVrShellGl(), pose, pose_num)); | |
| 277 } | |
| 278 } | |
| 279 | |
| 280 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { | 271 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { |
| 281 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR | 272 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR |
| 282 // render surface size. | 273 // render surface size. |
| 283 } | 274 } |
| 284 | 275 |
| 285 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { | 276 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { |
| 286 const gfx::Size& size = content_compositor_->GetWindowBounds(); | 277 const gfx::Size& size = content_compositor_->GetWindowBounds(); |
| 287 return {size.width(), size.height()}; | 278 return {size.width(), size.height()}; |
| 288 } | 279 } |
| 289 | 280 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 // Ensure we don't continue sending input to it. | 435 // Ensure we don't continue sending input to it. |
| 445 content_input_manager_.reset(); | 436 content_input_manager_.reset(); |
| 446 // TODO(mthiesse): Handle web contents being hidden. | 437 // TODO(mthiesse): Handle web contents being hidden. |
| 447 ForceExitVr(); | 438 ForceExitVr(); |
| 448 } | 439 } |
| 449 | 440 |
| 450 void VrShell::ForceExitVr() { | 441 void VrShell::ForceExitVr() { |
| 451 delegate_->ForceExitVr(); | 442 delegate_->ForceExitVr(); |
| 452 } | 443 } |
| 453 | 444 |
| 445 void VrShell::OnVRVsyncProviderReady() { |
| 446 delegate_->device_provider()->OnVRVsyncProviderReady( |
| 447 base::Bind(&VrShell::OnVRVSyncProviderClientConnected, |
| 448 weak_ptr_factory_.GetWeakPtr())); |
| 449 } |
| 450 |
| 451 void VrShell::OnVRVSyncProviderClientConnected( |
| 452 device::mojom::VRVSyncProviderClientPtr client) { |
| 453 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
| 454 PostToGlThreadWhenReady( |
| 455 base::Bind(&VrShellGl::OnVRVSyncProviderClientConnected, |
| 456 thread->GetVrShellGl(), |
| 457 base::Passed(std::move(client)))); |
| 458 } |
| 459 |
| 460 void VrShell::UpdateVSyncInterval(JNIEnv* env, const JavaParamRef<jobject>& obj, |
| 461 jlong timebase_nanos, |
| 462 jdouble interval_seconds) { |
| 463 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
| 464 PostToGlThreadWhenReady( |
| 465 base::Bind(&VrShellGl::UpdateVSyncInterval, |
| 466 thread->GetVrShellGl(), timebase_nanos, interval_seconds)); |
| 467 } |
| 468 |
| 454 void VrShell::SetContentCssSize(float width, float height, float dpr) { | 469 void VrShell::SetContentCssSize(float width, float height, float dpr) { |
| 455 JNIEnv* env = base::android::AttachCurrentThread(); | 470 JNIEnv* env = base::android::AttachCurrentThread(); |
| 456 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, | 471 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, |
| 457 dpr); | 472 dpr); |
| 458 } | 473 } |
| 459 | 474 |
| 460 void VrShell::SetUiCssSize(float width, float height, float dpr) { | 475 void VrShell::SetUiCssSize(float width, float height, float dpr) { |
| 461 JNIEnv* env = base::android::AttachCurrentThread(); | 476 JNIEnv* env = base::android::AttachCurrentThread(); |
| 462 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr); | 477 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr); |
| 463 } | 478 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 476 return reinterpret_cast<intptr_t>(new VrShell( | 491 return reinterpret_cast<intptr_t>(new VrShell( |
| 477 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 492 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
| 478 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 493 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 479 content::WebContents::FromJavaWebContents(ui_web_contents), | 494 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 480 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), | 495 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), |
| 481 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), | 496 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), |
| 482 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 497 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 483 } | 498 } |
| 484 | 499 |
| 485 } // namespace vr_shell | 500 } // namespace vr_shell |
| OLD | NEW |