| 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 79d159778ccad512838f9115c28d522887474682..996da9dbee77db397bac9034856c04fe36aea014 100644
|
| --- a/chrome/browser/android/vr_shell/vr_shell.cc
|
| +++ b/chrome/browser/android/vr_shell/vr_shell.cc
|
| @@ -274,6 +274,24 @@ void VrShell::UpdateController(const gvr::Vec3f& forward_vector) {
|
| }
|
| }
|
|
|
| +void VrShell::SetGvrPoseForWebVr(gvr::Mat4f pose, uint32_t pose_num) {
|
| + webvr_head_pose_[pose_num % POSE_QUEUE_SIZE] = pose;
|
| + webvr_newest_pose_num_ = pose_num;
|
| +}
|
| +
|
| +int32_t GetPixelEncodedFrameNumber() {
|
| + // Read the frame number encoded in a bottom left pixel as color values.
|
| + // See also third_party/WebKit/Source/modules/vr/VRDisplay.cpp which
|
| + // encodes the frame number, 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);
|
| + return pixels[0] | (pixels[1] << 8) | (pixels[2] << 16);
|
| +}
|
| +
|
| void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) {
|
| buffer_viewport_list_->SetToRecommendedBufferViewports();
|
|
|
| @@ -291,6 +309,13 @@ void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) {
|
| if (!webvr_secure_origin_) {
|
| DrawWebVrOverlay(target_time.monotonic_system_time_nanos);
|
| }
|
| +
|
| + int32_t webvr_pose_frame = GetPixelEncodedFrameNumber();
|
| + // LOG << "klausw: newest_pose=" << webvr_newest_pose_num_ <<
|
| + // " pixel=" << webvr_pose_frame <<
|
| + // "(" << webvr_pose_frame - webvr_newest_pose_num_ << ")";
|
| +
|
| + head_pose = webvr_head_pose_[webvr_pose_frame % POSE_QUEUE_SIZE];
|
| } else {
|
| DrawVrShell(head_pose);
|
| }
|
| @@ -516,7 +541,7 @@ void VrShell::DrawWebVrEye(const gvr::Mat4f& view_matrix,
|
| ScaleM(icon_pos, icon_pos, small_icon_width, small_icon_height, 1.0f);
|
| TranslateM(icon_pos, icon_pos, 0.0f, 0.0f, -kWebVrWarningDistance);
|
| icon_pos = MatrixMul(
|
| - QuatToMatrix(QuatFromAxisAngle(1.f, 0.f, 0.f, small_icon_angle)),
|
| + QuatToMatrix(QuatFromAxisAngle({1.f, 0.f, 0.f}, small_icon_angle)),
|
| icon_pos);
|
| gvr::Mat4f combined = MatrixMul(projection_matrix,
|
| MatrixMul(view_matrix, icon_pos));
|
|
|