Auto merge of #6566 - glennw:image-deps, r=pcwalton

Add servo Image type. Remove rust-png dependency from script, gfx, layout.



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6566)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-07-06 13:45:04 -06:00
commit 3a3ac2281b
13 changed files with 67 additions and 60 deletions

View file

@ -38,12 +38,6 @@ git = "https://github.com/servo/rust-azure"
[dependencies.layers] [dependencies.layers]
git = "https://github.com/servo/rust-layers" git = "https://github.com/servo/rust-layers"
[dependencies.stb_image]
git = "https://github.com/servo/rust-stb-image"
[dependencies.png]
git = "https://github.com/servo/rust-png"
[dependencies.skia] [dependencies.skia]
git = "https://github.com/servo/skia" git = "https://github.com/servo/skia"

View file

@ -25,8 +25,6 @@ extern crate fnv;
extern crate euclid; extern crate euclid;
extern crate layers; extern crate layers;
extern crate libc; extern crate libc;
extern crate stb_image;
extern crate png;
#[macro_use] #[macro_use]
extern crate profile_traits; extern crate profile_traits;
extern crate script_traits; extern crate script_traits;

View file

@ -30,8 +30,7 @@ use euclid::side_offsets::SideOffsets2D;
use euclid::size::Size2D; use euclid::size::Size2D;
use libc::types::common::c99::uint32_t; use libc::types::common::c99::uint32_t;
use msg::compositor_msg::LayerKind; use msg::compositor_msg::LayerKind;
use net_traits::image::base::Image; use net_traits::image::base::{Image, PixelFormat};
use png::PixelsByColorType;
use std::default::Default; use std::default::Default;
use std::f32; use std::f32;
use std::mem; use std::mem;
@ -134,17 +133,17 @@ impl<'a> PaintContext<'a> {
image: Arc<Image>, image: Arc<Image>,
image_rendering: image_rendering::T) { image_rendering: image_rendering::T) {
let size = Size2D::new(image.width as i32, image.height as i32); let size = Size2D::new(image.width as i32, image.height as i32);
let (pixel_width, pixels, source_format) = match image.pixels { let (pixel_width, source_format) = match image.format {
PixelsByColorType::RGBA8(ref pixels) => (4, pixels, SurfaceFormat::B8G8R8A8), PixelFormat::RGBA8 => (4, SurfaceFormat::B8G8R8A8),
PixelsByColorType::K8(ref pixels) => (1, pixels, SurfaceFormat::A8), PixelFormat::K8 => (1, SurfaceFormat::A8),
PixelsByColorType::RGB8(_) => panic!("RGB8 color type not supported"), PixelFormat::RGB8 => panic!("RGB8 color type not supported"),
PixelsByColorType::KA8(_) => panic!("KA8 color type not supported"), PixelFormat::KA8 => panic!("KA8 color type not supported"),
}; };
let stride = image.width * pixel_width; let stride = image.width * pixel_width;
self.draw_target.make_current(); self.draw_target.make_current();
let draw_target_ref = &self.draw_target; let draw_target_ref = &self.draw_target;
let azure_surface = draw_target_ref.create_source_surface_from_data(pixels, let azure_surface = draw_target_ref.create_source_surface_from_data(&image.bytes,
size, size,
stride as i32, stride as i32,
source_format); source_format);

View file

@ -52,9 +52,6 @@ path = "../util"
[dependencies.selectors] [dependencies.selectors]
git = "https://github.com/servo/rust-selectors" git = "https://github.com/servo/rust-selectors"
[dependencies.png]
git = "https://github.com/servo/rust-png"
[dependencies.clock_ticks] [dependencies.clock_ticks]
git = "https://github.com/tomaka/clock_ticks" git = "https://github.com/tomaka/clock_ticks"

View file

@ -36,7 +36,7 @@ use msg::compositor_msg::{ScrollPolicy, LayerId};
use msg::constellation_msg::ConstellationChan; use msg::constellation_msg::ConstellationChan;
use msg::constellation_msg::Msg as ConstellationMsg; use msg::constellation_msg::Msg as ConstellationMsg;
use net_traits::image_cache_task::UsePlaceholder; use net_traits::image_cache_task::UsePlaceholder;
use png::{self, PixelsByColorType}; use net_traits::image::base::{Image, PixelFormat};
use std::cmp; use std::cmp;
use std::default::Default; use std::default::Default;
use std::iter::repeat; use std::iter::repeat;
@ -50,7 +50,8 @@ use style::computed_values::{border_style, image_rendering, overflow_x, position
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::properties::style_structs::Border; use style::properties::style_structs::Border;
use style::values::RGBA; use style::values::RGBA;
use style::values::computed::{Image, LinearGradient}; use style::values::computed;
use style::values::computed::LinearGradient;
use style::values::computed::{LengthOrNone, LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::computed::{LengthOrNone, LengthOrPercentage, LengthOrPercentageOrAuto};
use style::values::specified::{AngleOrCorner, HorizontalDirection, VerticalDirection}; use style::values::specified::{AngleOrCorner, HorizontalDirection, VerticalDirection};
use url::Url; use url::Url;
@ -108,7 +109,7 @@ pub trait FragmentDisplayListBuilding {
fn compute_background_image_size(&self, fn compute_background_image_size(&self,
style: &ComputedValues, style: &ComputedValues,
bounds: &Rect<Au>, bounds: &Rect<Au>,
image: &png::Image) image: &Image)
-> Size2D<Au>; -> Size2D<Au>;
/// Adds the display items necessary to paint the background image of this fragment to the /// Adds the display items necessary to paint the background image of this fragment to the
@ -363,7 +364,7 @@ impl FragmentDisplayListBuilding for Fragment {
let background = style.get_background(); let background = style.get_background();
match background.background_image { match background.background_image {
None => {} None => {}
Some(Image::LinearGradient(ref gradient)) => { Some(computed::Image::LinearGradient(ref gradient)) => {
self.build_display_list_for_background_linear_gradient(display_list, self.build_display_list_for_background_linear_gradient(display_list,
level, level,
absolute_bounds, absolute_bounds,
@ -371,7 +372,7 @@ impl FragmentDisplayListBuilding for Fragment {
gradient, gradient,
style) style)
} }
Some(Image::Url(ref image_url)) => { Some(computed::Image::Url(ref image_url)) => {
self.build_display_list_for_background_image(style, self.build_display_list_for_background_image(style,
display_list, display_list,
layout_context, layout_context,
@ -386,7 +387,7 @@ impl FragmentDisplayListBuilding for Fragment {
fn compute_background_image_size(&self, fn compute_background_image_size(&self,
style: &ComputedValues, style: &ComputedValues,
bounds: &Rect<Au>, bounds: &Rect<Au>,
image: &png::Image) image: &Image)
-> Size2D<Au> { -> Size2D<Au> {
// If `image_aspect_ratio` < `bounds_aspect_ratio`, the image is tall; otherwise, it is // If `image_aspect_ratio` < `bounds_aspect_ratio`, the image is tall; otherwise, it is
// wide. // wide.
@ -1111,10 +1112,11 @@ impl FragmentDisplayListBuilding for Fragment {
&*self.style, &*self.style,
Cursor::DefaultCursor), Cursor::DefaultCursor),
(*clip).clone()), (*clip).clone()),
image: Arc::new(png::Image { image: Arc::new(Image {
width: width as u32, width: width as u32,
height: height as u32, height: height as u32,
pixels: PixelsByColorType::RGBA8(canvas_data), format: PixelFormat::RGBA8,
bytes: canvas_data,
}), }),
stretch_size: stacking_relative_content_box.size, stretch_size: stacking_relative_content_box.size,
image_rendering: image_rendering::T::Auto, image_rendering: image_rendering::T::Auto,

View file

@ -50,7 +50,6 @@ extern crate gfx_traits;
extern crate layout_traits; extern crate layout_traits;
extern crate libc; extern crate libc;
extern crate msg; extern crate msg;
extern crate png;
extern crate script; extern crate script;
extern crate script_traits; extern crate script_traits;
extern crate selectors; extern crate selectors;

View file

@ -4,11 +4,25 @@
use png; use png;
use stb_image::image as stb_image2; use stb_image::image as stb_image2;
use std::mem;
use util::vec::byte_swap; use util::vec::byte_swap;
// FIXME: Images must not be copied every frame. Instead we should atomically // FIXME: Images must not be copied every frame. Instead we should atomically
// reference count them. // reference count them.
pub type Image = png::Image;
pub enum PixelFormat {
K8, // Luminance channel only
KA8, // Luminance + alpha
RGB8, // RGB, 8 bits per channel
RGBA8, // RGB + alpha, 8 bits per channel
}
pub struct Image {
pub width: u32,
pub height: u32,
pub format: PixelFormat,
pub bytes: Vec<u8>,
}
// TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this. // TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this.
fn byte_swap_and_premultiply(data: &mut [u8]) { fn byte_swap_and_premultiply(data: &mut [u8]) {
@ -32,14 +46,33 @@ pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
if png::is_png(buffer) { if png::is_png(buffer) {
match png::load_png_from_memory(buffer) { match png::load_png_from_memory(buffer) {
Ok(mut png_image) => { Ok(mut png_image) => {
match png_image.pixels { let (bytes, format) = match png_image.pixels {
png::PixelsByColorType::RGB8(ref mut data) => byte_swap(data), png::PixelsByColorType::K8(ref mut data) => {
(data, PixelFormat::K8)
}
png::PixelsByColorType::KA8(ref mut data) => {
(data, PixelFormat::KA8)
}
png::PixelsByColorType::RGB8(ref mut data) => {
byte_swap(data);
(data, PixelFormat::RGB8)
}
png::PixelsByColorType::RGBA8(ref mut data) => { png::PixelsByColorType::RGBA8(ref mut data) => {
byte_swap_and_premultiply(data) byte_swap_and_premultiply(data);
(data, PixelFormat::RGBA8)
} }
_ => {} };
}
Some(png_image) let bytes = mem::replace(bytes, Vec::new());
let image = Image {
width: png_image.width,
height: png_image.height,
format: format,
bytes: bytes,
};
Some(image)
} }
Err(_err) => None, Err(_err) => None,
} }
@ -57,10 +90,11 @@ pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
} else { } else {
byte_swap(&mut image.data); byte_swap(&mut image.data);
} }
Some(png::Image { Some(Image {
width: image.width as u32, width: image.width as u32,
height: image.height as u32, height: image.height as u32,
pixels: png::PixelsByColorType::RGBA8(image.data) format: PixelFormat::RGBA8,
bytes: image.data,
}) })
} }
stb_image2::LoadResult::ImageF32(_image) => { stb_image2::LoadResult::ImageF32(_image) => {

View file

@ -48,9 +48,6 @@ git = "https://github.com/servo/rust-selectors"
[dependencies.js] [dependencies.js]
git = "https://github.com/servo/rust-mozjs" git = "https://github.com/servo/rust-mozjs"
[dependencies.png]
git = "https://github.com/servo/rust-png"
[dependencies.url] [dependencies.url]
version = "0.2.33" version = "0.2.33"
features = ["query_encoding"] features = ["query_encoding"]

View file

@ -35,7 +35,7 @@ use canvas_traits::{LineCapStyle, LineJoinStyle, CompositionOrBlending};
use canvas::canvas_paint_task::CanvasPaintTask; use canvas::canvas_paint_task::CanvasPaintTask;
use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; use net_traits::image_cache_task::{ImageCacheChan, ImageResponse};
use png::PixelsByColorType; use net_traits::image::base::PixelFormat;
use num::{Float, ToPrimitive}; use num::{Float, ToPrimitive};
use std::borrow::ToOwned; use std::borrow::ToOwned;
@ -286,11 +286,11 @@ impl CanvasRenderingContext2D {
}; };
let image_size = Size2D::new(img.width as f64, img.height as f64); let image_size = Size2D::new(img.width as f64, img.height as f64);
let image_data = match img.pixels { let image_data = match img.format {
PixelsByColorType::RGBA8(ref pixels) => pixels.to_vec(), PixelFormat::RGBA8 => img.bytes.to_vec(),
PixelsByColorType::K8(_) => panic!("K8 color type not supported"), PixelFormat::K8 => panic!("K8 color type not supported"),
PixelsByColorType::RGB8(_) => panic!("RGB8 color type not supported"), PixelFormat::RGB8 => panic!("RGB8 color type not supported"),
PixelsByColorType::KA8(_) => panic!("KA8 color type not supported"), PixelFormat::KA8 => panic!("KA8 color type not supported"),
}; };
return Some((image_data, image_size)); return Some((image_data, image_size));

View file

@ -48,7 +48,6 @@ extern crate libc;
extern crate msg; extern crate msg;
extern crate net_traits; extern crate net_traits;
extern crate num; extern crate num;
extern crate png;
extern crate rustc_serialize; extern crate rustc_serialize;
extern crate time; extern crate time;
extern crate canvas; extern crate canvas;

View file

@ -431,14 +431,12 @@ dependencies = [
"msg 0.0.1", "msg 0.0.1",
"net_traits 0.0.1", "net_traits 0.0.1",
"plugins 0.0.1", "plugins 0.0.1",
"png 0.1.0 (git+https://github.com/servo/rust-png)",
"profile_traits 0.0.1", "profile_traits 0.0.1",
"rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"script_traits 0.0.1", "script_traits 0.0.1",
"skia 0.0.20130412 (git+https://github.com/servo/skia)", "skia 0.0.20130412 (git+https://github.com/servo/skia)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image)",
"string_cache 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
"time 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
@ -680,7 +678,6 @@ dependencies = [
"msg 0.0.1", "msg 0.0.1",
"net_traits 0.0.1", "net_traits 0.0.1",
"plugins 0.0.1", "plugins 0.0.1",
"png 0.1.0 (git+https://github.com/servo/rust-png)",
"profile_traits 0.0.1", "profile_traits 0.0.1",
"rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"script 0.0.1", "script 0.0.1",
@ -1073,7 +1070,6 @@ dependencies = [
"num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"offscreen_gl_context 0.1.0 (git+https://github.com/ecoal95/rust-offscreen-rendering-context)", "offscreen_gl_context 0.1.0 (git+https://github.com/ecoal95/rust-offscreen-rendering-context)",
"plugins 0.0.1", "plugins 0.0.1",
"png 0.1.0 (git+https://github.com/servo/rust-png)",
"profile_traits 0.0.1", "profile_traits 0.0.1",
"rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",

4
ports/cef/Cargo.lock generated
View file

@ -430,14 +430,12 @@ dependencies = [
"msg 0.0.1", "msg 0.0.1",
"net_traits 0.0.1", "net_traits 0.0.1",
"plugins 0.0.1", "plugins 0.0.1",
"png 0.1.0 (git+https://github.com/servo/rust-png)",
"profile_traits 0.0.1", "profile_traits 0.0.1",
"rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"script_traits 0.0.1", "script_traits 0.0.1",
"skia 0.0.20130412 (git+https://github.com/servo/skia)", "skia 0.0.20130412 (git+https://github.com/servo/skia)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image)",
"string_cache 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
"time 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
@ -672,7 +670,6 @@ dependencies = [
"msg 0.0.1", "msg 0.0.1",
"net_traits 0.0.1", "net_traits 0.0.1",
"plugins 0.0.1", "plugins 0.0.1",
"png 0.1.0 (git+https://github.com/servo/rust-png)",
"profile_traits 0.0.1", "profile_traits 0.0.1",
"rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"script 0.0.1", "script 0.0.1",
@ -1053,7 +1050,6 @@ dependencies = [
"num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"offscreen_gl_context 0.1.0 (git+https://github.com/ecoal95/rust-offscreen-rendering-context)", "offscreen_gl_context 0.1.0 (git+https://github.com/ecoal95/rust-offscreen-rendering-context)",
"plugins 0.0.1", "plugins 0.0.1",
"png 0.1.0 (git+https://github.com/servo/rust-png)",
"profile_traits 0.0.1", "profile_traits 0.0.1",
"rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",

4
ports/gonk/Cargo.lock generated
View file

@ -409,14 +409,12 @@ dependencies = [
"msg 0.0.1", "msg 0.0.1",
"net_traits 0.0.1", "net_traits 0.0.1",
"plugins 0.0.1", "plugins 0.0.1",
"png 0.1.0 (git+https://github.com/servo/rust-png)",
"profile_traits 0.0.1", "profile_traits 0.0.1",
"rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"script_traits 0.0.1", "script_traits 0.0.1",
"skia 0.0.20130412 (git+https://github.com/servo/skia)", "skia 0.0.20130412 (git+https://github.com/servo/skia)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image)",
"string_cache 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
"time 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
@ -606,7 +604,6 @@ dependencies = [
"msg 0.0.1", "msg 0.0.1",
"net_traits 0.0.1", "net_traits 0.0.1",
"plugins 0.0.1", "plugins 0.0.1",
"png 0.1.0 (git+https://github.com/servo/rust-png)",
"profile_traits 0.0.1", "profile_traits 0.0.1",
"rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"script 0.0.1", "script 0.0.1",
@ -961,7 +958,6 @@ dependencies = [
"num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"offscreen_gl_context 0.1.0 (git+https://github.com/ecoal95/rust-offscreen-rendering-context)", "offscreen_gl_context 0.1.0 (git+https://github.com/ecoal95/rust-offscreen-rendering-context)",
"plugins 0.0.1", "plugins 0.0.1",
"png 0.1.0 (git+https://github.com/servo/rust-png)",
"profile_traits 0.0.1", "profile_traits 0.0.1",
"rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",