| 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 <limits> | 7 #include <limits> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 352 |
| 353 gvr_api_->InitializeGl(); | 353 gvr_api_->InitializeGl(); |
| 354 webvr_head_pose_.assign(kPoseRingBufferSize, | 354 webvr_head_pose_.assign(kPoseRingBufferSize, |
| 355 gvr_api_->GetHeadSpaceFromStartSpaceRotation( | 355 gvr_api_->GetHeadSpaceFromStartSpaceRotation( |
| 356 gvr::GvrApi::GetTimePointNow())); | 356 gvr::GvrApi::GetTimePointNow())); |
| 357 | 357 |
| 358 std::vector<gvr::BufferSpec> specs; | 358 std::vector<gvr::BufferSpec> specs; |
| 359 // For kFramePrimaryBuffer (primary VrShell and WebVR content) | 359 // For kFramePrimaryBuffer (primary VrShell and WebVR content) |
| 360 specs.push_back(gvr_api_->CreateBufferSpec()); | 360 specs.push_back(gvr_api_->CreateBufferSpec()); |
| 361 render_size_primary_ = specs[kFramePrimaryBuffer].GetSize(); | 361 render_size_primary_ = specs[kFramePrimaryBuffer].GetSize(); |
| 362 render_size_primary_vrshell_ = render_size_primary_; |
| 362 | 363 |
| 363 // For kFrameHeadlockedBuffer (for WebVR insecure content warning). | 364 // For kFrameHeadlockedBuffer (for WebVR insecure content warning). |
| 364 // Set this up at fixed resolution, the (smaller) FOV gets set below. | 365 // Set this up at fixed resolution, the (smaller) FOV gets set below. |
| 365 specs.push_back(gvr_api_->CreateBufferSpec()); | 366 specs.push_back(gvr_api_->CreateBufferSpec()); |
| 366 specs.back().SetSize(kHeadlockedBufferDimensions); | 367 specs.back().SetSize(kHeadlockedBufferDimensions); |
| 367 render_size_headlocked_ = specs[kFrameHeadlockedBuffer].GetSize(); | 368 render_size_headlocked_ = specs[kFrameHeadlockedBuffer].GetSize(); |
| 368 | 369 |
| 369 swap_chain_.reset(new gvr::SwapChain(gvr_api_->CreateSwapChain(specs))); | 370 swap_chain_.reset(new gvr::SwapChain(gvr_api_->CreateSwapChain(specs))); |
| 370 | 371 |
| 371 vr_shell_renderer_.reset(new VrShellRenderer()); | 372 vr_shell_renderer_.reset(new VrShellRenderer()); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 } | 632 } |
| 632 | 633 |
| 633 void VrShellGl::DrawFrame() { | 634 void VrShellGl::DrawFrame() { |
| 634 TRACE_EVENT0("gpu", "VrShellGl::DrawFrame"); | 635 TRACE_EVENT0("gpu", "VrShellGl::DrawFrame"); |
| 635 | 636 |
| 636 // Reset the viewport list to just the pair of viewports for the | 637 // Reset the viewport list to just the pair of viewports for the |
| 637 // primary buffer each frame. Head-locked viewports get added by | 638 // primary buffer each frame. Head-locked viewports get added by |
| 638 // DrawVrShell if needed. | 639 // DrawVrShell if needed. |
| 639 buffer_viewport_list_->SetToRecommendedBufferViewports(); | 640 buffer_viewport_list_->SetToRecommendedBufferViewports(); |
| 640 | 641 |
| 642 // Resize render buffers to match desired resolution when switching |
| 643 // modes between WebVR and VrShell mode. |
| 644 if (web_vr_mode_) { |
| 645 // If needed, resize the primary buffer for use with WebVR so that |
| 646 // it matches the canvas size used for WebGL rendering. |
| 647 if (render_size_primary_ != render_size_primary_webvr_) { |
| 648 if (!render_size_primary_webvr_.width) { |
| 649 DVLOG(2) << "WebVR rendering size not known yet, dropping frame"; |
| 650 return; |
| 651 } |
| 652 render_size_primary_ = render_size_primary_webvr_; |
| 653 swap_chain_->ResizeBuffer(kFramePrimaryBuffer, render_size_primary_); |
| 654 } |
| 655 } else { |
| 656 // Restore high resolution for VrShell mode. |
| 657 if (render_size_primary_ != render_size_primary_vrshell_) { |
| 658 render_size_primary_ = render_size_primary_vrshell_; |
| 659 swap_chain_->ResizeBuffer(kFramePrimaryBuffer, render_size_primary_); |
| 660 } |
| 661 } |
| 662 |
| 641 gvr::Frame frame = swap_chain_->AcquireFrame(); | 663 gvr::Frame frame = swap_chain_->AcquireFrame(); |
| 642 if (!frame.is_valid()) { | 664 if (!frame.is_valid()) { |
| 643 return; | 665 return; |
| 644 } | 666 } |
| 645 frame.BindBuffer(kFramePrimaryBuffer); | 667 frame.BindBuffer(kFramePrimaryBuffer); |
| 646 if (web_vr_mode_) { | 668 if (web_vr_mode_) { |
| 647 DrawWebVr(); | 669 DrawWebVr(); |
| 648 } | 670 } |
| 649 | 671 |
| 650 uint16_t frame_index; | 672 uint16_t frame_index; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 TRACE_EVENT0("gpu", "VrShellGl::ContentBoundsChanged"); | 1064 TRACE_EVENT0("gpu", "VrShellGl::ContentBoundsChanged"); |
| 1043 content_tex_css_width_ = width; | 1065 content_tex_css_width_ = width; |
| 1044 content_tex_css_height_ = height; | 1066 content_tex_css_height_ = height; |
| 1045 } | 1067 } |
| 1046 | 1068 |
| 1047 void VrShellGl::ContentPhysicalBoundsChanged(int width, int height) { | 1069 void VrShellGl::ContentPhysicalBoundsChanged(int width, int height) { |
| 1048 if (content_surface_texture_.get()) | 1070 if (content_surface_texture_.get()) |
| 1049 content_surface_texture_->SetDefaultBufferSize(width, height); | 1071 content_surface_texture_->SetDefaultBufferSize(width, height); |
| 1050 content_tex_physical_size_.width = width; | 1072 content_tex_physical_size_.width = width; |
| 1051 content_tex_physical_size_.height = height; | 1073 content_tex_physical_size_.height = height; |
| 1074 render_size_primary_webvr_.width = width; |
| 1075 render_size_primary_webvr_.height = height; |
| 1052 } | 1076 } |
| 1053 | 1077 |
| 1054 void VrShellGl::UIBoundsChanged(int width, int height) { | 1078 void VrShellGl::UIBoundsChanged(int width, int height) { |
| 1055 ui_tex_css_width_ = width; | 1079 ui_tex_css_width_ = width; |
| 1056 ui_tex_css_height_ = height; | 1080 ui_tex_css_height_ = height; |
| 1057 } | 1081 } |
| 1058 | 1082 |
| 1059 void VrShellGl::UIPhysicalBoundsChanged(int width, int height) { | 1083 void VrShellGl::UIPhysicalBoundsChanged(int width, int height) { |
| 1060 if (ui_surface_texture_.get()) | 1084 if (ui_surface_texture_.get()) |
| 1061 ui_surface_texture_->SetDefaultBufferSize(width, height); | 1085 ui_surface_texture_->SetDefaultBufferSize(width, height); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, | 1182 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 1159 uint32_t device_id) { | 1183 uint32_t device_id) { |
| 1160 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( | 1184 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( |
| 1161 gvr_api_.get(), content_tex_physical_size_, device_id); | 1185 gvr_api_.get(), content_tex_physical_size_, device_id); |
| 1162 main_thread_task_runner_->PostTask( | 1186 main_thread_task_runner_->PostTask( |
| 1163 FROM_HERE, | 1187 FROM_HERE, |
| 1164 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); | 1188 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); |
| 1165 } | 1189 } |
| 1166 | 1190 |
| 1167 } // namespace vr_shell | 1191 } // namespace vr_shell |
| OLD | NEW |