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

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

Issue 2668093002: VrShell background implemented in JS. (Closed)
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 702 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 switch (rect->fill) {
802 jint texture_handle; 796 case Fill::SPRITE: {
803 if (rect->content_quad) { 797 Rectf copy_rect;
804 copy_rect = {0, 0, 1, 1}; 798 jint texture_handle;
805 texture_handle = content_texture_id_; 799 if (rect->content_quad) {
806 } else { 800 copy_rect = {0, 0, 1, 1};
807 copy_rect.x = static_cast<float>(rect->copy_rect.x) / ui_tex_css_width_; 801 texture_handle = content_texture_id_;
808 copy_rect.y = static_cast<float>(rect->copy_rect.y) / ui_tex_css_height_; 802 } else {
809 copy_rect.width = static_cast<float>(rect->copy_rect.width) / 803 copy_rect.x =
810 ui_tex_css_width_; 804 static_cast<float>(rect->copy_rect.x) / ui_tex_css_width_;
811 copy_rect.height = static_cast<float>(rect->copy_rect.height) / 805 copy_rect.y =
812 ui_tex_css_height_; 806 static_cast<float>(rect->copy_rect.y) / ui_tex_css_height_;
813 texture_handle = ui_texture_id_; 807 copy_rect.width =
808 static_cast<float>(rect->copy_rect.width) / ui_tex_css_width_;
809 copy_rect.height =
810 static_cast<float>(rect->copy_rect.height) / ui_tex_css_height_;
811 texture_handle = ui_texture_id_;
812 }
813 gvr::Mat4f transform =
814 MatrixMul(render_matrix, rect->transform.to_world);
815 vr_shell_renderer_->GetTexturedQuadRenderer()->Draw(
816 texture_handle, transform, copy_rect, rect->computed_opacity);
817 } break;
mthiesse 2017/01/31 20:54:54 nit: break; should go inside braces.
tiborg1 2017/02/01 00:22:18 Done.
818 case Fill::OPAQUE_GRADIENT: {
819 gvr::Mat4f transform =
820 MatrixMul(render_matrix, rect->transform.to_world);
821 vr_shell_renderer_->GetGradientQuadRenderer()->Draw(
822 transform, rect->center_color, rect->edge_color);
mthiesse 2017/01/31 20:54:54 Should this not respect opacity?
tiborg1 2017/02/01 00:22:18 Good point! It's fixed.
823 } break;
824 case Fill::GRID_GRADIENT: {
825 gvr::Mat4f transform =
826 MatrixMul(render_matrix, rect->transform.to_world);
827 vr_shell_renderer_->GetGradientGridRenderer()->Draw(
828 transform, rect->center_color, rect->edge_color, rect->tile_number);
829 } break;
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