servo: Merge #18221 - Use FnvHashMap in WebGL implementation (from MortimerGoro:webgl_fnv); r=jdm

<!-- Please describe your changes on the following line: -->

Follow up from the WebGL redesign: https://github.com/servo/servo/pull/17891

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 4598ddb0bcf62aa2ec54d896a67eae20db4588c0

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : ae0f3f7bedbe4a6d2313cc3e0120a347b597d91c
This commit is contained in:
Imanol Fernandez 2017-08-24 16:25:53 -05:00
Родитель 78f10aaa0c
Коммит 08d3ad7c92
6 изменённых файлов: 30 добавлений и 26 удалений

1
servo/Cargo.lock сгенерированный
Просмотреть файл

@ -329,6 +329,7 @@ dependencies = [
"compositing 0.0.1",
"cssparser 0.19.2 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",

Просмотреть файл

@ -15,6 +15,7 @@ canvas_traits = {path = "../canvas_traits"}
compositing = {path = "../compositing"}
cssparser = "0.19"
euclid = "0.15"
fnv = "1.0"
gleam = "0.4"
ipc-channel = "0.8"
log = "0.3.5"

Просмотреть файл

@ -9,6 +9,7 @@ extern crate canvas_traits;
extern crate compositing;
extern crate cssparser;
extern crate euclid;
extern crate fnv;
extern crate gleam;
extern crate ipc_channel;
#[macro_use] extern crate log;

Просмотреть файл

@ -5,9 +5,9 @@
use canvas_traits::canvas::byte_swap;
use canvas_traits::webgl::*;
use euclid::Size2D;
use fnv::FnvHashMap;
use gleam::gl;
use offscreen_gl_context::{GLContext, GLContextAttributes, GLLimits, NativeGLContextMethods};
use std::collections::HashMap;
use std::mem;
use std::thread;
use super::gl_context::{GLContextFactory, GLContextWrapper};
@ -26,9 +26,9 @@ pub struct WebGLThread<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver
/// Channel used to generate/update or delete `webrender_api::ImageKey`s.
webrender_api: webrender_api::RenderApi,
/// Map of live WebGLContexts.
contexts: HashMap<WebGLContextId, GLContextWrapper>,
contexts: FnvHashMap<WebGLContextId, GLContextWrapper>,
/// Cached information for WebGLContexts.
cached_context_info: HashMap<WebGLContextId, WebGLContextInfo>,
cached_context_info: FnvHashMap<WebGLContextId, WebGLContextInfo>,
/// Current bound context.
bound_context_id: Option<WebGLContextId>,
/// Id generator for new WebGLContexts.
@ -47,8 +47,8 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
WebGLThread {
gl_factory,
webrender_api: webrender_api_sender.create_api(),
contexts: HashMap::new(),
cached_context_info: HashMap::new(),
contexts: Default::default(),
cached_context_info: Default::default(),
bound_context_id: None,
next_webgl_id: 0,
webvr_compositor,
@ -335,7 +335,7 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
/// Gets a reference to a GLContextWrapper for a given WebGLContextId and makes it current if required.
fn make_current_if_needed<'a>(context_id: WebGLContextId,
contexts: &'a HashMap<WebGLContextId, GLContextWrapper>,
contexts: &'a FnvHashMap<WebGLContextId, GLContextWrapper>,
bound_id: &mut Option<WebGLContextId>) -> Option<&'a GLContextWrapper> {
contexts.get(&context_id).and_then(|ctx| {
if Some(context_id) != *bound_id {
@ -349,7 +349,7 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
/// Gets a mutable reference to a GLContextWrapper for a WebGLContextId and makes it current if required.
fn make_current_if_needed_mut<'a>(context_id: WebGLContextId,
contexts: &'a mut HashMap<WebGLContextId, GLContextWrapper>,
contexts: &'a mut FnvHashMap<WebGLContextId, GLContextWrapper>,
bound_id: &mut Option<WebGLContextId>) -> &'a mut GLContextWrapper {
let ctx = contexts.get_mut(&context_id).expect("WebGLContext not found!");
if Some(context_id) != *bound_id {

Просмотреть файл

@ -12,13 +12,14 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi
use dom::bindings::js::Root;
use dom::bindings::trace::JSTraceable;
use dom::webglrenderingcontext::WebGLRenderingContext;
use fnv::{FnvHashMap, FnvHashSet};
use gleam::gl::GLenum;
use heapsize::HeapSizeOf;
use js::jsapi::{JSContext, JSObject};
use js::jsval::JSVal;
use ref_filter_map::ref_filter_map;
use std::cell::Ref;
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
use super::{ext, WebGLExtension};
use super::wrapper::{WebGLExtensionWrapper, TypedWebGLExtensionWrapper};
@ -46,26 +47,26 @@ const DEFAULT_DISABLED_GET_PARAMETER_NAMES: [GLenum; 1] = [
/// WebGL features that are enabled/disabled by WebGL Extensions.
#[derive(HeapSizeOf, JSTraceable)]
struct WebGLExtensionFeatures {
gl_extensions: HashSet<String>,
disabled_tex_types: HashSet<GLenum>,
not_filterable_tex_types: HashSet<GLenum>,
effective_tex_internal_formats: HashMap<TexFormatType, u32>,
query_parameter_handlers: HashMap<GLenum, WebGLQueryParameterHandler>,
gl_extensions: FnvHashSet<String>,
disabled_tex_types: FnvHashSet<GLenum>,
not_filterable_tex_types: FnvHashSet<GLenum>,
effective_tex_internal_formats: FnvHashMap<TexFormatType, u32>,
query_parameter_handlers: FnvHashMap<GLenum, WebGLQueryParameterHandler>,
/// WebGL Hint() targets enabled by extensions.
hint_targets: HashSet<GLenum>,
hint_targets: FnvHashSet<GLenum>,
/// WebGL GetParameter() names enabled by extensions.
disabled_get_parameter_names: HashSet<GLenum>,
disabled_get_parameter_names: FnvHashSet<GLenum>,
}
impl Default for WebGLExtensionFeatures {
fn default() -> WebGLExtensionFeatures {
WebGLExtensionFeatures {
gl_extensions: HashSet::new(),
gl_extensions: Default::default(),
disabled_tex_types: DEFAULT_DISABLED_TEX_TYPES.iter().cloned().collect(),
not_filterable_tex_types: DEFAULT_NOT_FILTERABLE_TEX_TYPES.iter().cloned().collect(),
effective_tex_internal_formats: HashMap::new(),
query_parameter_handlers: HashMap::new(),
hint_targets: HashSet::new(),
effective_tex_internal_formats: Default::default(),
query_parameter_handlers: Default::default(),
hint_targets: Default::default(),
disabled_get_parameter_names: DEFAULT_DISABLED_GET_PARAMETER_NAMES.iter().cloned().collect(),
}
}
@ -90,8 +91,8 @@ impl WebGLExtensions {
pub fn init_once<F>(&self, cb: F) where F: FnOnce() -> String {
if self.extensions.borrow().len() == 0 {
let gl_str = cb();
self.features.borrow_mut().gl_extensions = HashSet::from_iter(gl_str.split(&[',', ' '][..])
.map(|s| s.into()));
self.features.borrow_mut().gl_extensions = FnvHashSet::from_iter(gl_str.split(&[',', ' '][..])
.map(|s| s.into()));
self.register_all_extensions();
}
}

Просмотреть файл

@ -44,6 +44,7 @@ use dom::webgluniformlocation::WebGLUniformLocation;
use dom::window::Window;
use dom_struct::dom_struct;
use euclid::Size2D;
use fnv::FnvHashMap;
use half::f16;
use js::conversions::ConversionBehavior;
use js::jsapi::{JSContext, JSObject, Type, Rooted};
@ -55,7 +56,6 @@ use offscreen_gl_context::{GLContextAttributes, GLLimits};
use script_layout_interface::HTMLCanvasDataSource;
use servo_config::prefs::PREFS;
use std::cell::Cell;
use std::collections::HashMap;
use webrender_api;
type ImagePixelResult = Result<(Vec<u8>, Size2D<i32>, bool), ()>;
@ -151,7 +151,7 @@ pub struct WebGLRenderingContext {
bound_texture_cube_map: MutNullableJS<WebGLTexture>,
bound_buffer_array: MutNullableJS<WebGLBuffer>,
bound_buffer_element_array: MutNullableJS<WebGLBuffer>,
bound_attrib_buffers: DOMRefCell<HashMap<u32, JS<WebGLBuffer>>>,
bound_attrib_buffers: DOMRefCell<FnvHashMap<u32, JS<WebGLBuffer>>>,
current_program: MutNullableJS<WebGLProgram>,
#[ignore_heap_size_of = "Because it's small"]
current_vertex_attrib_0: Cell<(f32, f32, f32, f32)>,
@ -194,7 +194,7 @@ impl WebGLRenderingContext {
bound_texture_cube_map: MutNullableJS::new(None),
bound_buffer_array: MutNullableJS::new(None),
bound_buffer_element_array: MutNullableJS::new(None),
bound_attrib_buffers: DOMRefCell::new(HashMap::new()),
bound_attrib_buffers: DOMRefCell::new(Default::default()),
bound_renderbuffer: MutNullableJS::new(None),
current_program: MutNullableJS::new(None),
current_vertex_attrib_0: Cell::new((0f32, 0f32, 0f32, 1f32)),
@ -239,12 +239,12 @@ impl WebGLRenderingContext {
}
}
pub fn borrow_bound_attrib_buffers(&self) -> Ref<HashMap<u32, JS<WebGLBuffer>>> {
pub fn borrow_bound_attrib_buffers(&self) -> Ref<FnvHashMap<u32, JS<WebGLBuffer>>> {
self.bound_attrib_buffers.borrow()
}
pub fn set_bound_attrib_buffers<'a, T>(&self, iter: T) where T: Iterator<Item=(u32, &'a WebGLBuffer)> {
*self.bound_attrib_buffers.borrow_mut() = HashMap::from_iter(iter.map(|(k,v)| (k, JS::from_ref(v))));
*self.bound_attrib_buffers.borrow_mut() = FnvHashMap::from_iter(iter.map(|(k,v)| (k, JS::from_ref(v))));
}
pub fn bound_buffer_element_array(&self) -> Option<Root<WebGLBuffer>> {