diff --git a/components/canvas/webgl_thread.rs b/components/canvas/webgl_thread.rs index 700fdf0db72..abc0ed2f768 100644 --- a/components/canvas/webgl_thread.rs +++ b/components/canvas/webgl_thread.rs @@ -1045,25 +1045,40 @@ impl WebGLImpl { WebGLCommand::TexImage2D { target, level, - internal_format, + effective_internal_format, size, format, data_type, + effective_data_type, unpacking_alignment, + alpha_treatment, + y_axis_treatment, + tex_source, ref receiver, } => { + let pixels = prepare_pixels( + format, + data_type, + size, + unpacking_alignment, + alpha_treatment, + y_axis_treatment, + tex_source, + receiver.recv().unwrap(), + ); + ctx.gl() .pixel_store_i(gl::UNPACK_ALIGNMENT, unpacking_alignment as i32); ctx.gl().tex_image_2d( target, level as i32, - internal_format as i32, + effective_internal_format as i32, size.width as i32, size.height as i32, 0, - format, - data_type, - Some(&receiver.recv().unwrap()), + format.as_gl_constant(), + effective_data_type, + Some(&pixels), ); }, WebGLCommand::TexSubImage2D { @@ -1074,9 +1089,24 @@ impl WebGLImpl { size, format, data_type, + effective_data_type, unpacking_alignment, + alpha_treatment, + y_axis_treatment, + tex_source, ref receiver, } => { + let pixels = prepare_pixels( + format, + data_type, + size, + unpacking_alignment, + alpha_treatment, + y_axis_treatment, + tex_source, + receiver.recv().unwrap(), + ); + ctx.gl() .pixel_store_i(gl::UNPACK_ALIGNMENT, unpacking_alignment as i32); ctx.gl().tex_sub_image_2d( @@ -1086,9 +1116,9 @@ impl WebGLImpl { yoffset, size.width as i32, size.height as i32, - format, - data_type, - &receiver.recv().unwrap(), + format.as_gl_constant(), + effective_data_type, + &pixels, ); }, WebGLCommand::DrawingBufferWidth(ref sender) => sender diff --git a/components/canvas_traits/webgl.rs b/components/canvas_traits/webgl.rs index 7abf39a8c83..7e16b59addc 100644 --- a/components/canvas_traits/webgl.rs +++ b/components/canvas_traits/webgl.rs @@ -275,11 +275,17 @@ pub enum WebGLCommand { TexImage2D { target: u32, level: u32, - internal_format: u32, + // FIXME(nox): This should be computed on the WebGL thread. + effective_internal_format: u32, size: Size2D, - format: u32, - data_type: u32, + format: TexFormat, + data_type: TexDataType, + // FIXME(nox): This should be computed on the WebGL thread. + effective_data_type: u32, unpacking_alignment: u32, + alpha_treatment: Option, + y_axis_treatment: YAxisTreatment, + tex_source: TexSource, receiver: IpcBytesReceiver, }, TexSubImage2D { @@ -288,9 +294,14 @@ pub enum WebGLCommand { xoffset: i32, yoffset: i32, size: Size2D, - format: u32, - data_type: u32, + format: TexFormat, + data_type: TexDataType, + // FIXME(nox): This should be computed on the WebGL thread. + effective_data_type: u32, unpacking_alignment: u32, + alpha_treatment: Option, + y_axis_treatment: YAxisTreatment, + tex_source: TexSource, receiver: IpcBytesReceiver, }, DrawingBufferWidth(WebGLSender), @@ -671,7 +682,8 @@ pub fn is_gles() -> bool { macro_rules! gl_enums { ($(pub enum $name:ident { $($variant:ident = $mod:ident::$constant:ident,)+ })*) => { $( - #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq)] + #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf)] + #[derive(PartialEq, Serialize)] #[repr(u32)] pub enum $name { $($variant = $mod::$constant,)+ } @@ -755,19 +767,19 @@ impl TexDataType { } } -#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq)] +#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)] pub enum AlphaTreatment { Premultiply, Unmultiply, } -#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq)] +#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)] pub enum YAxisTreatment { AsIs, Flipped, } -#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq)] +#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)] pub enum TexSource { FromHtmlElement, FromArray, diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 2b9f62ed3b9..8833c9e959e 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -89,7 +89,7 @@ script_layout_interface = {path = "../script_layout_interface"} script_plugins = {path = "../script_plugins"} script_traits = {path = "../script_traits"} selectors = { path = "../selectors" } -serde = "1.0" +serde = {version = "1", features = ["derive"]} serde_bytes = "0.10" servo_allocator = {path = "../allocator"} servo_arc = {path = "../servo_arc"} diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 1435c9133c9..4e8c835f7bf 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -6,7 +6,7 @@ use backtrace::Backtrace; use canvas_traits::webgl::WebGLError::*; use canvas_traits::webgl::{ - self, webgl_channel, AlphaTreatment, DOMToTextureCommand, Parameter, TexDataType, TexFormat, + webgl_channel, AlphaTreatment, DOMToTextureCommand, Parameter, TexDataType, TexFormat, TexParameter, TexSource, WebGLCommand, WebGLCommandBacktrace, WebGLContextShareMode, WebGLError, WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender, WebGLProgramId, WebGLResult, WebGLSLVersion, WebGLSender, WebGLVersion, WebVRCommand, YAxisTreatment, @@ -643,7 +643,7 @@ impl WebGLRenderingContext { texture: &WebGLTexture, target: TexImageTarget, data_type: TexDataType, - internal_format: TexFormat, + format: TexFormat, level: u32, _border: u32, unpacking_alignment: u32, @@ -658,7 +658,7 @@ impl WebGLRenderingContext { pixels.size.width, pixels.size.height, 1, - internal_format, + format, level, Some(data_type) ) @@ -679,36 +679,30 @@ impl WebGLRenderingContext { YAxisTreatment::AsIs }; - let buff = webgl::prepare_pixels( - internal_format, - data_type, - pixels.size, - unpacking_alignment, - alpha_treatment, - y_axis_treatment, - tex_source, - pixels.data, - ); - - let format = internal_format.as_gl_constant(); - let data_type = data_type.as_gl_constant(); - let internal_format = self + let effective_internal_format = self .extension_manager - .get_effective_tex_internal_format(format, data_type); + .get_effective_tex_internal_format(format.as_gl_constant(), data_type.as_gl_constant()); + let effective_data_type = self + .extension_manager + .effective_type(data_type.as_gl_constant()); // TODO(emilio): convert colorspace if requested let (sender, receiver) = ipc::bytes_channel().unwrap(); self.send_command(WebGLCommand::TexImage2D { target: target.as_gl_constant(), level, - internal_format, + effective_internal_format, size: pixels.size, format, - data_type: self.extension_manager.effective_type(data_type), + data_type, + effective_data_type, unpacking_alignment, + alpha_treatment, + y_axis_treatment, + tex_source, receiver, }); - sender.send(&buff).unwrap(); + sender.send(&pixels.data).unwrap(); if let Some(fb) = self.bound_framebuffer.get() { fb.invalidate_texture(&*texture); @@ -765,16 +759,9 @@ impl WebGLRenderingContext { YAxisTreatment::AsIs }; - let buff = webgl::prepare_pixels( - format, - data_type, - pixels.size, - unpacking_alignment, - alpha_treatment, - y_axis_treatment, - tex_source, - pixels.data, - ); + let effective_data_type = self + .extension_manager + .effective_type(data_type.as_gl_constant()); // TODO(emilio): convert colorspace if requested let (sender, receiver) = ipc::bytes_channel().unwrap(); @@ -784,14 +771,16 @@ impl WebGLRenderingContext { xoffset, yoffset, size: pixels.size, - format: format.as_gl_constant(), - data_type: self - .extension_manager - .effective_type(data_type.as_gl_constant()), + format, + data_type, + effective_data_type, unpacking_alignment, + alpha_treatment, + y_axis_treatment, + tex_source, receiver, }); - sender.send(&buff).unwrap(); + sender.send(&pixels.data).unwrap(); } fn get_gl_extensions(&self) -> String { diff --git a/components/script/lib.rs b/components/script/lib.rs index e4a9a67792a..ed0e52ba50e 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -46,6 +46,8 @@ extern crate malloc_size_of_derive; #[macro_use] extern crate profile_traits; #[macro_use] +extern crate serde; +#[macro_use] extern crate servo_atoms; #[macro_use] extern crate style;