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 <thread> | 7 #include <thread> |
8 | 8 |
9 #include "chrome/browser/android/vr_shell/ui_scene.h" | 9 #include "chrome/browser/android/vr_shell/ui_scene.h" |
10 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 10 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f; | 267 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f; |
268 if (is_inside) { | 268 if (is_inside) { |
269 closest_element = distance_to_plane; | 269 closest_element = distance_to_plane; |
270 target_point_ = plane_intersection_point; | 270 target_point_ = plane_intersection_point; |
271 target_element_ = &plane; | 271 target_element_ = &plane; |
272 } | 272 } |
273 } | 273 } |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
| 277 void VrShell::SetGvrPoseForWebVr(gvr::Mat4f pose, uint32_t pose_num) { |
| 278 webvr_head_pose_[pose_num % POSE_QUEUE_SIZE] = pose; |
| 279 webvr_newest_pose_num_ = pose_num; |
| 280 } |
| 281 |
| 282 int32_t GetPixelEncodedFrameNumber() { |
| 283 // Read the frame number encoded in a bottom left pixel as color values. |
| 284 // See also third_party/WebKit/Source/modules/vr/VRDisplay.cpp which |
| 285 // encodes the frame number, and device/vr/android/gvr/gvr_device.cc |
| 286 // which tracks poses. |
| 287 uint8_t pixels[4]; |
| 288 // Assume we're reading from the frambebuffer we just wrote to. |
| 289 // That's true currently, we may need to use glReadBuffer(GL_BACK) |
| 290 // or equivalent if the rendering setup changes in the future. |
| 291 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 292 return pixels[0] | (pixels[1] << 8) | (pixels[2] << 16); |
| 293 } |
| 294 |
277 void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 295 void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
278 buffer_viewport_list_->SetToRecommendedBufferViewports(); | 296 buffer_viewport_list_->SetToRecommendedBufferViewports(); |
279 | 297 |
280 gvr::Frame frame = swap_chain_->AcquireFrame(); | 298 gvr::Frame frame = swap_chain_->AcquireFrame(); |
281 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 299 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
282 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 300 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; |
283 gvr::Mat4f head_pose = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_tim
e); | 301 gvr::Mat4f head_pose = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_tim
e); |
284 head_pose = gvr_api_->ApplyNeckModel(head_pose, 1.0f); | 302 head_pose = gvr_api_->ApplyNeckModel(head_pose, 1.0f); |
285 | 303 |
286 // Bind back to the default framebuffer. | 304 // Bind back to the default framebuffer. |
287 frame.BindBuffer(0); | 305 frame.BindBuffer(0); |
288 | 306 |
289 if (webvr_mode_) { | 307 if (webvr_mode_) { |
290 DrawWebVr(); | 308 DrawWebVr(); |
291 if (!webvr_secure_origin_) { | 309 if (!webvr_secure_origin_) { |
292 DrawWebVrOverlay(target_time.monotonic_system_time_nanos); | 310 DrawWebVrOverlay(target_time.monotonic_system_time_nanos); |
293 } | 311 } |
| 312 |
| 313 int32_t webvr_pose_frame = GetPixelEncodedFrameNumber(); |
| 314 // LOG << "klausw: newest_pose=" << webvr_newest_pose_num_ << |
| 315 // " pixel=" << webvr_pose_frame << |
| 316 // "(" << webvr_pose_frame - webvr_newest_pose_num_ << ")"; |
| 317 |
| 318 head_pose = webvr_head_pose_[webvr_pose_frame % POSE_QUEUE_SIZE]; |
294 } else { | 319 } else { |
295 DrawVrShell(head_pose); | 320 DrawVrShell(head_pose); |
296 } | 321 } |
297 | 322 |
298 frame.Unbind(); | 323 frame.Unbind(); |
299 frame.Submit(*buffer_viewport_list_, head_pose); | 324 frame.Submit(*buffer_viewport_list_, head_pose); |
300 } | 325 } |
301 | 326 |
302 void VrShell::DrawVrShell(const gvr::Mat4f& head_pose) { | 327 void VrShell::DrawVrShell(const gvr::Mat4f& head_pose) { |
303 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; | 328 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 SetIdentityM(icon_pos); | 534 SetIdentityM(icon_pos); |
510 const float small_icon_width = | 535 const float small_icon_width = |
511 kWebVrWarningPermanentRect.width / 1000.f * kWebVrWarningDistance; | 536 kWebVrWarningPermanentRect.width / 1000.f * kWebVrWarningDistance; |
512 const float small_icon_height = | 537 const float small_icon_height = |
513 kWebVrWarningPermanentRect.height / 1000.f * kWebVrWarningDistance; | 538 kWebVrWarningPermanentRect.height / 1000.f * kWebVrWarningDistance; |
514 const float small_icon_angle = | 539 const float small_icon_angle = |
515 kWebVrWarningPermanentAngle * M_PI / 180.f; // Degrees to radians. | 540 kWebVrWarningPermanentAngle * M_PI / 180.f; // Degrees to radians. |
516 ScaleM(icon_pos, icon_pos, small_icon_width, small_icon_height, 1.0f); | 541 ScaleM(icon_pos, icon_pos, small_icon_width, small_icon_height, 1.0f); |
517 TranslateM(icon_pos, icon_pos, 0.0f, 0.0f, -kWebVrWarningDistance); | 542 TranslateM(icon_pos, icon_pos, 0.0f, 0.0f, -kWebVrWarningDistance); |
518 icon_pos = MatrixMul( | 543 icon_pos = MatrixMul( |
519 QuatToMatrix(QuatFromAxisAngle(1.f, 0.f, 0.f, small_icon_angle)), | 544 QuatToMatrix(QuatFromAxisAngle({1.f, 0.f, 0.f}, small_icon_angle)), |
520 icon_pos); | 545 icon_pos); |
521 gvr::Mat4f combined = MatrixMul(projection_matrix, | 546 gvr::Mat4f combined = MatrixMul(projection_matrix, |
522 MatrixMul(view_matrix, icon_pos)); | 547 MatrixMul(view_matrix, icon_pos)); |
523 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw( | 548 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw( |
524 ui_texture_id_, combined, MakeUiGlCopyRect(kWebVrWarningPermanentRect)); | 549 ui_texture_id_, combined, MakeUiGlCopyRect(kWebVrWarningPermanentRect)); |
525 | 550 |
526 // Check if we also need to show the transient warning. | 551 // Check if we also need to show the transient warning. |
527 if (present_time_nanos > webvr_warning_end_nanos_) { | 552 if (present_time_nanos > webvr_warning_end_nanos_) { |
528 return; | 553 return; |
529 } | 554 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 content::WebContents::FromJavaWebContents(content_web_contents)); | 694 content::WebContents::FromJavaWebContents(content_web_contents)); |
670 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents( | 695 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents( |
671 content::WebContents::FromJavaWebContents(ui_web_contents)); | 696 content::WebContents::FromJavaWebContents(ui_web_contents)); |
672 return reinterpret_cast<intptr_t>(new VrShell( | 697 return reinterpret_cast<intptr_t>(new VrShell( |
673 env, obj, c_core, | 698 env, obj, c_core, |
674 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core, | 699 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core, |
675 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); | 700 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); |
676 } | 701 } |
677 | 702 |
678 } // namespace vr_shell | 703 } // namespace vr_shell |
OLD | NEW |