Update azure

https://github.com/servo/rust-azure/pull/293
This commit is contained in:
Anthony Ramine 2018-09-16 20:53:38 +02:00
parent f1e8eb640c
commit 21e992bf40
2 changed files with 42 additions and 41 deletions

10
Cargo.lock generated
View file

@ -109,8 +109,8 @@ dependencies = [
[[package]]
name = "azure"
version = "0.33.0"
source = "git+https://github.com/servo/rust-azure#43e61bda11f26e8462cfa63affac17c43df53b84"
version = "0.34.0"
source = "git+https://github.com/servo/rust-azure#1536ca66954356ece017343e3cd30b293134dc3f"
dependencies = [
"cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -324,7 +324,7 @@ dependencies = [
name = "canvas"
version = "0.0.1"
dependencies = [
"azure 0.33.0 (git+https://github.com/servo/rust-azure)",
"azure 0.34.0 (git+https://github.com/servo/rust-azure)",
"canvas_traits 0.0.1",
"compositing 0.0.1",
"cssparser 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2851,7 +2851,7 @@ dependencies = [
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -4335,7 +4335,7 @@ dependencies = [
"checksum atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fb2dcb6e6d35f20276943cc04bb98e538b348d525a04ac79c10021561d202f21"
"checksum atty 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "21e50800ec991574876040fff8ee46b136a53e985286fbe6a3bdfe6421b78860"
"checksum audio-video-metadata 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3c23600291b35b9cd381f5cfca636f5d7d75e7d7192eddf867de84a6732cad5c"
"checksum azure 0.33.0 (git+https://github.com/servo/rust-azure)" = "<none>"
"checksum azure 0.34.0 (git+https://github.com/servo/rust-azure)" = "<none>"
"checksum backtrace 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "72f9b4182546f4b04ebc4ab7f84948953a118bd6021a1b6a6c909e3e94f6be76"
"checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661"
"checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9"

View file

@ -405,51 +405,52 @@ impl<'a> CanvasData<'a> {
}
}
#[allow(unsafe_code)]
pub fn send_pixels(&mut self, chan: IpcSender<Option<ByteBuf>>) {
self.drawtarget.snapshot().get_data_surface().with_data(|element| {
chan.send(Some(Vec::from(element).into())).unwrap();
})
let data = unsafe { self.drawtarget.snapshot().get_data_surface().data().to_vec() };
chan.send(Some(data.into())).unwrap();
}
#[allow(unsafe_code)]
pub fn send_data(&mut self, chan: IpcSender<CanvasImageData>) {
self.drawtarget.snapshot().get_data_surface().with_data(|element| {
let size = self.drawtarget.get_size();
let size = self.drawtarget.get_size();
let descriptor = webrender_api::ImageDescriptor {
size: webrender_api::DeviceUintSize::new(size.width as u32, size.height as u32),
stride: None,
format: webrender_api::ImageFormat::BGRA8,
offset: 0,
is_opaque: false,
allow_mipmaps: false,
};
let data = webrender_api::ImageData::Raw(Arc::new(element.into()));
let descriptor = webrender_api::ImageDescriptor {
size: webrender_api::DeviceUintSize::new(size.width as u32, size.height as u32),
stride: None,
format: webrender_api::ImageFormat::BGRA8,
offset: 0,
is_opaque: false,
allow_mipmaps: false,
};
let data = webrender_api::ImageData::Raw(Arc::new(
unsafe { self.drawtarget.snapshot().get_data_surface().data().into() },
));
let mut txn = webrender_api::Transaction::new();
let mut txn = webrender_api::Transaction::new();
match self.image_key {
Some(image_key) => {
debug!("Updating image {:?}.", image_key);
txn.update_image(image_key, descriptor, data, None);
}
None => {
self.image_key = Some(self.webrender_api.generate_image_key());
debug!("New image {:?}.", self.image_key);
txn.add_image(self.image_key.unwrap(), descriptor, data, None);
}
match self.image_key {
Some(image_key) => {
debug!("Updating image {:?}.", image_key);
txn.update_image(image_key, descriptor, data, None);
}
if let Some(image_key) = mem::replace(&mut self.very_old_image_key, self.old_image_key.take()) {
txn.delete_image(image_key);
None => {
self.image_key = Some(self.webrender_api.generate_image_key());
debug!("New image {:?}.", self.image_key);
txn.add_image(self.image_key.unwrap(), descriptor, data, None);
}
}
self.webrender_api.update_resources(txn.resource_updates);
if let Some(image_key) = mem::replace(&mut self.very_old_image_key, self.old_image_key.take()) {
txn.delete_image(image_key);
}
let data = CanvasImageData {
image_key: self.image_key.unwrap(),
};
chan.send(data).unwrap();
})
self.webrender_api.update_resources(txn.resource_updates);
let data = CanvasImageData {
image_key: self.image_key.unwrap(),
};
chan.send(data).unwrap();
}
pub fn image_data(
@ -606,6 +607,7 @@ impl<'a> CanvasData<'a> {
/// It reads image data from the canvas
/// canvas_size: The size of the canvas we're reading from
/// read_rect: The area of the canvas we want to read from
#[allow(unsafe_code)]
pub fn read_pixels(&self, read_rect: Rect<i32>, canvas_size: Size2D<f64>) -> Vec<u8> {
let canvas_size = canvas_size.to_i32();
let canvas_rect = Rect::new(Point2D::new(0i32, 0i32), canvas_size);
@ -617,8 +619,7 @@ impl<'a> CanvasData<'a> {
}
let data_surface = self.drawtarget.snapshot().get_data_surface();
let mut src_data = Vec::new();
data_surface.with_data(|element| { src_data = element.to_vec(); });
let src_data = unsafe { data_surface.data() };
let stride = data_surface.stride();
//start offset of the copyable rectangle