Auto merge of #21701 - servo:webgl, r=jdm

Yet another batch of arbitrary improvements to our WebGL stuff

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21701)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-09-13 16:05:04 -04:00 committed by GitHub
commit 93fbc1575f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 103 additions and 141 deletions

View file

@ -11,7 +11,7 @@ use azure::azure_hl::SurfacePattern;
use canvas_traits::canvas::*;
use cssparser::RGBA;
use euclid::{Transform2D, Point2D, Vector2D, Rect, Size2D};
use ipc_channel::ipc::IpcSender;
use ipc_channel::ipc::{IpcBytesSender, IpcSender};
use num_traits::ToPrimitive;
use serde_bytes::ByteBuf;
use std::mem;
@ -456,13 +456,9 @@ impl<'a> CanvasData<'a> {
&self,
dest_rect: Rect<i32>,
canvas_size: Size2D<f64>,
chan: IpcSender<ByteBuf>,
sender: IpcBytesSender,
) {
let mut dest_data = self.read_pixels(dest_rect, canvas_size);
// bgra -> rgba
byte_swap(&mut dest_data);
chan.send(dest_data.into()).unwrap();
sender.send(&self.read_pixels(dest_rect, canvas_size)).unwrap();
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata

View file

@ -4,7 +4,7 @@
use cssparser::RGBA;
use euclid::{Transform2D, Point2D, Vector2D, Rect, Size2D};
use ipc_channel::ipc::IpcSender;
use ipc_channel::ipc::{IpcBytesSender, IpcSender};
use serde_bytes::ByteBuf;
use std::default::Default;
use std::str::FromStr;
@ -51,7 +51,7 @@ pub enum Canvas2dMsg {
Fill,
FillText(String, f64, f64, Option<f64>),
FillRect(Rect<f32>),
GetImageData(Rect<i32>, Size2D<f64>, IpcSender<ByteBuf>),
GetImageData(Rect<i32>, Size2D<f64>, IpcBytesSender),
IsPointInPath(f64, f64, FillRule, IpcSender<bool>),
LineTo(Point2D<f32>),
MoveTo(Point2D<f32>),

View file

@ -32,7 +32,7 @@ use dom::imagedata::ImageData;
use dom::node::{Node, NodeDamage, window_from_node};
use dom_struct::dom_struct;
use euclid::{Transform2D, Point2D, Vector2D, Rect, Size2D, vec2};
use ipc_channel::ipc::IpcSender;
use ipc_channel::ipc::{self, IpcSender};
use net_traits::image::base::PixelFormat;
use net_traits::image_cache::CanRequestImages;
use net_traits::image_cache::ImageCache;
@ -41,7 +41,7 @@ use net_traits::image_cache::ImageResponse;
use net_traits::image_cache::ImageState;
use net_traits::image_cache::UsePlaceholder;
use num_traits::ToPrimitive;
use profile_traits::ipc;
use profile_traits::ipc as profiled_ipc;
use script_traits::ScriptMsg;
use servo_url::ServoUrl;
use std::{cmp, fmt, mem};
@ -130,7 +130,7 @@ impl CanvasRenderingContext2D {
size: Size2D<i32>)
-> CanvasRenderingContext2D {
debug!("Creating new canvas rendering context.");
let (sender, receiver) = ipc::channel(global.time_profiler_chan().clone()).unwrap();
let (sender, receiver) = profiled_ipc::channel(global.time_profiler_chan().clone()).unwrap();
let script_to_constellation_chan = global.script_to_constellation_chan();
debug!("Asking constellation to create new canvas thread.");
script_to_constellation_chan.send(ScriptMsg::CreateCanvasPaintThread(size, sender)).unwrap();
@ -790,7 +790,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
CanvasFillRule::Nonzero => FillRule::Nonzero,
CanvasFillRule::Evenodd => FillRule::Evenodd,
};
let (sender, receiver) = ipc::channel::<bool>(self.global().time_profiler_chan().clone()).unwrap();
let (sender, receiver) = profiled_ipc::channel::<bool>(self.global().time_profiler_chan().clone()).unwrap();
self.send_canvas_2d_msg(Canvas2dMsg::IsPointInPath(x, y, fill_rule, sender));
receiver.recv().unwrap()
}
@ -1107,7 +1107,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
let sh = cmp::max(1, sh.to_u32().unwrap());
let sw = cmp::max(1, sw.to_u32().unwrap());
let (sender, receiver) = ipc::channel(self.global().time_profiler_chan().clone()).unwrap();
let (sender, receiver) = ipc::bytes_channel().unwrap();
let dest_rect = Rect::new(Point2D::new(sx.to_i32().unwrap(), sy.to_i32().unwrap()),
Size2D::new(sw as i32, sh as i32));
let canvas_size = self.canvas.as_ref().map(|c| c.get_size()).unwrap_or(Size2D::zero());
@ -1115,12 +1115,12 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
self.send_canvas_2d_msg(Canvas2dMsg::GetImageData(dest_rect, canvas_size, sender));
let mut data = receiver.recv().unwrap();
// Un-premultiply alpha
// Byte swap and unmultiply alpha.
for chunk in data.chunks_mut(4) {
let alpha = chunk[3] as usize;
chunk[0] = UNPREMULTIPLY_TABLE[256 * alpha + chunk[0] as usize];
chunk[1] = UNPREMULTIPLY_TABLE[256 * alpha + chunk[1] as usize];
chunk[2] = UNPREMULTIPLY_TABLE[256 * alpha + chunk[2] as usize];
let (b, g, r, a) = (chunk[0], chunk[1], chunk[2], chunk[3]);
chunk[0] = UNPREMULTIPLY_TABLE[256 * (a as usize) + r as usize];
chunk[1] = UNPREMULTIPLY_TABLE[256 * (a as usize) + g as usize];
chunk[2] = UNPREMULTIPLY_TABLE[256 * (a as usize) + b as usize];
}
ImageData::new(&self.global(), sw, sh, Some(data.to_vec()))

View file

@ -1752,22 +1752,6 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
Err(_) => return,
};
let image_info = texture.image_info_for_target(&target, level);
// The color buffer components can be dropped during the conversion to
// the internal_format, but new components cannot be added.
//
// Note that this only applies if we're copying to an already
// initialized texture.
//
// GL_INVALID_OPERATION is generated if the color buffer cannot be
// converted to the internal_format.
if let Some(old_internal_format) = image_info.internal_format() {
if old_internal_format.components() > internal_format.components() {
return self.webgl_error(InvalidOperation);
}
}
// NB: TexImage2D depth is always equal to 1
handle_potential_webgl_error!(self, texture.initialize(target,
width as u32,