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 "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "chrome/browser/android/vr_shell/ui_elements.h" | 8 #include "chrome/browser/android/vr_shell/ui_elements.h" |
9 #include "chrome/browser/android/vr_shell/ui_interface.h" | 9 #include "chrome/browser/android/vr_shell/ui_interface.h" |
10 #include "chrome/browser/android/vr_shell/ui_scene.h" | 10 #include "chrome/browser/android/vr_shell/ui_scene.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 static constexpr float kReticleOffset = 0.99f; | 66 static constexpr float kReticleOffset = 0.99f; |
67 | 67 |
68 // Limit the rendering distance of the reticle to the distance to a corner of | 68 // Limit the rendering distance of the reticle to the distance to a corner of |
69 // the content quad, times this value. This lets the rendering distance | 69 // the content quad, times this value. This lets the rendering distance |
70 // adjust according to content quad placement. | 70 // adjust according to content quad placement. |
71 static constexpr float kReticleDistanceMultiplier = 1.5f; | 71 static constexpr float kReticleDistanceMultiplier = 1.5f; |
72 | 72 |
73 // UI element 0 is the browser content rectangle. | 73 // UI element 0 is the browser content rectangle. |
74 static constexpr int kBrowserUiElementId = 0; | 74 static constexpr int kBrowserUiElementId = 0; |
75 | 75 |
76 // Positions and sizes of statically placed UI elements in the UI texture. | |
77 // TODO(klausw): replace the hardcoded positions with JS position/offset | |
78 // retrieval once the infrastructure for that is hooked up. | |
79 // | |
80 // UI is designed with 1 pixel = 1mm at 1m distance. It's rescaled to | |
81 // maintain the same angular resolution if placed closer or further. | |
82 // The warning overlays should be fairly close since they cut holes | |
83 // into geometry (they ignore the Z buffer), leading to odd effects | |
84 // if they are far away. | |
85 static constexpr vr_shell::Recti kWebVrWarningTransientRect = { | |
86 0, 128, 512, 250}; | |
87 static constexpr vr_shell::Recti kWebVrWarningPermanentRect = {0, 0, 512, 128}; | |
88 static constexpr float kWebVrWarningDistance = 0.7f; // meters | |
89 static constexpr float kWebVrWarningPermanentAngle = 16.3f; // degrees up | |
90 // How long the transient warning needs to be displayed. | |
91 static constexpr int64_t kWebVrWarningSeconds = 30; | |
92 | |
93 static constexpr int kFramePrimaryBuffer = 0; | 76 static constexpr int kFramePrimaryBuffer = 0; |
94 static constexpr int kFrameHeadlockedBuffer = 1; | 77 static constexpr int kFrameHeadlockedBuffer = 1; |
95 | 78 |
96 vr_shell::VrShell* g_instance; | 79 vr_shell::VrShell* g_instance; |
97 | 80 |
98 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; | 81 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; |
99 | 82 |
100 float Distance(const gvr::Vec3f& vec1, const gvr::Vec3f& vec2) { | 83 float Distance(const gvr::Vec3f& vec1, const gvr::Vec3f& vec2) { |
101 float xdiff = (vec1.x - vec2.x); | 84 float xdiff = (vec1.x - vec2.x); |
102 float ydiff = (vec1.y - vec2.y); | 85 float ydiff = (vec1.y - vec2.y); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 // The head pose has redundant data. Assume we're only using the | 420 // The head pose has redundant data. Assume we're only using the |
438 // object_from_reference_matrix, we're not updating position_external. | 421 // object_from_reference_matrix, we're not updating position_external. |
439 // TODO: Not sure what object_from_reference_matrix is. The new api removed | 422 // TODO: Not sure what object_from_reference_matrix is. The new api removed |
440 // it. For now, removing it seems working fine. | 423 // it. For now, removing it seems working fine. |
441 gvr_api_->ApplyNeckModel(head_pose, 1.0f); | 424 gvr_api_->ApplyNeckModel(head_pose, 1.0f); |
442 } | 425 } |
443 | 426 |
444 // Bind the primary framebuffer. | 427 // Bind the primary framebuffer. |
445 frame.BindBuffer(kFramePrimaryBuffer); | 428 frame.BindBuffer(kFramePrimaryBuffer); |
446 | 429 |
| 430 HandleQueuedTasks(); |
| 431 |
| 432 // Update the render position of all UI elements (including desktop). |
| 433 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; |
| 434 scene_->UpdateTransforms(screen_tilt, UiScene::TimeInMicroseconds()); |
| 435 |
| 436 UpdateController(GetForwardVector(head_pose)); |
| 437 |
447 if (webvr_mode_) { | 438 if (webvr_mode_) { |
448 DrawWebVr(); | 439 DrawWebVr(); |
449 | 440 |
450 // When using async reprojection, we need to know which pose was used in | 441 // When using async reprojection, we need to know which pose was used in |
451 // the WebVR app for drawing this frame. Due to unknown amounts of | 442 // the WebVR app for drawing this frame. Due to unknown amounts of |
452 // buffering in the compositor and SurfaceTexture, we read the pose number | 443 // buffering in the compositor and SurfaceTexture, we read the pose number |
453 // from a corner pixel. There's no point in doing this for legacy | 444 // from a corner pixel. There's no point in doing this for legacy |
454 // distortion rendering since that doesn't need a pose, and reading back | 445 // distortion rendering since that doesn't need a pose, and reading back |
455 // pixels is an expensive operation. TODO(klausw): stop doing this once we | 446 // pixels is an expensive operation. TODO(klausw): stop doing this once we |
456 // have working no-compositor rendering for WebVR. | 447 // have working no-compositor rendering for WebVR. |
457 if (gvr_api_->GetAsyncReprojectionEnabled()) { | 448 if (gvr_api_->GetAsyncReprojectionEnabled()) { |
458 uint32_t webvr_pose_frame = GetPixelEncodedPoseIndex(); | 449 uint32_t webvr_pose_frame = GetPixelEncodedPoseIndex(); |
459 head_pose = webvr_head_pose_[webvr_pose_frame % kPoseRingBufferSize]; | 450 head_pose = webvr_head_pose_[webvr_pose_frame % kPoseRingBufferSize]; |
460 } | 451 } |
| 452 } |
461 | 453 |
462 // Wait for the DOM contents to be loaded before rendering to avoid drawing | 454 DrawVrShell(head_pose, frame); |
463 // white rectangles with no content. | |
464 if (!webvr_secure_origin_ && IsUiTextureReady()) { | |
465 size_t last_viewport = buffer_viewport_list_->GetSize(); | |
466 buffer_viewport_list_->SetBufferViewport(last_viewport++, | |
467 *headlocked_left_viewport_); | |
468 buffer_viewport_list_->SetBufferViewport(last_viewport++, | |
469 *headlocked_right_viewport_); | |
470 | |
471 // Bind the headlocked framebuffer. | |
472 frame.BindBuffer(kFrameHeadlockedBuffer); | |
473 DrawWebVrOverlay(target_time.monotonic_system_time_nanos); | |
474 } | |
475 } else { | |
476 DrawVrShell(head_pose); | |
477 } | |
478 | 455 |
479 frame.Unbind(); | 456 frame.Unbind(); |
480 frame.Submit(*buffer_viewport_list_, head_pose); | 457 frame.Submit(*buffer_viewport_list_, head_pose); |
481 } | 458 } |
482 | 459 |
483 void VrShell::DrawVrShell(const gvr::Mat4f& head_pose) { | 460 void VrShell::DrawVrShell(const gvr::Mat4f& head_pose, |
484 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; | 461 gvr::Frame &frame) { |
485 | 462 std::vector<const ContentRectangle*> head_locked_elements; |
486 HandleQueuedTasks(); | 463 std::vector<const ContentRectangle*> world_elements; |
487 | |
488 // Update the render position of all UI elements (including desktop). | |
489 scene_->UpdateTransforms(screen_tilt, UiScene::TimeInMicroseconds()); | |
490 | |
491 UpdateController(GetForwardVector(head_pose)); | |
492 | |
493 // Use culling to remove back faces. | |
494 glEnable(GL_CULL_FACE); | |
495 | |
496 // Enable depth testing. | |
497 glEnable(GL_DEPTH_TEST); | |
498 glEnable(GL_SCISSOR_TEST); | |
499 | |
500 glClearColor(0.1f, 0.1f, 0.1f, 1.0f); | |
501 | |
502 buffer_viewport_list_->GetBufferViewport(GVR_LEFT_EYE, | |
503 buffer_viewport_.get()); | |
504 DrawEye(GVR_LEFT_EYE, head_pose, *buffer_viewport_); | |
505 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE, | |
506 buffer_viewport_.get()); | |
507 DrawEye(GVR_RIGHT_EYE, head_pose, *buffer_viewport_); | |
508 } | |
509 | |
510 void VrShell::DrawEye(gvr::Eye eye, | |
511 const gvr::Mat4f& head_pose, | |
512 const gvr::BufferViewport& params) { | |
513 gvr::Mat4f eye_matrix = gvr_api_->GetEyeFromHeadMatrix(eye); | |
514 gvr::Mat4f view_matrix = MatrixMul(eye_matrix, head_pose); | |
515 | |
516 gvr::Recti pixel_rect = | |
517 CalculatePixelSpaceRect(render_size_, params.GetSourceUv()); | |
518 glViewport(pixel_rect.left, pixel_rect.bottom, | |
519 pixel_rect.right - pixel_rect.left, | |
520 pixel_rect.top - pixel_rect.bottom); | |
521 glScissor(pixel_rect.left, pixel_rect.bottom, | |
522 pixel_rect.right - pixel_rect.left, | |
523 pixel_rect.top - pixel_rect.bottom); | |
524 | |
525 const gvr::Mat4f fov_render_matrix = MatrixMul( | |
526 PerspectiveMatrixFromView(params.GetSourceFov(), kZNear, kZFar), | |
527 eye_matrix); | |
528 const gvr::Mat4f world_render_matrix = MatrixMul( | |
529 PerspectiveMatrixFromView(params.GetSourceFov(), kZNear, kZFar), | |
530 view_matrix); | |
531 | |
532 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
533 | |
534 // TODO(mthiesse): Draw order for transparency. | |
535 DrawUI(world_render_matrix, fov_render_matrix); | |
536 DrawCursor(world_render_matrix); | |
537 } | |
538 | |
539 bool VrShell::IsUiTextureReady() { | |
540 return ui_tex_width_ > 0 && ui_tex_height_ > 0 && dom_contents_loaded_; | |
541 } | |
542 | |
543 Rectf VrShell::MakeUiGlCopyRect(Recti pixel_rect) { | |
544 CHECK(IsUiTextureReady()); | |
545 return Rectf({ | |
546 static_cast<float>(pixel_rect.x) / ui_tex_width_, | |
547 static_cast<float>(pixel_rect.y) / ui_tex_height_, | |
548 static_cast<float>(pixel_rect.width) / ui_tex_width_, | |
549 static_cast<float>(pixel_rect.height) / ui_tex_height_}); | |
550 } | |
551 | |
552 void VrShell::DrawUI(const gvr::Mat4f& world_matrix, | |
553 const gvr::Mat4f& fov_matrix) { | |
554 for (const auto& rect : scene_->GetUiElements()) { | 464 for (const auto& rect : scene_->GetUiElements()) { |
555 if (!rect->visible) { | 465 if (!rect->visible) { |
556 continue; | 466 continue; |
557 } | 467 } |
| 468 if (webvr_mode_ && rect->id == kBrowserUiElementId) { |
| 469 continue; |
| 470 } |
| 471 if (rect->lock_to_fov) { |
| 472 head_locked_elements.push_back(rect.get()); |
| 473 } else { |
| 474 world_elements.push_back(rect.get()); |
| 475 } |
| 476 } |
558 | 477 |
| 478 if (!webvr_mode_) { |
| 479 glEnable(GL_CULL_FACE); |
| 480 glEnable(GL_DEPTH_TEST); |
| 481 glEnable(GL_SCISSOR_TEST); |
| 482 glClearColor(0.1f, 0.1f, 0.1f, 1.0f); |
| 483 } |
| 484 |
| 485 if (!world_elements.empty()) { |
| 486 DrawUiView(&head_pose, world_elements); |
| 487 } |
| 488 |
| 489 if (!head_locked_elements.empty()) { |
| 490 // Switch to head-locked viewports. |
| 491 size_t last_viewport = buffer_viewport_list_->GetSize(); |
| 492 buffer_viewport_list_->SetBufferViewport(last_viewport++, |
| 493 *headlocked_left_viewport_); |
| 494 buffer_viewport_list_->SetBufferViewport(last_viewport++, |
| 495 *headlocked_right_viewport_); |
| 496 |
| 497 // Bind the headlocked framebuffer. |
| 498 frame.BindBuffer(kFrameHeadlockedBuffer); |
| 499 glClear(GL_COLOR_BUFFER_BIT); |
| 500 |
| 501 DrawUiView(nullptr, head_locked_elements); |
| 502 } |
| 503 } |
| 504 |
| 505 void VrShell::DrawUiView(const gvr::Mat4f* head_pose, |
| 506 const std::vector<const ContentRectangle*>& elements) { |
| 507 for (auto eye : {GVR_LEFT_EYE, GVR_RIGHT_EYE}) { |
| 508 buffer_viewport_list_->GetBufferViewport(eye, buffer_viewport_.get()); |
| 509 |
| 510 gvr::Mat4f view_matrix = gvr_api_->GetEyeFromHeadMatrix(eye); |
| 511 if (head_pose != nullptr) { |
| 512 view_matrix = MatrixMul(view_matrix, *head_pose); |
| 513 } |
| 514 |
| 515 gvr::Recti pixel_rect = |
| 516 CalculatePixelSpaceRect(render_size_, buffer_viewport_->GetSourceUv()); |
| 517 glViewport(pixel_rect.left, pixel_rect.bottom, |
| 518 pixel_rect.right - pixel_rect.left, |
| 519 pixel_rect.top - pixel_rect.bottom); |
| 520 glScissor(pixel_rect.left, pixel_rect.bottom, |
| 521 pixel_rect.right - pixel_rect.left, |
| 522 pixel_rect.top - pixel_rect.bottom); |
| 523 |
| 524 if (!webvr_mode_) { |
| 525 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 526 } |
| 527 |
| 528 const gvr::Mat4f render_matrix = MatrixMul( |
| 529 PerspectiveMatrixFromView( |
| 530 buffer_viewport_->GetSourceFov(), kZNear, kZFar), |
| 531 view_matrix); |
| 532 |
| 533 DrawElements(render_matrix, elements); |
| 534 if (head_pose != nullptr) { |
| 535 DrawCursor(render_matrix); |
| 536 } |
| 537 } |
| 538 } |
| 539 |
| 540 void VrShell::DrawElements( |
| 541 const gvr::Mat4f& render_matrix, |
| 542 const std::vector<const ContentRectangle*>& elements) { |
| 543 for (const auto& rect : elements) { |
559 Rectf copy_rect; | 544 Rectf copy_rect; |
560 jint texture_handle; | 545 jint texture_handle; |
561 if (rect->id == kBrowserUiElementId) { | 546 if (rect->id == kBrowserUiElementId) { |
562 copy_rect = {0, 0, 1, 1}; | 547 copy_rect = {0, 0, 1, 1}; |
563 texture_handle = content_texture_id_; | 548 texture_handle = content_texture_id_; |
564 } else { | 549 } else { |
565 copy_rect.x = static_cast<float>(rect->copy_rect.x) / ui_tex_width_; | 550 copy_rect.x = static_cast<float>(rect->copy_rect.x) / ui_tex_width_; |
566 copy_rect.y = static_cast<float>(rect->copy_rect.y) / ui_tex_height_; | 551 copy_rect.y = static_cast<float>(rect->copy_rect.y) / ui_tex_height_; |
567 copy_rect.width = static_cast<float>(rect->copy_rect.width) / | 552 copy_rect.width = static_cast<float>(rect->copy_rect.width) / |
568 ui_tex_width_; | 553 ui_tex_width_; |
569 copy_rect.height = static_cast<float>(rect->copy_rect.height) / | 554 copy_rect.height = static_cast<float>(rect->copy_rect.height) / |
570 ui_tex_height_; | 555 ui_tex_height_; |
571 texture_handle = ui_texture_id_; | 556 texture_handle = ui_texture_id_; |
572 } | 557 } |
573 | 558 gvr::Mat4f transform = MatrixMul(render_matrix, rect->transform.to_world); |
574 const gvr::Mat4f& view_matrix = | |
575 rect->lock_to_fov ? fov_matrix : world_matrix; | |
576 gvr::Mat4f transform = MatrixMul(view_matrix, rect->transform.to_world); | |
577 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw( | 559 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw( |
578 texture_handle, transform, copy_rect); | 560 texture_handle, transform, copy_rect); |
579 } | 561 } |
580 } | 562 } |
581 | 563 |
582 void VrShell::DrawCursor(const gvr::Mat4f& render_matrix) { | 564 void VrShell::DrawCursor(const gvr::Mat4f& render_matrix) { |
583 gvr::Mat4f mat; | 565 gvr::Mat4f mat; |
584 SetIdentityM(mat); | 566 SetIdentityM(mat); |
585 | 567 |
586 // Draw the reticle. | 568 // Draw the reticle. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 glDisable(GL_BLEND); | 644 glDisable(GL_BLEND); |
663 glDisable(GL_POLYGON_OFFSET_FILL); | 645 glDisable(GL_POLYGON_OFFSET_FILL); |
664 | 646 |
665 // Don't need to clear, since we're drawing over the entire render target. | 647 // Don't need to clear, since we're drawing over the entire render target. |
666 glClear(GL_COLOR_BUFFER_BIT); | 648 glClear(GL_COLOR_BUFFER_BIT); |
667 | 649 |
668 glViewport(0, 0, render_size_.width, render_size_.height); | 650 glViewport(0, 0, render_size_.width, render_size_.height); |
669 vr_shell_renderer_->GetWebVrRenderer()->Draw(content_texture_id_); | 651 vr_shell_renderer_->GetWebVrRenderer()->Draw(content_texture_id_); |
670 } | 652 } |
671 | 653 |
672 void VrShell::DrawWebVrOverlay(int64_t present_time_nanos) { | |
673 // Draw WebVR security warning overlays for each eye. This uses the | |
674 // eye-from-head matrices but not the pose, goal is to place the icons in an | |
675 // eye-relative position so that they follow along with head rotations. | |
676 | |
677 gvr::Mat4f left_eye_view_matrix = | |
678 gvr_api_->GetEyeFromHeadMatrix(GVR_LEFT_EYE); | |
679 gvr::Mat4f right_eye_view_matrix = | |
680 gvr_api_->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); | |
681 | |
682 glClear(GL_COLOR_BUFFER_BIT); | |
683 | |
684 buffer_viewport_list_->GetBufferViewport(GVR_LEFT_EYE, | |
685 buffer_viewport_.get()); | |
686 DrawWebVrEye(left_eye_view_matrix, *buffer_viewport_, present_time_nanos); | |
687 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE, | |
688 buffer_viewport_.get()); | |
689 DrawWebVrEye(right_eye_view_matrix, *buffer_viewport_, present_time_nanos); | |
690 } | |
691 | |
692 void VrShell::DrawWebVrEye(const gvr::Mat4f& view_matrix, | |
693 const gvr::BufferViewport& params, | |
694 int64_t present_time_nanos) { | |
695 gvr::Recti pixel_rect = | |
696 CalculatePixelSpaceRect(render_size_, params.GetSourceUv()); | |
697 glViewport(pixel_rect.left, pixel_rect.bottom, | |
698 pixel_rect.right - pixel_rect.left, | |
699 pixel_rect.top - pixel_rect.bottom); | |
700 glScissor(pixel_rect.left, pixel_rect.bottom, | |
701 pixel_rect.right - pixel_rect.left, | |
702 pixel_rect.top - pixel_rect.bottom); | |
703 | |
704 gvr::Mat4f projection_matrix = | |
705 PerspectiveMatrixFromView(params.GetSourceFov(), kZNear, kZFar); | |
706 | |
707 if (!IsUiTextureReady()) { | |
708 // If the UI texture hasn't been initialized yet, we can't draw the overlay. | |
709 return; | |
710 } | |
711 | |
712 // Show IDS_WEBSITE_SETTINGS_INSECURE_WEBVR_CONTENT_PERMANENT text. | |
713 gvr::Mat4f icon_pos; | |
714 SetIdentityM(icon_pos); | |
715 // The UI is designed in pixels with the assumption that 1px = 1mm at 1m | |
716 // distance. Scale mm-to-m and adjust to keep the same angular size if the | |
717 // distance changes. | |
718 const float small_icon_width = | |
719 kWebVrWarningPermanentRect.width / 1000.f * kWebVrWarningDistance; | |
720 const float small_icon_height = | |
721 kWebVrWarningPermanentRect.height / 1000.f * kWebVrWarningDistance; | |
722 const float small_icon_angle = | |
723 kWebVrWarningPermanentAngle * M_PI / 180.f; // Degrees to radians. | |
724 ScaleM(icon_pos, icon_pos, small_icon_width, small_icon_height, 1.0f); | |
725 TranslateM(icon_pos, icon_pos, 0.0f, 0.0f, -kWebVrWarningDistance); | |
726 icon_pos = MatrixMul( | |
727 QuatToMatrix(QuatFromAxisAngle({1.f, 0.f, 0.f}, small_icon_angle)), | |
728 icon_pos); | |
729 gvr::Mat4f combined = MatrixMul(projection_matrix, | |
730 MatrixMul(view_matrix, icon_pos)); | |
731 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw( | |
732 ui_texture_id_, combined, MakeUiGlCopyRect(kWebVrWarningPermanentRect)); | |
733 | |
734 // Check if we also need to show the transient warning. | |
735 if (present_time_nanos > webvr_warning_end_nanos_) { | |
736 return; | |
737 } | |
738 | |
739 // Show IDS_WEBSITE_SETTINGS_INSECURE_WEBVR_CONTENT_TRANSIENT text. | |
740 SetIdentityM(icon_pos); | |
741 const float large_icon_width = | |
742 kWebVrWarningTransientRect.width / 1000.f * kWebVrWarningDistance; | |
743 const float large_icon_height = | |
744 kWebVrWarningTransientRect.height / 1000.f * kWebVrWarningDistance; | |
745 ScaleM(icon_pos, icon_pos, large_icon_width, large_icon_height, 1.0f); | |
746 TranslateM(icon_pos, icon_pos, 0.0f, 0.0f, -kWebVrWarningDistance); | |
747 combined = MatrixMul(projection_matrix, | |
748 MatrixMul(view_matrix, icon_pos)); | |
749 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw( | |
750 ui_texture_id_, combined, MakeUiGlCopyRect(kWebVrWarningTransientRect)); | |
751 | |
752 } | |
753 | |
754 void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 654 void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
755 // Set a flag to handle this on the render thread at the next frame. | 655 // Set a flag to handle this on the render thread at the next frame. |
756 touch_pending_ = true; | 656 touch_pending_ = true; |
757 } | 657 } |
758 | 658 |
759 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 659 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
760 if (gvr_api_ == nullptr) | 660 if (gvr_api_ == nullptr) |
761 return; | 661 return; |
762 controller_->OnPause(); | 662 controller_->OnPause(); |
763 gvr_api_->PauseTracking(); | 663 gvr_api_->PauseTracking(); |
(...skipping 29 matching lines...) Expand all Loading... |
793 SK_ColorTRANSPARENT); | 693 SK_ColorTRANSPARENT); |
794 html_interface_->OnDomContentsLoaded(); | 694 html_interface_->OnDomContentsLoaded(); |
795 dom_contents_loaded_ = true; | 695 dom_contents_loaded_ = true; |
796 } | 696 } |
797 | 697 |
798 void VrShell::SetWebVrMode(JNIEnv* env, | 698 void VrShell::SetWebVrMode(JNIEnv* env, |
799 const base::android::JavaParamRef<jobject>& obj, | 699 const base::android::JavaParamRef<jobject>& obj, |
800 bool enabled) { | 700 bool enabled) { |
801 webvr_mode_ = enabled; | 701 webvr_mode_ = enabled; |
802 if (enabled) { | 702 if (enabled) { |
803 int64_t now = gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; | |
804 constexpr int64_t seconds_to_nanos = 1000 * 1000 * 1000; | |
805 webvr_warning_end_nanos_ = now + kWebVrWarningSeconds * seconds_to_nanos; | |
806 html_interface_->SetMode(UiInterface::Mode::WEB_VR); | 703 html_interface_->SetMode(UiInterface::Mode::WEB_VR); |
807 } else { | 704 } else { |
808 webvr_warning_end_nanos_ = 0; | |
809 html_interface_->SetMode(UiInterface::Mode::STANDARD); | 705 html_interface_->SetMode(UiInterface::Mode::STANDARD); |
810 } | 706 } |
811 } | 707 } |
812 | 708 |
813 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { | 709 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { |
814 webvr_secure_origin_ = secure_origin; | 710 html_interface_->SetSecureOrigin(secure_origin); |
815 } | 711 } |
816 | 712 |
817 void VrShell::SubmitWebVRFrame() { | 713 void VrShell::SubmitWebVRFrame() { |
818 } | 714 } |
819 | 715 |
820 void VrShell::UpdateWebVRTextureBounds( | 716 void VrShell::UpdateWebVRTextureBounds( |
821 int eye, float left, float top, float width, float height) { | 717 int eye, float left, float top, float width, float height) { |
822 gvr::Rectf bounds = { left, top, width, height }; | 718 gvr::Rectf bounds = { left, top, width, height }; |
823 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds); | 719 vr_shell_renderer_->GetWebVrRenderer()->UpdateTextureBounds(eye, bounds); |
824 } | 720 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 const JavaParamRef<jobject>& ui_web_contents, | 813 const JavaParamRef<jobject>& ui_web_contents, |
918 jlong ui_window_android) { | 814 jlong ui_window_android) { |
919 return reinterpret_cast<intptr_t>(new VrShell( | 815 return reinterpret_cast<intptr_t>(new VrShell( |
920 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 816 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
921 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 817 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
922 content::WebContents::FromJavaWebContents(ui_web_contents), | 818 content::WebContents::FromJavaWebContents(ui_web_contents), |
923 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); | 819 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); |
924 } | 820 } |
925 | 821 |
926 } // namespace vr_shell | 822 } // namespace vr_shell |
OLD | NEW |