| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 callback.Run(std::move(info)); | 133 callback.Run(std::move(info)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace | 136 } // namespace |
| 137 | 137 |
| 138 VrShellGl::VrShellGl( | 138 VrShellGl::VrShellGl( |
| 139 const base::WeakPtr<VrShell>& weak_vr_shell, | 139 const base::WeakPtr<VrShell>& weak_vr_shell, |
| 140 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 140 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
| 141 gvr_context* gvr_api, | 141 gvr_context* gvr_api, |
| 142 bool initially_web_vr, | 142 bool initially_web_vr, |
| 143 bool reprojected_rendering) | 143 bool reprojected_rendering, |
| 144 : web_vr_mode_(initially_web_vr), | 144 UiScene* scene) |
| 145 : scene_(scene), |
| 146 web_vr_mode_(initially_web_vr), |
| 145 surfaceless_rendering_(reprojected_rendering), | 147 surfaceless_rendering_(reprojected_rendering), |
| 146 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 148 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 147 binding_(this), | 149 binding_(this), |
| 148 weak_vr_shell_(weak_vr_shell), | 150 weak_vr_shell_(weak_vr_shell), |
| 149 main_thread_task_runner_(std::move(main_thread_task_runner)), | 151 main_thread_task_runner_(std::move(main_thread_task_runner)), |
| 150 weak_ptr_factory_(this) { | 152 weak_ptr_factory_(this) { |
| 151 GvrInit(gvr_api); | 153 GvrInit(gvr_api); |
| 152 } | 154 } |
| 153 | 155 |
| 154 VrShellGl::~VrShellGl() { | 156 VrShellGl::~VrShellGl() { |
| 155 vsync_task_.Cancel(); | 157 vsync_task_.Cancel(); |
| 156 // TODO(mthiesse): Can we omit the Close() here? Concern is that if | 158 // TODO(mthiesse): Can we omit the Close() here? Concern is that if |
| 157 // both ends of the connection ever live in the same process for | 159 // both ends of the connection ever live in the same process for |
| 158 // some reason, we could receive another VSync request in response | 160 // some reason, we could receive another VSync request in response |
| 159 // to the closing message in the destructor but fail to respond to | 161 // to the closing message in the destructor but fail to respond to |
| 160 // the callback. | 162 // the callback. |
| 161 binding_.Close(); | 163 binding_.Close(); |
| 162 if (!callback_.is_null()) { | 164 if (!callback_.is_null()) { |
| 163 // When this VSync provider is going away we have to respond to pending | 165 // When this VSync provider is going away we have to respond to pending |
| 164 // callbacks, so instead of providing a VSync, tell the requester to try | 166 // callbacks, so instead of providing a VSync, tell the requester to try |
| 165 // again. A VSyncProvider is guaranteed to exist, so the request in response | 167 // again. A VSyncProvider is guaranteed to exist, so the request in response |
| 166 // to this message will go through some other VSyncProvider. | 168 // to this message will go through some other VSyncProvider. |
| 167 base::ResetAndReturn(&callback_) | 169 base::ResetAndReturn(&callback_) |
| 168 .Run(nullptr, base::TimeDelta(), -1, | 170 .Run(nullptr, base::TimeDelta(), -1, |
| 169 device::mojom::VRVSyncProvider::Status::CLOSING); | 171 device::mojom::VRVSyncProvider::Status::CLOSING); |
| 170 } | 172 } |
| 171 } | 173 } |
| 172 | 174 |
| 173 void VrShellGl::Initialize() { | 175 void VrShellGl::Initialize() { |
| 174 scene_ = base::MakeUnique<UiScene>(); | |
| 175 | |
| 176 if (surfaceless_rendering_) { | 176 if (surfaceless_rendering_) { |
| 177 // If we're rendering surfaceless, we'll never get a java surface to render | 177 // If we're rendering surfaceless, we'll never get a java surface to render |
| 178 // into, so we can initialize GL right away. | 178 // into, so we can initialize GL right away. |
| 179 InitializeGl(nullptr); | 179 InitializeGl(nullptr); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 void VrShellGl::InitializeGl(gfx::AcceleratedWidget window) { | 183 void VrShellGl::InitializeGl(gfx::AcceleratedWidget window) { |
| 184 CHECK(!ready_to_draw_); | 184 CHECK(!ready_to_draw_); |
| 185 if (gl::GetGLImplementation() == gl::kGLImplementationNone && | 185 if (gl::GetGLImplementation() == gl::kGLImplementationNone && |
| (...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); | 1240 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); |
| 1241 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); | 1241 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); |
| 1242 OnVSync(); | 1242 OnVSync(); |
| 1243 } | 1243 } |
| 1244 | 1244 |
| 1245 void VrShellGl::ForceExitVr() { | 1245 void VrShellGl::ForceExitVr() { |
| 1246 main_thread_task_runner_->PostTask( | 1246 main_thread_task_runner_->PostTask( |
| 1247 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_)); | 1247 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_)); |
| 1248 } | 1248 } |
| 1249 | 1249 |
| 1250 void VrShellGl::UpdateScene(std::unique_ptr<base::ListValue> commands) { | |
| 1251 scene_->HandleCommands(std::move(commands), base::TimeTicks::Now()); | |
| 1252 } | |
| 1253 | |
| 1254 void VrShellGl::SendVSync(base::TimeDelta time, | 1250 void VrShellGl::SendVSync(base::TimeDelta time, |
| 1255 const GetVSyncCallback& callback) { | 1251 const GetVSyncCallback& callback) { |
| 1256 uint8_t frame_index = frame_index_++; | 1252 uint8_t frame_index = frame_index_++; |
| 1257 | 1253 |
| 1258 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); | 1254 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); |
| 1259 | 1255 |
| 1260 gvr::Mat4f head_mat; | 1256 gvr::Mat4f head_mat; |
| 1261 device::mojom::VRPosePtr pose = | 1257 device::mojom::VRPosePtr pose = |
| 1262 device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), &head_mat); | 1258 device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), &head_mat); |
| 1263 | 1259 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1275 // InitializeGl. Revisit if the initialization order changes. | 1271 // InitializeGl. Revisit if the initialization order changes. |
| 1276 device::mojom::VRDisplayInfoPtr info = | 1272 device::mojom::VRDisplayInfoPtr info = |
| 1277 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), | 1273 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), |
| 1278 webvr_surface_size_, device_id); | 1274 webvr_surface_size_, device_id); |
| 1279 main_thread_task_runner_->PostTask( | 1275 main_thread_task_runner_->PostTask( |
| 1280 FROM_HERE, | 1276 FROM_HERE, |
| 1281 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); | 1277 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); |
| 1282 } | 1278 } |
| 1283 | 1279 |
| 1284 } // namespace vr_shell | 1280 } // namespace vr_shell |
| OLD | NEW |