| 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_gl.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 6 | 6 |
| 7 #include <chrono> | 7 #include <chrono> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 pixel_rect.top - pixel_rect.bottom); | 928 pixel_rect.top - pixel_rect.bottom); |
| 929 | 929 |
| 930 const gvr::Mat4f render_matrix = | 930 const gvr::Mat4f render_matrix = |
| 931 MatrixMul(PerspectiveMatrixFromView(buffer_viewport_->GetSourceFov(), | 931 MatrixMul(PerspectiveMatrixFromView(buffer_viewport_->GetSourceFov(), |
| 932 kZNear, kZFar), | 932 kZNear, kZFar), |
| 933 eye_view_matrix); | 933 eye_view_matrix); |
| 934 | 934 |
| 935 DrawElements(render_matrix, elementsInDrawOrder); | 935 DrawElements(render_matrix, elementsInDrawOrder); |
| 936 if (draw_cursor) { | 936 if (draw_cursor) { |
| 937 DrawCursor(render_matrix); | 937 DrawCursor(render_matrix); |
| 938 DrawController(render_matrix); |
| 938 } | 939 } |
| 939 } | 940 } |
| 940 } | 941 } |
| 941 | 942 |
| 942 void VrShellGl::DrawElements( | 943 void VrShellGl::DrawElements( |
| 943 const gvr::Mat4f& view_proj_matrix, | 944 const gvr::Mat4f& view_proj_matrix, |
| 944 const std::vector<const ContentRectangle*>& elements) { | 945 const std::vector<const ContentRectangle*>& elements) { |
| 945 for (const auto* rect : elements) { | 946 for (const auto* rect : elements) { |
| 946 gvr::Mat4f transform = MatrixMul(view_proj_matrix, rect->TransformMatrix()); | 947 gvr::Mat4f transform = MatrixMul(view_proj_matrix, rect->TransformMatrix()); |
| 947 | 948 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 | 1089 |
| 1089 // Move the beam origin to the hand. | 1090 // Move the beam origin to the hand. |
| 1090 TranslateM(face_transform, face_transform, kHandPosition.x, kHandPosition.y, | 1091 TranslateM(face_transform, face_transform, kHandPosition.x, kHandPosition.y, |
| 1091 kHandPosition.z); | 1092 kHandPosition.z); |
| 1092 | 1093 |
| 1093 transform = MatrixMul(render_matrix, face_transform); | 1094 transform = MatrixMul(render_matrix, face_transform); |
| 1094 vr_shell_renderer_->GetLaserRenderer()->Draw(transform); | 1095 vr_shell_renderer_->GetLaserRenderer()->Draw(transform); |
| 1095 } | 1096 } |
| 1096 } | 1097 } |
| 1097 | 1098 |
| 1099 void VrShellGl::DrawController(const gvr::Mat4f& view_proj_matrix) { |
| 1100 if (!vr_shell_renderer_->GetControllerRenderer()->IsSetUp()) |
| 1101 return; |
| 1102 auto transform = MatrixMul(view_proj_matrix, controller_->GetTransform()); |
| 1103 auto state = controller_->GetModelState(); |
| 1104 vr_shell_renderer_->GetControllerRenderer()->Draw(state, transform); |
| 1105 } |
| 1106 |
| 1098 bool VrShellGl::ShouldDrawWebVr() { | 1107 bool VrShellGl::ShouldDrawWebVr() { |
| 1099 return web_vr_mode_ && scene_->GetWebVrRenderingEnabled(); | 1108 return web_vr_mode_ && scene_->GetWebVrRenderingEnabled(); |
| 1100 } | 1109 } |
| 1101 | 1110 |
| 1102 void VrShellGl::DrawWebVr() { | 1111 void VrShellGl::DrawWebVr() { |
| 1103 TRACE_EVENT0("gpu", "VrShellGl::DrawWebVr"); | 1112 TRACE_EVENT0("gpu", "VrShellGl::DrawWebVr"); |
| 1104 // Don't need face culling, depth testing, blending, etc. Turn it all off. | 1113 // Don't need face culling, depth testing, blending, etc. Turn it all off. |
| 1105 glDisable(GL_CULL_FACE); | 1114 glDisable(GL_CULL_FACE); |
| 1106 glDepthMask(GL_FALSE); | 1115 glDepthMask(GL_FALSE); |
| 1107 glDisable(GL_DEPTH_TEST); | 1116 glDisable(GL_DEPTH_TEST); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 if (ui_surface_texture_.get()) | 1191 if (ui_surface_texture_.get()) |
| 1183 ui_surface_texture_->SetDefaultBufferSize(width, height); | 1192 ui_surface_texture_->SetDefaultBufferSize(width, height); |
| 1184 ui_tex_physical_size_.width = width; | 1193 ui_tex_physical_size_.width = width; |
| 1185 ui_tex_physical_size_.height = height; | 1194 ui_tex_physical_size_.height = height; |
| 1186 } | 1195 } |
| 1187 | 1196 |
| 1188 base::WeakPtr<VrShellGl> VrShellGl::GetWeakPtr() { | 1197 base::WeakPtr<VrShellGl> VrShellGl::GetWeakPtr() { |
| 1189 return weak_ptr_factory_.GetWeakPtr(); | 1198 return weak_ptr_factory_.GetWeakPtr(); |
| 1190 } | 1199 } |
| 1191 | 1200 |
| 1201 void VrShellGl::SetControllerModel(std::unique_ptr<VrControllerModel> model) { |
| 1202 vr_shell_renderer_->GetControllerRenderer()->SetUp(std::move(model)); |
| 1203 } |
| 1204 |
| 1192 void VrShellGl::OnVSync() { | 1205 void VrShellGl::OnVSync() { |
| 1193 while (premature_received_frames_ > 0) { | 1206 while (premature_received_frames_ > 0) { |
| 1194 TRACE_EVENT0("gpu", "VrShellGl::OnWebVRFrameAvailableRetry"); | 1207 TRACE_EVENT0("gpu", "VrShellGl::OnWebVRFrameAvailableRetry"); |
| 1195 --premature_received_frames_; | 1208 --premature_received_frames_; |
| 1196 OnWebVRFrameAvailable(); | 1209 OnWebVRFrameAvailable(); |
| 1197 } | 1210 } |
| 1198 | 1211 |
| 1199 base::TimeTicks now = base::TimeTicks::Now(); | 1212 base::TimeTicks now = base::TimeTicks::Now(); |
| 1200 base::TimeTicks target; | 1213 base::TimeTicks target; |
| 1201 | 1214 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 // appropriate recommended render resolution as the default size during | 1304 // appropriate recommended render resolution as the default size during |
| 1292 // InitializeGl. Revisit if the initialization order changes. | 1305 // InitializeGl. Revisit if the initialization order changes. |
| 1293 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( | 1306 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( |
| 1294 gvr_api_.get(), webvr_surface_size_, device_id); | 1307 gvr_api_.get(), webvr_surface_size_, device_id); |
| 1295 main_thread_task_runner_->PostTask( | 1308 main_thread_task_runner_->PostTask( |
| 1296 FROM_HERE, | 1309 FROM_HERE, |
| 1297 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); | 1310 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); |
| 1298 } | 1311 } |
| 1299 | 1312 |
| 1300 } // namespace vr_shell | 1313 } // namespace vr_shell |
| OLD | NEW |