From 2fa15cd7a950906f77844d4e6d75ac885ab1abf0 Mon Sep 17 00:00:00 2001 From: sotaro Date: Fri, 27 Jan 2017 10:42:28 -0800 Subject: [PATCH] Replaces code conditional on ARM by gl::GlType::default() --- Cargo.lock | 18 ++-- webrender/Cargo.toml | 2 +- webrender/src/device.rs | 230 ++++++++++++++++++++++------------------ 3 files changed, 139 insertions(+), 111 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9bb32d5573..dc1b856dbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,7 @@ dependencies = [ "dwrote 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", "font-loader 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -103,7 +103,7 @@ name = "cgl" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gleam 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -381,7 +381,7 @@ dependencies = [ [[package]] name = "gleam" -version = "0.2.30" +version = "0.2.32" 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)", @@ -674,7 +674,7 @@ dependencies = [ "euclid 0.10.3 (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.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.2.32 (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.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1157,7 +1157,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.4 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1176,7 +1176,7 @@ dependencies = [ "core-graphics 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "dwrote 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "offscreen_gl_context 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1228,7 +1228,7 @@ dependencies = [ "bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "webrender 0.11.1", "webrender_traits 0.11.0", @@ -1240,7 +1240,7 @@ version = "0.1.0" dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", - "gleam 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "gleam 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "webrender 0.11.1", "webrender_traits 0.11.0", @@ -1326,7 +1326,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0912515a8ff24ba900422ecda800b52f4016a56251922d397c576bf92c690518" "checksum gif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01c7c19a035de94bd7afbaa62c241aadfbdf1a70f560b348d2312eafa566ca16" "checksum gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1d8edc81c5ae84605a62f5dac661a2313003b26d59839f81d47d46cf0f16a55" -"checksum gleam 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "6af023107aa969ccf8868a0304fead4b2f813c19aa9a6a243fddc041f3e51da5" +"checksum gleam 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)" = "9590e0e578d528a080c5abac678e7efbe349a73c7316faafd4073edf5f462d01" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum glutin 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "06786fae66e7aa8464b3d8d3fb7a7c470f89d62ae511f9613ea7fbbeef61d680" "checksum glutin 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f10fe6cb2f7e559e470cc0dfa2c89a4f476fc99ec1862632b057e68c3831eb7a" diff --git a/webrender/Cargo.toml b/webrender/Cargo.toml index de468d2ca2..6a0e3a84bd 100644 --- a/webrender/Cargo.toml +++ b/webrender/Cargo.toml @@ -20,7 +20,7 @@ bit-set = "0.4" byteorder = "0.5" euclid = "0.10.3" fnv="1.0" -gleam = "0.2.30" +gleam = "0.2.32" lazy_static = "0.2" log = "0.3" num-traits = "0.1.32" diff --git a/webrender/src/device.rs b/webrender/src/device.rs index dcb73c2d56..1f85a500ff 100644 --- a/webrender/src/device.rs +++ b/webrender/src/device.rs @@ -33,11 +33,9 @@ const GL_FORMAT_BGRA: gl::GLuint = gl::BGRA; #[cfg(target_os = "android")] const GL_FORMAT_BGRA: gl::GLuint = gl::BGRA_EXT; -#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))] -const SHADER_VERSION: &'static str = "#version 150\n"; +const SHADER_VERSION_GL: &'static str = "#version 150\n"; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -const SHADER_VERSION: &'static str = "#version 300 es\n"; +const SHADER_VERSION_GLES: &'static str = "#version 300 es\n"; static SHADER_PREAMBLE: &'static str = "shared"; @@ -80,6 +78,21 @@ enum FBOTarget { Draw, } +fn get_gl_format_bgra() -> gl::GLuint { + GL_FORMAT_BGRA +} + +fn get_shader_version() -> &'static str { + match gl::GlType::default() { + gl::GlType::Gl => { + SHADER_VERSION_GL + } + gl::GlType::Gles => { + SHADER_VERSION_GLES + } + } +} + fn get_optional_shader_source(shader_name: &str, base_path: &Option) -> Option { if let Some(ref base) = *base_path { let shader_path = base.join(&format!("{}.glsl", shader_name)); @@ -509,25 +522,26 @@ pub struct GpuFrameProfile { } impl GpuFrameProfile { - #[cfg(not(target_os = "android"))] fn new() -> GpuFrameProfile { - let queries = gl::gen_queries(MAX_EVENTS_PER_FRAME as gl::GLint); - - GpuFrameProfile { - queries: queries, - samples: Vec::new(), - next_query: 0, - pending_query: 0, - } - } - - #[cfg(target_os = "android")] - fn new() -> GpuFrameProfile { - GpuFrameProfile { - queries: Vec::new(), - samples: Vec::new(), - next_query: 0, - pending_query: 0, + match gl::GlType::default() { + gl::GlType::Gl => { + let queries = gl::gen_queries(MAX_EVENTS_PER_FRAME as gl::GLint); + + GpuFrameProfile { + queries: queries, + samples: Vec::new(), + next_query: 0, + pending_query: 0, + } + } + gl::GlType::Gles => { + GpuFrameProfile { + queries: Vec::new(), + samples: Vec::new(), + next_query: 0, + pending_query: 0, + } + } } } @@ -537,76 +551,80 @@ impl GpuFrameProfile { self.samples.clear(); } - #[cfg(not(target_os = "android"))] fn end_frame(&mut self) { - if self.pending_query != 0 { - gl::end_query(gl::TIME_ELAPSED); + match gl::GlType::default() { + gl::GlType::Gl => { + if self.pending_query != 0 { + gl::end_query(gl::TIME_ELAPSED); + } + } + gl::GlType::Gles => (), } } - #[cfg(target_os = "android")] - fn end_frame(&mut self) { - } - - #[cfg(not(target_os = "android"))] fn add_marker(&mut self, tag: T) -> GpuMarker where T: NamedTag { - if self.pending_query != 0 { - gl::end_query(gl::TIME_ELAPSED); - } + match gl::GlType::default() { + gl::GlType::Gl => { + if self.pending_query != 0 { + gl::end_query(gl::TIME_ELAPSED); + } - let marker = GpuMarker::new(tag.get_label()); + let marker = GpuMarker::new(tag.get_label()); - if self.next_query < MAX_EVENTS_PER_FRAME { - self.pending_query = self.queries[self.next_query]; - gl::begin_query(gl::TIME_ELAPSED, self.pending_query); - self.samples.push(GpuSample { - tag: tag, - time_ns: 0, - }); - } else { - self.pending_query = 0; - } - - self.next_query += 1; - marker - } + if self.next_query < MAX_EVENTS_PER_FRAME { + self.pending_query = self.queries[self.next_query]; + gl::begin_query(gl::TIME_ELAPSED, self.pending_query); + self.samples.push(GpuSample { + tag: tag, + time_ns: 0, + }); + } else { + self.pending_query = 0; + } - #[cfg(target_os = "android")] - fn add_marker(&mut self, tag: T) { - self.samples.push(GpuSample { - tag: tag, - time_ns: 0, - }); + self.next_query += 1; + marker + } + gl::GlType::Gles => { + let marker = GpuMarker::new(tag.get_label()); + self.samples.push(GpuSample { + tag: tag, + time_ns: 0, + }); + marker + } + } } fn is_valid(&self) -> bool { self.next_query <= MAX_EVENTS_PER_FRAME } - #[cfg(not(target_os = "android"))] fn build_samples(&mut self) -> Vec> { - for (index, sample) in self.samples.iter_mut().enumerate() { - sample.time_ns = gl::get_query_object_ui64v(self.queries[index], gl::QUERY_RESULT) - } - - mem::replace(&mut self.samples, Vec::new()) - } + match gl::GlType::default() { + gl::GlType::Gl => { + for (index, sample) in self.samples.iter_mut().enumerate() { + sample.time_ns = gl::get_query_object_ui64v(self.queries[index], gl::QUERY_RESULT) + } - #[cfg(target_os = "android")] - fn build_samples(&mut self) -> Vec> { - mem::replace(&mut self.samples, Vec::new()) + mem::replace(&mut self.samples, Vec::new()) + } + gl::GlType::Gles => { + mem::replace(&mut self.samples, Vec::new()) + } + } } } impl Drop for GpuFrameProfile { - #[cfg(not(target_os = "android"))] - fn drop(&mut self) { - gl::delete_queries(&self.queries); - } - - #[cfg(target_os = "android")] fn drop(&mut self) { + match gl::GlType::default() { + gl::GlType::Gl => { + gl::delete_queries(&self.queries); + } + gl::GlType::Gles => (), + } } } @@ -648,47 +666,54 @@ impl GpuProfiler { self.next_frame = (self.next_frame + 1) % MAX_PROFILE_FRAMES; } - #[cfg(not(target_os = "android"))] pub fn add_marker(&mut self, tag: T) -> GpuMarker where T: NamedTag { - self.frames[self.next_frame].add_marker(tag) - } - - #[cfg(target_os = "android")] - pub fn add_marker(&mut self, tag: T) { - self.frames[self.next_frame].add_marker(tag) + match gl::GlType::default() { + gl::GlType::Gl => { + self.frames[self.next_frame].add_marker(tag) + } + gl::GlType::Gles => { + self.frames[self.next_frame].add_marker(tag) + } + } } } #[must_use] pub struct GpuMarker(()); -#[cfg(any(target_arch="arm", target_arch="aarch64"))] -impl GpuMarker { - pub fn new(_: &str) -> GpuMarker { - GpuMarker(()) - } - - pub fn fire(_: &str) {} -} - - -#[cfg(not(any(target_arch="arm", target_arch="aarch64")))] impl GpuMarker { pub fn new(message: &str) -> GpuMarker { - gl::push_group_marker_ext(message); - GpuMarker(()) + match gl::GlType::default() { + gl::GlType::Gl => { + gl::push_group_marker_ext(message); + GpuMarker(()) + } + gl::GlType::Gles => { + GpuMarker(()) + } + } + } pub fn fire(message: &str) { - gl::insert_event_marker_ext(message); + match gl::GlType::default() { + gl::GlType::Gl => { + gl::insert_event_marker_ext(message); + } + gl::GlType::Gles => (), + } } } -#[cfg(not(any(target_arch="arm", target_arch="aarch64")))] impl Drop for GpuMarker { fn drop(&mut self) { - gl::pop_group_marker_ext(); + match gl::GlType::default() { + gl::GlType::Gl => { + gl::pop_group_marker_ext(); + } + gl::GlType::Gles => (), + } } } @@ -876,7 +901,7 @@ impl Device { debug!("compile {:?}", name); let mut s = String::new(); - s.push_str(SHADER_VERSION); + s.push_str(get_shader_version()); for prefix in shader_preamble { s.push_str(&prefix); } @@ -1616,13 +1641,13 @@ impl Device { expanded_data.push(*byte); expanded_data.push(*byte); } - (GL_FORMAT_BGRA, 4, expanded_data.as_slice()) + (get_gl_format_bgra(), 4, expanded_data.as_slice()) } else { (GL_FORMAT_A, 1, data) } } ImageFormat::RGB8 => (gl::RGB, 3, data), - ImageFormat::RGBA8 => (GL_FORMAT_BGRA, 4, data), + ImageFormat::RGBA8 => (get_gl_format_bgra(), 4, data), ImageFormat::Invalid | ImageFormat::RGBAF32 => unreachable!(), }; @@ -1951,17 +1976,20 @@ fn gl_texture_formats_for_image_format(format: ImageFormat) -> (gl::GLint, gl::G match format { ImageFormat::A8 => { if cfg!(any(target_arch="arm", target_arch="aarch64")) { - (GL_FORMAT_BGRA as gl::GLint, GL_FORMAT_BGRA) + (get_gl_format_bgra() as gl::GLint, get_gl_format_bgra()) } else { (GL_FORMAT_A as gl::GLint, GL_FORMAT_A) } }, ImageFormat::RGB8 => (gl::RGB as gl::GLint, gl::RGB), ImageFormat::RGBA8 => { - if cfg!(any(target_arch="arm", target_arch="aarch64")) { - (GL_FORMAT_BGRA as gl::GLint, GL_FORMAT_BGRA) - } else { - (gl::RGBA as gl::GLint, GL_FORMAT_BGRA) + match gl::GlType::default() { + gl::GlType::Gl => { + (gl::RGBA as gl::GLint, get_gl_format_bgra()) + } + gl::GlType::Gles => { + (get_gl_format_bgra() as gl::GLint, get_gl_format_bgra()) + } } } ImageFormat::RGBAF32 => (gl::RGBA32F as gl::GLint, gl::RGBA),