diff --git a/components/gfx/paint_task.rs b/components/gfx/paint_task.rs index 69251d0b0ae..ba9f73a154d 100644 --- a/components/gfx/paint_task.rs +++ b/components/gfx/paint_task.rs @@ -28,6 +28,7 @@ use msg::constellation_msg::PipelineExitType; use profile_traits::mem::{self, Reporter, ReporterRequest, ReportsChan}; use profile_traits::time::{self, profile}; use rand::{self, Rng}; +use skia::gl_context::GLContext; use std::borrow::ToOwned; use std::mem as std_mem; use std::sync::Arc; @@ -467,6 +468,24 @@ struct WorkerThread { native_display: Option, font_context: Box, time_profiler_sender: time::ProfilerChan, + gl_context: Option>, +} + +fn create_gl_context(native_display: Option) -> Option> { + if !opts::get().gpu_painting { + return None; + } + + match native_display { + Some(display) => { + let tile_size = opts::get().tile_size as i32; + GLContext::new(display.platform_display_data(), Size2D::new(tile_size, tile_size)) + } + None => { + warn!("Could not create GLContext, falling back to CPU rasterization"); + None + } + } } impl WorkerThread { @@ -476,14 +495,14 @@ impl WorkerThread { font_cache_task: FontCacheTask, time_profiler_sender: time::ProfilerChan) -> WorkerThread { + let gl_context = create_gl_context(native_display); WorkerThread { sender: sender, receiver: receiver, - native_display: native_display.map(|display| { - display - }), + native_display: native_display, font_context: box FontContext::new(font_cache_task.clone()), time_profiler_sender: time_profiler_sender, + gl_context: gl_context, } } @@ -507,18 +526,19 @@ impl WorkerThread { size: Size2D, layer_buffer: &mut Box) -> DrawTarget { - if !opts::get().gpu_painting { - DrawTarget::new(BackendType::Skia, size, SurfaceFormat::B8G8R8A8) - } else { - let gl_rasterization_context = - layer_buffer.native_surface.gl_rasterization_context(native_display!(self)); - match gl_rasterization_context { - Some(gl_rasterization_context) => { - gl_rasterization_context.make_current(); - DrawTarget::new_with_gl_rasterization_context(gl_rasterization_context, - SurfaceFormat::B8G8R8A8) + match self.gl_context { + Some(ref gl_context) => { + match layer_buffer.native_surface.gl_rasterization_context(gl_context.clone()) { + Some(rasterization_context) => { + DrawTarget::new_with_gl_rasterization_context(rasterization_context, + SurfaceFormat::B8G8R8A8) + } + None => panic!("Could not create GLRasterizationContext for LayerBuffer"), } - None => panic!("Could not create GPU rasterization context for LayerBuffer"), + }, + None => { + // A missing GLContext means we want CPU rasterization. + DrawTarget::new(BackendType::Skia, size, SurfaceFormat::B8G8R8A8) } } } @@ -596,7 +616,7 @@ impl WorkerThread { // Extract the texture from the draw target and place it into its slot in the buffer. If // using CPU painting, upload it first. - if !opts::get().gpu_painting { + if self.gl_context.is_none() { draw_target.snapshot().get_data_surface().with_data(|data| { buffer.native_surface.upload(native_display!(self), data); debug!("painting worker thread uploading to native surface {}", @@ -626,7 +646,7 @@ impl WorkerThread { rect: tile.page_rect, screen_pos: tile.screen_rect, resolution: scale, - painted_with_cpu: !opts::get().gpu_painting, + painted_with_cpu: self.gl_context.is_none(), content_age: tile.content_age, } } diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 4f635924bcc..25a8de073eb 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -55,7 +55,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "azure" version = "0.1.0" -source = "git+https://github.com/servo/rust-azure#5d2baca5fbbe3924a76b57b4b98dbbefd62cea99" +source = "git+https://github.com/servo/rust-azure#53ac8495ca2618a4e795c402ab24ec96d5d6f596" dependencies = [ "core-foundation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -697,7 +697,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "layers" version = "0.1.0" -source = "git+https://github.com/servo/rust-layers#251c48b7a3c0d563acd96397679c114add2c4fd7" +source = "git+https://github.com/servo/rust-layers#e2283b8ec3d3eb2e10afa8a318deda71dd59d11a" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", "cgl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1271,7 +1271,7 @@ dependencies = [ [[package]] name = "skia" version = "0.0.20130412" -source = "git+https://github.com/servo/skia#4569e30e308f33f45ee773e73393d769feaf8494" +source = "git+https://github.com/servo/skia#6eddb1b798c8f1fa9182a4ebfe38f2a84c7ef418" dependencies = [ "cgl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "egl 0.1.0 (git+https://github.com/servo/rust-egl)", diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index dc5dbdfd744..42958a81d11 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -54,7 +54,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "azure" version = "0.1.0" -source = "git+https://github.com/servo/rust-azure#5d2baca5fbbe3924a76b57b4b98dbbefd62cea99" +source = "git+https://github.com/servo/rust-azure#53ac8495ca2618a4e795c402ab24ec96d5d6f596" dependencies = [ "core-foundation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -689,7 +689,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "layers" version = "0.1.0" -source = "git+https://github.com/servo/rust-layers#251c48b7a3c0d563acd96397679c114add2c4fd7" +source = "git+https://github.com/servo/rust-layers#e2283b8ec3d3eb2e10afa8a318deda71dd59d11a" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", "cgl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1268,7 +1268,7 @@ dependencies = [ [[package]] name = "skia" version = "0.0.20130412" -source = "git+https://github.com/servo/skia#4569e30e308f33f45ee773e73393d769feaf8494" +source = "git+https://github.com/servo/skia#6eddb1b798c8f1fa9182a4ebfe38f2a84c7ef418" dependencies = [ "cgl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "egl 0.1.0 (git+https://github.com/servo/rust-egl)", diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index 06c6de27216..3b2db075b9e 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -41,7 +41,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "azure" version = "0.1.0" -source = "git+https://github.com/servo/rust-azure#5d2baca5fbbe3924a76b57b4b98dbbefd62cea99" +source = "git+https://github.com/servo/rust-azure#53ac8495ca2618a4e795c402ab24ec96d5d6f596" dependencies = [ "core-foundation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -623,7 +623,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "layers" version = "0.1.0" -source = "git+https://github.com/servo/rust-layers#251c48b7a3c0d563acd96397679c114add2c4fd7" +source = "git+https://github.com/servo/rust-layers#e2283b8ec3d3eb2e10afa8a318deda71dd59d11a" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", "cgl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1166,7 +1166,7 @@ dependencies = [ [[package]] name = "skia" version = "0.0.20130412" -source = "git+https://github.com/servo/skia#4569e30e308f33f45ee773e73393d769feaf8494" +source = "git+https://github.com/servo/skia#6eddb1b798c8f1fa9182a4ebfe38f2a84c7ef418" dependencies = [ "cgl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "egl 0.1.0 (git+https://github.com/servo/rust-egl)",