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 642a0caf3d58dff62f8dc17f676845f69d1d6f45..847d6583752dd34c37c9ff271b197ba16ec5ba36 100644 |
--- a/chrome/browser/android/vr_shell/vr_shell.cc |
+++ b/chrome/browser/android/vr_shell/vr_shell.cc |
@@ -156,6 +156,15 @@ VrShell::VrShell(JNIEnv* env, |
desktop_plane_ = scene_.GetUiElementById(kBrowserUiElementId); |
LoadUIContent(); |
+ |
+ webvr_head_pose_.resize(kPoseRingBufferSize); |
dcheng
2016/10/05 07:34:44
resize() takes a second argument, so I think this
klausw
2016/10/05 17:02:10
Done.
|
+ const gvr::Mat4f identity = {{{1.0f, 0.0f, 0.0f, 0.0f}, |
dcheng
2016/10/05 07:34:44
Nit: prefer constexpr to const (also prefix with k
mthiesse
2016/10/05 15:40:01
Might as well re-use SetIdentityM in vr_math.cc
A
klausw
2016/10/05 17:02:10
Acknowledged, but it's no longer const (or constex
klausw
2016/10/05 17:02:10
I changed it to use SetIdentityM. Somehow I was un
dcheng
2016/10/05 17:35:21
Casting away const-ness would be a Bad Thing™ to d
|
+ {0.0f, 1.0f, 0.0f, 0.0f}, |
+ {0.0f, 0.0f, 1.0f, 0.0f}, |
+ {0.0f, 0.0f, 0.0f, 1.0f}}}; |
+ for (int i = 0; i < kPoseRingBufferSize; ++i) { |
+ webvr_head_pose_[i] = identity; |
+ } |
} |
void VrShell::UpdateCompositorLayers(JNIEnv* env, |
@@ -276,6 +285,23 @@ void VrShell::UpdateController(const gvr::Vec3f& forward_vector) { |
} |
} |
+void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { |
+ webvr_head_pose_[pose_num % kPoseRingBufferSize] = pose; |
+} |
+ |
+uint32_t GetPixelEncodedPoseIndex() { |
+ // Read the pose index encoded in a bottom left pixel as color values. |
+ // See also third_party/WebKit/Source/modules/vr/VRDisplay.cpp which |
+ // encodes the pose index, and device/vr/android/gvr/gvr_device.cc |
+ // which tracks poses. |
+ uint8_t pixels[4]; |
+ // Assume we're reading from the frambebuffer we just wrote to. |
+ // That's true currently, we may need to use glReadBuffer(GL_BACK) |
+ // or equivalent if the rendering setup changes in the future. |
+ glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
mthiesse
2016/10/05 13:14:06
After you start presenting, aren't the poses and f
mthiesse
2016/10/05 14:58:42
Acknowledged.
|
+ return pixels[0] | (pixels[1] << 8) | (pixels[2] << 16); |
+} |
+ |
void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
buffer_viewport_list_->SetToRecommendedBufferViewports(); |
@@ -293,6 +319,18 @@ void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
if (!webvr_secure_origin_) { |
DrawWebVrOverlay(target_time.monotonic_system_time_nanos); |
} |
+ |
+ // When using async reprojection, we need to know which pose was used in |
+ // the WebVR app for drawing this frame. Due to unknown amounts of |
+ // buffering in the compositor and SurfaceTexture, we read the pose number |
+ // from a corner pixel. There's no point in doing this for legacy |
+ // distortion rendering since that doesn't need a pose, and reading back |
+ // pixels is an expensive operation. TODO(klausw): stop doing this once we |
+ // have working no-compositor rendering for WebVR. |
+ if (gvr_api_->GetAsyncReprojectionEnabled()) { |
+ int32_t webvr_pose_frame = GetPixelEncodedPoseIndex(); |
dcheng
2016/10/05 07:34:44
Nit: match types with uint32_t here as well.
klausw
2016/10/05 17:02:10
Done. I'm surprised the compiler didn't complain a
dcheng
2016/10/05 17:35:21
We suppress a lot of unsigned / signed conversion
|
+ head_pose = webvr_head_pose_[webvr_pose_frame % kPoseRingBufferSize]; |
+ } |
} else { |
DrawVrShell(head_pose); |
} |