mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Use FnvHashMap in WebGL implementation.
This commit is contained in:
parent
6eb46b1a39
commit
0a64455c71
6 changed files with 30 additions and 26 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -329,6 +329,7 @@ dependencies = [
|
||||||
"compositing 0.0.1",
|
"compositing 0.0.1",
|
||||||
"cssparser 0.19.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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"}
|
compositing = {path = "../compositing"}
|
||||||
cssparser = "0.19"
|
cssparser = "0.19"
|
||||||
euclid = "0.15"
|
euclid = "0.15"
|
||||||
|
fnv = "1.0"
|
||||||
gleam = "0.4"
|
gleam = "0.4"
|
||||||
ipc-channel = "0.8"
|
ipc-channel = "0.8"
|
||||||
log = "0.3.5"
|
log = "0.3.5"
|
||||||
|
|
|
@ -9,6 +9,7 @@ extern crate canvas_traits;
|
||||||
extern crate compositing;
|
extern crate compositing;
|
||||||
extern crate cssparser;
|
extern crate cssparser;
|
||||||
extern crate euclid;
|
extern crate euclid;
|
||||||
|
extern crate fnv;
|
||||||
extern crate gleam;
|
extern crate gleam;
|
||||||
extern crate ipc_channel;
|
extern crate ipc_channel;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
use canvas_traits::canvas::byte_swap;
|
use canvas_traits::canvas::byte_swap;
|
||||||
use canvas_traits::webgl::*;
|
use canvas_traits::webgl::*;
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
|
use fnv::FnvHashMap;
|
||||||
use gleam::gl;
|
use gleam::gl;
|
||||||
use offscreen_gl_context::{GLContext, GLContextAttributes, GLLimits, NativeGLContextMethods};
|
use offscreen_gl_context::{GLContext, GLContextAttributes, GLLimits, NativeGLContextMethods};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use super::gl_context::{GLContextFactory, GLContextWrapper};
|
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.
|
/// Channel used to generate/update or delete `webrender_api::ImageKey`s.
|
||||||
webrender_api: webrender_api::RenderApi,
|
webrender_api: webrender_api::RenderApi,
|
||||||
/// Map of live WebGLContexts.
|
/// Map of live WebGLContexts.
|
||||||
contexts: HashMap<WebGLContextId, GLContextWrapper>,
|
contexts: FnvHashMap<WebGLContextId, GLContextWrapper>,
|
||||||
/// Cached information for WebGLContexts.
|
/// Cached information for WebGLContexts.
|
||||||
cached_context_info: HashMap<WebGLContextId, WebGLContextInfo>,
|
cached_context_info: FnvHashMap<WebGLContextId, WebGLContextInfo>,
|
||||||
/// Current bound context.
|
/// Current bound context.
|
||||||
bound_context_id: Option<WebGLContextId>,
|
bound_context_id: Option<WebGLContextId>,
|
||||||
/// Id generator for new WebGLContexts.
|
/// Id generator for new WebGLContexts.
|
||||||
|
@ -47,8 +47,8 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
WebGLThread {
|
WebGLThread {
|
||||||
gl_factory,
|
gl_factory,
|
||||||
webrender_api: webrender_api_sender.create_api(),
|
webrender_api: webrender_api_sender.create_api(),
|
||||||
contexts: HashMap::new(),
|
contexts: Default::default(),
|
||||||
cached_context_info: HashMap::new(),
|
cached_context_info: Default::default(),
|
||||||
bound_context_id: None,
|
bound_context_id: None,
|
||||||
next_webgl_id: 0,
|
next_webgl_id: 0,
|
||||||
webvr_compositor,
|
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.
|
/// 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,
|
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> {
|
bound_id: &mut Option<WebGLContextId>) -> Option<&'a GLContextWrapper> {
|
||||||
contexts.get(&context_id).and_then(|ctx| {
|
contexts.get(&context_id).and_then(|ctx| {
|
||||||
if Some(context_id) != *bound_id {
|
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.
|
/// 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,
|
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 {
|
bound_id: &mut Option<WebGLContextId>) -> &'a mut GLContextWrapper {
|
||||||
let ctx = contexts.get_mut(&context_id).expect("WebGLContext not found!");
|
let ctx = contexts.get_mut(&context_id).expect("WebGLContext not found!");
|
||||||
if Some(context_id) != *bound_id {
|
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::js::Root;
|
||||||
use dom::bindings::trace::JSTraceable;
|
use dom::bindings::trace::JSTraceable;
|
||||||
use dom::webglrenderingcontext::WebGLRenderingContext;
|
use dom::webglrenderingcontext::WebGLRenderingContext;
|
||||||
|
use fnv::{FnvHashMap, FnvHashSet};
|
||||||
use gleam::gl::GLenum;
|
use gleam::gl::GLenum;
|
||||||
use heapsize::HeapSizeOf;
|
use heapsize::HeapSizeOf;
|
||||||
use js::jsapi::{JSContext, JSObject};
|
use js::jsapi::{JSContext, JSObject};
|
||||||
use js::jsval::JSVal;
|
use js::jsval::JSVal;
|
||||||
use ref_filter_map::ref_filter_map;
|
use ref_filter_map::ref_filter_map;
|
||||||
use std::cell::Ref;
|
use std::cell::Ref;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::HashMap;
|
||||||
use super::{ext, WebGLExtension};
|
use super::{ext, WebGLExtension};
|
||||||
use super::wrapper::{WebGLExtensionWrapper, TypedWebGLExtensionWrapper};
|
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.
|
/// WebGL features that are enabled/disabled by WebGL Extensions.
|
||||||
#[derive(HeapSizeOf, JSTraceable)]
|
#[derive(HeapSizeOf, JSTraceable)]
|
||||||
struct WebGLExtensionFeatures {
|
struct WebGLExtensionFeatures {
|
||||||
gl_extensions: HashSet<String>,
|
gl_extensions: FnvHashSet<String>,
|
||||||
disabled_tex_types: HashSet<GLenum>,
|
disabled_tex_types: FnvHashSet<GLenum>,
|
||||||
not_filterable_tex_types: HashSet<GLenum>,
|
not_filterable_tex_types: FnvHashSet<GLenum>,
|
||||||
effective_tex_internal_formats: HashMap<TexFormatType, u32>,
|
effective_tex_internal_formats: FnvHashMap<TexFormatType, u32>,
|
||||||
query_parameter_handlers: HashMap<GLenum, WebGLQueryParameterHandler>,
|
query_parameter_handlers: FnvHashMap<GLenum, WebGLQueryParameterHandler>,
|
||||||
/// WebGL Hint() targets enabled by extensions.
|
/// WebGL Hint() targets enabled by extensions.
|
||||||
hint_targets: HashSet<GLenum>,
|
hint_targets: FnvHashSet<GLenum>,
|
||||||
/// WebGL GetParameter() names enabled by extensions.
|
/// WebGL GetParameter() names enabled by extensions.
|
||||||
disabled_get_parameter_names: HashSet<GLenum>,
|
disabled_get_parameter_names: FnvHashSet<GLenum>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for WebGLExtensionFeatures {
|
impl Default for WebGLExtensionFeatures {
|
||||||
fn default() -> WebGLExtensionFeatures {
|
fn default() -> WebGLExtensionFeatures {
|
||||||
WebGLExtensionFeatures {
|
WebGLExtensionFeatures {
|
||||||
gl_extensions: HashSet::new(),
|
gl_extensions: Default::default(),
|
||||||
disabled_tex_types: DEFAULT_DISABLED_TEX_TYPES.iter().cloned().collect(),
|
disabled_tex_types: DEFAULT_DISABLED_TEX_TYPES.iter().cloned().collect(),
|
||||||
not_filterable_tex_types: DEFAULT_NOT_FILTERABLE_TEX_TYPES.iter().cloned().collect(),
|
not_filterable_tex_types: DEFAULT_NOT_FILTERABLE_TEX_TYPES.iter().cloned().collect(),
|
||||||
effective_tex_internal_formats: HashMap::new(),
|
effective_tex_internal_formats: Default::default(),
|
||||||
query_parameter_handlers: HashMap::new(),
|
query_parameter_handlers: Default::default(),
|
||||||
hint_targets: HashSet::new(),
|
hint_targets: Default::default(),
|
||||||
disabled_get_parameter_names: DEFAULT_DISABLED_GET_PARAMETER_NAMES.iter().cloned().collect(),
|
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 {
|
pub fn init_once<F>(&self, cb: F) where F: FnOnce() -> String {
|
||||||
if self.extensions.borrow().len() == 0 {
|
if self.extensions.borrow().len() == 0 {
|
||||||
let gl_str = cb();
|
let gl_str = cb();
|
||||||
self.features.borrow_mut().gl_extensions = HashSet::from_iter(gl_str.split(&[',', ' '][..])
|
self.features.borrow_mut().gl_extensions = FnvHashSet::from_iter(gl_str.split(&[',', ' '][..])
|
||||||
.map(|s| s.into()));
|
.map(|s| s.into()));
|
||||||
self.register_all_extensions();
|
self.register_all_extensions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ use dom::webgluniformlocation::WebGLUniformLocation;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
|
use fnv::FnvHashMap;
|
||||||
use half::f16;
|
use half::f16;
|
||||||
use js::conversions::ConversionBehavior;
|
use js::conversions::ConversionBehavior;
|
||||||
use js::jsapi::{JSContext, JSObject, Type, Rooted};
|
use js::jsapi::{JSContext, JSObject, Type, Rooted};
|
||||||
|
@ -55,7 +56,6 @@ use offscreen_gl_context::{GLContextAttributes, GLLimits};
|
||||||
use script_layout_interface::HTMLCanvasDataSource;
|
use script_layout_interface::HTMLCanvasDataSource;
|
||||||
use servo_config::prefs::PREFS;
|
use servo_config::prefs::PREFS;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::collections::HashMap;
|
|
||||||
use webrender_api;
|
use webrender_api;
|
||||||
|
|
||||||
type ImagePixelResult = Result<(Vec<u8>, Size2D<i32>, bool), ()>;
|
type ImagePixelResult = Result<(Vec<u8>, Size2D<i32>, bool), ()>;
|
||||||
|
@ -151,7 +151,7 @@ pub struct WebGLRenderingContext {
|
||||||
bound_texture_cube_map: MutNullableJS<WebGLTexture>,
|
bound_texture_cube_map: MutNullableJS<WebGLTexture>,
|
||||||
bound_buffer_array: MutNullableJS<WebGLBuffer>,
|
bound_buffer_array: MutNullableJS<WebGLBuffer>,
|
||||||
bound_buffer_element_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>,
|
current_program: MutNullableJS<WebGLProgram>,
|
||||||
#[ignore_heap_size_of = "Because it's small"]
|
#[ignore_heap_size_of = "Because it's small"]
|
||||||
current_vertex_attrib_0: Cell<(f32, f32, f32, f32)>,
|
current_vertex_attrib_0: Cell<(f32, f32, f32, f32)>,
|
||||||
|
@ -194,7 +194,7 @@ impl WebGLRenderingContext {
|
||||||
bound_texture_cube_map: MutNullableJS::new(None),
|
bound_texture_cube_map: MutNullableJS::new(None),
|
||||||
bound_buffer_array: MutNullableJS::new(None),
|
bound_buffer_array: MutNullableJS::new(None),
|
||||||
bound_buffer_element_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),
|
bound_renderbuffer: MutNullableJS::new(None),
|
||||||
current_program: MutNullableJS::new(None),
|
current_program: MutNullableJS::new(None),
|
||||||
current_vertex_attrib_0: Cell::new((0f32, 0f32, 0f32, 1f32)),
|
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()
|
self.bound_attrib_buffers.borrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_bound_attrib_buffers<'a, T>(&self, iter: T) where T: Iterator<Item=(u32, &'a WebGLBuffer)> {
|
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>> {
|
pub fn bound_buffer_element_array(&self) -> Option<Root<WebGLBuffer>> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue