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

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

Issue 2668093002: VrShell background implemented in JS. (Closed)
Patch Set: Removed superfluous tests from previous patch set 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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 MatrixVectorMul(plane->transform.from_world, plane_intersection_point); 504 MatrixVectorMul(plane->transform.from_world, plane_intersection_point);
505 if (distance_to_plane > 0 && distance_to_plane < closest_element_distance) { 505 if (distance_to_plane > 0 && distance_to_plane < closest_element_distance) {
506 float x = rect_2d_point.x + 0.5f; 506 float x = rect_2d_point.x + 0.5f;
507 float y = 0.5f - rect_2d_point.y; 507 float y = 0.5f - rect_2d_point.y;
508 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f; 508 bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f;
509 if (!is_inside) 509 if (!is_inside)
510 continue; 510 continue;
511 511
512 closest_element_distance = distance_to_plane; 512 closest_element_distance = distance_to_plane;
513 Rectf pixel_rect; 513 Rectf pixel_rect;
514 if (plane->content_quad) { 514 if (plane->fill == Fill::CONTENT) {
515 pixel_rect = {0, 0, content_tex_css_width_, content_tex_css_height_}; 515 pixel_rect = {0, 0, content_tex_css_width_, content_tex_css_height_};
516 } else { 516 } else {
517 pixel_rect = {plane->copy_rect.x, plane->copy_rect.y, 517 pixel_rect = {plane->copy_rect.x, plane->copy_rect.y,
518 plane->copy_rect.width, plane->copy_rect.height}; 518 plane->copy_rect.width, plane->copy_rect.height};
519 } 519 }
520 pixel_x = pixel_rect.width * x + pixel_rect.x; 520 pixel_x = pixel_rect.width * x + pixel_rect.x;
521 pixel_y = pixel_rect.height * y + pixel_rect.y; 521 pixel_y = pixel_rect.height * y + pixel_rect.y;
522 522
523 target_point_ = plane_intersection_point; 523 target_point_ = plane_intersection_point;
524 target_element_ = plane.get(); 524 target_element_ = plane.get();
525 input_target = plane->content_quad ? InputTarget::CONTENT 525 input_target = (plane->fill == Fill::CONTENT) ? InputTarget::CONTENT
526 : InputTarget::UI; 526 : InputTarget::UI;
527 } 527 }
528 } 528 }
529 SendEventsToTarget(input_target, pixel_x, pixel_y); 529 SendEventsToTarget(input_target, pixel_x, pixel_y);
530 } 530 }
531 531
532 void VrShellGl::SendEventsToTarget(InputTarget input_target, 532 void VrShellGl::SendEventsToTarget(InputTarget input_target,
533 int pixel_x, 533 int pixel_x,
534 int pixel_y) { 534 int pixel_y) {
535 std::vector<std::unique_ptr<WebGestureEvent>> gesture_list = 535 std::vector<std::unique_ptr<WebGestureEvent>> gesture_list =
536 controller_->DetectGestures(); 536 controller_->DetectGestures();
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 // existing content in place in the primary buffer without 713 // existing content in place in the primary buffer without
714 // clearing. Currently, there aren't any world elements in WebVR 714 // clearing. Currently, there aren't any world elements in WebVR
715 // mode, this will need further testing if those get added 715 // mode, this will need further testing if those get added
716 // later. 716 // later.
717 } else { 717 } else {
718 // Non-WebVR mode, enable depth testing and clear the primary buffers. 718 // Non-WebVR mode, enable depth testing and clear the primary buffers.
719 glEnable(GL_CULL_FACE); 719 glEnable(GL_CULL_FACE);
720 glEnable(GL_DEPTH_TEST); 720 glEnable(GL_DEPTH_TEST);
721 glDepthMask(GL_TRUE); 721 glDepthMask(GL_TRUE);
722 722
723 glClearColor(BackgroundRenderer::kFogBrightness, 723 glClearColor(kFogBrightness, kFogBrightness, kFogBrightness, 1.0f);
724 BackgroundRenderer::kFogBrightness,
725 BackgroundRenderer::kFogBrightness, 1.0f);
726 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 724 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
727 } 725 }
728 if (!world_elements.empty()) { 726 if (!world_elements.empty()) {
729 DrawUiView(&head_pose, world_elements, render_size_primary_, 727 DrawUiView(&head_pose, world_elements, render_size_primary_,
730 kViewportListPrimaryOffset); 728 kViewportListPrimaryOffset);
731 } 729 }
732 730
733 if (!head_locked_elements.empty()) { 731 if (!head_locked_elements.empty()) {
734 // Add head-locked viewports. The list gets reset to just 732 // Add head-locked viewports. The list gets reset to just
735 // the recommended viewports (for the primary buffer) each frame. 733 // the recommended viewports (for the primary buffer) each frame.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 CalculatePixelSpaceRect(render_size, buffer_viewport_->GetSourceUv()); 774 CalculatePixelSpaceRect(render_size, buffer_viewport_->GetSourceUv());
777 glViewport(pixel_rect.left, pixel_rect.bottom, 775 glViewport(pixel_rect.left, pixel_rect.bottom,
778 pixel_rect.right - pixel_rect.left, 776 pixel_rect.right - pixel_rect.left,
779 pixel_rect.top - pixel_rect.bottom); 777 pixel_rect.top - pixel_rect.bottom);
780 778
781 const gvr::Mat4f render_matrix = MatrixMul( 779 const gvr::Mat4f render_matrix = MatrixMul(
782 PerspectiveMatrixFromView( 780 PerspectiveMatrixFromView(
783 buffer_viewport_->GetSourceFov(), kZNear, kZFar), 781 buffer_viewport_->GetSourceFov(), kZNear, kZFar),
784 view_matrix); 782 view_matrix);
785 783
786 if (!web_vr_mode_) {
787 // TODO(tiborg): Enable through the UI API.
788 // DrawBackground(render_matrix);
789 }
790 DrawElements(render_matrix, elements); 784 DrawElements(render_matrix, elements);
791 if (head_pose != nullptr && !web_vr_mode_) { 785 if (head_pose != nullptr && !web_vr_mode_) {
792 DrawCursor(render_matrix); 786 DrawCursor(render_matrix);
793 } 787 }
794 } 788 }
795 } 789 }
796 790
797 void VrShellGl::DrawElements( 791 void VrShellGl::DrawElements(
798 const gvr::Mat4f& render_matrix, 792 const gvr::Mat4f& render_matrix,
799 const std::vector<const ContentRectangle*>& elements) { 793 const std::vector<const ContentRectangle*>& elements) {
800 for (const auto& rect : elements) { 794 for (const auto& rect : elements) {
801 Rectf copy_rect; 795 gvr::Mat4f transform = MatrixMul(render_matrix, rect->transform.to_world);
802 jint texture_handle; 796 switch (rect->fill) {
803 if (rect->content_quad) { 797 case Fill::SPRITE: {
804 copy_rect = {0, 0, 1, 1}; 798 Rectf copy_rect;
805 texture_handle = content_texture_id_; 799 copy_rect.x = static_cast<float>(rect->copy_rect.x) / ui_tex_css_width_;
806 } else { 800 copy_rect.y =
807 copy_rect.x = static_cast<float>(rect->copy_rect.x) / ui_tex_css_width_; 801 static_cast<float>(rect->copy_rect.y) / ui_tex_css_height_;
808 copy_rect.y = static_cast<float>(rect->copy_rect.y) / ui_tex_css_height_; 802 copy_rect.width =
809 copy_rect.width = static_cast<float>(rect->copy_rect.width) / 803 static_cast<float>(rect->copy_rect.width) / ui_tex_css_width_;
810 ui_tex_css_width_; 804 copy_rect.height =
811 copy_rect.height = static_cast<float>(rect->copy_rect.height) / 805 static_cast<float>(rect->copy_rect.height) / ui_tex_css_height_;
812 ui_tex_css_height_; 806 jint texture_handle = ui_texture_id_;
813 texture_handle = ui_texture_id_; 807 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw(
808 texture_handle, transform, copy_rect, rect->computed_opacity);
809 break;
810 }
811 case Fill::OPAQUE_GRADIENT: {
812 vr_shell_renderer_->GetGradientQuadRenderer()->Draw(
813 transform, rect->edge_color, rect->center_color,
814 rect->computed_opacity);
815 break;
816 }
817 case Fill::GRID_GRADIENT: {
818 vr_shell_renderer_->GetGradientGridRenderer()->Draw(
819 transform, rect->edge_color, rect->center_color, rect->tile_number,
820 rect->computed_opacity);
821 break;
822 }
823 case Fill::CONTENT: {
824 Rectf copy_rect = {0, 0, 1, 1};
825 jint texture_handle = content_texture_id_;
826 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw(
827 texture_handle, transform, copy_rect, rect->computed_opacity);
828 break;
829 }
830 default:
831 break;
814 } 832 }
815 gvr::Mat4f transform = MatrixMul(render_matrix, rect->transform.to_world);
816 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw(
817 texture_handle, transform, copy_rect, rect->computed_opacity);
818 } 833 }
819 } 834 }
820 835
821 void VrShellGl::DrawCursor(const gvr::Mat4f& render_matrix) { 836 void VrShellGl::DrawCursor(const gvr::Mat4f& render_matrix) {
822 gvr::Mat4f mat; 837 gvr::Mat4f mat;
823 SetIdentityM(mat); 838 SetIdentityM(mat);
824 839
825 // Draw the reticle. 840 // Draw the reticle.
826 841
827 // Scale the pointer to have a fixed FOV size at any distance. 842 // Scale the pointer to have a fixed FOV size at any distance.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 glDepthMask(GL_FALSE); 913 glDepthMask(GL_FALSE);
899 glDisable(GL_DEPTH_TEST); 914 glDisable(GL_DEPTH_TEST);
900 glDisable(GL_SCISSOR_TEST); 915 glDisable(GL_SCISSOR_TEST);
901 glDisable(GL_BLEND); 916 glDisable(GL_BLEND);
902 glDisable(GL_POLYGON_OFFSET_FILL); 917 glDisable(GL_POLYGON_OFFSET_FILL);
903 918
904 glViewport(0, 0, render_size_primary_.width, render_size_primary_.height); 919 glViewport(0, 0, render_size_primary_.width, render_size_primary_.height);
905 vr_shell_renderer_->GetWebVrRenderer()->Draw(webvr_texture_id_); 920 vr_shell_renderer_->GetWebVrRenderer()->Draw(webvr_texture_id_);
906 } 921 }
907 922
908 void VrShellGl::DrawBackground(const gvr::Mat4f& render_matrix) {
909 vr_shell_renderer_->GetBackgroundRenderer()->Draw(render_matrix);
910 }
911
912 void VrShellGl::OnTriggerEvent() { 923 void VrShellGl::OnTriggerEvent() {
913 // Set a flag to handle this on the render thread at the next frame. 924 // Set a flag to handle this on the render thread at the next frame.
914 touch_pending_ = true; 925 touch_pending_ = true;
915 } 926 }
916 927
917 void VrShellGl::OnPause() { 928 void VrShellGl::OnPause() {
918 vsync_task_.Cancel(); 929 vsync_task_.Cancel();
919 controller_->OnPause(); 930 controller_->OnPause();
920 gvr_api_->PauseTracking(); 931 gvr_api_->PauseTracking();
921 } 932 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 gvr::Mat4f head_mat = 1062 gvr::Mat4f head_mat =
1052 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); 1063 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time);
1053 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); 1064 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f);
1054 1065
1055 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; 1066 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat;
1056 1067
1057 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, frame_index); 1068 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, frame_index);
1058 } 1069 }
1059 1070
1060 } // namespace vr_shell 1071 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698