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

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

Issue 2861343002: Enable gpu rasterization in the vr shell
Patch Set: additional trace instrumentation 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
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | skia/BUILD.gn » ('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 <chrono> 7 #include <chrono>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" 23 #include "chrome/browser/android/vr_shell/vr_gl_thread.h"
24 #include "chrome/browser/android/vr_shell/vr_gl_util.h" 24 #include "chrome/browser/android/vr_shell/vr_gl_util.h"
25 #include "chrome/browser/android/vr_shell/vr_shell.h" 25 #include "chrome/browser/android/vr_shell/vr_shell.h"
26 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" 26 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
27 #include "device/vr/android/gvr/gvr_delegate.h" 27 #include "device/vr/android/gvr/gvr_delegate.h"
28 #include "device/vr/android/gvr/gvr_device.h" 28 #include "device/vr/android/gvr/gvr_device.h"
29 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" 29 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h"
30 #include "device/vr/vr_math.h" 30 #include "device/vr/vr_math.h"
31 #include "third_party/WebKit/public/platform/WebInputEvent.h" 31 #include "third_party/WebKit/public/platform/WebInputEvent.h"
32 #include "third_party/WebKit/public/platform/WebMouseEvent.h" 32 #include "third_party/WebKit/public/platform/WebMouseEvent.h"
33 #include "third_party/skia/include/gpu/GrContext.h"
34 #include "third_party/skia/include/gpu/GrContextOptions.h"
35 #include "third_party/skia/include/gpu/GrTypes.h"
36 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
33 #include "ui/gl/android/scoped_java_surface.h" 37 #include "ui/gl/android/scoped_java_surface.h"
34 #include "ui/gl/android/surface_texture.h" 38 #include "ui/gl/android/surface_texture.h"
35 #include "ui/gl/gl_bindings.h" 39 #include "ui/gl/gl_bindings.h"
36 #include "ui/gl/gl_context.h" 40 #include "ui/gl/gl_context.h"
37 #include "ui/gl/gl_surface.h" 41 #include "ui/gl/gl_surface.h"
38 #include "ui/gl/init/gl_factory.h" 42 #include "ui/gl/init/gl_factory.h"
39 43
40 namespace vr_shell { 44 namespace vr_shell {
41 45
42 namespace { 46 namespace {
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 LOG(ERROR) << "gl::init::CreateGLContext failed"; 260 LOG(ERROR) << "gl::init::CreateGLContext failed";
257 ForceExitVr(); 261 ForceExitVr();
258 return; 262 return;
259 } 263 }
260 if (!context_->MakeCurrent(surface_.get())) { 264 if (!context_->MakeCurrent(surface_.get())) {
261 LOG(ERROR) << "gl::GLContext::MakeCurrent() failed"; 265 LOG(ERROR) << "gl::GLContext::MakeCurrent() failed";
262 ForceExitVr(); 266 ForceExitVr();
263 return; 267 return;
264 } 268 }
265 269
270 GrContextOptions gr_context_options;
271 gr_interface_ = GrGLCreateNativeInterface();
272 DCHECK_NE(nullptr, gr_interface_);
273 gr_context_ = GrContext::Create(
274 kOpenGL_GrBackend, (GrBackendContext)gr_interface_, gr_context_options);
275
266 unsigned int textures[2]; 276 unsigned int textures[2];
267 glGenTextures(2, textures); 277 glGenTextures(2, textures);
268 content_texture_id_ = textures[0]; 278 content_texture_id_ = textures[0];
269 webvr_texture_id_ = textures[1]; 279 webvr_texture_id_ = textures[1];
270 content_surface_texture_ = gl::SurfaceTexture::Create(content_texture_id_); 280 content_surface_texture_ = gl::SurfaceTexture::Create(content_texture_id_);
271 webvr_surface_texture_ = gl::SurfaceTexture::Create(webvr_texture_id_); 281 webvr_surface_texture_ = gl::SurfaceTexture::Create(webvr_texture_id_);
272 CreateContentSurface(); 282 CreateContentSurface();
273 content_surface_texture_->SetFrameAvailableCallback(base::Bind( 283 content_surface_texture_->SetFrameAvailableCallback(base::Bind(
274 &VrShellGl::OnContentFrameAvailable, weak_ptr_factory_.GetWeakPtr())); 284 &VrShellGl::OnContentFrameAvailable, weak_ptr_factory_.GetWeakPtr()));
275 webvr_surface_texture_->SetFrameAvailableCallback(base::Bind( 285 webvr_surface_texture_->SetFrameAvailableCallback(base::Bind(
276 &VrShellGl::OnWebVRFrameAvailable, weak_ptr_factory_.GetWeakPtr())); 286 &VrShellGl::OnWebVRFrameAvailable, weak_ptr_factory_.GetWeakPtr()));
277 content_surface_texture_->SetDefaultBufferSize( 287 content_surface_texture_->SetDefaultBufferSize(
278 content_tex_physical_size_.width(), content_tex_physical_size_.height()); 288 content_tex_physical_size_.width(), content_tex_physical_size_.height());
279 289
280 InitializeRenderer(); 290 InitializeRenderer();
281 291
282 scene_->OnGLInitialized(); 292 scene_->OnGLInitialized(this);
283 293
284 gfx::Size webvr_size = 294 gfx::Size webvr_size =
285 device::GvrDelegate::GetRecommendedWebVrSize(gvr_api_.get()); 295 device::GvrDelegate::GetRecommendedWebVrSize(gvr_api_.get());
286 DVLOG(1) << __FUNCTION__ << ": resize initial to " << webvr_size.width() 296 DVLOG(1) << __FUNCTION__ << ": resize initial to " << webvr_size.width()
287 << "x" << webvr_size.height(); 297 << "x" << webvr_size.height();
288 298
289 CreateOrResizeWebVRSurface(webvr_size); 299 CreateOrResizeWebVRSurface(webvr_size);
290 300
291 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); 301 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this)));
292 OnVSync(); 302 OnVSync();
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 1314
1305 void VrShellGl::UpdateVSyncInterval(int64_t timebase_nanos, 1315 void VrShellGl::UpdateVSyncInterval(int64_t timebase_nanos,
1306 double interval_seconds) { 1316 double interval_seconds) {
1307 vsync_timebase_ = base::TimeTicks(); 1317 vsync_timebase_ = base::TimeTicks();
1308 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000); 1318 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000);
1309 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); 1319 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds);
1310 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); 1320 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this)));
1311 OnVSync(); 1321 OnVSync();
1312 } 1322 }
1313 1323
1324 sk_sp<SkSurface> VrShellGl::MakeSurface(int width, int height) {
1325 return SkSurface::MakeRenderTarget(gr_context_, SkBudgeted::kNo,
1326 SkImageInfo::MakeN32Premul(width, height),
1327 0, kTopLeft_GrSurfaceOrigin, nullptr);
1328 }
1329
1314 void VrShellGl::ForceExitVr() { 1330 void VrShellGl::ForceExitVr() {
1315 browser_->ForceExitVr(); 1331 browser_->ForceExitVr();
1316 } 1332 }
1317 1333
1318 void VrShellGl::SendVSync(base::TimeDelta time, 1334 void VrShellGl::SendVSync(base::TimeDelta time,
1319 const GetVSyncCallback& callback) { 1335 const GetVSyncCallback& callback) {
1320 uint8_t frame_index = frame_index_++; 1336 uint8_t frame_index = frame_index_++;
1321 1337
1322 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); 1338 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index);
1323 1339
(...skipping 13 matching lines...) Expand all
1337 // This assumes that the initial webvr_surface_size_ was set to the 1353 // This assumes that the initial webvr_surface_size_ was set to the
1338 // appropriate recommended render resolution as the default size during 1354 // appropriate recommended render resolution as the default size during
1339 // InitializeGl. Revisit if the initialization order changes. 1355 // InitializeGl. Revisit if the initialization order changes.
1340 device::mojom::VRDisplayInfoPtr info = 1356 device::mojom::VRDisplayInfoPtr info =
1341 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), 1357 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(),
1342 webvr_surface_size_, device_id); 1358 webvr_surface_size_, device_id);
1343 browser_->RunVRDisplayInfoCallback(callback, &info); 1359 browser_->RunVRDisplayInfoCallback(callback, &info);
1344 } 1360 }
1345 1361
1346 } // namespace vr_shell 1362 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | skia/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698