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

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

Issue 2729523002: Re-land^2 WebVR compositor bypass via BrowserMain context + mailbox (Closed)
Patch Set: Comments only, add explanations from review thread. Created 3 years, 9 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
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 <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"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h"
15 #include "chrome/browser/android/vr_shell/ui_elements.h" 16 #include "chrome/browser/android/vr_shell/ui_elements.h"
16 #include "chrome/browser/android/vr_shell/ui_scene.h" 17 #include "chrome/browser/android/vr_shell/ui_scene.h"
17 #include "chrome/browser/android/vr_shell/vr_controller.h" 18 #include "chrome/browser/android/vr_shell/vr_controller.h"
18 #include "chrome/browser/android/vr_shell/vr_gl_util.h" 19 #include "chrome/browser/android/vr_shell/vr_gl_util.h"
19 #include "chrome/browser/android/vr_shell/vr_math.h" 20 #include "chrome/browser/android/vr_shell/vr_math.h"
20 #include "chrome/browser/android/vr_shell/vr_shell.h" 21 #include "chrome/browser/android/vr_shell/vr_shell.h"
21 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 22 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
22 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" 23 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
23 #include "device/vr/android/gvr/gvr_device.h" 24 #include "device/vr/android/gvr/gvr_device.h"
24 #include "third_party/WebKit/public/platform/WebInputEvent.h" 25 #include "third_party/WebKit/public/platform/WebInputEvent.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 74
74 // The GVR viewport list has two entries (left eye and right eye) for each 75 // The GVR viewport list has two entries (left eye and right eye) for each
75 // GVR buffer. 76 // GVR buffer.
76 static constexpr int kViewportListPrimaryOffset = 0; 77 static constexpr int kViewportListPrimaryOffset = 0;
77 static constexpr int kViewportListHeadlockedOffset = 2; 78 static constexpr int kViewportListHeadlockedOffset = 2;
78 79
79 // Buffer size large enough to handle the current backlog of poses which is 80 // Buffer size large enough to handle the current backlog of poses which is
80 // 2-3 frames. 81 // 2-3 frames.
81 static constexpr unsigned kPoseRingBufferSize = 8; 82 static constexpr unsigned kPoseRingBufferSize = 8;
82 83
83 // Magic numbers used to mark valid pose index values encoded in frame 84 // Default downscale factor for computing the recommended WebVR
84 // data. Must match the magic numbers used in blink's VRDisplay.cpp. 85 // renderWidth/Height from the 1:1 pixel mapped size. Using a rather
85 static constexpr std::array<uint8_t, 2> kWebVrPosePixelMagicNumbers{{42, 142}}; 86 // aggressive downscale due to the high overhead of copying pixels
87 // twice before handing off to GVR. For comparison, the polyfill
88 // uses approximately 0.55 on a Pixel XL.
89 static constexpr float kWebVrRecommendedResolutionScale = 0.5;
klausw 2017/03/10 02:49:32 Moved to vr_shell.gl
86 90
87 float Distance(const gvr::Vec3f& vec1, const gvr::Vec3f& vec2) { 91 float Distance(const gvr::Vec3f& vec1, const gvr::Vec3f& vec2) {
88 float xdiff = (vec1.x - vec2.x); 92 float xdiff = (vec1.x - vec2.x);
89 float ydiff = (vec1.y - vec2.y); 93 float ydiff = (vec1.y - vec2.y);
90 float zdiff = (vec1.z - vec2.z); 94 float zdiff = (vec1.z - vec2.z);
91 float scale = xdiff * xdiff + ydiff * ydiff + zdiff * zdiff; 95 float scale = xdiff * xdiff + ydiff * ydiff + zdiff * zdiff;
92 return std::sqrt(scale); 96 return std::sqrt(scale);
93 } 97 }
94 98
95 // Generate a quaternion representing the rotation from the negative Z axis 99 // Generate a quaternion representing the rotation from the negative Z axis
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 binding_(this), 169 binding_(this),
166 weak_vr_shell_(weak_vr_shell), 170 weak_vr_shell_(weak_vr_shell),
167 delegate_provider_(delegate_provider), 171 delegate_provider_(delegate_provider),
168 main_thread_task_runner_(std::move(main_thread_task_runner)), 172 main_thread_task_runner_(std::move(main_thread_task_runner)),
169 weak_ptr_factory_(this) { 173 weak_ptr_factory_(this) {
170 GvrInit(gvr_api); 174 GvrInit(gvr_api);
171 } 175 }
172 176
173 VrShellGl::~VrShellGl() { 177 VrShellGl::~VrShellGl() {
174 vsync_task_.Cancel(); 178 vsync_task_.Cancel();
179 // TODO(mthiesse): Can we omit the Close() here? Concern is that if
180 // both ends of the connection ever live in the same process for
181 // some reason, we could receive another VSync request in response
182 // to the closing message in the destructor but fail to respond to
183 // the callback.
184 binding_.Close();
175 if (!callback_.is_null()) { 185 if (!callback_.is_null()) {
176 // When this VSync provider is going away we have to respond to pending 186 // When this VSync provider is going away we have to respond to pending
177 // callbacks, so instead of providing a VSync, tell the requester to try 187 // callbacks, so instead of providing a VSync, tell the requester to try
178 // again. A VSyncProvider is guaranteed to exist, so the request in response 188 // again. A VSyncProvider is guaranteed to exist, so the request in response
179 // to this message will go through some other VSyncProvider. 189 // to this message will go through some other VSyncProvider.
180 base::ResetAndReturn(&callback_) 190 base::ResetAndReturn(&callback_)
181 .Run(nullptr, base::TimeDelta(), -1, 191 .Run(nullptr, base::TimeDelta(), -1,
182 device::mojom::VRVSyncProvider::Status::RETRY); 192 device::mojom::VRVSyncProvider::Status::CLOSING);
183 }
184 if (binding_.is_bound()) {
185 main_thread_task_runner_->PostTask(
186 FROM_HERE,
187 base::Bind(&VrShellDelegate::OnVRVsyncProviderRequest,
188 delegate_provider_, base::Passed(binding_.Unbind())));
189 } 193 }
190 } 194 }
191 195
192 void VrShellGl::Initialize() { 196 void VrShellGl::Initialize() {
193 scene_.reset(new UiScene); 197 scene_.reset(new UiScene);
194 198
195 if (surfaceless_rendering_) { 199 if (surfaceless_rendering_) {
196 // If we're rendering surfaceless, we'll never get a java surface to render 200 // If we're rendering surfaceless, we'll never get a java surface to render
197 // into, so we can initialize GL right away. 201 // into, so we can initialize GL right away.
198 InitializeGl(nullptr); 202 InitializeGl(nullptr);
(...skipping 26 matching lines...) Expand all
225 LOG(ERROR) << "gl::init::CreateGLContext failed"; 229 LOG(ERROR) << "gl::init::CreateGLContext failed";
226 ForceExitVr(); 230 ForceExitVr();
227 return; 231 return;
228 } 232 }
229 if (!context_->MakeCurrent(surface_.get())) { 233 if (!context_->MakeCurrent(surface_.get())) {
230 LOG(ERROR) << "gl::GLContext::MakeCurrent() failed"; 234 LOG(ERROR) << "gl::GLContext::MakeCurrent() failed";
231 ForceExitVr(); 235 ForceExitVr();
232 return; 236 return;
233 } 237 }
234 238
235 unsigned int textures[2]; 239 unsigned int textures[3];
236 glGenTextures(2, textures); 240 glGenTextures(3, textures);
237 ui_texture_id_ = textures[0]; 241 ui_texture_id_ = textures[0];
238 content_texture_id_ = textures[1]; 242 content_texture_id_ = textures[1];
243 webvr_texture_id_ = textures[2];
239 ui_surface_texture_ = gl::SurfaceTexture::Create(ui_texture_id_); 244 ui_surface_texture_ = gl::SurfaceTexture::Create(ui_texture_id_);
240 content_surface_texture_ = gl::SurfaceTexture::Create(content_texture_id_); 245 content_surface_texture_ = gl::SurfaceTexture::Create(content_texture_id_);
246 webvr_surface_texture_ = gl::SurfaceTexture::Create(webvr_texture_id_);
241 CreateUiSurface(); 247 CreateUiSurface();
242 CreateContentSurface(); 248 CreateContentSurface();
243 ui_surface_texture_->SetFrameAvailableCallback(base::Bind( 249 ui_surface_texture_->SetFrameAvailableCallback(base::Bind(
244 &VrShellGl::OnUIFrameAvailable, weak_ptr_factory_.GetWeakPtr())); 250 &VrShellGl::OnUIFrameAvailable, weak_ptr_factory_.GetWeakPtr()));
245 content_surface_texture_->SetFrameAvailableCallback(base::Bind( 251 content_surface_texture_->SetFrameAvailableCallback(base::Bind(
246 &VrShellGl::OnContentFrameAvailable, weak_ptr_factory_.GetWeakPtr())); 252 &VrShellGl::OnContentFrameAvailable, weak_ptr_factory_.GetWeakPtr()));
253 webvr_surface_texture_->SetFrameAvailableCallback(base::Bind(
254 &VrShellGl::OnWebVRFrameAvailable, weak_ptr_factory_.GetWeakPtr()));
255 ui_surface_texture_->SetDefaultBufferSize(ui_tex_physical_size_.width,
256 ui_tex_physical_size_.height);
247 content_surface_texture_->SetDefaultBufferSize( 257 content_surface_texture_->SetDefaultBufferSize(
248 content_tex_physical_size_.width, content_tex_physical_size_.height); 258 content_tex_physical_size_.width, content_tex_physical_size_.height);
249 ui_surface_texture_->SetDefaultBufferSize(ui_tex_physical_size_.width,
250 ui_tex_physical_size_.height);
251 InitializeRenderer(); 259 InitializeRenderer();
252 260
261 // Pick a reasonable default size for the WebVR transfer surface
262 // based on a downscaled 1:1 render resolution. This size will also
263 // be reported to the client via CreateVRDisplayInfo as the
264 // client-recommended renderWidth/renderHeight and for the GVR
265 // framebuffer. If the client chooses a different size or resizes it
266 // while presenting, we'll resize the transfer surface and GVR
267 // framebuffer to match.
268 gvr::Sizei render_target_size =
269 gvr_api_->GetMaximumEffectiveRenderTargetSize();
270 gvr::Sizei webvr_size = {static_cast<int>(render_target_size.width *
271 kWebVrRecommendedResolutionScale),
272 static_cast<int>(render_target_size.height *
273 kWebVrRecommendedResolutionScale)};
274
275 // TODO(klausw,crbug.com/699350): should we round the recommended
276 // size to a multiple of 2^N pixels to be friendlier to the GPU? The
277 // exact size doesn't matter.
278
279 CreateOrResizeWebVRSurface(webvr_size);
280
253 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); 281 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this)));
254 OnVSync(); 282 OnVSync();
255 283
256 ready_to_draw_ = true; 284 ready_to_draw_ = true;
257 } 285 }
258 286
259 void VrShellGl::CreateContentSurface() { 287 void VrShellGl::CreateContentSurface() {
260 content_surface_ = 288 content_surface_ =
261 base::MakeUnique<gl::ScopedJavaSurface>(content_surface_texture_.get()); 289 base::MakeUnique<gl::ScopedJavaSurface>(content_surface_texture_.get());
262 main_thread_task_runner_->PostTask( 290 main_thread_task_runner_->PostTask(
263 FROM_HERE, base::Bind(&VrShell::ContentSurfaceChanged, weak_vr_shell_, 291 FROM_HERE, base::Bind(&VrShell::ContentSurfaceChanged, weak_vr_shell_,
264 content_surface_->j_surface().obj())); 292 content_surface_->j_surface().obj()));
265 } 293 }
266 294
267 void VrShellGl::CreateUiSurface() { 295 void VrShellGl::CreateUiSurface() {
268 ui_surface_ = 296 ui_surface_ =
269 base::MakeUnique<gl::ScopedJavaSurface>(ui_surface_texture_.get()); 297 base::MakeUnique<gl::ScopedJavaSurface>(ui_surface_texture_.get());
270 main_thread_task_runner_->PostTask( 298 main_thread_task_runner_->PostTask(
271 FROM_HERE, base::Bind(&VrShell::UiSurfaceChanged, weak_vr_shell_, 299 FROM_HERE, base::Bind(&VrShell::UiSurfaceChanged, weak_vr_shell_,
272 ui_surface_->j_surface().obj())); 300 ui_surface_->j_surface().obj()));
273 } 301 }
274 302
303 void VrShellGl::CreateOrResizeWebVRSurface(const gvr::Sizei& size) {
304 if (!webvr_surface_texture_) {
305 DLOG(ERROR) << "No WebVR surface texture available";
306 return;
307 }
308
309 // ContentPhysicalBoundsChanged is getting called twice with
310 // identical sizes? Avoid thrashing the existing context.
311 if (size == webvr_surface_size_) {
312 return;
313 }
314
315 if (!size.width || !size.height) {
316 // Invalid size, defer until a new size arrives on a future bounds update.
317 return;
318 }
319
320 webvr_surface_texture_->SetDefaultBufferSize(size.width, size.height);
321 webvr_surface_size_ = size;
322
323 if (mailbox_bridge_) {
324 mailbox_bridge_->ResizeSurface(size.width, size.height);
325 } else {
326 mailbox_bridge_ = base::MakeUnique<MailboxToSurfaceBridge>();
327 mailbox_bridge_->CreateSurface(webvr_surface_texture_.get());
328 }
329 }
330
331 void VrShellGl::SubmitWebVRFrame(int16_t frame_index,
332 const gpu::MailboxHolder& mailbox) {
333 TRACE_EVENT0("gpu", "VrShellGl::SubmitWebVRFrame");
334
335 // Swapping twice on a Surface without calling updateTexImage in
336 // between can lose frames, so don't draw+swap if we already have
337 // a pending frame we haven't consumed yet.
338 bool swapped = false;
339 if (pending_frames_.empty()) {
340 swapped = mailbox_bridge_->CopyMailboxToSurfaceAndSwap(mailbox);
341 if (swapped) {
342 // Tell OnWebVRFrameAvailable to expect a new frame to arrive on
343 // the SurfaceTexture, and save the associated frame index.
344 pending_frames_.emplace(frame_index);
345 }
346 }
347 // Always notify the client that we're done with the mailbox even
348 // if we haven't drawn it, so that it's eligible for destruction.
349 submit_client_->OnSubmitFrameTransferred();
350 if (!swapped) {
351 // We dropped without drawing, report this as completed rendering
352 // now to unblock the client. We're not going to receive it in
353 // OnWebVRFrameAvailable where we'd normally report that.
354 submit_client_->OnSubmitFrameRendered();
355 }
356
357 TRACE_EVENT0("gpu", "VrShellGl::glFinish");
358 // This is a load-bearing glFinish, please don't remove it without
359 // before/after timing comparisons. Goal is to clear the GPU queue
360 // of the native GL context to avoid stalls later in GVR frame
361 // acquire/submit.
362 glFinish();
363 }
364
365 void VrShellGl::SetSubmitClient(
366 device::mojom::VRSubmitFrameClientPtrInfo submit_client_info) {
367 submit_client_.Bind(std::move(submit_client_info));
368 }
369
275 void VrShellGl::OnUIFrameAvailable() { 370 void VrShellGl::OnUIFrameAvailable() {
276 ui_surface_texture_->UpdateTexImage(); 371 ui_surface_texture_->UpdateTexImage();
277 } 372 }
278 373
279 void VrShellGl::OnContentFrameAvailable() { 374 void VrShellGl::OnContentFrameAvailable() {
280 content_surface_texture_->UpdateTexImage(); 375 content_surface_texture_->UpdateTexImage();
281 received_frame_ = true; 376 received_frame_ = true;
282 } 377 }
283 378
284 bool VrShellGl::GetPixelEncodedFrameIndex(uint16_t* frame_index) { 379 void VrShellGl::OnWebVRFrameAvailable() {
285 TRACE_EVENT0("gpu", "VrShellGl::GetPixelEncodedFrameIndex"); 380 // A "while" loop here is a bad idea. It's legal to call
286 if (!received_frame_) { 381 // UpdateTexImage repeatedly even if no frames are available, but
287 if (last_frame_index_ == (uint16_t)-1) 382 // that does *not* wait for a new frame, it just reuses the most
288 return false; 383 // recent one. That would mess up the count.
289 *frame_index = last_frame_index_; 384 if (pending_frames_.empty()) {
290 return true; 385 // We're expecting a frame, but it's not here yet. Retry in OnVsync.
386 ++premature_received_frames_;
387 return;
291 } 388 }
292 received_frame_ = false;
293 389
294 // Read the pose index encoded in a bottom left pixel as color values. 390 webvr_surface_texture_->UpdateTexImage();
295 // See also third_party/WebKit/Source/modules/vr/VRDisplay.cpp which 391 int frame_index = pending_frames_.front();
296 // encodes the pose index, and device/vr/android/gvr/gvr_device.cc 392 TRACE_EVENT1("gpu", "VrShellGl::OnWebVRFrameAvailable", "frame", frame_index);
297 // which tracks poses. Returns the low byte (0..255) if valid, or -1 393 pending_frames_.pop();
298 // if not valid due to bad magic number.
299 uint8_t pixels[4];
300 // Assume we're reading from the framebuffer we just wrote to.
301 // That's true currently, we may need to use glReadBuffer(GL_BACK)
302 // or equivalent if the rendering setup changes in the future.
303 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
304 394
305 // Check for the magic number written by VRDevice.cpp on submit. 395 // It is legal for the WebVR client to submit a new frame now, since
306 // This helps avoid glitches from garbage data in the render 396 // we've consumed the image. TODO(klausw): would timing be better if
307 // buffer that can appear during initialization or resizing. These 397 // we move the "rendered" notification after draw, or suppress
308 // often appear as flashes of all-black or all-white pixels. 398 // the next vsync until that's done?
309 if (pixels[1] == kWebVrPosePixelMagicNumbers[0] && 399
310 pixels[2] == kWebVrPosePixelMagicNumbers[1]) { 400 submit_client_->OnSubmitFrameRendered();
311 // Pose is good. 401
312 *frame_index = pixels[0]; 402 DrawFrame(frame_index);
313 last_frame_index_ = pixels[0];
314 return true;
315 }
316 VLOG(1) << "WebVR: reject decoded pose index " << static_cast<int>(pixels[0])
317 << ", bad magic number " << static_cast<int>(pixels[1]) << ", "
318 << static_cast<int>(pixels[2]);
319 return false;
320 } 403 }
321 404
322 void VrShellGl::GvrInit(gvr_context* gvr_api) { 405 void VrShellGl::GvrInit(gvr_context* gvr_api) {
323 gvr_api_ = gvr::GvrApi::WrapNonOwned(gvr_api); 406 gvr_api_ = gvr::GvrApi::WrapNonOwned(gvr_api);
324 controller_.reset(new VrController(gvr_api)); 407 controller_.reset(new VrController(gvr_api));
325 408
326 ViewerType viewerType; 409 ViewerType viewerType;
327 switch (gvr_api_->GetViewerType()) { 410 switch (gvr_api_->GetViewerType()) {
328 case gvr::ViewerType::GVR_VIEWER_TYPE_DAYDREAM: 411 case gvr::ViewerType::GVR_VIEWER_TYPE_DAYDREAM:
329 viewerType = ViewerType::DAYDREAM; 412 viewerType = ViewerType::DAYDREAM;
330 break; 413 break;
331 case gvr::ViewerType::GVR_VIEWER_TYPE_CARDBOARD: 414 case gvr::ViewerType::GVR_VIEWER_TYPE_CARDBOARD:
332 viewerType = ViewerType::CARDBOARD; 415 viewerType = ViewerType::CARDBOARD;
333 break; 416 break;
334 default: 417 default:
335 NOTREACHED(); 418 NOTREACHED();
336 viewerType = ViewerType::UNKNOWN_TYPE; 419 viewerType = ViewerType::UNKNOWN_TYPE;
337 break; 420 break;
338 } 421 }
339 UMA_HISTOGRAM_ENUMERATION("VRViewerType", static_cast<int>(viewerType), 422 UMA_HISTOGRAM_ENUMERATION("VRViewerType", static_cast<int>(viewerType),
340 static_cast<int>(ViewerType::VIEWER_TYPE_MAX)); 423 static_cast<int>(ViewerType::VIEWER_TYPE_MAX));
341 } 424 }
342 425
343 void VrShellGl::InitializeRenderer() { 426 void VrShellGl::InitializeRenderer() {
344 // While WebVR is going through the compositor path, it shares
345 // the same texture ID. This will change once it gets its own
346 // surface, but store it separately to avoid future confusion.
347 // TODO(klausw,crbug.com/655722): remove this.
348 webvr_texture_id_ = content_texture_id_;
349
350 gvr_api_->InitializeGl(); 427 gvr_api_->InitializeGl();
351 webvr_head_pose_.assign(kPoseRingBufferSize, 428 webvr_head_pose_.assign(kPoseRingBufferSize,
352 gvr_api_->GetHeadSpaceFromStartSpaceRotation( 429 gvr_api_->GetHeadSpaceFromStartSpaceRotation(
353 gvr::GvrApi::GetTimePointNow())); 430 gvr::GvrApi::GetTimePointNow()));
354 431
355 std::vector<gvr::BufferSpec> specs; 432 std::vector<gvr::BufferSpec> specs;
356 // For kFramePrimaryBuffer (primary VrShell and WebVR content) 433 // For kFramePrimaryBuffer (primary VrShell and WebVR content)
357 specs.push_back(gvr_api_->CreateBufferSpec()); 434 specs.push_back(gvr_api_->CreateBufferSpec());
358 render_size_primary_ = specs[kFramePrimaryBuffer].GetSize(); 435 render_size_primary_ = specs[kFramePrimaryBuffer].GetSize();
436 render_size_vrshell_ = render_size_primary_;
359 437
360 // For kFrameHeadlockedBuffer (for WebVR insecure content warning). 438 // For kFrameHeadlockedBuffer (for WebVR insecure content warning).
361 // Set this up at fixed resolution, the (smaller) FOV gets set below. 439 // Set this up at fixed resolution, the (smaller) FOV gets set below.
362 specs.push_back(gvr_api_->CreateBufferSpec()); 440 specs.push_back(gvr_api_->CreateBufferSpec());
363 specs.back().SetSize(kHeadlockedBufferDimensions); 441 specs.back().SetSize(kHeadlockedBufferDimensions);
364 render_size_headlocked_ = specs[kFrameHeadlockedBuffer].GetSize(); 442 render_size_headlocked_ = specs[kFrameHeadlockedBuffer].GetSize();
365 443
366 swap_chain_.reset(new gvr::SwapChain(gvr_api_->CreateSwapChain(specs))); 444 swap_chain_.reset(new gvr::SwapChain(gvr_api_->CreateSwapChain(specs)));
367 445
368 vr_shell_renderer_.reset(new VrShellRenderer()); 446 vr_shell_renderer_.reset(new VrShellRenderer());
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 std::unique_ptr<blink::WebInputEvent> event) { 703 std::unique_ptr<blink::WebInputEvent> event) {
626 DCHECK(input_target != InputTarget::NONE); 704 DCHECK(input_target != InputTarget::NONE);
627 auto&& target = input_target == InputTarget::CONTENT 705 auto&& target = input_target == InputTarget::CONTENT
628 ? &VrShell::ProcessContentGesture 706 ? &VrShell::ProcessContentGesture
629 : &VrShell::ProcessUIGesture; 707 : &VrShell::ProcessUIGesture;
630 main_thread_task_runner_->PostTask( 708 main_thread_task_runner_->PostTask(
631 FROM_HERE, 709 FROM_HERE,
632 base::Bind(target, weak_vr_shell_, base::Passed(std::move(event)))); 710 base::Bind(target, weak_vr_shell_, base::Passed(std::move(event))));
633 } 711 }
634 712
635 void VrShellGl::DrawFrame() { 713 void VrShellGl::DrawFrame(int16_t frame_index) {
636 TRACE_EVENT0("gpu", "VrShellGl::DrawFrame"); 714 TRACE_EVENT1("gpu", "VrShellGl::DrawFrame", "frame", frame_index);
637 715
638 // Reset the viewport list to just the pair of viewports for the 716 // Reset the viewport list to just the pair of viewports for the
639 // primary buffer each frame. Head-locked viewports get added by 717 // primary buffer each frame. Head-locked viewports get added by
640 // DrawVrShell if needed. 718 // DrawVrShell if needed.
641 buffer_viewport_list_->SetToRecommendedBufferViewports(); 719 buffer_viewport_list_->SetToRecommendedBufferViewports();
642 720
721 // If needed, resize the primary buffer for use with WebVR.
722 if (web_vr_mode_) {
723 if (render_size_primary_ != webvr_surface_size_) {
724 if (!webvr_surface_size_.width) {
725 return;
726 }
727 render_size_primary_ = webvr_surface_size_;
728 swap_chain_->ResizeBuffer(kFramePrimaryBuffer, render_size_primary_);
729 }
730 } else {
731 if (render_size_primary_ != render_size_vrshell_) {
732 render_size_primary_ = render_size_vrshell_;
733 swap_chain_->ResizeBuffer(kFramePrimaryBuffer, render_size_primary_);
734 }
735 }
736
737 TRACE_EVENT_BEGIN0("gpu", "VrShellGl::AcquireFrame");
643 gvr::Frame frame = swap_chain_->AcquireFrame(); 738 gvr::Frame frame = swap_chain_->AcquireFrame();
739 TRACE_EVENT_END0("gpu", "VrShellGl::AcquireFrame");
644 if (!frame.is_valid()) { 740 if (!frame.is_valid()) {
645 return; 741 return;
646 } 742 }
647 frame.BindBuffer(kFramePrimaryBuffer); 743 frame.BindBuffer(kFramePrimaryBuffer);
648 if (web_vr_mode_) { 744 if (web_vr_mode_) {
649 DrawWebVr(); 745 DrawWebVr();
650 } 746 }
651 747
652 uint16_t frame_index;
653 gvr::Mat4f head_pose; 748 gvr::Mat4f head_pose;
654 749
655 // When using async reprojection, we need to know which pose was used in 750 // When using async reprojection, we need to know which pose was used in
656 // the WebVR app for drawing this frame. Due to unknown amounts of 751 // the WebVR app for drawing this frame. Only needed if reprojection is
657 // buffering in the compositor and SurfaceTexture, we read the pose number 752 // in use.
658 // from a corner pixel. There's no point in doing this for legacy 753 if (web_vr_mode_ && gvr_api_->GetAsyncReprojectionEnabled()) {
659 // distortion rendering since that doesn't need a pose, and reading back
660 // pixels is an expensive operation. TODO(klausw,crbug.com/655722): stop
661 // doing this once we have working no-compositor rendering for WebVR.
662 if (web_vr_mode_ && gvr_api_->GetAsyncReprojectionEnabled() &&
663 GetPixelEncodedFrameIndex(&frame_index)) {
664 static_assert(!((kPoseRingBufferSize - 1) & kPoseRingBufferSize), 754 static_assert(!((kPoseRingBufferSize - 1) & kPoseRingBufferSize),
665 "kPoseRingBufferSize must be a power of 2"); 755 "kPoseRingBufferSize must be a power of 2");
666 head_pose = webvr_head_pose_[frame_index % kPoseRingBufferSize]; 756 head_pose = webvr_head_pose_[frame_index % kPoseRingBufferSize];
667 // Process all pending_bounds_ changes targeted for before this frame, being 757 // Process all pending_bounds_ changes targeted for before this frame, being
668 // careful of wrapping frame indices. 758 // careful of wrapping frame indices.
669 static constexpr unsigned max = 759 static constexpr unsigned max =
670 std::numeric_limits<decltype(frame_index_)>::max(); 760 std::numeric_limits<decltype(frame_index_)>::max();
671 static_assert(max > kPoseRingBufferSize * 2, 761 static_assert(max > kPoseRingBufferSize * 2,
672 "To detect wrapping, kPoseRingBufferSize must be smaller " 762 "To detect wrapping, kPoseRingBufferSize must be smaller "
673 "than half of frame_index_ range."); 763 "than half of frame_index_ range.");
674 while (!pending_bounds_.empty()) { 764 while (!pending_bounds_.empty()) {
675 uint16_t index = pending_bounds_.front().first; 765 uint16_t index = pending_bounds_.front().first;
676 // If index is less than the frame_index it's possible we've wrapped, so 766 // If index is less than the frame_index it's possible we've wrapped, so
677 // we extend the range and 'un-wrap' to account for this. 767 // we extend the range and 'un-wrap' to account for this.
678 if (index < frame_index) 768 if (index < frame_index)
679 index += max; 769 index += max;
680 // If the pending bounds change is for an upcoming frame within our buffer 770 // If the pending bounds change is for an upcoming frame within our buffer
681 // size, wait to apply it. Otherwise, apply it immediately. This 771 // size, wait to apply it. Otherwise, apply it immediately. This
682 // guarantees that even if we miss many frames, the queue can't fill up 772 // guarantees that even if we miss many frames, the queue can't fill up
683 // with stale bounds. 773 // with stale bounds.
684 if (index > frame_index && index <= frame_index + kPoseRingBufferSize) 774 if (index > frame_index && index <= frame_index + kPoseRingBufferSize)
685 break; 775 break;
686 776
687 const BoundsPair& bounds = pending_bounds_.front().second; 777 const WebVrBounds& bounds = pending_bounds_.front().second;
688 webvr_left_viewport_->SetSourceUv(bounds.first); 778 webvr_left_viewport_->SetSourceUv(bounds.left_bounds);
689 webvr_right_viewport_->SetSourceUv(bounds.second); 779 webvr_right_viewport_->SetSourceUv(bounds.right_bounds);
780 CreateOrResizeWebVRSurface(bounds.source_size);
690 pending_bounds_.pop(); 781 pending_bounds_.pop();
691 } 782 }
692 buffer_viewport_list_->SetBufferViewport(GVR_LEFT_EYE, 783 buffer_viewport_list_->SetBufferViewport(GVR_LEFT_EYE,
693 *webvr_left_viewport_); 784 *webvr_left_viewport_);
694 buffer_viewport_list_->SetBufferViewport(GVR_RIGHT_EYE, 785 buffer_viewport_list_->SetBufferViewport(GVR_RIGHT_EYE,
695 *webvr_right_viewport_); 786 *webvr_right_viewport_);
696 } else { 787 } else {
697 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); 788 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow();
698 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; 789 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos;
699 head_pose = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); 790 head_pose = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time);
700 } 791 }
701 792
702 gvr::Vec3f position = GetTranslation(head_pose); 793 gvr::Vec3f position = GetTranslation(head_pose);
703 if (position.x == 0.0f && position.y == 0.0f && position.z == 0.0f) { 794 if (position.x == 0.0f && position.y == 0.0f && position.z == 0.0f) {
704 // This appears to be a 3DOF pose without a neck model. Add one. 795 // This appears to be a 3DOF pose without a neck model. Add one.
705 // The head pose has redundant data. Assume we're only using the 796 // The head pose has redundant data. Assume we're only using the
706 // object_from_reference_matrix, we're not updating position_external. 797 // object_from_reference_matrix, we're not updating position_external.
707 // TODO: Not sure what object_from_reference_matrix is. The new api removed 798 // TODO: Not sure what object_from_reference_matrix is. The new api removed
708 // it. For now, removing it seems working fine. 799 // it. For now, removing it seems working fine.
709 gvr_api_->ApplyNeckModel(head_pose, 1.0f); 800 gvr_api_->ApplyNeckModel(head_pose, 1.0f);
710 } 801 }
711 802
712 // Update the render position of all UI elements (including desktop). 803 // Update the render position of all UI elements (including desktop).
713 scene_->UpdateTransforms(TimeInMicroseconds()); 804 scene_->UpdateTransforms(TimeInMicroseconds());
714 805
715 UpdateController(GetForwardVector(head_pose)); 806 {
807 TRACE_EVENT0("gpu", "VrShellGl::UpdateController");
808 UpdateController(GetForwardVector(head_pose));
809 }
716 810
717 DrawVrShell(head_pose, frame); 811 // Finish drawing in the primary buffer, and draw the headlocked buffer
812 // if needed. This must be the last drawing call, this method will
813 // return with no frame being bound.
814 DrawVrShellAndUnbind(head_pose, frame);
718 815
719 frame.Unbind(); 816 {
720 frame.Submit(*buffer_viewport_list_, head_pose); 817 TRACE_EVENT0("gpu", "VrShellGl::Submit");
818 frame.Submit(*buffer_viewport_list_, head_pose);
819 }
721 820
722 // No need to swap buffers for surfaceless rendering. 821 // No need to swap buffers for surfaceless rendering.
723 if (!surfaceless_rendering_) { 822 if (!surfaceless_rendering_) {
724 // TODO(mthiesse): Support asynchronous SwapBuffers. 823 // TODO(mthiesse): Support asynchronous SwapBuffers.
824 TRACE_EVENT0("gpu", "VrShellGl::SwapBuffers");
725 surface_->SwapBuffers(); 825 surface_->SwapBuffers();
726 } 826 }
727 } 827 }
728 828
729 void VrShellGl::DrawVrShell(const gvr::Mat4f& head_pose, gvr::Frame& frame) { 829 void VrShellGl::DrawVrShellAndUnbind(const gvr::Mat4f& head_pose,
830 gvr::Frame& frame) {
730 TRACE_EVENT0("gpu", "VrShellGl::DrawVrShell"); 831 TRACE_EVENT0("gpu", "VrShellGl::DrawVrShell");
731 std::vector<const ContentRectangle*> head_locked_elements; 832 std::vector<const ContentRectangle*> head_locked_elements;
732 std::vector<const ContentRectangle*> world_elements; 833 std::vector<const ContentRectangle*> world_elements;
733 for (const auto& rect : scene_->GetUiElements()) { 834 for (const auto& rect : scene_->GetUiElements()) {
734 if (!rect->IsVisible()) 835 if (!rect->IsVisible())
735 continue; 836 continue;
736 if (rect->lock_to_fov) { 837 if (rect->lock_to_fov) {
737 head_locked_elements.push_back(rect.get()); 838 head_locked_elements.push_back(rect.get());
738 } else { 839 } else {
739 world_elements.push_back(rect.get()); 840 world_elements.push_back(rect.get());
(...skipping 16 matching lines...) Expand all
756 857
757 const Colorf& backgroundColor = scene_->GetBackgroundColor(); 858 const Colorf& backgroundColor = scene_->GetBackgroundColor();
758 glClearColor(backgroundColor.r, backgroundColor.g, backgroundColor.b, 859 glClearColor(backgroundColor.r, backgroundColor.g, backgroundColor.b,
759 backgroundColor.a); 860 backgroundColor.a);
760 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 861 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
761 } 862 }
762 if (!world_elements.empty()) { 863 if (!world_elements.empty()) {
763 DrawUiView(&head_pose, world_elements, render_size_primary_, 864 DrawUiView(&head_pose, world_elements, render_size_primary_,
764 kViewportListPrimaryOffset); 865 kViewportListPrimaryOffset);
765 } 866 }
867 frame.Unbind(); // Done with the primary buffer.
766 868
767 if (!head_locked_elements.empty()) { 869 if (!head_locked_elements.empty()) {
768 // Add head-locked viewports. The list gets reset to just 870 // Add head-locked viewports. The list gets reset to just
769 // the recommended viewports (for the primary buffer) each frame. 871 // the recommended viewports (for the primary buffer) each frame.
770 buffer_viewport_list_->SetBufferViewport( 872 buffer_viewport_list_->SetBufferViewport(
771 kViewportListHeadlockedOffset + GVR_LEFT_EYE, 873 kViewportListHeadlockedOffset + GVR_LEFT_EYE,
772 *headlocked_left_viewport_); 874 *headlocked_left_viewport_);
773 buffer_viewport_list_->SetBufferViewport( 875 buffer_viewport_list_->SetBufferViewport(
774 kViewportListHeadlockedOffset + GVR_RIGHT_EYE, 876 kViewportListHeadlockedOffset + GVR_RIGHT_EYE,
775 *headlocked_right_viewport_); 877 *headlocked_right_viewport_);
776 878
777 // Bind the headlocked framebuffer. 879 // Bind the headlocked framebuffer.
778 // TODO(mthiesse): We don't unbind this? Maybe some cleanup is in order
779 // here.
780 frame.BindBuffer(kFrameHeadlockedBuffer); 880 frame.BindBuffer(kFrameHeadlockedBuffer);
781 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 881 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
782 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 882 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
783 DrawUiView(nullptr, head_locked_elements, render_size_headlocked_, 883 DrawUiView(nullptr, head_locked_elements, render_size_headlocked_,
784 kViewportListHeadlockedOffset); 884 kViewportListHeadlockedOffset);
885 frame.Unbind(); // Done with the headlocked buffer.
785 } 886 }
786 } 887 }
787 888
788 gvr::Sizei VrShellGl::GetWebVRCompositorSurfaceSize() {
789 // This is a stopgap while we're using the WebVR compositor rendering path.
790 // TODO(klausw,crbug.com/655722): Remove this method and member once we're
791 // using a separate WebVR render surface.
792 return content_tex_physical_size_;
793 }
794
795 void VrShellGl::DrawUiView(const gvr::Mat4f* head_pose, 889 void VrShellGl::DrawUiView(const gvr::Mat4f* head_pose,
796 const std::vector<const ContentRectangle*>& elements, 890 const std::vector<const ContentRectangle*>& elements,
797 const gvr::Sizei& render_size, 891 const gvr::Sizei& render_size,
798 int viewport_offset) { 892 int viewport_offset) {
799 TRACE_EVENT0("gpu", "VrShellGl::DrawUiView"); 893 TRACE_EVENT0("gpu", "VrShellGl::DrawUiView");
800 894
801 gvr::Mat4f view_matrix; 895 gvr::Mat4f view_matrix;
802 if (head_pose) { 896 if (head_pose) {
803 view_matrix = *head_pose; 897 view_matrix = *head_pose;
804 } else { 898 } else {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 void VrShellGl::DrawWebVr() { 1084 void VrShellGl::DrawWebVr() {
991 TRACE_EVENT0("gpu", "VrShellGl::DrawWebVr"); 1085 TRACE_EVENT0("gpu", "VrShellGl::DrawWebVr");
992 // Don't need face culling, depth testing, blending, etc. Turn it all off. 1086 // Don't need face culling, depth testing, blending, etc. Turn it all off.
993 glDisable(GL_CULL_FACE); 1087 glDisable(GL_CULL_FACE);
994 glDepthMask(GL_FALSE); 1088 glDepthMask(GL_FALSE);
995 glDisable(GL_DEPTH_TEST); 1089 glDisable(GL_DEPTH_TEST);
996 glDisable(GL_SCISSOR_TEST); 1090 glDisable(GL_SCISSOR_TEST);
997 glDisable(GL_BLEND); 1091 glDisable(GL_BLEND);
998 glDisable(GL_POLYGON_OFFSET_FILL); 1092 glDisable(GL_POLYGON_OFFSET_FILL);
999 1093
1000 glViewport(0, 0, render_size_primary_.width, render_size_primary_.height); 1094 glViewport(0, 0, webvr_surface_size_.width, webvr_surface_size_.height);
1001 vr_shell_renderer_->GetWebVrRenderer()->Draw(webvr_texture_id_); 1095 vr_shell_renderer_->GetWebVrRenderer()->Draw(webvr_texture_id_);
1002 } 1096 }
1003 1097
1004 void VrShellGl::OnTriggerEvent() { 1098 void VrShellGl::OnTriggerEvent() {
1005 // Set a flag to handle this on the render thread at the next frame. 1099 // Set a flag to handle this on the render thread at the next frame.
1006 touch_pending_ = true; 1100 touch_pending_ = true;
1007 } 1101 }
1008 1102
1009 void VrShellGl::OnPause() { 1103 void VrShellGl::OnPause() {
1010 vsync_task_.Cancel(); 1104 vsync_task_.Cancel();
(...skipping 10 matching lines...) Expand all
1021 OnVSync(); 1115 OnVSync();
1022 } 1116 }
1023 } 1117 }
1024 1118
1025 void VrShellGl::SetWebVrMode(bool enabled) { 1119 void VrShellGl::SetWebVrMode(bool enabled) {
1026 web_vr_mode_ = enabled; 1120 web_vr_mode_ = enabled;
1027 } 1121 }
1028 1122
1029 void VrShellGl::UpdateWebVRTextureBounds(int16_t frame_index, 1123 void VrShellGl::UpdateWebVRTextureBounds(int16_t frame_index,
1030 const gvr::Rectf& left_bounds, 1124 const gvr::Rectf& left_bounds,
1031 const gvr::Rectf& right_bounds) { 1125 const gvr::Rectf& right_bounds,
1126 const gvr::Sizei& source_size) {
1032 if (frame_index < 0) { 1127 if (frame_index < 0) {
1033 webvr_left_viewport_->SetSourceUv(left_bounds); 1128 webvr_left_viewport_->SetSourceUv(left_bounds);
1034 webvr_right_viewport_->SetSourceUv(right_bounds); 1129 webvr_right_viewport_->SetSourceUv(right_bounds);
1035 } else { 1130 } else {
1036 pending_bounds_.emplace( 1131 pending_bounds_.emplace(
1037 std::make_pair(frame_index, std::make_pair(left_bounds, right_bounds))); 1132 frame_index, WebVrBounds(left_bounds, right_bounds, source_size));
1038 } 1133 }
1039 } 1134 }
1040 1135
1041 void VrShellGl::ContentBoundsChanged(int width, int height) { 1136 void VrShellGl::ContentBoundsChanged(int width, int height) {
1042 TRACE_EVENT0("gpu", "VrShellGl::ContentBoundsChanged"); 1137 TRACE_EVENT0("gpu", "VrShellGl::ContentBoundsChanged");
1043 content_tex_css_width_ = width; 1138 content_tex_css_width_ = width;
1044 content_tex_css_height_ = height; 1139 content_tex_css_height_ = height;
1045 } 1140 }
1046 1141
1047 void VrShellGl::ContentPhysicalBoundsChanged(int width, int height) { 1142 void VrShellGl::ContentPhysicalBoundsChanged(int width, int height) {
(...skipping 13 matching lines...) Expand all
1061 ui_surface_texture_->SetDefaultBufferSize(width, height); 1156 ui_surface_texture_->SetDefaultBufferSize(width, height);
1062 ui_tex_physical_size_.width = width; 1157 ui_tex_physical_size_.width = width;
1063 ui_tex_physical_size_.height = height; 1158 ui_tex_physical_size_.height = height;
1064 } 1159 }
1065 1160
1066 base::WeakPtr<VrShellGl> VrShellGl::GetWeakPtr() { 1161 base::WeakPtr<VrShellGl> VrShellGl::GetWeakPtr() {
1067 return weak_ptr_factory_.GetWeakPtr(); 1162 return weak_ptr_factory_.GetWeakPtr();
1068 } 1163 }
1069 1164
1070 void VrShellGl::OnVSync() { 1165 void VrShellGl::OnVSync() {
1166 while (premature_received_frames_ > 0) {
1167 TRACE_EVENT0("gpu", "VrShellGl::OnWebVRFrameAvailableRetry");
1168 --premature_received_frames_;
1169 OnWebVRFrameAvailable();
1170 }
1171
1071 base::TimeTicks now = base::TimeTicks::Now(); 1172 base::TimeTicks now = base::TimeTicks::Now();
1072 base::TimeTicks target; 1173 base::TimeTicks target;
1073 1174
1074 // Don't send VSyncs until we have a timebase/interval. 1175 // Don't send VSyncs until we have a timebase/interval.
1075 if (vsync_interval_.is_zero()) 1176 if (vsync_interval_.is_zero())
1076 return; 1177 return;
1077 target = now + vsync_interval_; 1178 target = now + vsync_interval_;
1078 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; 1179 int64_t intervals = (target - vsync_timebase_) / vsync_interval_;
1079 target = vsync_timebase_ + intervals * vsync_interval_; 1180 target = vsync_timebase_ + intervals * vsync_interval_;
1080 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(), 1181 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(),
1081 target - now); 1182 target - now);
1082 1183
1083 base::TimeDelta time = intervals * vsync_interval_; 1184 base::TimeDelta time = intervals * vsync_interval_;
1084 if (!callback_.is_null()) { 1185 if (!callback_.is_null()) {
1085 SendVSync(time, base::ResetAndReturn(&callback_)); 1186 SendVSync(time, base::ResetAndReturn(&callback_));
1086 } else { 1187 } else {
1087 pending_vsync_ = true; 1188 pending_vsync_ = true;
1088 pending_time_ = time; 1189 pending_time_ = time;
1089 } 1190 }
1090 DrawFrame(); 1191 if (!web_vr_mode_) {
1192 DrawFrame(-1);
1193 }
1091 } 1194 }
1092 1195
1093 void VrShellGl::OnRequest(device::mojom::VRVSyncProviderRequest request) { 1196 void VrShellGl::OnRequest(device::mojom::VRVSyncProviderRequest request) {
1094 binding_.Close(); 1197 binding_.Close();
1095 binding_.Bind(std::move(request)); 1198 binding_.Bind(std::move(request));
1096 } 1199 }
1097 1200
1098 void VrShellGl::GetVSync(const GetVSyncCallback& callback) { 1201 void VrShellGl::GetVSync(const GetVSyncCallback& callback) {
1099 if (!pending_vsync_) { 1202 if (!pending_vsync_) {
1100 if (!callback_.is_null()) { 1203 if (!callback_.is_null()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 void VrShellGl::ResetPose() { 1253 void VrShellGl::ResetPose() {
1151 // Should never call RecenterTracking when using with Daydream viewers. On 1254 // Should never call RecenterTracking when using with Daydream viewers. On
1152 // those devices recentering should only be done via the controller. 1255 // those devices recentering should only be done via the controller.
1153 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) 1256 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD)
1154 gvr_api_->RecenterTracking(); 1257 gvr_api_->RecenterTracking();
1155 } 1258 }
1156 1259
1157 void VrShellGl::CreateVRDisplayInfo( 1260 void VrShellGl::CreateVRDisplayInfo(
1158 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, 1261 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
1159 uint32_t device_id) { 1262 uint32_t device_id) {
1263 // This assumes that the initial webvr_surface_size_ was set to the
1264 // appropriate recommended render resolution as the default size during
1265 // InitializeGl. Revisit if the initialization order changes.
1160 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( 1266 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo(
1161 gvr_api_.get(), content_tex_physical_size_, device_id); 1267 gvr_api_.get(), webvr_surface_size_, device_id);
1162 main_thread_task_runner_->PostTask( 1268 main_thread_task_runner_->PostTask(
1163 FROM_HERE, 1269 FROM_HERE,
1164 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); 1270 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info)));
1165 } 1271 }
1166 1272
1167 } // namespace vr_shell 1273 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698