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 14 matching lines...) Expand all Loading... |
25 #include "content/public/browser/render_widget_host_view.h" | 25 #include "content/public/browser/render_widget_host_view.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "content/public/common/referrer.h" | 27 #include "content/public/common/referrer.h" |
28 #include "device/vr/android/gvr/gvr_device_provider.h" | 28 #include "device/vr/android/gvr/gvr_device_provider.h" |
29 #include "jni/VrShellImpl_jni.h" | 29 #include "jni/VrShellImpl_jni.h" |
30 #include "ui/android/view_android.h" | 30 #include "ui/android/view_android.h" |
31 #include "ui/android/window_android.h" | 31 #include "ui/android/window_android.h" |
32 #include "ui/base/page_transition_types.h" | 32 #include "ui/base/page_transition_types.h" |
33 #include "ui/display/display.h" | 33 #include "ui/display/display.h" |
34 #include "ui/display/screen.h" | 34 #include "ui/display/screen.h" |
| 35 #include "ui/gfx/transform.h" |
| 36 #include "ui/gfx/transform_util.h" |
35 | 37 |
36 using base::android::JavaParamRef; | 38 using base::android::JavaParamRef; |
37 using base::android::JavaRef; | 39 using base::android::JavaRef; |
38 | 40 |
39 namespace vr_shell { | 41 namespace vr_shell { |
40 | 42 |
41 namespace { | 43 namespace { |
42 vr_shell::VrShell* g_instance; | 44 vr_shell::VrShell* g_instance; |
43 | 45 |
44 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; | 46 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 263 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
262 PostToGlThreadWhenReady( | 264 PostToGlThreadWhenReady( |
263 base::Bind(&VrShellGl::SetWebVrMode, thread->GetVrShellGl(), enabled)); | 265 base::Bind(&VrShellGl::SetWebVrMode, thread->GetVrShellGl(), enabled)); |
264 if (enabled) { | 266 if (enabled) { |
265 html_interface_->SetMode(UiInterface::Mode::WEB_VR); | 267 html_interface_->SetMode(UiInterface::Mode::WEB_VR); |
266 } else { | 268 } else { |
267 html_interface_->SetMode(UiInterface::Mode::STANDARD); | 269 html_interface_->SetMode(UiInterface::Mode::STANDARD); |
268 } | 270 } |
269 } | 271 } |
270 | 272 |
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) { | 273 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { |
281 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR | 274 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR |
282 // render surface size. | 275 // render surface size. |
283 } | 276 } |
284 | 277 |
285 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { | 278 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { |
286 const gfx::Size& size = content_compositor_->GetWindowBounds(); | 279 const gfx::Size& size = content_compositor_->GetWindowBounds(); |
287 return {size.width(), size.height()}; | 280 return {size.width(), size.height()}; |
288 } | 281 } |
289 | 282 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 // Ensure we don't continue sending input to it. | 438 // Ensure we don't continue sending input to it. |
446 content_input_manager_.reset(); | 439 content_input_manager_.reset(); |
447 // TODO(mthiesse): Handle web contents being hidden. | 440 // TODO(mthiesse): Handle web contents being hidden. |
448 ForceExitVr(); | 441 ForceExitVr(); |
449 } | 442 } |
450 | 443 |
451 void VrShell::ForceExitVr() { | 444 void VrShell::ForceExitVr() { |
452 delegate_->ForceExitVr(); | 445 delegate_->ForceExitVr(); |
453 } | 446 } |
454 | 447 |
| 448 void VrShell::OnVRVsyncProviderRequest( |
| 449 device::mojom::VRVSyncProviderRequest request) { |
| 450 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
| 451 PostToGlThreadWhenReady(base::Bind( |
| 452 &VrShellGl::OnRequest, thread->GetVrShellGl(), base::Passed(&request))); |
| 453 } |
| 454 |
| 455 void VrShell::UpdateVSyncInterval(long timebase_nanos, |
| 456 double interval_seconds) { |
| 457 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
| 458 PostToGlThreadWhenReady( |
| 459 base::Bind(&VrShellGl::UpdateVSyncInterval, |
| 460 thread->GetVrShellGl(), timebase_nanos, interval_seconds)); |
| 461 } |
| 462 |
455 void VrShell::SetContentCssSize(float width, float height, float dpr) { | 463 void VrShell::SetContentCssSize(float width, float height, float dpr) { |
456 JNIEnv* env = base::android::AttachCurrentThread(); | 464 JNIEnv* env = base::android::AttachCurrentThread(); |
457 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, | 465 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, |
458 dpr); | 466 dpr); |
459 } | 467 } |
460 | 468 |
461 void VrShell::SetUiCssSize(float width, float height, float dpr) { | 469 void VrShell::SetUiCssSize(float width, float height, float dpr) { |
462 JNIEnv* env = base::android::AttachCurrentThread(); | 470 JNIEnv* env = base::android::AttachCurrentThread(); |
463 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr); | 471 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr); |
464 } | 472 } |
465 | 473 |
| 474 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat, |
| 475 uint32_t pose_index) { |
| 476 device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); |
| 477 |
| 478 pose->timestamp = base::Time::Now().ToJsTime(); |
| 479 |
| 480 // Increment pose frame counter always, even if it's a faked pose. |
| 481 pose->poseIndex = pose_index; |
| 482 pose->orientation.emplace(4); |
| 483 |
| 484 gfx::Transform inv_transform( |
| 485 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3], |
| 486 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3], |
| 487 head_mat.m[2][0], head_mat.m[2][1], head_mat.m[2][2], head_mat.m[2][3], |
| 488 head_mat.m[3][0], head_mat.m[3][1], head_mat.m[3][2], head_mat.m[3][3]); |
| 489 |
| 490 gfx::Transform transform; |
| 491 if (inv_transform.GetInverse(&transform)) { |
| 492 gfx::DecomposedTransform decomposed_transform; |
| 493 gfx::DecomposeTransform(&decomposed_transform, transform); |
| 494 |
| 495 pose->orientation.value()[0] = decomposed_transform.quaternion[0]; |
| 496 pose->orientation.value()[1] = decomposed_transform.quaternion[1]; |
| 497 pose->orientation.value()[2] = decomposed_transform.quaternion[2]; |
| 498 pose->orientation.value()[3] = decomposed_transform.quaternion[3]; |
| 499 |
| 500 pose->position.emplace(3); |
| 501 pose->position.value()[0] = decomposed_transform.translate[0]; |
| 502 pose->position.value()[1] = decomposed_transform.translate[1]; |
| 503 pose->position.value()[2] = decomposed_transform.translate[2]; |
| 504 } |
| 505 |
| 506 return pose; |
| 507 } |
| 508 |
466 // ---------------------------------------------------------------------------- | 509 // ---------------------------------------------------------------------------- |
467 // Native JNI methods | 510 // Native JNI methods |
468 // ---------------------------------------------------------------------------- | 511 // ---------------------------------------------------------------------------- |
469 | 512 |
470 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, | 513 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, |
471 const JavaParamRef<jobject>& content_web_contents, | 514 const JavaParamRef<jobject>& content_web_contents, |
472 jlong content_window_android, | 515 jlong content_window_android, |
473 const JavaParamRef<jobject>& ui_web_contents, | 516 const JavaParamRef<jobject>& ui_web_contents, |
474 jlong ui_window_android, jboolean for_web_vr, | 517 jlong ui_window_android, jboolean for_web_vr, |
475 const base::android::JavaParamRef<jobject>& delegate, | 518 const base::android::JavaParamRef<jobject>& delegate, |
476 jlong gvr_api, jboolean reprojected_rendering) { | 519 jlong gvr_api, jboolean reprojected_rendering) { |
477 return reinterpret_cast<intptr_t>(new VrShell( | 520 return reinterpret_cast<intptr_t>(new VrShell( |
478 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 521 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
479 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 522 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
480 content::WebContents::FromJavaWebContents(ui_web_contents), | 523 content::WebContents::FromJavaWebContents(ui_web_contents), |
481 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), | 524 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), |
482 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), | 525 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), |
483 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 526 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
484 } | 527 } |
485 | 528 |
486 } // namespace vr_shell | 529 } // namespace vr_shell |
OLD | NEW |