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 ccff37fc607841bfdc5032bd1adea5edfd7be7b4..4f0875f6c3fa34008728d8e76ff9f30cdcd8a53c 100644 |
--- a/chrome/browser/android/vr_shell/vr_shell.cc |
+++ b/chrome/browser/android/vr_shell/vr_shell.cc |
@@ -32,6 +32,8 @@ |
#include "ui/base/page_transition_types.h" |
#include "ui/display/display.h" |
#include "ui/display/screen.h" |
+#include "ui/gfx/transform.h" |
+#include "ui/gfx/transform_util.h" |
using base::android::JavaParamRef; |
using base::android::JavaRef; |
@@ -268,15 +270,6 @@ void VrShell::SetWebVrMode(JNIEnv* env, |
} |
} |
-void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { |
- GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
- if (thread->IsRunning()) { |
- thread->task_runner()->PostTask( |
- FROM_HERE, base::Bind(&VrShellGl::SetGvrPoseForWebVr, |
- thread->GetVrShellGl(), pose, pose_num)); |
- } |
-} |
- |
void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { |
// TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR |
// render surface size. |
@@ -452,6 +445,21 @@ void VrShell::ForceExitVr() { |
delegate_->ForceExitVr(); |
} |
+void VrShell::OnVRVsyncProviderRequest( |
+ device::mojom::VRVSyncProviderRequest request) { |
+ GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
+ PostToGlThreadWhenReady(base::Bind( |
+ &VrShellGl::OnRequest, thread->GetVrShellGl(), base::Passed(&request))); |
+} |
+ |
+void VrShell::UpdateVSyncInterval(long timebase_nanos, |
+ double interval_seconds) { |
+ GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
+ PostToGlThreadWhenReady( |
+ base::Bind(&VrShellGl::UpdateVSyncInterval, |
+ thread->GetVrShellGl(), timebase_nanos, interval_seconds)); |
+} |
+ |
void VrShell::SetContentCssSize(float width, float height, float dpr) { |
JNIEnv* env = base::android::AttachCurrentThread(); |
Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, |
@@ -463,6 +471,41 @@ void VrShell::SetUiCssSize(float width, float height, float dpr) { |
Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr); |
} |
+device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat, |
+ uint32_t pose_index) { |
+ device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); |
+ |
+ pose->timestamp = base::Time::Now().ToJsTime(); |
+ |
+ // Increment pose frame counter always, even if it's a faked pose. |
+ pose->poseIndex = pose_index; |
+ pose->orientation.emplace(4); |
+ |
+ gfx::Transform inv_transform( |
+ head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3], |
+ head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3], |
+ head_mat.m[2][0], head_mat.m[2][1], head_mat.m[2][2], head_mat.m[2][3], |
+ head_mat.m[3][0], head_mat.m[3][1], head_mat.m[3][2], head_mat.m[3][3]); |
+ |
+ gfx::Transform transform; |
+ if (inv_transform.GetInverse(&transform)) { |
+ gfx::DecomposedTransform decomposed_transform; |
+ gfx::DecomposeTransform(&decomposed_transform, transform); |
+ |
+ pose->orientation.value()[0] = decomposed_transform.quaternion[0]; |
+ pose->orientation.value()[1] = decomposed_transform.quaternion[1]; |
+ pose->orientation.value()[2] = decomposed_transform.quaternion[2]; |
+ pose->orientation.value()[3] = decomposed_transform.quaternion[3]; |
+ |
+ pose->position.emplace(3); |
+ pose->position.value()[0] = decomposed_transform.translate[0]; |
+ pose->position.value()[1] = decomposed_transform.translate[1]; |
+ pose->position.value()[2] = decomposed_transform.translate[2]; |
+ } |
+ |
+ return pose; |
+} |
+ |
// ---------------------------------------------------------------------------- |
// Native JNI methods |
// ---------------------------------------------------------------------------- |