diff --git a/Cargo.lock b/Cargo.lock index 2fea61e3e8..4940067882 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1441,17 +1441,6 @@ dependencies = [ "opaque-debug 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "sha2" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "opaque-debug 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "shared_library" version = "0.1.8" @@ -1786,7 +1775,6 @@ dependencies = [ "ron 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", - "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "svg_fmt 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "thread_profiler 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1837,7 +1825,6 @@ name = "webrender_build" version = "0.0.1" dependencies = [ "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", - "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2176,7 +2163,6 @@ dependencies = [ "checksum servo-fontconfig-sys 4.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "62b3e166450f523f4db06c14f02a2d39e76d49b5d8cbd224338d93e3595c156c" "checksum servo-freetype-sys 4.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4ccb6d0d32d277d3ef7dea86203d8210945eb7a45fba89dd445b3595dd0dfc" "checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68" -"checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" "checksum shared_library 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8254bf098ce4d8d7cc7cc6de438c5488adc5297e5b7ffef88816c0a91bd289c1" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "26df3bb03ca5eac2e64192b723d51f56c1b1e0860e7c766281f4598f181acdc8" diff --git a/webrender/Cargo.toml b/webrender/Cargo.toml index 2b2fa3cd49..14677d16ad 100644 --- a/webrender/Cargo.toml +++ b/webrender/Cargo.toml @@ -44,7 +44,6 @@ rayon = "1" ron = { optional = true, version = "0.1.7" } serde = { optional = true, version = "1.0", features = ["serde_derive"] } serde_json = { optional = true, version = "1.0" } -sha2 = "0.8" smallvec = "0.6" thread_profiler = "0.1.1" time = "0.1" diff --git a/webrender/build.rs b/webrender/build.rs index db7dea4412..77fc683fda 100644 --- a/webrender/build.rs +++ b/webrender/build.rs @@ -9,6 +9,8 @@ use std::env; use std::fs::{canonicalize, read_dir, File}; use std::io::prelude::*; use std::path::{Path, PathBuf}; +use std::collections::hash_map::DefaultHasher; +use std::hash::Hasher; use webrender_build::shader::*; fn write_shaders(glsl_files: Vec, shader_file_path: &Path) { @@ -33,13 +35,13 @@ fn write_shaders(glsl_files: Vec, shader_file_path: &Path) { // Compute a digest of the #include-expanded shader source. We store // this as a literal alongside the source string so that we don't need // to hash large strings at runtime. - let mut hasher = Sha256::new(); + let mut hasher = DefaultHasher::new(); let base = glsl.parent().unwrap(); assert!(base.is_dir()); ShaderSourceParser::new().parse( Cow::Owned(shader_source_from_file(&glsl)), &|f| Cow::Owned(shader_source_from_file(&base.join(&format!("{}.glsl", f)))), - &mut |s| hasher.input(s.as_bytes()), + &mut |s| hasher.write(s.as_bytes()), ); let digest: ProgramSourceDigest = hasher.into(); diff --git a/webrender/src/device/gl.rs b/webrender/src/device/gl.rs index cd08775638..bf30978b13 100644 --- a/webrender/src/device/gl.rs +++ b/webrender/src/device/gl.rs @@ -12,7 +12,6 @@ use crate::internal_types::{FastHashMap, LayerIndex, RenderTargetInfo, Swizzle, use crate::util::round_up_to_multiple; use crate::profiler; use log::Level; -use sha2::{Digest, Sha256}; use smallvec::SmallVec; use std::{ borrow::Cow, @@ -759,6 +758,7 @@ impl ProgramSourceInfo { name: &'static str, features: String, ) -> Self { + // Compute the digest. Assuming the device has a `ProgramCache`, this // will always be needed, whereas the source is rarely needed. As such, // we compute the hash by walking the static strings in the same order @@ -771,14 +771,17 @@ impl ProgramSourceInfo { // we precompute the digest of the expanded source file at build time, // and then just hash that digest here. + use std::collections::hash_map::DefaultHasher; + use std::hash::Hasher; + // Setup. - let mut hasher = Sha256::new(); + let mut hasher = DefaultHasher::new(); let version_str = get_shader_version(&*device.gl()); let override_path = device.resource_override_path.as_ref(); let source_and_digest = SHADERS.get(&name).expect("Shader not found"); // Hash the renderer name. - hasher.input(device.renderer_name.as_bytes()); + hasher.write(device.renderer_name.as_bytes()); // Hash the prefix string. build_shader_prefix_string( @@ -786,20 +789,20 @@ impl ProgramSourceInfo { &features, &"DUMMY", &name, - &mut |s| hasher.input(s.as_bytes()), + &mut |s| hasher.write(s.as_bytes()), ); // Hash the shader file contents. We use a precomputed digest, and // verify it in debug builds. if override_path.is_some() || cfg!(debug_assertions) { - let mut h = Sha256::new(); - build_shader_main_string(&name, override_path, &mut |s| h.input(s.as_bytes())); + let mut h = DefaultHasher::new(); + build_shader_main_string(&name, override_path, &mut |s| h.write(s.as_bytes())); let d: ProgramSourceDigest = h.into(); let digest = format!("{}", d); debug_assert!(override_path.is_some() || digest == source_and_digest.digest); - hasher.input(digest.as_bytes()); + hasher.write(digest.as_bytes()); } else { - hasher.input(source_and_digest.digest.as_bytes()); + hasher.write(source_and_digest.digest.as_bytes()); }; // Finish. diff --git a/webrender/src/lib.rs b/webrender/src/lib.rs index a77069f927..0aeb12b3dd 100644 --- a/webrender/src/lib.rs +++ b/webrender/src/lib.rs @@ -184,7 +184,6 @@ extern crate rayon; extern crate ron; #[cfg(feature = "debugger")] extern crate serde_json; -extern crate sha2; #[macro_use] extern crate smallvec; extern crate time; diff --git a/webrender_api/src/display_item_cache.rs b/webrender_api/src/display_item_cache.rs index 53f5b79db5..9118bd7c4a 100644 --- a/webrender_api/src/display_item_cache.rs +++ b/webrender_api/src/display_item_cache.rs @@ -68,8 +68,8 @@ impl DisplayItemCache { ) { if capacity > self.items.len() { self.items.resize_with(capacity, || None::); - // println!("Current cache size: {:?}", - // mem::size_of::() * capacity); + // println!("Current cache size: {:?} elements, {:?} bytes", + // capacity, std::mem::size_of::() * capacity); } } diff --git a/webrender_api/src/display_list.rs b/webrender_api/src/display_list.rs index 2f7d3f1aff..9cf4dd8933 100644 --- a/webrender_api/src/display_list.rs +++ b/webrender_api/src/display_list.rs @@ -911,7 +911,7 @@ pub struct DisplayListBuilder { pub pipeline_id: PipelineId, extra_data: Vec, - extra_data_chunk_len: usize, + extra_data_chunk_start: usize, writing_extra_data_chunk: bool, next_clip_index: usize, @@ -945,7 +945,7 @@ impl DisplayListBuilder { pipeline_id, extra_data: Vec::new(), - extra_data_chunk_len: 0, + extra_data_chunk_start: 0, writing_extra_data_chunk: false, next_clip_index: FIRST_CLIP_NODE_INDEX, @@ -1744,29 +1744,38 @@ impl DisplayListBuilder { self.push_item(&di::DisplayItem::PopAllShadows); } - pub fn start_extra_data_chunk(&mut self) { + fn truncate_extra_data_chunk(&mut self) { + self.extra_data.truncate(self.extra_data_chunk_start) + } + + pub fn start_item_group(&mut self, _key: di::ItemKey) { self.writing_extra_data_chunk = true; - self.extra_data_chunk_len = self.extra_data.len(); + self.extra_data_chunk_start = self.extra_data.len(); } - /// Returns true, if any bytes were written to extra data buffer. - pub fn end_extra_data_chunk(&mut self) -> bool { + pub fn finish_item_group(&mut self, key: di::ItemKey) -> bool { self.writing_extra_data_chunk = false; - (self.extra_data.len() - self.extra_data_chunk_len) > 0 + + let chunk_size = self.extra_data.len() - self.extra_data_chunk_start; + if chunk_size > 0 { + self.push_reuse_items(key); + return true + } + + false } - pub fn push_reuse_item( - &mut self, - key: di::ItemKey, - ) { - let item = di::DisplayItem::ReuseItem(key); - self.push_item(&item); + pub fn cancel_item_group(&mut self) { + debug_assert!(self.writing_extra_data_chunk); + self.writing_extra_data_chunk = false; + self.truncate_extra_data_chunk(); } - pub fn set_cache_size( - &mut self, - cache_size: usize, - ) { + pub fn push_reuse_items(&mut self, key: di::ItemKey) { + self.push_item(&di::DisplayItem::ReuseItem(key)); + } + + pub fn set_cache_size(&mut self, cache_size: usize) { self.cache_size = cache_size; } diff --git a/webrender_build/Cargo.toml b/webrender_build/Cargo.toml index 3227ed7b7a..411118dc3f 100644 --- a/webrender_build/Cargo.toml +++ b/webrender_build/Cargo.toml @@ -12,4 +12,3 @@ serialize_program = ["serde"] [dependencies] serde = { optional = true, version = "1.0", features = ["serde_derive"] } -sha2 = "0.8" diff --git a/webrender_build/src/lib.rs b/webrender_build/src/lib.rs index 7e90fab02c..0abd144725 100644 --- a/webrender_build/src/lib.rs +++ b/webrender_build/src/lib.rs @@ -6,6 +6,4 @@ #[macro_use] extern crate serde; -extern crate sha2; - pub mod shader; diff --git a/webrender_build/src/shader.rs b/webrender_build/src/shader.rs index 3bb04cb39a..48367f3658 100644 --- a/webrender_build/src/shader.rs +++ b/webrender_build/src/shader.rs @@ -7,31 +7,27 @@ //! This module is used during precompilation (build.rs) and regular compilation, //! so it has minimal dependencies. -pub use sha2::{Digest, Sha256}; use std::borrow::Cow; use std::fs::File; use std::io::Read; use std::path::Path; use std::collections::HashSet; +use std::collections::hash_map::DefaultHasher; #[derive(PartialEq, Eq, Hash, Debug, Clone, Default)] #[cfg_attr(feature = "serialize_program", derive(Deserialize, Serialize))] -pub struct ProgramSourceDigest([u8; 32]); +pub struct ProgramSourceDigest(u64); impl ::std::fmt::Display for ProgramSourceDigest { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - for byte in self.0.iter() { - f.write_fmt(format_args!("{:02x}", byte))?; - } - Ok(()) + write!(f, "{:02x}", self.0) } } -impl From for ProgramSourceDigest { - fn from(hasher: Sha256) -> Self { - let mut digest = Self::default(); - digest.0.copy_from_slice(hasher.result().as_slice()); - digest +impl From for ProgramSourceDigest { + fn from(hasher: DefaultHasher) -> Self { + use std::hash::Hasher; + ProgramSourceDigest(hasher.finish()) } }