diff options
author | Josh Matthews <josh@joshmatthews.net> | 2018-08-01 14:50:40 -0400 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2018-10-01 10:43:13 +0200 |
commit | 5dc80dd07ad75d68cfea2babe64d421eb7b07ba3 (patch) | |
tree | 7face525bdd3c91c4d3b23551447834265e81010 /components/canvas | |
parent | 515afac456d162bab6bf8edbf9745920b2420e4a (diff) | |
download | servo-5dc80dd07ad75d68cfea2babe64d421eb7b07ba3.tar.gz servo-5dc80dd07ad75d68cfea2babe64d421eb7b07ba3.zip |
webgl: Add feature to store backtraces for each WebGL API call for easier debugging.
Diffstat (limited to 'components/canvas')
-rw-r--r-- | components/canvas/Cargo.toml | 3 | ||||
-rw-r--r-- | components/canvas/gl_context.rs | 13 | ||||
-rw-r--r-- | components/canvas/webgl_thread.rs | 25 |
3 files changed, 31 insertions, 10 deletions
diff --git a/components/canvas/Cargo.toml b/components/canvas/Cargo.toml index d65c1b4b110..4006947acf6 100644 --- a/components/canvas/Cargo.toml +++ b/components/canvas/Cargo.toml @@ -9,6 +9,9 @@ publish = false name = "canvas" path = "lib.rs" +[features] +webgl_backtrace = ["canvas_traits/webgl_backtrace"] + [dependencies] azure = {git = "https://github.com/servo/rust-azure"} canvas_traits = {path = "../canvas_traits"} diff --git a/components/canvas/gl_context.rs b/components/canvas/gl_context.rs index 00e3f3ba4a9..c90ecec9cca 100644 --- a/components/canvas/gl_context.rs +++ b/components/canvas/gl_context.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use canvas_traits::webgl::{WebGLCommand, WebGLVersion}; +use canvas_traits::webgl::{WebGLCommand, WebGLVersion, WebGLCommandBacktrace}; use compositing::compositor_thread::{CompositorProxy, self}; use euclid::Size2D; use gleam::gl; @@ -144,13 +144,18 @@ impl GLContextWrapper { } } - pub fn apply_command(&self, cmd: WebGLCommand, state: &mut GLState) { + pub fn apply_command( + &self, + cmd: WebGLCommand, + backtrace: WebGLCommandBacktrace, + state: &mut GLState + ) { match *self { GLContextWrapper::Native(ref ctx) => { - WebGLImpl::apply(ctx, state, cmd); + WebGLImpl::apply(ctx, state, cmd, backtrace); } GLContextWrapper::OSMesa(ref ctx) => { - WebGLImpl::apply(ctx, state, cmd); + WebGLImpl::apply(ctx, state, cmd, backtrace); } } } diff --git a/components/canvas/webgl_thread.rs b/components/canvas/webgl_thread.rs index 9256692599a..4a2466d64e3 100644 --- a/components/canvas/webgl_thread.rs +++ b/components/canvas/webgl_thread.rs @@ -137,8 +137,8 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> { WebGLMsg::RemoveContext(ctx_id) => { self.remove_webgl_context(ctx_id); }, - WebGLMsg::WebGLCommand(ctx_id, command) => { - self.handle_webgl_command(ctx_id, command); + WebGLMsg::WebGLCommand(ctx_id, command, backtrace) => { + self.handle_webgl_command(ctx_id, command, backtrace); }, WebGLMsg::WebVRCommand(ctx_id, command) => { self.handle_webvr_command(ctx_id, command); @@ -164,10 +164,15 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> { } /// Handles a WebGLCommand for a specific WebGLContext - fn handle_webgl_command(&mut self, context_id: WebGLContextId, command: WebGLCommand) { + fn handle_webgl_command( + &mut self, + context_id: WebGLContextId, + command: WebGLCommand, + backtrace: WebGLCommandBacktrace, + ) { let data = Self::make_current_if_needed_mut(context_id, &mut self.contexts, &mut self.bound_context_id); if let Some(data) = data { - data.ctx.apply_command(command, &mut data.state); + data.ctx.apply_command(command, backtrace, &mut data.state); } } @@ -670,7 +675,8 @@ impl WebGLImpl { pub fn apply<Native: NativeGLContextMethods>( ctx: &GLContext<Native>, state: &mut GLState, - command: WebGLCommand + command: WebGLCommand, + _backtrace: WebGLCommandBacktrace, ) { match command { WebGLCommand::GetContextAttributes(ref sender) => @@ -1191,7 +1197,14 @@ impl WebGLImpl { // TODO: update test expectations in order to enable debug assertions let error = ctx.gl().get_error(); if error != gl::NO_ERROR { - error!("Last GL operation failed: {:?}", command) + error!("Last GL operation failed: {:?}", command); + #[cfg(feature = "webgl_backtrace")] + { + error!("Backtrace from failed WebGL API:\n{}", _backtrace.backtrace); + if let Some(backtrace) = _backtrace.js_backtrace { + error!("JS backtrace from failed WebGL API:\n{}", backtrace); + } + } } assert_eq!(error, gl::NO_ERROR, "Unexpected WebGL error: 0x{:x} ({})", error, error); } |