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

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

Issue 2809143004: VR: Add a native UI element scene manager (Closed)
Patch Set: Rebase. Created 3 years, 8 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') | no next file » | 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 <chrono> 7 #include <chrono>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 *out = *reinterpret_cast<vr::Mat4f*>(const_cast<gvr::Mat4f*>(&in)); 149 *out = *reinterpret_cast<vr::Mat4f*>(const_cast<gvr::Mat4f*>(&in));
150 } 150 }
151 151
152 } // namespace 152 } // namespace
153 153
154 VrShellGl::VrShellGl( 154 VrShellGl::VrShellGl(
155 const base::WeakPtr<VrShell>& weak_vr_shell, 155 const base::WeakPtr<VrShell>& weak_vr_shell,
156 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, 156 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
157 gvr_context* gvr_api, 157 gvr_context* gvr_api,
158 bool initially_web_vr, 158 bool initially_web_vr,
159 bool reprojected_rendering) 159 bool reprojected_rendering,
160 : web_vr_mode_(initially_web_vr), 160 UiScene* scene)
161 : scene_(scene),
162 web_vr_mode_(initially_web_vr),
161 surfaceless_rendering_(reprojected_rendering), 163 surfaceless_rendering_(reprojected_rendering),
162 task_runner_(base::ThreadTaskRunnerHandle::Get()), 164 task_runner_(base::ThreadTaskRunnerHandle::Get()),
163 binding_(this), 165 binding_(this),
164 weak_vr_shell_(weak_vr_shell), 166 weak_vr_shell_(weak_vr_shell),
165 main_thread_task_runner_(std::move(main_thread_task_runner)), 167 main_thread_task_runner_(std::move(main_thread_task_runner)),
166 weak_ptr_factory_(this) { 168 weak_ptr_factory_(this) {
167 GvrInit(gvr_api); 169 GvrInit(gvr_api);
168 } 170 }
169 171
170 VrShellGl::~VrShellGl() { 172 VrShellGl::~VrShellGl() {
171 vsync_task_.Cancel(); 173 vsync_task_.Cancel();
172 // TODO(mthiesse): Can we omit the Close() here? Concern is that if 174 // TODO(mthiesse): Can we omit the Close() here? Concern is that if
173 // both ends of the connection ever live in the same process for 175 // both ends of the connection ever live in the same process for
174 // some reason, we could receive another VSync request in response 176 // some reason, we could receive another VSync request in response
175 // to the closing message in the destructor but fail to respond to 177 // to the closing message in the destructor but fail to respond to
176 // the callback. 178 // the callback.
177 binding_.Close(); 179 binding_.Close();
178 if (!callback_.is_null()) { 180 if (!callback_.is_null()) {
179 // When this VSync provider is going away we have to respond to pending 181 // When this VSync provider is going away we have to respond to pending
180 // callbacks, so instead of providing a VSync, tell the requester to try 182 // callbacks, so instead of providing a VSync, tell the requester to try
181 // again. A VSyncProvider is guaranteed to exist, so the request in response 183 // again. A VSyncProvider is guaranteed to exist, so the request in response
182 // to this message will go through some other VSyncProvider. 184 // to this message will go through some other VSyncProvider.
183 base::ResetAndReturn(&callback_) 185 base::ResetAndReturn(&callback_)
184 .Run(nullptr, base::TimeDelta(), -1, 186 .Run(nullptr, base::TimeDelta(), -1,
185 device::mojom::VRVSyncProvider::Status::CLOSING); 187 device::mojom::VRVSyncProvider::Status::CLOSING);
186 } 188 }
187 } 189 }
188 190
189 void VrShellGl::Initialize() { 191 void VrShellGl::Initialize() {
190 scene_ = base::MakeUnique<UiScene>();
191
192 if (surfaceless_rendering_) { 192 if (surfaceless_rendering_) {
193 // If we're rendering surfaceless, we'll never get a java surface to render 193 // If we're rendering surfaceless, we'll never get a java surface to render
194 // into, so we can initialize GL right away. 194 // into, so we can initialize GL right away.
195 InitializeGl(nullptr); 195 InitializeGl(nullptr);
196 } 196 }
197 } 197 }
198 198
199 void VrShellGl::InitializeGl(gfx::AcceleratedWidget window) { 199 void VrShellGl::InitializeGl(gfx::AcceleratedWidget window) {
200 CHECK(!ready_to_draw_); 200 CHECK(!ready_to_draw_);
201 if (gl::GetGLImplementation() == gl::kGLImplementationNone && 201 if (gl::GetGLImplementation() == gl::kGLImplementationNone &&
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); 1297 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds);
1298 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); 1298 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this)));
1299 OnVSync(); 1299 OnVSync();
1300 } 1300 }
1301 1301
1302 void VrShellGl::ForceExitVr() { 1302 void VrShellGl::ForceExitVr() {
1303 main_thread_task_runner_->PostTask( 1303 main_thread_task_runner_->PostTask(
1304 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_)); 1304 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_));
1305 } 1305 }
1306 1306
1307 void VrShellGl::UpdateScene(std::unique_ptr<base::ListValue> commands) {
1308 scene_->HandleCommands(std::move(commands), base::TimeTicks::Now());
1309 }
1310
1311 void VrShellGl::SendVSync(base::TimeDelta time, 1307 void VrShellGl::SendVSync(base::TimeDelta time,
1312 const GetVSyncCallback& callback) { 1308 const GetVSyncCallback& callback) {
1313 uint8_t frame_index = frame_index_++; 1309 uint8_t frame_index = frame_index_++;
1314 1310
1315 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); 1311 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index);
1316 1312
1317 vr::Mat4f head_mat; 1313 vr::Mat4f head_mat;
1318 device::mojom::VRPosePtr pose = 1314 device::mojom::VRPosePtr pose =
1319 device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), &head_mat); 1315 device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), &head_mat);
1320 1316
(...skipping 11 matching lines...) Expand all
1332 // InitializeGl. Revisit if the initialization order changes. 1328 // InitializeGl. Revisit if the initialization order changes.
1333 device::mojom::VRDisplayInfoPtr info = 1329 device::mojom::VRDisplayInfoPtr info =
1334 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), 1330 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(),
1335 webvr_surface_size_, device_id); 1331 webvr_surface_size_, device_id);
1336 main_thread_task_runner_->PostTask( 1332 main_thread_task_runner_->PostTask(
1337 FROM_HERE, 1333 FROM_HERE,
1338 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); 1334 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info)));
1339 } 1335 }
1340 1336
1341 } // namespace vr_shell 1337 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698