diff options
author | Josh Matthews <josh@joshmatthews.net> | 2019-01-10 23:47:58 -0500 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2019-01-17 22:44:41 -0500 |
commit | 878f0200138a5ba24554df5cdb1b9fb3220c69b9 (patch) | |
tree | 7ceca224c77852e3d3fb40b60652cdbf0facad84 | |
parent | 85c1c5ad13f891a8b1d4ce13aead7fd0f176a1a7 (diff) | |
download | servo-878f0200138a5ba24554df5cdb1b9fb3220c69b9.tar.gz servo-878f0200138a5ba24554df5cdb1b9fb3220c69b9.zip |
Ensure that resized GL contexts do not destroy their resources while in use by WR.
-rw-r--r-- | Cargo.lock | 23 | ||||
-rw-r--r-- | components/canvas/Cargo.toml | 2 | ||||
-rw-r--r-- | components/canvas/gl_context.rs | 4 | ||||
-rw-r--r-- | components/canvas/webgl_thread.rs | 29 | ||||
-rw-r--r-- | components/canvas_traits/Cargo.toml | 2 | ||||
-rw-r--r-- | components/script/Cargo.toml | 2 | ||||
-rw-r--r-- | tests/wpt/webgl/meta/conformance/canvas/to-data-url-test.html.ini | 2 | ||||
-rw-r--r-- | tests/wpt/webgl/meta/conformance/textures/misc/texture-size-cube-maps.html.ini | 2 |
8 files changed, 43 insertions, 23 deletions
diff --git a/Cargo.lock b/Cargo.lock index c9d8a1282cf..1a0d1643205 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -417,7 +417,7 @@ dependencies = [ "ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "offscreen_gl_context 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)", + "offscreen_gl_context 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", "pixels 0.0.1", "serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", "servo_config 0.0.1", @@ -436,7 +436,7 @@ dependencies = [ "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "malloc_size_of 0.0.1", "malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "offscreen_gl_context 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)", + "offscreen_gl_context 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", "pixels 0.0.1", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1466,7 +1466,7 @@ name = "gst-plugin" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "glib 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "glib-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "gobject-subclass 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2201,7 +2201,7 @@ version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "crc32fast 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2832,7 +2832,7 @@ dependencies = [ [[package]] name = "offscreen_gl_context" -version = "0.21.1" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2895,8 +2895,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "osmesa-src" -version = "0.1.1" -source = "git+https://github.com/servo/osmesa-src#939207de2f4617cb958548490764f7380cf0c6e4" +version = "0.1.0" +source = "git+https://github.com/servo/osmesa-src#97f4613fd80eee153ab134dfe349777bc5a27bab" [[package]] name = "osmesa-sys" @@ -3352,7 +3352,7 @@ dependencies = [ "msg 0.0.1", "net_traits 0.0.1", "num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "offscreen_gl_context 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)", + "offscreen_gl_context 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3548,7 +3548,7 @@ dependencies = [ "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "libservo 0.0.1", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "osmesa-src 0.1.1 (git+https://github.com/servo/osmesa-src)", + "osmesa-src 0.1.0 (git+https://github.com/servo/osmesa-src)", "osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sig 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tinyfiledialogs 3.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3968,7 +3968,6 @@ dependencies = [ "bindgen 0.46.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.25.1 (registry+https://github.com/rust-lang/crates.io-index)", "encoding_rs 0.8.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5164,13 +5163,13 @@ dependencies = [ "checksum objc 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5ffd1ab984e2a5ed8a222a6b567d38a69c1d04d64b19eb7c2b10794c6af9f76c" "checksum objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" "checksum objc_id 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e4730aa1c64d722db45f7ccc4113a3e2c465d018de6db4d3e7dfe031e8c8a297" -"checksum offscreen_gl_context 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5e86c90338962922a5f623128079b5c01d03784c8fd0809691f4eba233d69a1c" +"checksum offscreen_gl_context 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e41ac2a2751637c40a7daff7ac6783cff25a51cfb8cf06294c1ffcc56ecafd5" "checksum opaque-debug 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "51ecbcb821e1bd256d456fe858aaa7f380b63863eab2eb86eee1bd9f33dd6682" "checksum openssl 0.10.11 (registry+https://github.com/rust-lang/crates.io-index)" = "6c24d3508b4fb6da175c10baac54c578b33f09c89ae90c6fe9788b3b4768efdc" "checksum openssl-sys 0.9.35 (registry+https://github.com/rust-lang/crates.io-index)" = "912f301a749394e1025d9dcddef6106ddee9252620e6d0a0e5f8d0681de9b129" "checksum ordered-float 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e9a3c8db0fca1fdb34404f0b1286db252f23930b9f7a481e376c16c0d5c309d4" "checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" -"checksum osmesa-src 0.1.1 (git+https://github.com/servo/osmesa-src)" = "<none>" +"checksum osmesa-src 0.1.0 (git+https://github.com/servo/osmesa-src)" = "<none>" "checksum osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b" "checksum ovr-mobile-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a69b517feac6fc640f0679625defa0998bbcb32871a6901e63063c2abf9c4cbe" "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" diff --git a/components/canvas/Cargo.toml b/components/canvas/Cargo.toml index fc519588339..37ee56d6e5a 100644 --- a/components/canvas/Cargo.toml +++ b/components/canvas/Cargo.toml @@ -26,7 +26,7 @@ half = "1" ipc-channel = "0.11" log = "0.4" num-traits = "0.2" -offscreen_gl_context = {version = "0.21", features = ["serde", "osmesa"]} +offscreen_gl_context = {version = "0.22", features = ["serde", "osmesa"]} pixels = {path = "../pixels"} serde_bytes = "0.10" servo_config = {path = "../config"} diff --git a/components/canvas/gl_context.rs b/components/canvas/gl_context.rs index 093d1837920..281c78b7f3b 100644 --- a/components/canvas/gl_context.rs +++ b/components/canvas/gl_context.rs @@ -8,7 +8,7 @@ use compositing::compositor_thread::{self, CompositorProxy}; use euclid::Size2D; use gleam::gl; use offscreen_gl_context::{ - ColorAttachmentType, GLContext, GLContextAttributes, GLContextDispatcher, + ColorAttachmentType, DrawBuffer, GLContext, GLContextAttributes, GLContextDispatcher, }; use offscreen_gl_context::{GLLimits, GLVersion}; use offscreen_gl_context::{NativeGLContext, NativeGLContextHandle, NativeGLContextMethods}; @@ -207,7 +207,7 @@ impl GLContextWrapper { } } - pub fn resize(&mut self, size: Size2D<u32>) -> Result<(), &'static str> { + pub fn resize(&mut self, size: Size2D<u32>) -> Result<DrawBuffer, &'static str> { match *self { GLContextWrapper::Native(ref mut ctx) => { // FIXME(nox): Why are those i32 values? diff --git a/components/canvas/webgl_thread.rs b/components/canvas/webgl_thread.rs index 93134dd7487..2add67cfd2a 100644 --- a/components/canvas/webgl_thread.rs +++ b/components/canvas/webgl_thread.rs @@ -9,7 +9,9 @@ use euclid::Size2D; use fnv::FnvHashMap; use gleam::gl; use half::f16; -use offscreen_gl_context::{GLContext, GLContextAttributes, GLLimits, NativeGLContextMethods}; +use offscreen_gl_context::{ + DrawBuffer, GLContext, GLContextAttributes, GLLimits, NativeGLContextMethods, +}; use pixels::{self, PixelFormat}; use std::borrow::Cow; use std::thread; @@ -228,6 +230,7 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> { Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id) .expect("WebGLContext not found in a WebGLMsg::Lock message"); let info = self.cached_context_info.get_mut(&context_id).unwrap(); + info.render_state = ContextRenderState::Locked(None); // Insert a OpenGL Fence sync object that sends a signal when all the WebGL commands are finished. // The related gl().wait_sync call is performed in the WR thread. See WebGLExternalImageApi for mor details. let gl_sync = data.ctx.gl().fence_sync(gl::SYNC_GPU_COMMANDS_COMPLETE, 0); @@ -247,6 +250,7 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> { Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id) .expect("WebGLContext not found in a WebGLMsg::Unlock message"); let info = self.cached_context_info.get_mut(&context_id).unwrap(); + info.render_state = ContextRenderState::Unlocked; if let Some(gl_sync) = info.gl_sync.take() { // Release the GLSync object. data.ctx.gl().delete_sync(gl_sync); @@ -299,6 +303,7 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> { image_key: None, share_mode, gl_sync: None, + render_state: ContextRenderState::Unlocked, }, ); @@ -319,9 +324,19 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> { ) .expect("Missing WebGL context!"); match data.ctx.resize(size) { - Ok(_) => { + Ok(old_draw_buffer) => { let (real_size, texture_id, _) = data.ctx.get_info(); let info = self.cached_context_info.get_mut(&context_id).unwrap(); + if let ContextRenderState::Locked(ref mut in_use) = info.render_state { + // If there's already an outdated draw buffer present, we can ignore + // the newly resized one since it's not in use by the renderer. + if in_use.is_none() { + // We're resizing the context while WR is actively rendering + // it, so we need to retain the GL resources until WR is + // finished with them. + *in_use = Some(old_draw_buffer); + } + } // Update webgl texture size. Texture id may change too. info.texture_id = texture_id; info.size = real_size; @@ -682,6 +697,14 @@ impl<VR: WebVRRenderHandler + 'static> Drop for WebGLThread<VR> { } } +enum ContextRenderState { + /// The context is not being actively rendered. + Unlocked, + /// The context is actively being rendered. If a DrawBuffer value is present, + /// it is outdated but in use as long as the context is locked. + Locked(Option<DrawBuffer>), +} + /// Helper struct to store cached WebGLContext information. struct WebGLContextInfo { /// Render to texture identifier used by the WebGLContext. @@ -696,6 +719,8 @@ struct WebGLContextInfo { share_mode: WebGLContextShareMode, /// GLSync Object used for a correct synchronization with Webrender external image callbacks. gl_sync: Option<gl::GLsync>, + /// The status of this context with respect to external consumers. + render_state: ContextRenderState, } /// This trait is used as a bridge between the `WebGLThreads` implementation and diff --git a/components/canvas_traits/Cargo.toml b/components/canvas_traits/Cargo.toml index 1e7e17f8b9e..9d022072511 100644 --- a/components/canvas_traits/Cargo.toml +++ b/components/canvas_traits/Cargo.toml @@ -21,7 +21,7 @@ gleam = "0.6.7" lazy_static = "1" malloc_size_of = { path = "../malloc_size_of" } malloc_size_of_derive = "0.1" -offscreen_gl_context = {version = "0.21", features = ["serde"]} +offscreen_gl_context = {version = "0.22", features = ["serde"]} pixels = {path = "../pixels"} serde = "1.0" serde_bytes = "0.10" diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index e6cb81366d0..cae434ab7d4 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -77,7 +77,7 @@ mime_guess = "2.0.0-alpha.6" msg = {path = "../msg"} net_traits = {path = "../net_traits"} num-traits = "0.2" -offscreen_gl_context = {version = "0.21", features = ["serde"]} +offscreen_gl_context = {version = "0.22", features = ["serde"]} parking_lot = "0.6" phf = "0.7.18" pixels = {path = "../pixels"} diff --git a/tests/wpt/webgl/meta/conformance/canvas/to-data-url-test.html.ini b/tests/wpt/webgl/meta/conformance/canvas/to-data-url-test.html.ini index b3727b5f4bc..ed8c57315e8 100644 --- a/tests/wpt/webgl/meta/conformance/canvas/to-data-url-test.html.ini +++ b/tests/wpt/webgl/meta/conformance/canvas/to-data-url-test.html.ini @@ -1,6 +1,4 @@ [to-data-url-test.html] - expected: - if os == "linux": CRASH [WebGL test #12: should be 0,255,0,255\nat (0, 0) expected: 0,255,0,255 was 255,0,0,255] expected: FAIL diff --git a/tests/wpt/webgl/meta/conformance/textures/misc/texture-size-cube-maps.html.ini b/tests/wpt/webgl/meta/conformance/textures/misc/texture-size-cube-maps.html.ini index c52e4f589ea..d12c43168d2 100644 --- a/tests/wpt/webgl/meta/conformance/textures/misc/texture-size-cube-maps.html.ini +++ b/tests/wpt/webgl/meta/conformance/textures/misc/texture-size-cube-maps.html.ini @@ -1,6 +1,4 @@ [texture-size-cube-maps.html] - expected: - if os == "linux": CRASH [WebGL test #87: 0, 0, 2, 1 should be green\nat (0, 0) expected: 0,255,0,255 was 0,255,255,255] expected: FAIL |