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

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

Issue 2658643003: Refactor GvrDelegate ownership into GvrDelegateProvider and fix more threading violations. (Closed)
Patch Set: Address comments 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
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | device/vr/android/gvr/gvr_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 CARDBOARD = 1, 147 CARDBOARD = 1,
148 DAYDREAM = 2, 148 DAYDREAM = 2,
149 VIEWER_TYPE_MAX, 149 VIEWER_TYPE_MAX,
150 }; 150 };
151 151
152 int64_t TimeInMicroseconds() { 152 int64_t TimeInMicroseconds() {
153 return std::chrono::duration_cast<std::chrono::microseconds>( 153 return std::chrono::duration_cast<std::chrono::microseconds>(
154 std::chrono::steady_clock::now().time_since_epoch()).count(); 154 std::chrono::steady_clock::now().time_since_epoch()).count();
155 } 155 }
156 156
157 void RunVRDisplayInfoCallback(
158 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
159 device::mojom::VRDisplayInfoPtr info) {
160 callback.Run(std::move(info));
161 }
162
157 } // namespace 163 } // namespace
158 164
159 VrShellGl::VrShellGl( 165 VrShellGl::VrShellGl(
160 const base::WeakPtr<VrShell>& weak_vr_shell, 166 const base::WeakPtr<VrShell>& weak_vr_shell,
161 const base::WeakPtr<VrShellDelegate>& delegate_provider, 167 const base::WeakPtr<VrShellDelegate>& delegate_provider,
162 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, 168 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
163 gvr_context* gvr_api, 169 gvr_context* gvr_api,
164 bool initially_web_vr, 170 bool initially_web_vr,
165 bool reprojected_rendering) 171 bool reprojected_rendering)
166 : web_vr_mode_(initially_web_vr), 172 : web_vr_mode_(initially_web_vr),
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 const gvr::Rectf& right_bounds) { 945 const gvr::Rectf& right_bounds) {
940 if (frame_index < 0) { 946 if (frame_index < 0) {
941 webvr_left_viewport_->SetSourceUv(left_bounds); 947 webvr_left_viewport_->SetSourceUv(left_bounds);
942 webvr_right_viewport_->SetSourceUv(right_bounds); 948 webvr_right_viewport_->SetSourceUv(right_bounds);
943 } else { 949 } else {
944 pending_bounds_.emplace( 950 pending_bounds_.emplace(
945 std::make_pair(frame_index, std::make_pair(left_bounds, right_bounds))); 951 std::make_pair(frame_index, std::make_pair(left_bounds, right_bounds)));
946 } 952 }
947 } 953 }
948 954
949 gvr::GvrApi* VrShellGl::gvr_api() {
950 return gvr_api_.get();
951 }
952
953 void VrShellGl::ContentBoundsChanged(int width, int height) { 955 void VrShellGl::ContentBoundsChanged(int width, int height) {
954 TRACE_EVENT0("gpu", "VrShellGl::ContentBoundsChanged"); 956 TRACE_EVENT0("gpu", "VrShellGl::ContentBoundsChanged");
955 content_tex_css_width_ = width; 957 content_tex_css_width_ = width;
956 content_tex_css_height_ = height; 958 content_tex_css_height_ = height;
957 } 959 }
958 960
959 void VrShellGl::ContentPhysicalBoundsChanged(int width, int height) { 961 void VrShellGl::ContentPhysicalBoundsChanged(int width, int height) {
960 if (content_surface_texture_.get()) 962 if (content_surface_texture_.get())
961 content_surface_texture_->SetDefaultBufferSize(width, height); 963 content_surface_texture_->SetDefaultBufferSize(width, height);
962 content_tex_physical_size_.width = width; 964 content_tex_physical_size_.width = width;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 1052
1051 gvr::Mat4f head_mat = 1053 gvr::Mat4f head_mat =
1052 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); 1054 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time);
1053 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); 1055 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f);
1054 1056
1055 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; 1057 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat;
1056 1058
1057 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, frame_index); 1059 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, frame_index);
1058 } 1060 }
1059 1061
1062 void VrShellGl::ResetPose() {
1063 // Should never call RecenterTracking when using with Daydream viewers. On
1064 // those devices recentering should only be done via the controller.
1065 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD)
1066 gvr_api_->RecenterTracking();
1067 }
1068
1069 void VrShellGl::CreateVRDisplayInfo(
1070 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
1071 uint32_t device_id) {
1072 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo(
1073 gvr_api_.get(), content_tex_physical_size_, device_id);
1074 main_thread_task_runner_->PostTask(
1075 FROM_HERE,
1076 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info)));
1077 }
1078
1060 } // namespace vr_shell 1079 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | device/vr/android/gvr/gvr_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698