From 6dd3bc29e15927ed1250f2ee49d8c3979709125f Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Fri, 31 Mar 2017 13:38:15 +1000 Subject: [PATCH] Update WR (various optimizations, gradient improvements). --- Cargo.lock | 76 ++++++++++++------------ components/canvas/canvas_paint_thread.rs | 49 ++++++++++----- components/canvas/webgl_paint_thread.rs | 52 ++++++++++------ components/compositing/compositor.rs | 9 ++- components/layout/webrender_helpers.rs | 4 +- 5 files changed, 112 insertions(+), 78 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c051407a71f..49f552b7a14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -291,13 +291,13 @@ dependencies = [ "canvas_traits 0.0.1", "cssparser 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "offscreen_gl_context 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", "servo_config 0.0.1", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", ] [[package]] @@ -311,7 +311,7 @@ dependencies = [ "ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", ] [[package]] @@ -341,7 +341,7 @@ name = "cgl" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gleam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -419,7 +419,7 @@ version = "0.0.1" dependencies = [ "euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", - "gleam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -432,8 +432,8 @@ dependencies = [ "servo_url 0.0.1", "style_traits 0.0.1", "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", - "webrender 0.26.0 (git+https://github.com/servo/webrender)", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", ] [[package]] @@ -467,7 +467,7 @@ dependencies = [ "servo_remutex 0.0.1", "servo_url 0.0.1", "style_traits 0.0.1", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", "webvr_traits 0.0.1", ] @@ -696,7 +696,7 @@ dependencies = [ "compositing 0.0.1", "devtools 0.0.1", "euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "glutin_app 0.0.1", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "libservo 0.0.1", @@ -709,7 +709,7 @@ dependencies = [ "servo_geometry 0.0.1", "servo_url 0.0.1", "style_traits 0.0.1", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", "x11 2.12.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -996,7 +996,7 @@ dependencies = [ "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", "truetype 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-script 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", "xi-unicode 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1041,7 +1041,7 @@ dependencies = [ [[package]] name = "gleam" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1061,7 +1061,7 @@ dependencies = [ "compositing 0.0.1", "euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "net_traits 0.0.1", @@ -1075,7 +1075,7 @@ dependencies = [ "servo_url 0.0.1", "style_traits 0.0.1", "user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "x11 2.12.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1261,7 +1261,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cgl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "leaky-cow 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1385,7 +1385,7 @@ dependencies = [ "style_traits 0.0.1", "unicode-bidi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-script 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", ] [[package]] @@ -1425,7 +1425,7 @@ dependencies = [ "servo_geometry 0.0.1", "servo_url 0.0.1", "style 0.0.1", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", ] [[package]] @@ -1439,7 +1439,7 @@ dependencies = [ "profile_traits 0.0.1", "script_traits 0.0.1", "servo_url 0.0.1", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", ] [[package]] @@ -1498,7 +1498,7 @@ dependencies = [ "euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "gaol 0.0.1 (git+https://github.com/servo/gaol)", "gfx 0.0.1", - "gleam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "layout_thread 0.0.1", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1516,8 +1516,8 @@ dependencies = [ "style 0.0.1", "style_traits 0.0.1", "webdriver_server 0.0.1", - "webrender 0.26.0 (git+https://github.com/servo/webrender)", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", "webvr 0.0.1", "webvr_traits 0.0.1", ] @@ -1666,7 +1666,7 @@ dependencies = [ "heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", ] [[package]] @@ -1708,7 +1708,7 @@ dependencies = [ "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", ] [[package]] @@ -1768,7 +1768,7 @@ dependencies = [ "servo_url 0.0.1", "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", ] [[package]] @@ -1857,7 +1857,7 @@ dependencies = [ "euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2286,7 +2286,7 @@ dependencies = [ "tinyfiledialogs 2.5.9 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", "webvr 0.0.1", "webvr_traits 0.0.1", "xml5ever 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2507,7 +2507,7 @@ dependencies = [ "cmake 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "expat-sys 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "glx 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "io-surface 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3144,8 +3144,8 @@ dependencies = [ [[package]] name = "webrender" -version = "0.26.0" -source = "git+https://github.com/servo/webrender#b2dd9f792d0cb3dfc591567c105755f56f35956d" +version = "0.27.0" +source = "git+https://github.com/servo/webrender#4b72bb1921628d01b08ab356c0f2365a927b711e" dependencies = [ "app_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.0.0-alpha2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3159,7 +3159,7 @@ dependencies = [ "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "freetype 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "gamma-lut 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3167,20 +3167,20 @@ dependencies = [ "thread_profiler 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", ] [[package]] name = "webrender_traits" -version = "0.27.0" -source = "git+https://github.com/servo/webrender#b2dd9f792d0cb3dfc591567c105755f56f35956d" +version = "0.28.0" +source = "git+https://github.com/servo/webrender#4b72bb1921628d01b08ab356c0f2365a927b711e" dependencies = [ "app_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "dwrote 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "offscreen_gl_context 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3197,7 +3197,7 @@ dependencies = [ "msg 0.0.1", "script_traits 0.0.1", "servo_config 0.0.1", - "webrender_traits 0.27.0 (git+https://github.com/servo/webrender)", + "webrender_traits 0.28.0 (git+https://github.com/servo/webrender)", "webvr_traits 0.0.1", ] @@ -3375,7 +3375,7 @@ dependencies = [ "checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685" "checksum gif 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8a80d6fe9e52f637df9afd4779449a7be17c39cc9c35b01589bb833f956ba596" "checksum gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1d8edc81c5ae84605a62f5dac661a2313003b26d59839f81d47d46cf0f16a55" -"checksum gleam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2958396a0a358d2de747b31329f5ae2229070602b0f51edd5d682f92c307c332" +"checksum gleam 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3232655dbe4fc5ab688c05024f2c816b5d20c19ad8216d5c7d85cf915b24e005" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum glx 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b280007fa9c7442cfd1e0b1addb8d1a59240267110e8705f8f7e2c7bfb7e2f72" "checksum harfbuzz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6b76113246f5c089dcf272cf89c3f61168a4d77b50ec5b2c1fab8c628c9ea762" @@ -3536,8 +3536,8 @@ dependencies = [ "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "bb08f9e670fab86099470b97cd2b252d6527f0b3cc1401acdb595ffc9dd288ff" "checksum webdriver 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d548aabf87411b1b4ba91fd07eacd8b238135c7131a452b8a9f6386209167e18" -"checksum webrender 0.26.0 (git+https://github.com/servo/webrender)" = "" -"checksum webrender_traits 0.27.0 (git+https://github.com/servo/webrender)" = "" +"checksum webrender 0.27.0 (git+https://github.com/servo/webrender)" = "" +"checksum webrender_traits 0.28.0 (git+https://github.com/servo/webrender)" = "" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum ws 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "04614a58714f3fd4a8b1da4bcae9f031c532d35988c3d39627619248113f8be8" diff --git a/components/canvas/canvas_paint_thread.rs b/components/canvas/canvas_paint_thread.rs index 7f09603d322..39c633e127b 100644 --- a/components/canvas/canvas_paint_thread.rs +++ b/components/canvas/canvas_paint_thread.rs @@ -18,6 +18,7 @@ use ipc_channel::ipc::{self, IpcSender}; use num_traits::ToPrimitive; use std::borrow::ToOwned; use std::mem; +use std::sync::Arc; use std::thread; use webrender_traits; @@ -60,7 +61,7 @@ pub struct CanvasPaintThread<'a> { state: CanvasPaintState<'a>, saved_states: Vec>, webrender_api: webrender_traits::RenderApi, - webrender_image_key: webrender_traits::ImageKey, + image_key: Option, } #[derive(Clone)] @@ -106,14 +107,13 @@ impl<'a> CanvasPaintThread<'a> { let draw_target = CanvasPaintThread::create(size); let path_builder = draw_target.create_path_builder(); let webrender_api = webrender_api_sender.create_api(); - let webrender_image_key = webrender_api.generate_image_key(); CanvasPaintThread { drawtarget: draw_target, path_builder: path_builder, state: CanvasPaintState::new(antialias), saved_states: vec![], webrender_api: webrender_api, - webrender_image_key: webrender_image_key, + image_key: None, } } @@ -558,20 +558,35 @@ impl<'a> CanvasPaintThread<'a> { fn send_data(&mut self, chan: IpcSender) { self.drawtarget.snapshot().get_data_surface().with_data(|element| { let size = self.drawtarget.get_size(); - self.webrender_api.update_image(self.webrender_image_key, - webrender_traits::ImageDescriptor { - width: size.width as u32, - height: size.height as u32, - stride: None, - format: webrender_traits::ImageFormat::RGBA8, - offset: 0, - is_opaque: false, - }, - element.into(), - None); + + let descriptor = webrender_traits::ImageDescriptor { + width: size.width as u32, + height: size.height as u32, + stride: None, + format: webrender_traits::ImageFormat::RGBA8, + offset: 0, + is_opaque: false, + }; + let data = webrender_traits::ImageData::Raw(Arc::new(element.into())); + + match self.image_key { + Some(image_key) => { + self.webrender_api.update_image(image_key, + descriptor, + data, + None); + } + None => { + self.image_key = Some(self.webrender_api.generate_image_key()); + self.webrender_api.add_image(self.image_key.unwrap(), + descriptor, + data, + None); + } + } let data = CanvasImageData { - image_key: self.webrender_image_key, + image_key: self.image_key.unwrap(), }; chan.send(CanvasData::Image(data)).unwrap(); }) @@ -728,7 +743,9 @@ impl<'a> CanvasPaintThread<'a> { impl<'a> Drop for CanvasPaintThread<'a> { fn drop(&mut self) { - self.webrender_api.delete_image(self.webrender_image_key); + if let Some(image_key) = self.image_key { + self.webrender_api.delete_image(image_key); + } } } diff --git a/components/canvas/webgl_paint_thread.rs b/components/canvas/webgl_paint_thread.rs index b5893c15058..9f87d3a4f51 100644 --- a/components/canvas/webgl_paint_thread.rs +++ b/components/canvas/webgl_paint_thread.rs @@ -11,6 +11,7 @@ use offscreen_gl_context::{ColorAttachmentType, GLContext, GLLimits}; use offscreen_gl_context::{GLContextAttributes, NativeGLContext, OSMesaContext}; use servo_config::opts; use std::borrow::ToOwned; +use std::sync::Arc; use std::sync::mpsc::channel; use std::thread; use webrender_traits; @@ -101,7 +102,7 @@ impl GLContextWrapper { enum WebGLPaintTaskData { WebRender(webrender_traits::RenderApi, webrender_traits::WebGLContextId), - Readback(GLContextWrapper, webrender_traits::RenderApi, webrender_traits::ImageKey), + Readback(GLContextWrapper, webrender_traits::RenderApi, Option), } pub struct WebGLPaintThread { @@ -116,10 +117,9 @@ fn create_readback_painter(size: Size2D, -> Result<(WebGLPaintThread, GLLimits), String> { let context = try!(GLContextWrapper::new(size, attrs, gl_type)); let limits = context.get_limits(); - let image_key = webrender_api.generate_image_key(); let painter = WebGLPaintThread { size: size, - data: WebGLPaintTaskData::Readback(context, webrender_api, image_key) + data: WebGLPaintTaskData::Readback(context, webrender_api, None) }; Ok((painter, limits)) @@ -229,7 +229,7 @@ impl WebGLPaintThread { fn send_data(&mut self, chan: IpcSender) { match self.data { - WebGLPaintTaskData::Readback(ref ctx, ref webrender_api, image_key) => { + WebGLPaintTaskData::Readback(ref ctx, ref webrender_api, ref mut image_key) => { let width = self.size.width as usize; let height = self.size.height as usize; @@ -250,22 +250,34 @@ impl WebGLPaintThread { // rgba -> bgra byte_swap(&mut pixels); - // TODO: This shouldn't be a common path, but try to avoid - // the spurious clone(). - webrender_api.update_image(image_key, - webrender_traits::ImageDescriptor { - width: width as u32, - height: height as u32, - stride: None, - format: webrender_traits::ImageFormat::RGBA8, - offset: 0, - is_opaque: false, - }, - pixels.clone(), - None); + let descriptor = webrender_traits::ImageDescriptor { + width: width as u32, + height: height as u32, + stride: None, + format: webrender_traits::ImageFormat::RGBA8, + offset: 0, + is_opaque: false, + }; + let data = webrender_traits::ImageData::Raw(Arc::new(pixels)); + + match *image_key { + Some(image_key) => { + webrender_api.update_image(image_key, + descriptor, + data, + None); + } + None => { + *image_key = Some(webrender_api.generate_image_key()); + webrender_api.add_image(image_key.unwrap(), + descriptor, + data, + None); + } + } let image_data = CanvasImageData { - image_key: image_key, + image_key: image_key.unwrap(), }; chan.send(CanvasData::Image(image_data)).unwrap(); @@ -307,7 +319,9 @@ impl WebGLPaintThread { impl Drop for WebGLPaintThread { fn drop(&mut self) { if let WebGLPaintTaskData::Readback(_, ref mut wr, image_key) = self.data { - wr.delete_image(image_key); + if let Some(image_key) = image_key { + wr.delete_image(image_key); + } } } } diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index f679e3ee1b3..201bcc9e858 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -76,9 +76,12 @@ trait ConvertScrollRootIdFromWebRender { fn from_webrender(&self) -> ScrollRootId; } -impl ConvertScrollRootIdFromWebRender for usize { +impl ConvertScrollRootIdFromWebRender for u64 { fn from_webrender(&self) -> ScrollRootId { - ScrollRootId(*self) + // This conversion is lossy on 32 bit platforms, + // but we only actually use the bottom 32 bits + // on Servo anyway. + ScrollRootId(*self as usize) } } @@ -794,7 +797,7 @@ impl IOCompositor { pipeline_id: PipelineId, scroll_root_id: ScrollRootId, point: Point2D) { - let id = ScrollLayerId::new(scroll_root_id.0, pipeline_id.to_webrender()); + let id = ScrollLayerId::new(scroll_root_id.0 as u64, pipeline_id.to_webrender()); self.webrender_api.scroll_layer_with_id(LayoutPoint::from_untyped(&point), id); } diff --git a/components/layout/webrender_helpers.rs b/components/layout/webrender_helpers.rs index 87c9305596f..ec83eb996e2 100644 --- a/components/layout/webrender_helpers.rs +++ b/components/layout/webrender_helpers.rs @@ -425,7 +425,7 @@ impl WebRenderDisplayItemConverter for DisplayItem { vec![], None); - let provided_id = ScrollLayerId::new(item.scroll_root.id.0, builder.pipeline_id); + let provided_id = ScrollLayerId::new(item.scroll_root.id.0 as u64, builder.pipeline_id); let id = builder.define_clip(clip, item.scroll_root.size.to_sizef(), Some(provided_id)); @@ -444,7 +444,7 @@ impl WebRenderScrollRootIdConverter for ScrollRootId { if *self == ScrollRootId::root() { ScrollLayerId::root_scroll_layer(pipeline_id) } else { - ScrollLayerId::new(self.0, pipeline_id) + ScrollLayerId::new(self.0 as u64, pipeline_id) } } }