| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 CARDBOARD = 1, | 146 CARDBOARD = 1, |
| 147 DAYDREAM = 2, | 147 DAYDREAM = 2, |
| 148 VIEWER_TYPE_MAX, | 148 VIEWER_TYPE_MAX, |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 int64_t TimeInMicroseconds() { | 151 int64_t TimeInMicroseconds() { |
| 152 return std::chrono::duration_cast<std::chrono::microseconds>( | 152 return std::chrono::duration_cast<std::chrono::microseconds>( |
| 153 std::chrono::steady_clock::now().time_since_epoch()).count(); | 153 std::chrono::steady_clock::now().time_since_epoch()).count(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void RunVRDisplayInfoCallback( |
| 157 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 158 device::mojom::VRDisplayInfoPtr info) { |
| 159 callback.Run(std::move(info)); |
| 160 } |
| 161 |
| 156 } // namespace | 162 } // namespace |
| 157 | 163 |
| 158 VrShellGl::VrShellGl( | 164 VrShellGl::VrShellGl( |
| 159 const base::WeakPtr<VrShell>& weak_vr_shell, | 165 const base::WeakPtr<VrShell>& weak_vr_shell, |
| 160 const base::WeakPtr<VrInputManager>& content_input_manager, | 166 const base::WeakPtr<VrInputManager>& content_input_manager, |
| 161 const base::WeakPtr<VrInputManager>& ui_input_manager, | 167 const base::WeakPtr<VrInputManager>& ui_input_manager, |
| 162 const base::WeakPtr<VrShellDelegate>& delegate_provider, | 168 const base::WeakPtr<VrShellDelegate>& delegate_provider, |
| 163 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 169 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
| 164 gvr_context* gvr_api, | 170 gvr_context* gvr_api, |
| 165 bool initially_web_vr, | 171 bool initially_web_vr, |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 const gvr::Rectf& right_bounds) { | 934 const gvr::Rectf& right_bounds) { |
| 929 if (frame_index < 0) { | 935 if (frame_index < 0) { |
| 930 webvr_left_viewport_->SetSourceUv(left_bounds); | 936 webvr_left_viewport_->SetSourceUv(left_bounds); |
| 931 webvr_right_viewport_->SetSourceUv(right_bounds); | 937 webvr_right_viewport_->SetSourceUv(right_bounds); |
| 932 } else { | 938 } else { |
| 933 pending_bounds_.emplace( | 939 pending_bounds_.emplace( |
| 934 std::make_pair(frame_index, std::make_pair(left_bounds, right_bounds))); | 940 std::make_pair(frame_index, std::make_pair(left_bounds, right_bounds))); |
| 935 } | 941 } |
| 936 } | 942 } |
| 937 | 943 |
| 938 gvr::GvrApi* VrShellGl::gvr_api() { | |
| 939 return gvr_api_.get(); | |
| 940 } | |
| 941 | |
| 942 void VrShellGl::ContentBoundsChanged(int width, int height) { | 944 void VrShellGl::ContentBoundsChanged(int width, int height) { |
| 943 TRACE_EVENT0("gpu", "VrShellGl::ContentBoundsChanged"); | 945 TRACE_EVENT0("gpu", "VrShellGl::ContentBoundsChanged"); |
| 944 content_tex_css_width_ = width; | 946 content_tex_css_width_ = width; |
| 945 content_tex_css_height_ = height; | 947 content_tex_css_height_ = height; |
| 946 } | 948 } |
| 947 | 949 |
| 948 void VrShellGl::ContentPhysicalBoundsChanged(int width, int height) { | 950 void VrShellGl::ContentPhysicalBoundsChanged(int width, int height) { |
| 949 if (content_surface_texture_.get()) | 951 if (content_surface_texture_.get()) |
| 950 content_surface_texture_->SetDefaultBufferSize(width, height); | 952 content_surface_texture_->SetDefaultBufferSize(width, height); |
| 951 content_tex_physical_size_.width = width; | 953 content_tex_physical_size_.width = width; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 | 1042 |
| 1041 gvr::Mat4f head_mat = | 1043 gvr::Mat4f head_mat = |
| 1042 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); | 1044 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); |
| 1043 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); | 1045 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); |
| 1044 | 1046 |
| 1045 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; | 1047 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; |
| 1046 | 1048 |
| 1047 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, frame_index); | 1049 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, frame_index); |
| 1048 } | 1050 } |
| 1049 | 1051 |
| 1052 void VrShellGl::ResetPose() { |
| 1053 // Should never call RecenterTracking when using with Daydream viewers. On |
| 1054 // those devices recentering should only be done via the controller. |
| 1055 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) |
| 1056 gvr_api_->RecenterTracking(); |
| 1057 } |
| 1058 |
| 1059 void VrShellGl::CreateVRDisplayInfo( |
| 1060 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 1061 uint32_t device_id) { |
| 1062 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( |
| 1063 gvr_api_.get(), content_tex_physical_size_, device_id); |
| 1064 main_thread_task_runner_->PostTask( |
| 1065 FROM_HERE, |
| 1066 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); |
| 1067 } |
| 1068 |
| 1050 } // namespace vr_shell | 1069 } // namespace vr_shell |
| OLD | NEW |