Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(581)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_gl.cc

Issue 2668093002: VrShell background implemented in JS. (Closed)
Patch Set: Fixed tests Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_gl.h" 5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 MatrixVectorMul(plane->transform.from_world, plane_intersection_point); 510 MatrixVectorMul(plane->transform.from_world, plane_intersection_point);
511 if (distance_to_plane > 0 && distance_to_plane < closest_element_distance) { 511 if (distance_to_plane > 0 && distance_to_plane < closest_element_distance) {
512 float x = rect_2d_point.x + 0.5f; 512 float x = rect_2d_point.x + 0.5f;
513 float y = 0.5f - rect_2d_point.y; 513 float y = 0.5f - rect_2d_point.y;
514 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f; 514 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f;
515 if (!is_inside) 515 if (!is_inside)
516 continue; 516 continue;
517 517
518 closest_element_distance = distance_to_plane; 518 closest_element_distance = distance_to_plane;
519 Rectf pixel_rect; 519 Rectf pixel_rect;
520 if (plane->content_quad) { 520 if (plane->fill == Fill::CONTENT) {
521 pixel_rect = {0, 0, content_tex_css_width_, content_tex_css_height_}; 521 pixel_rect = {0, 0, content_tex_css_width_, content_tex_css_height_};
522 } else { 522 } else {
523 pixel_rect = {plane->copy_rect.x, plane->copy_rect.y, 523 pixel_rect = {plane->copy_rect.x, plane->copy_rect.y,
524 plane->copy_rect.width, plane->copy_rect.height}; 524 plane->copy_rect.width, plane->copy_rect.height};
525 } 525 }
526 pixel_x = pixel_rect.width * x + pixel_rect.x; 526 pixel_x = pixel_rect.width * x + pixel_rect.x;
527 pixel_y = pixel_rect.height * y + pixel_rect.y; 527 pixel_y = pixel_rect.height * y + pixel_rect.y;
528 528
529 target_point_ = plane_intersection_point; 529 target_point_ = plane_intersection_point;
530 target_element_ = plane.get(); 530 target_element_ = plane.get();
531 input_target = plane->content_quad ? InputTarget::CONTENT 531 input_target = (plane->fill == Fill::CONTENT) ? InputTarget::CONTENT
532 : InputTarget::UI; 532 : InputTarget::UI;
533 } 533 }
534 } 534 }
535 SendEventsToTarget(input_target, pixel_x, pixel_y); 535 SendEventsToTarget(input_target, pixel_x, pixel_y);
536 } 536 }
537 537
538 void VrShellGl::SendEventsToTarget(InputTarget input_target, 538 void VrShellGl::SendEventsToTarget(InputTarget input_target,
539 int pixel_x, 539 int pixel_x,
540 int pixel_y) { 540 int pixel_y) {
541 std::vector<std::unique_ptr<WebGestureEvent>> gesture_list = 541 std::vector<std::unique_ptr<WebGestureEvent>> gesture_list =
542 controller_->DetectGestures(); 542 controller_->DetectGestures();
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 // existing content in place in the primary buffer without 719 // existing content in place in the primary buffer without
720 // clearing. Currently, there aren't any world elements in WebVR 720 // clearing. Currently, there aren't any world elements in WebVR
721 // mode, this will need further testing if those get added 721 // mode, this will need further testing if those get added
722 // later. 722 // later.
723 } else { 723 } else {
724 // Non-WebVR mode, enable depth testing and clear the primary buffers. 724 // Non-WebVR mode, enable depth testing and clear the primary buffers.
725 glEnable(GL_CULL_FACE); 725 glEnable(GL_CULL_FACE);
726 glEnable(GL_DEPTH_TEST); 726 glEnable(GL_DEPTH_TEST);
727 glDepthMask(GL_TRUE); 727 glDepthMask(GL_TRUE);
728 728
729 glClearColor(BackgroundRenderer::kFogBrightness, 729 glClearColor(kFogBrightness, kFogBrightness, kFogBrightness, 1.0f);
730 BackgroundRenderer::kFogBrightness,
731 BackgroundRenderer::kFogBrightness, 1.0f);
732 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 730 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
733 } 731 }
734 if (!world_elements.empty()) { 732 if (!world_elements.empty()) {
735 DrawUiView(&head_pose, world_elements, render_size_primary_, 733 DrawUiView(&head_pose, world_elements, render_size_primary_,
736 kViewportListPrimaryOffset); 734 kViewportListPrimaryOffset);
737 } 735 }
738 736
739 if (!head_locked_elements.empty()) { 737 if (!head_locked_elements.empty()) {
740 // Add head-locked viewports. The list gets reset to just 738 // Add head-locked viewports. The list gets reset to just
741 // the recommended viewports (for the primary buffer) each frame. 739 // the recommended viewports (for the primary buffer) each frame.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 CalculatePixelSpaceRect(render_size, buffer_viewport_->GetSourceUv()); 780 CalculatePixelSpaceRect(render_size, buffer_viewport_->GetSourceUv());
783 glViewport(pixel_rect.left, pixel_rect.bottom, 781 glViewport(pixel_rect.left, pixel_rect.bottom,
784 pixel_rect.right - pixel_rect.left, 782 pixel_rect.right - pixel_rect.left,
785 pixel_rect.top - pixel_rect.bottom); 783 pixel_rect.top - pixel_rect.bottom);
786 784
787 const gvr::Mat4f render_matrix = MatrixMul( 785 const gvr::Mat4f render_matrix = MatrixMul(
788 PerspectiveMatrixFromView( 786 PerspectiveMatrixFromView(
789 buffer_viewport_->GetSourceFov(), kZNear, kZFar), 787 buffer_viewport_->GetSourceFov(), kZNear, kZFar),
790 view_matrix); 788 view_matrix);
791 789
792 if (!web_vr_mode_) {
793 // TODO(tiborg): Enable through the UI API.
794 // DrawBackground(render_matrix);
795 }
796 DrawElements(render_matrix, elements); 790 DrawElements(render_matrix, elements);
797 if (head_pose != nullptr && !web_vr_mode_) { 791 if (head_pose != nullptr && !web_vr_mode_) {
798 DrawCursor(render_matrix); 792 DrawCursor(render_matrix);
799 } 793 }
800 } 794 }
801 } 795 }
802 796
803 void VrShellGl::DrawElements( 797 void VrShellGl::DrawElements(
804 const gvr::Mat4f& render_matrix, 798 const gvr::Mat4f& render_matrix,
805 const std::vector<const ContentRectangle*>& elements) { 799 const std::vector<const ContentRectangle*>& elements) {
806 for (const auto& rect : elements) { 800 for (const auto& rect : elements) {
807 Rectf copy_rect; 801 gvr::Mat4f transform = MatrixMul(render_matrix, rect->transform.to_world);
808 jint texture_handle; 802 switch (rect->fill) {
809 if (rect->content_quad) { 803 case Fill::SPRITE: {
810 copy_rect = {0, 0, 1, 1}; 804 Rectf copy_rect;
811 texture_handle = content_texture_id_; 805 copy_rect.x = static_cast<float>(rect->copy_rect.x) / ui_tex_css_width_;
812 } else { 806 copy_rect.y =
813 copy_rect.x = static_cast<float>(rect->copy_rect.x) / ui_tex_css_width_; 807 static_cast<float>(rect->copy_rect.y) / ui_tex_css_height_;
814 copy_rect.y = static_cast<float>(rect->copy_rect.y) / ui_tex_css_height_; 808 copy_rect.width =
815 copy_rect.width = static_cast<float>(rect->copy_rect.width) / 809 static_cast<float>(rect->copy_rect.width) / ui_tex_css_width_;
816 ui_tex_css_width_; 810 copy_rect.height =
817 copy_rect.height = static_cast<float>(rect->copy_rect.height) / 811 static_cast<float>(rect->copy_rect.height) / ui_tex_css_height_;
818 ui_tex_css_height_; 812 jint texture_handle = ui_texture_id_;
819 texture_handle = ui_texture_id_; 813 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw(
814 texture_handle, transform, copy_rect, rect->computed_opacity);
815 break;
816 }
817 case Fill::OPAQUE_GRADIENT: {
818 vr_shell_renderer_->GetGradientQuadRenderer()->Draw(
819 transform, rect->edge_color, rect->center_color,
820 rect->computed_opacity);
821 break;
822 }
823 case Fill::GRID_GRADIENT: {
824 vr_shell_renderer_->GetGradientGridRenderer()->Draw(
825 transform, rect->edge_color, rect->center_color,
826 rect->gridline_count, rect->computed_opacity);
827 break;
828 }
829 case Fill::CONTENT: {
830 Rectf copy_rect = {0, 0, 1, 1};
831 jint texture_handle = content_texture_id_;
832 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw(
833 texture_handle, transform, copy_rect, rect->computed_opacity);
834 break;
835 }
836 default:
837 break;
820 } 838 }
821 gvr::Mat4f transform = MatrixMul(render_matrix, rect->transform.to_world);
822 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw(
823 texture_handle, transform, copy_rect, rect->computed_opacity);
824 } 839 }
825 } 840 }
826 841
827 void VrShellGl::DrawCursor(const gvr::Mat4f& render_matrix) { 842 void VrShellGl::DrawCursor(const gvr::Mat4f& render_matrix) {
828 gvr::Mat4f mat; 843 gvr::Mat4f mat;
829 SetIdentityM(mat); 844 SetIdentityM(mat);
830 845
831 // Draw the reticle. 846 // Draw the reticle.
832 847
833 // Scale the pointer to have a fixed FOV size at any distance. 848 // Scale the pointer to have a fixed FOV size at any distance.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 glDepthMask(GL_FALSE); 919 glDepthMask(GL_FALSE);
905 glDisable(GL_DEPTH_TEST); 920 glDisable(GL_DEPTH_TEST);
906 glDisable(GL_SCISSOR_TEST); 921 glDisable(GL_SCISSOR_TEST);
907 glDisable(GL_BLEND); 922 glDisable(GL_BLEND);
908 glDisable(GL_POLYGON_OFFSET_FILL); 923 glDisable(GL_POLYGON_OFFSET_FILL);
909 924
910 glViewport(0, 0, render_size_primary_.width, render_size_primary_.height); 925 glViewport(0, 0, render_size_primary_.width, render_size_primary_.height);
911 vr_shell_renderer_->GetWebVrRenderer()->Draw(webvr_texture_id_); 926 vr_shell_renderer_->GetWebVrRenderer()->Draw(webvr_texture_id_);
912 } 927 }
913 928
914 void VrShellGl::DrawBackground(const gvr::Mat4f& render_matrix) {
915 vr_shell_renderer_->GetBackgroundRenderer()->Draw(render_matrix);
916 }
917
918 void VrShellGl::OnTriggerEvent() { 929 void VrShellGl::OnTriggerEvent() {
919 // Set a flag to handle this on the render thread at the next frame. 930 // Set a flag to handle this on the render thread at the next frame.
920 touch_pending_ = true; 931 touch_pending_ = true;
921 } 932 }
922 933
923 void VrShellGl::OnPause() { 934 void VrShellGl::OnPause() {
924 vsync_task_.Cancel(); 935 vsync_task_.Cancel();
925 controller_->OnPause(); 936 controller_->OnPause();
926 gvr_api_->PauseTracking(); 937 gvr_api_->PauseTracking();
927 } 938 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, 1081 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
1071 uint32_t device_id) { 1082 uint32_t device_id) {
1072 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( 1083 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo(
1073 gvr_api_.get(), content_tex_physical_size_, device_id); 1084 gvr_api_.get(), content_tex_physical_size_, device_id);
1074 main_thread_task_runner_->PostTask( 1085 main_thread_task_runner_->PostTask(
1075 FROM_HERE, 1086 FROM_HERE,
1076 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); 1087 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info)));
1077 } 1088 }
1078 1089
1079 } // namespace vr_shell 1090 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | chrome/browser/android/vr_shell/vr_shell_renderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698