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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 243 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
244 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 244 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; |
245 head_pose_ = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); | 245 head_pose_ = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); |
246 head_pose_ = gvr_api_->ApplyNeckModel(head_pose_, 1.0f); | 246 head_pose_ = gvr_api_->ApplyNeckModel(head_pose_, 1.0f); |
247 | 247 |
248 // Bind back to the default framebuffer. | 248 // Bind back to the default framebuffer. |
249 frame.BindBuffer(0); | 249 frame.BindBuffer(0); |
250 | 250 |
251 if (webvr_mode_) { | 251 if (webvr_mode_) { |
252 DrawWebVr(); | 252 DrawWebVr(); |
| 253 if (!webvr_secure_origin_) { |
| 254 DrawWebVrOverlay(target_time.monotonic_system_time_nanos); |
| 255 } |
253 } else { | 256 } else { |
254 DrawVrShell(target_time.monotonic_system_time_nanos); | 257 DrawVrShell(target_time.monotonic_system_time_nanos); |
255 } | 258 } |
256 | 259 |
257 frame.Unbind(); | 260 frame.Unbind(); |
258 frame.Submit(*buffer_viewport_list_, head_pose_); | 261 frame.Submit(*buffer_viewport_list_, head_pose_); |
259 } | 262 } |
260 | 263 |
261 void VrShell::DrawVrShell(int64_t time) { | 264 void VrShell::DrawVrShell(int64_t time) { |
262 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; | 265 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 glDisable(GL_DEPTH_TEST); | 401 glDisable(GL_DEPTH_TEST); |
399 glDisable(GL_SCISSOR_TEST); | 402 glDisable(GL_SCISSOR_TEST); |
400 glDisable(GL_BLEND); | 403 glDisable(GL_BLEND); |
401 glDisable(GL_POLYGON_OFFSET_FILL); | 404 glDisable(GL_POLYGON_OFFSET_FILL); |
402 | 405 |
403 // Don't need to clear, since we're drawing over the entire render target. | 406 // Don't need to clear, since we're drawing over the entire render target. |
404 glClear(GL_COLOR_BUFFER_BIT); | 407 glClear(GL_COLOR_BUFFER_BIT); |
405 | 408 |
406 glViewport(0, 0, render_size_.width, render_size_.height); | 409 glViewport(0, 0, render_size_.width, render_size_.height); |
407 vr_shell_renderer_->GetWebVrRenderer()->Draw(content_texture_id_); | 410 vr_shell_renderer_->GetWebVrRenderer()->Draw(content_texture_id_); |
| 411 } |
408 | 412 |
409 if (!webvr_secure_origin_) { | 413 void VrShell::DrawWebVrOverlay(int64_t present_time_nanos) { |
410 // TODO(klausw): Draw the insecure origin warning here. | 414 // Draw WebVR security warning overlays for each eye. This uses |
| 415 // the eye-from-head matrices but not the pose, goal is to place |
| 416 // the icons in an eye-relative position so that they follow along |
| 417 // with head rotations. |
| 418 |
| 419 gvr::Mat4f left_eye_view_matrix = |
| 420 gvr_api_->GetEyeFromHeadMatrix(GVR_LEFT_EYE); |
| 421 gvr::Mat4f right_eye_view_matrix = |
| 422 gvr_api_->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); |
| 423 |
| 424 buffer_viewport_list_->GetBufferViewport(GVR_LEFT_EYE, |
| 425 buffer_viewport_.get()); |
| 426 DrawWebVrEye(left_eye_view_matrix, *buffer_viewport_, present_time_nanos); |
| 427 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE, |
| 428 buffer_viewport_.get()); |
| 429 DrawWebVrEye(right_eye_view_matrix, *buffer_viewport_, present_time_nanos); |
| 430 } |
| 431 |
| 432 void VrShell::DrawWebVrEye(const gvr::Mat4f& view_matrix, |
| 433 const gvr::BufferViewport& params, |
| 434 int64_t present_time_nanos) { |
| 435 gvr::Recti pixel_rect = |
| 436 CalculatePixelSpaceRect(render_size_, params.GetSourceUv()); |
| 437 glViewport(pixel_rect.left, pixel_rect.bottom, |
| 438 pixel_rect.right - pixel_rect.left, |
| 439 pixel_rect.top - pixel_rect.bottom); |
| 440 glScissor(pixel_rect.left, pixel_rect.bottom, |
| 441 pixel_rect.right - pixel_rect.left, |
| 442 pixel_rect.top - pixel_rect.bottom); |
| 443 |
| 444 gvr::Mat4f projection_matrix = |
| 445 PerspectiveMatrixFromView(params.GetSourceFov(), kZNear, kZFar); |
| 446 |
| 447 // If the UI texture hasn't been initialized yet, we can't draw yet. |
| 448 if (ui_tex_width_ == 0.0f || ui_tex_height_ == 0.0f) { |
| 449 return; |
411 } | 450 } |
| 451 |
| 452 // Draw insecure content warning icons. |
| 453 const float warning_depth = 0.7f; // Distance in meters. |
| 454 |
| 455 // Show IDS_WEBSITE_SETTINGS_INSECURE_WEBVR_CONTENT_PERMANENT text. |
| 456 gvr::Mat4f icon_pos; |
| 457 SetIdentityM(icon_pos); |
| 458 const float small_icon_width = 2 * 0.15f * warning_depth; |
| 459 const float small_icon_height = small_icon_width / 2.0f; // 2:1 aspect. |
| 460 const float small_icon_angle = 20.0f * M_PI / 180.f; // Degrees to radians. |
| 461 ScaleM(icon_pos, icon_pos, small_icon_width, small_icon_height, 1.0f); |
| 462 TranslateM(icon_pos, icon_pos, 0.0f, 0.0f, -warning_depth); |
| 463 icon_pos = MatrixMul( |
| 464 QuatToMatrix(QuatFromAxisAngle(1.f, 0.f, 0.f, small_icon_angle)), |
| 465 icon_pos); |
| 466 gvr::Mat4f combined = MatrixMul(projection_matrix, |
| 467 MatrixMul(view_matrix, icon_pos)); |
| 468 Rectf copy_rect = {256.f / ui_tex_width_, 0.f / ui_tex_height_, |
| 469 128.f / ui_tex_width_, 64.f / ui_tex_height_}; |
| 470 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw( |
| 471 ui_texture_id_, combined, copy_rect); |
| 472 |
| 473 // Check if we also need to show the transient warning. |
| 474 if (present_time_nanos > webvr_warning_end_nanos_) { |
| 475 return; |
| 476 } |
| 477 |
| 478 // Show IDS_WEBSITE_SETTINGS_INSECURE_WEBVR_CONTENT_TRANSIENT text. |
| 479 SetIdentityM(icon_pos); |
| 480 const float large_icon_width = 2 * 0.25f * warning_depth; |
| 481 const float large_icon_height = large_icon_width / 2.0f; // 2:1 aspect. |
| 482 ScaleM(icon_pos, icon_pos, large_icon_width, large_icon_height, 1.0f); |
| 483 TranslateM(icon_pos, icon_pos, 0.0f, 0.0f, -warning_depth); |
| 484 combined = MatrixMul(projection_matrix, |
| 485 MatrixMul(view_matrix, icon_pos)); |
| 486 copy_rect = {0.f / ui_tex_width_, 0.f / ui_tex_height_, |
| 487 256.f / ui_tex_width_, 128.f / ui_tex_height_}; |
| 488 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw( |
| 489 ui_texture_id_, combined, copy_rect); |
| 490 |
412 } | 491 } |
413 | 492 |
414 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 493 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
415 if (gvr_api_ == nullptr) | 494 if (gvr_api_ == nullptr) |
416 return; | 495 return; |
417 gvr_api_->PauseTracking(); | 496 gvr_api_->PauseTracking(); |
418 } | 497 } |
419 | 498 |
420 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 499 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
421 if (gvr_api_ == nullptr) | 500 if (gvr_api_ == nullptr) |
(...skipping 18 matching lines...) Expand all Loading... |
440 // TODO(bshe): ui_text_width_ and ui_tex_height_ should be only used on render | 519 // TODO(bshe): ui_text_width_ and ui_tex_height_ should be only used on render |
441 // thread. | 520 // thread. |
442 ui_tex_width_ = width; | 521 ui_tex_width_ = width; |
443 ui_tex_height_ = height; | 522 ui_tex_height_ = height; |
444 } | 523 } |
445 | 524 |
446 void VrShell::SetWebVrMode(JNIEnv* env, | 525 void VrShell::SetWebVrMode(JNIEnv* env, |
447 const base::android::JavaParamRef<jobject>& obj, | 526 const base::android::JavaParamRef<jobject>& obj, |
448 bool enabled) { | 527 bool enabled) { |
449 webvr_mode_ = enabled; | 528 webvr_mode_ = enabled; |
| 529 if (enabled) { |
| 530 const int64_t warning_seconds = 30; |
| 531 int64_t now = gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; |
| 532 webvr_warning_end_nanos_ = now + warning_seconds * 1000 * 1000 * 1000; |
| 533 } else { |
| 534 webvr_warning_end_nanos_ = 0; |
| 535 } |
450 } | 536 } |
451 | 537 |
452 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { | 538 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { |
453 webvr_secure_origin_ = secure_origin; | 539 webvr_secure_origin_ = secure_origin; |
454 } | 540 } |
455 | 541 |
456 void VrShell::SubmitWebVRFrame() { | 542 void VrShell::SubmitWebVRFrame() { |
457 } | 543 } |
458 | 544 |
459 void VrShell::UpdateWebVRTextureBounds( | 545 void VrShell::UpdateWebVRTextureBounds( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 content::WebContents::FromJavaWebContents(content_web_contents)); | 582 content::WebContents::FromJavaWebContents(content_web_contents)); |
497 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents( | 583 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents( |
498 content::WebContents::FromJavaWebContents(ui_web_contents)); | 584 content::WebContents::FromJavaWebContents(ui_web_contents)); |
499 return reinterpret_cast<intptr_t>(new VrShell( | 585 return reinterpret_cast<intptr_t>(new VrShell( |
500 env, obj, c_core, | 586 env, obj, c_core, |
501 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core, | 587 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core, |
502 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); | 588 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); |
503 } | 589 } |
504 | 590 |
505 } // namespace vr_shell | 591 } // namespace vr_shell |
OLD | NEW |