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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 } | 270 } |
269 } | 271 } |
270 | 272 |
271 void VrShell::OnLoadProgressChanged( | 273 void VrShell::OnLoadProgressChanged( |
272 JNIEnv* env, | 274 JNIEnv* env, |
273 const base::android::JavaParamRef<jobject>& obj, | 275 const base::android::JavaParamRef<jobject>& obj, |
274 double progress) { | 276 double progress) { |
275 html_interface_->SetLoadProgress(progress); | 277 html_interface_->SetLoadProgress(progress); |
276 } | 278 } |
277 | 279 |
278 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { | |
279 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | |
280 if (thread->IsRunning()) { | |
281 thread->task_runner()->PostTask( | |
282 FROM_HERE, base::Bind(&VrShellGl::SetGvrPoseForWebVr, | |
283 thread->GetVrShellGl(), pose, pose_num)); | |
284 } | |
285 } | |
286 | |
287 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { | 280 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { |
288 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR | 281 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR |
289 // render surface size. | 282 // render surface size. |
290 } | 283 } |
291 | 284 |
292 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { | 285 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { |
293 const gfx::Size& size = content_compositor_->GetWindowBounds(); | 286 const gfx::Size& size = content_compositor_->GetWindowBounds(); |
294 return {size.width(), size.height()}; | 287 return {size.width(), size.height()}; |
295 } | 288 } |
296 | 289 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 // Ensure we don't continue sending input to it. | 445 // Ensure we don't continue sending input to it. |
453 content_input_manager_.reset(); | 446 content_input_manager_.reset(); |
454 // TODO(mthiesse): Handle web contents being hidden. | 447 // TODO(mthiesse): Handle web contents being hidden. |
455 ForceExitVr(); | 448 ForceExitVr(); |
456 } | 449 } |
457 | 450 |
458 void VrShell::ForceExitVr() { | 451 void VrShell::ForceExitVr() { |
459 delegate_->ForceExitVr(); | 452 delegate_->ForceExitVr(); |
460 } | 453 } |
461 | 454 |
455 void VrShell::OnVRVsyncProviderRequest( | |
456 device::mojom::VRVSyncProviderRequest request) { | |
457 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | |
dcheng
2017/01/14 11:22:53
Can gl_thread_ just be std::unique_ptr<GLThread>?
mthiesse
2017/01/16 20:52:57
Done, but this required moving GLThread to its own
| |
458 PostToGlThreadWhenReady(base::Bind( | |
459 &VrShellGl::OnRequest, thread->GetVrShellGl(), base::Passed(&request))); | |
460 } | |
461 | |
462 void VrShell::UpdateVSyncInterval(long timebase_nanos, | |
463 double interval_seconds) { | |
464 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | |
465 PostToGlThreadWhenReady( | |
466 base::Bind(&VrShellGl::UpdateVSyncInterval, | |
467 thread->GetVrShellGl(), timebase_nanos, interval_seconds)); | |
468 } | |
469 | |
462 void VrShell::SetContentCssSize(float width, float height, float dpr) { | 470 void VrShell::SetContentCssSize(float width, float height, float dpr) { |
463 JNIEnv* env = base::android::AttachCurrentThread(); | 471 JNIEnv* env = base::android::AttachCurrentThread(); |
464 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, | 472 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, |
465 dpr); | 473 dpr); |
466 } | 474 } |
467 | 475 |
468 void VrShell::SetUiCssSize(float width, float height, float dpr) { | 476 void VrShell::SetUiCssSize(float width, float height, float dpr) { |
469 JNIEnv* env = base::android::AttachCurrentThread(); | 477 JNIEnv* env = base::android::AttachCurrentThread(); |
470 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr); | 478 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr); |
471 } | 479 } |
472 | 480 |
481 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat, | |
482 uint32_t pose_index) { | |
483 device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); | |
484 | |
485 pose->timestamp = base::Time::Now().ToJsTime(); | |
486 | |
487 // Increment pose frame counter always, even if it's a faked pose. | |
klausw
2017/01/13 21:04:36
Comment doesn't match code, I don't see any increm
mthiesse
2017/01/16 20:52:57
Done.
| |
488 pose->poseIndex = pose_index; | |
489 pose->orientation.emplace(4); | |
490 | |
491 gfx::Transform inv_transform( | |
492 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3], | |
493 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3], | |
494 head_mat.m[2][0], head_mat.m[2][1], head_mat.m[2][2], head_mat.m[2][3], | |
495 head_mat.m[3][0], head_mat.m[3][1], head_mat.m[3][2], head_mat.m[3][3]); | |
496 | |
497 gfx::Transform transform; | |
498 if (inv_transform.GetInverse(&transform)) { | |
499 gfx::DecomposedTransform decomposed_transform; | |
500 gfx::DecomposeTransform(&decomposed_transform, transform); | |
501 | |
502 pose->orientation.value()[0] = decomposed_transform.quaternion[0]; | |
503 pose->orientation.value()[1] = decomposed_transform.quaternion[1]; | |
504 pose->orientation.value()[2] = decomposed_transform.quaternion[2]; | |
505 pose->orientation.value()[3] = decomposed_transform.quaternion[3]; | |
506 | |
507 pose->position.emplace(3); | |
508 pose->position.value()[0] = decomposed_transform.translate[0]; | |
509 pose->position.value()[1] = decomposed_transform.translate[1]; | |
510 pose->position.value()[2] = decomposed_transform.translate[2]; | |
511 } | |
512 | |
513 return pose; | |
514 } | |
515 | |
473 // ---------------------------------------------------------------------------- | 516 // ---------------------------------------------------------------------------- |
474 // Native JNI methods | 517 // Native JNI methods |
475 // ---------------------------------------------------------------------------- | 518 // ---------------------------------------------------------------------------- |
476 | 519 |
477 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, | 520 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, |
478 const JavaParamRef<jobject>& content_web_contents, | 521 const JavaParamRef<jobject>& content_web_contents, |
479 jlong content_window_android, | 522 jlong content_window_android, |
480 const JavaParamRef<jobject>& ui_web_contents, | 523 const JavaParamRef<jobject>& ui_web_contents, |
481 jlong ui_window_android, jboolean for_web_vr, | 524 jlong ui_window_android, jboolean for_web_vr, |
482 const base::android::JavaParamRef<jobject>& delegate, | 525 const base::android::JavaParamRef<jobject>& delegate, |
483 jlong gvr_api, jboolean reprojected_rendering) { | 526 jlong gvr_api, jboolean reprojected_rendering) { |
484 return reinterpret_cast<intptr_t>(new VrShell( | 527 return reinterpret_cast<intptr_t>(new VrShell( |
485 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 528 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
486 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 529 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
487 content::WebContents::FromJavaWebContents(ui_web_contents), | 530 content::WebContents::FromJavaWebContents(ui_web_contents), |
488 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), | 531 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), |
489 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), | 532 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), |
490 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 533 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
491 } | 534 } |
492 | 535 |
493 } // namespace vr_shell | 536 } // namespace vr_shell |
OLD | NEW |