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

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

Issue 2891243002: VR: Loading DD controller model after GL is initialized (Closed)
Patch Set: Created 3 years, 7 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 <chrono> 7 #include <chrono>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/task_scheduler/post_task.h"
15 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
16 #include "chrome/browser/android/vr_shell/fps_meter.h" 17 #include "chrome/browser/android/vr_shell/fps_meter.h"
17 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h" 18 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h"
18 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" 19 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h"
19 #include "chrome/browser/android/vr_shell/ui_interface.h" 20 #include "chrome/browser/android/vr_shell/ui_interface.h"
20 #include "chrome/browser/android/vr_shell/ui_scene.h" 21 #include "chrome/browser/android/vr_shell/ui_scene.h"
21 #include "chrome/browser/android/vr_shell/ui_scene_manager.h" 22 #include "chrome/browser/android/vr_shell/ui_scene_manager.h"
22 #include "chrome/browser/android/vr_shell/vr_controller.h" 23 #include "chrome/browser/android/vr_shell/vr_controller.h"
23 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" 24 #include "chrome/browser/android/vr_shell/vr_gl_thread.h"
24 #include "chrome/browser/android/vr_shell/vr_gl_util.h" 25 #include "chrome/browser/android/vr_shell/vr_gl_util.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 191
191 gfx::RectF GfxRectFromUV(gvr::Rectf rect) { 192 gfx::RectF GfxRectFromUV(gvr::Rectf rect) {
192 return gfx::RectF(rect.left, 1.0 - rect.top, rect.right - rect.left, 193 return gfx::RectF(rect.left, 1.0 - rect.top, rect.right - rect.left,
193 rect.top - rect.bottom); 194 rect.top - rect.bottom);
194 } 195 }
195 196
196 double NowSeconds() { 197 double NowSeconds() {
197 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); 198 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
198 } 199 }
199 200
201 void LoadControllerModelTask(
202 base::WeakPtr<VrShellGl> weak_vr_shell_gl,
203 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
204 auto controller_model = VrControllerModel::LoadFromResources();
205 if (controller_model) {
206 task_runner->PostTask(
207 FROM_HERE, base::Bind(&VrShellGl::SetControllerModel, weak_vr_shell_gl,
mthiesse 2017/05/19 14:32:42 You said SetControllerModel was slow too, right? S
acondor_ 2017/05/19 16:06:49 As discussed offline, I reduced the runtime of Set
208 base::Passed(&controller_model)));
209 }
210 }
211
200 } // namespace 212 } // namespace
201 213
202 VrShellGl::VrShellGl(VrBrowserInterface* browser, 214 VrShellGl::VrShellGl(VrBrowserInterface* browser,
203 gvr_context* gvr_api, 215 gvr_context* gvr_api,
204 bool initially_web_vr, 216 bool initially_web_vr,
205 bool reprojected_rendering, 217 bool reprojected_rendering,
218 bool daydream_support,
206 UiScene* scene) 219 UiScene* scene)
207 : web_vr_mode_(initially_web_vr), 220 : web_vr_mode_(initially_web_vr),
208 surfaceless_rendering_(reprojected_rendering), 221 surfaceless_rendering_(reprojected_rendering),
222 daydream_support_(daydream_support),
209 task_runner_(base::ThreadTaskRunnerHandle::Get()), 223 task_runner_(base::ThreadTaskRunnerHandle::Get()),
210 binding_(this), 224 binding_(this),
211 browser_(browser), 225 browser_(browser),
212 scene_(scene), 226 scene_(scene),
213 #if DCHECK_IS_ON() 227 #if DCHECK_IS_ON()
214 fps_meter_(new FPSMeter()), 228 fps_meter_(new FPSMeter()),
215 #endif 229 #endif
216 weak_ptr_factory_(this) { 230 weak_ptr_factory_(this) {
217 GvrInit(gvr_api); 231 GvrInit(gvr_api);
218 } 232 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 device::GvrDelegate::GetRecommendedWebVrSize(gvr_api_.get()); 313 device::GvrDelegate::GetRecommendedWebVrSize(gvr_api_.get());
300 DVLOG(1) << __FUNCTION__ << ": resize initial to " << webvr_size.width() 314 DVLOG(1) << __FUNCTION__ << ": resize initial to " << webvr_size.width()
301 << "x" << webvr_size.height(); 315 << "x" << webvr_size.height();
302 316
303 CreateOrResizeWebVRSurface(webvr_size); 317 CreateOrResizeWebVRSurface(webvr_size);
304 318
305 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); 319 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this)));
306 OnVSync(); 320 OnVSync();
307 321
308 ready_to_draw_ = true; 322 ready_to_draw_ = true;
323
324 if (daydream_support_) {
325 base::PostTaskWithTraits(
326 FROM_HERE, {base::TaskPriority::BACKGROUND},
327 base::Bind(LoadControllerModelTask, weak_ptr_factory_.GetWeakPtr(),
328 task_runner_));
329 }
309 } 330 }
310 331
311 void VrShellGl::CreateContentSurface() { 332 void VrShellGl::CreateContentSurface() {
312 content_surface_ = 333 content_surface_ =
313 base::MakeUnique<gl::ScopedJavaSurface>(content_surface_texture_.get()); 334 base::MakeUnique<gl::ScopedJavaSurface>(content_surface_texture_.get());
314 browser_->ContentSurfaceChanged(content_surface_->j_surface().obj()); 335 browser_->ContentSurfaceChanged(content_surface_->j_surface().obj());
315 } 336 }
316 337
317 void VrShellGl::CreateOrResizeWebVRSurface(const gfx::Size& size) { 338 void VrShellGl::CreateOrResizeWebVRSurface(const gfx::Size& size) {
318 if (!webvr_surface_texture_) { 339 if (!webvr_surface_texture_) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 473
453 // For kFrameHeadlockedBuffer (for WebVR insecure content warning). 474 // For kFrameHeadlockedBuffer (for WebVR insecure content warning).
454 // Set this up at fixed resolution, the (smaller) FOV gets set below. 475 // Set this up at fixed resolution, the (smaller) FOV gets set below.
455 specs.push_back(gvr_api_->CreateBufferSpec()); 476 specs.push_back(gvr_api_->CreateBufferSpec());
456 specs.back().SetSize({kHeadlockedBufferDimensions.width(), 477 specs.back().SetSize({kHeadlockedBufferDimensions.width(),
457 kHeadlockedBufferDimensions.height()}); 478 kHeadlockedBufferDimensions.height()});
458 gvr::Sizei render_size_headlocked = specs[kFrameHeadlockedBuffer].GetSize(); 479 gvr::Sizei render_size_headlocked = specs[kFrameHeadlockedBuffer].GetSize();
459 render_size_headlocked_ = {render_size_headlocked.width, 480 render_size_headlocked_ = {render_size_headlocked.width,
460 render_size_headlocked.height}; 481 render_size_headlocked.height};
461 482
462 swap_chain_.reset(new gvr::SwapChain(gvr_api_->CreateSwapChain(specs))); 483 swap_chain_ =
484 base::MakeUnique<gvr::SwapChain>(gvr_api_->CreateSwapChain(specs));
463 485
464 vr_shell_renderer_.reset(new VrShellRenderer()); 486 vr_shell_renderer_ = base::MakeUnique<VrShellRenderer>();
465 487
466 // Allocate a buffer viewport for use in UI drawing. This isn't 488 // Allocate a buffer viewport for use in UI drawing. This isn't
467 // initialized at this point, it'll be set from other viewport list 489 // initialized at this point, it'll be set from other viewport list
468 // entries as needed. 490 // entries as needed.
469 buffer_viewport_.reset( 491 buffer_viewport_.reset(
470 new gvr::BufferViewport(gvr_api_->CreateBufferViewport())); 492 new gvr::BufferViewport(gvr_api_->CreateBufferViewport()));
471 493
472 // Set up main content viewports. The list has two elements, 0=left 494 // Set up main content viewports. The list has two elements, 0=left
473 // eye and 1=right eye. 495 // eye and 1=right eye.
474 buffer_viewport_list_.reset( 496 buffer_viewport_list_.reset(
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 // This assumes that the initial webvr_surface_size_ was set to the 1489 // This assumes that the initial webvr_surface_size_ was set to the
1468 // appropriate recommended render resolution as the default size during 1490 // appropriate recommended render resolution as the default size during
1469 // InitializeGl. Revisit if the initialization order changes. 1491 // InitializeGl. Revisit if the initialization order changes.
1470 device::mojom::VRDisplayInfoPtr info = 1492 device::mojom::VRDisplayInfoPtr info =
1471 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), 1493 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(),
1472 webvr_surface_size_, device_id); 1494 webvr_surface_size_, device_id);
1473 browser_->RunVRDisplayInfoCallback(callback, &info); 1495 browser_->RunVRDisplayInfoCallback(callback, &info);
1474 } 1496 }
1475 1497
1476 } // namespace vr_shell 1498 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698