| 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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 gesture->data.tapDown.height = pixel_y; | 524 gesture->data.tapDown.height = pixel_y; |
| 525 current_input_target_->ProcessUpdatedGesture(*gesture.get()); | 525 current_input_target_->ProcessUpdatedGesture(*gesture.get()); |
| 526 } | 526 } |
| 527 } | 527 } |
| 528 | 528 |
| 529 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { | 529 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { |
| 530 webvr_head_pose_[pose_num % kPoseRingBufferSize] = pose; | 530 webvr_head_pose_[pose_num % kPoseRingBufferSize] = pose; |
| 531 } | 531 } |
| 532 | 532 |
| 533 uint32_t GetPixelEncodedPoseIndex() { | 533 uint32_t GetPixelEncodedPoseIndex() { |
| 534 TRACE_EVENT0("gpu", "VrShell::GetPixelEncodedPoseIndex"); |
| 534 // Read the pose index encoded in a bottom left pixel as color values. | 535 // Read the pose index encoded in a bottom left pixel as color values. |
| 535 // See also third_party/WebKit/Source/modules/vr/VRDisplay.cpp which | 536 // See also third_party/WebKit/Source/modules/vr/VRDisplay.cpp which |
| 536 // encodes the pose index, and device/vr/android/gvr/gvr_device.cc | 537 // encodes the pose index, and device/vr/android/gvr/gvr_device.cc |
| 537 // which tracks poses. | 538 // which tracks poses. |
| 538 uint8_t pixels[4]; | 539 uint8_t pixels[4]; |
| 539 // Assume we're reading from the framebuffer we just wrote to. | 540 // Assume we're reading from the framebuffer we just wrote to. |
| 540 // That's true currently, we may need to use glReadBuffer(GL_BACK) | 541 // That's true currently, we may need to use glReadBuffer(GL_BACK) |
| 541 // or equivalent if the rendering setup changes in the future. | 542 // or equivalent if the rendering setup changes in the future. |
| 542 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | 543 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 543 return pixels[0] | (pixels[1] << 8) | (pixels[2] << 16); | 544 return pixels[0] | (pixels[1] << 8) | (pixels[2] << 16); |
| 544 } | 545 } |
| 545 | 546 |
| 546 void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 547 void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 548 TRACE_EVENT0("gpu", "VrShell::DrawFrame"); |
| 547 // Reset the viewport list to just the pair of viewports for the | 549 // Reset the viewport list to just the pair of viewports for the |
| 548 // primary buffer each frame. Head-locked viewports get added by | 550 // primary buffer each frame. Head-locked viewports get added by |
| 549 // DrawVrShell if needed. | 551 // DrawVrShell if needed. |
| 550 buffer_viewport_list_->SetToRecommendedBufferViewports(); | 552 buffer_viewport_list_->SetToRecommendedBufferViewports(); |
| 551 | 553 |
| 552 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { | 554 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { |
| 553 // If needed, resize the primary buffer for use with WebVR. | 555 // If needed, resize the primary buffer for use with WebVR. |
| 554 if (render_size_primary_ != render_size_primary_webvr_) { | 556 if (render_size_primary_ != render_size_primary_webvr_) { |
| 555 render_size_primary_ = render_size_primary_webvr_; | 557 render_size_primary_ = render_size_primary_webvr_; |
| 556 swap_chain_->ResizeBuffer(kFramePrimaryBuffer, render_size_primary_); | 558 swap_chain_->ResizeBuffer(kFramePrimaryBuffer, render_size_primary_); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 } | 618 } |
| 617 | 619 |
| 618 DrawVrShell(head_pose, frame); | 620 DrawVrShell(head_pose, frame); |
| 619 | 621 |
| 620 frame.Unbind(); | 622 frame.Unbind(); |
| 621 frame.Submit(*buffer_viewport_list_, head_pose); | 623 frame.Submit(*buffer_viewport_list_, head_pose); |
| 622 } | 624 } |
| 623 | 625 |
| 624 void VrShell::DrawVrShell(const gvr::Mat4f& head_pose, | 626 void VrShell::DrawVrShell(const gvr::Mat4f& head_pose, |
| 625 gvr::Frame &frame) { | 627 gvr::Frame &frame) { |
| 628 TRACE_EVENT0("gpu", "VrShell::DrawVrShell"); |
| 626 std::vector<const ContentRectangle*> head_locked_elements; | 629 std::vector<const ContentRectangle*> head_locked_elements; |
| 627 std::vector<const ContentRectangle*> world_elements; | 630 std::vector<const ContentRectangle*> world_elements; |
| 628 for (const auto& rect : scene_->GetUiElements()) { | 631 for (const auto& rect : scene_->GetUiElements()) { |
| 629 if (!rect->visible) { | 632 if (!rect->visible) { |
| 630 continue; | 633 continue; |
| 631 } | 634 } |
| 632 if (rect->lock_to_fov) { | 635 if (rect->lock_to_fov) { |
| 633 head_locked_elements.push_back(rect.get()); | 636 head_locked_elements.push_back(rect.get()); |
| 634 } else { | 637 } else { |
| 635 world_elements.push_back(rect.get()); | 638 world_elements.push_back(rect.get()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 // This is a stopgap while we're using the WebVR compositor rendering path. | 692 // This is a stopgap while we're using the WebVR compositor rendering path. |
| 690 // TODO(klausw,crbug.com/655722): Remove this method and member once we're | 693 // TODO(klausw,crbug.com/655722): Remove this method and member once we're |
| 691 // using a separate WebVR render surface. | 694 // using a separate WebVR render surface. |
| 692 return content_tex_pixels_for_webvr_; | 695 return content_tex_pixels_for_webvr_; |
| 693 } | 696 } |
| 694 | 697 |
| 695 | 698 |
| 696 void VrShell::DrawUiView(const gvr::Mat4f* head_pose, | 699 void VrShell::DrawUiView(const gvr::Mat4f* head_pose, |
| 697 const std::vector<const ContentRectangle*>& elements, | 700 const std::vector<const ContentRectangle*>& elements, |
| 698 const gvr::Sizei& render_size, int viewport_offset) { | 701 const gvr::Sizei& render_size, int viewport_offset) { |
| 702 TRACE_EVENT0("gpu", "VrShell::DrawUiView"); |
| 699 for (auto eye : {GVR_LEFT_EYE, GVR_RIGHT_EYE}) { | 703 for (auto eye : {GVR_LEFT_EYE, GVR_RIGHT_EYE}) { |
| 700 buffer_viewport_list_->GetBufferViewport( | 704 buffer_viewport_list_->GetBufferViewport( |
| 701 eye + viewport_offset, buffer_viewport_.get()); | 705 eye + viewport_offset, buffer_viewport_.get()); |
| 702 | 706 |
| 703 gvr::Mat4f view_matrix = gvr_api_->GetEyeFromHeadMatrix(eye); | 707 gvr::Mat4f view_matrix = gvr_api_->GetEyeFromHeadMatrix(eye); |
| 704 if (head_pose != nullptr) { | 708 if (head_pose != nullptr) { |
| 705 view_matrix = MatrixMul(view_matrix, *head_pose); | 709 view_matrix = MatrixMul(view_matrix, *head_pose); |
| 706 } | 710 } |
| 707 | 711 |
| 708 gvr::Recti pixel_rect = | 712 gvr::Recti pixel_rect = |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 // Move the beam origin to the hand. | 820 // Move the beam origin to the hand. |
| 817 TranslateM(face_transform, face_transform, kHandPosition.x, kHandPosition.y, | 821 TranslateM(face_transform, face_transform, kHandPosition.x, kHandPosition.y, |
| 818 kHandPosition.z); | 822 kHandPosition.z); |
| 819 | 823 |
| 820 transform = MatrixMul(render_matrix, face_transform); | 824 transform = MatrixMul(render_matrix, face_transform); |
| 821 vr_shell_renderer_->GetLaserRenderer()->Draw(transform); | 825 vr_shell_renderer_->GetLaserRenderer()->Draw(transform); |
| 822 } | 826 } |
| 823 } | 827 } |
| 824 | 828 |
| 825 void VrShell::DrawWebVr() { | 829 void VrShell::DrawWebVr() { |
| 830 TRACE_EVENT0("gpu", "VrShell::DrawWebVr"); |
| 826 // Don't need face culling, depth testing, blending, etc. Turn it all off. | 831 // Don't need face culling, depth testing, blending, etc. Turn it all off. |
| 827 glDisable(GL_CULL_FACE); | 832 glDisable(GL_CULL_FACE); |
| 828 glDepthMask(GL_FALSE); | 833 glDepthMask(GL_FALSE); |
| 829 glDisable(GL_DEPTH_TEST); | 834 glDisable(GL_DEPTH_TEST); |
| 830 glDisable(GL_SCISSOR_TEST); | 835 glDisable(GL_SCISSOR_TEST); |
| 831 glDisable(GL_BLEND); | 836 glDisable(GL_BLEND); |
| 832 glDisable(GL_POLYGON_OFFSET_FILL); | 837 glDisable(GL_POLYGON_OFFSET_FILL); |
| 833 | 838 |
| 834 glViewport(0, 0, render_size_primary_.width, render_size_primary_.height); | 839 glViewport(0, 0, render_size_primary_.width, render_size_primary_.height); |
| 835 vr_shell_renderer_->GetWebVrRenderer()->Draw(webvr_texture_id_); | 840 vr_shell_renderer_->GetWebVrRenderer()->Draw(webvr_texture_id_); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 | 914 |
| 910 gvr::GvrApi* VrShell::gvr_api() { | 915 gvr::GvrApi* VrShell::gvr_api() { |
| 911 return gvr_api_.get(); | 916 return gvr_api_.get(); |
| 912 } | 917 } |
| 913 | 918 |
| 914 void VrShell::ContentSurfaceChanged(JNIEnv* env, | 919 void VrShell::ContentSurfaceChanged(JNIEnv* env, |
| 915 const JavaParamRef<jobject>& object, | 920 const JavaParamRef<jobject>& object, |
| 916 jint width, | 921 jint width, |
| 917 jint height, | 922 jint height, |
| 918 const JavaParamRef<jobject>& surface) { | 923 const JavaParamRef<jobject>& surface) { |
| 924 TRACE_EVENT0("gpu", "VrShell::ContentSurfaceChanged"); |
| 919 // If we have a delegate, must trigger "ready" callback one time only. | 925 // If we have a delegate, must trigger "ready" callback one time only. |
| 920 // Do so the first time we got a nonzero size. (This assumes it doesn't | 926 // Do so the first time we got a nonzero size. (This assumes it doesn't |
| 921 // change, but once we get resize ability we'll no longer need this hack.) | 927 // change, but once we get resize ability we'll no longer need this hack.) |
| 922 // TODO(klausw,crbug.com/655722): remove when we have surface support. | 928 // TODO(klausw,crbug.com/655722): remove when we have surface support. |
| 923 bool delegate_not_ready = delegate_ && !content_tex_pixels_for_webvr_.width; | 929 bool delegate_not_ready = delegate_ && !content_tex_pixels_for_webvr_.width; |
| 924 | 930 |
| 925 content_compositor_->SurfaceChanged((int)width, (int)height, surface); | 931 content_compositor_->SurfaceChanged((int)width, (int)height, surface); |
| 926 content_tex_pixels_for_webvr_.width = width; | 932 content_tex_pixels_for_webvr_.width = width; |
| 927 content_tex_pixels_for_webvr_.height = height; | 933 content_tex_pixels_for_webvr_.height = height; |
| 928 float scale_factor = display::Screen::GetScreen() | 934 float scale_factor = display::Screen::GetScreen() |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 const JavaParamRef<jobject>& ui_web_contents, | 1034 const JavaParamRef<jobject>& ui_web_contents, |
| 1029 jlong ui_window_android) { | 1035 jlong ui_window_android) { |
| 1030 return reinterpret_cast<intptr_t>(new VrShell( | 1036 return reinterpret_cast<intptr_t>(new VrShell( |
| 1031 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 1037 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
| 1032 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 1038 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 1033 content::WebContents::FromJavaWebContents(ui_web_contents), | 1039 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 1034 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); | 1040 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); |
| 1035 } | 1041 } |
| 1036 | 1042 |
| 1037 } // namespace vr_shell | 1043 } // namespace vr_shell |
| OLD | NEW |