mirror of
https://github.com/servo/servo.git
synced 2025-06-12 02:14:41 +00:00
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:
commit
3a3ac2281b
13 changed files with 67 additions and 60 deletions
|
@ -38,12 +38,6 @@ git = "https://github.com/servo/rust-azure"
|
|||
[dependencies.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]
|
||||
git = "https://github.com/servo/skia"
|
||||
|
||||
|
|
|
@ -25,8 +25,6 @@ extern crate fnv;
|
|||
extern crate euclid;
|
||||
extern crate layers;
|
||||
extern crate libc;
|
||||
extern crate stb_image;
|
||||
extern crate png;
|
||||
#[macro_use]
|
||||
extern crate profile_traits;
|
||||
extern crate script_traits;
|
||||
|
|
|
@ -30,8 +30,7 @@ use euclid::side_offsets::SideOffsets2D;
|
|||
use euclid::size::Size2D;
|
||||
use libc::types::common::c99::uint32_t;
|
||||
use msg::compositor_msg::LayerKind;
|
||||
use net_traits::image::base::Image;
|
||||
use png::PixelsByColorType;
|
||||
use net_traits::image::base::{Image, PixelFormat};
|
||||
use std::default::Default;
|
||||
use std::f32;
|
||||
use std::mem;
|
||||
|
@ -134,17 +133,17 @@ impl<'a> PaintContext<'a> {
|
|||
image: Arc<Image>,
|
||||
image_rendering: image_rendering::T) {
|
||||
let size = Size2D::new(image.width as i32, image.height as i32);
|
||||
let (pixel_width, pixels, source_format) = match image.pixels {
|
||||
PixelsByColorType::RGBA8(ref pixels) => (4, pixels, SurfaceFormat::B8G8R8A8),
|
||||
PixelsByColorType::K8(ref pixels) => (1, pixels, SurfaceFormat::A8),
|
||||
PixelsByColorType::RGB8(_) => panic!("RGB8 color type not supported"),
|
||||
PixelsByColorType::KA8(_) => panic!("KA8 color type not supported"),
|
||||
let (pixel_width, source_format) = match image.format {
|
||||
PixelFormat::RGBA8 => (4, SurfaceFormat::B8G8R8A8),
|
||||
PixelFormat::K8 => (1, SurfaceFormat::A8),
|
||||
PixelFormat::RGB8 => panic!("RGB8 color type not supported"),
|
||||
PixelFormat::KA8 => panic!("KA8 color type not supported"),
|
||||
};
|
||||
let stride = image.width * pixel_width;
|
||||
|
||||
self.draw_target.make_current();
|
||||
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,
|
||||
stride as i32,
|
||||
source_format);
|
||||
|
|
|
@ -52,9 +52,6 @@ path = "../util"
|
|||
[dependencies.selectors]
|
||||
git = "https://github.com/servo/rust-selectors"
|
||||
|
||||
[dependencies.png]
|
||||
git = "https://github.com/servo/rust-png"
|
||||
|
||||
[dependencies.clock_ticks]
|
||||
git = "https://github.com/tomaka/clock_ticks"
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ use msg::compositor_msg::{ScrollPolicy, LayerId};
|
|||
use msg::constellation_msg::ConstellationChan;
|
||||
use msg::constellation_msg::Msg as ConstellationMsg;
|
||||
use net_traits::image_cache_task::UsePlaceholder;
|
||||
use png::{self, PixelsByColorType};
|
||||
use net_traits::image::base::{Image, PixelFormat};
|
||||
use std::cmp;
|
||||
use std::default::Default;
|
||||
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::style_structs::Border;
|
||||
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::specified::{AngleOrCorner, HorizontalDirection, VerticalDirection};
|
||||
use url::Url;
|
||||
|
@ -108,7 +109,7 @@ pub trait FragmentDisplayListBuilding {
|
|||
fn compute_background_image_size(&self,
|
||||
style: &ComputedValues,
|
||||
bounds: &Rect<Au>,
|
||||
image: &png::Image)
|
||||
image: &Image)
|
||||
-> Size2D<Au>;
|
||||
|
||||
/// 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();
|
||||
match background.background_image {
|
||||
None => {}
|
||||
Some(Image::LinearGradient(ref gradient)) => {
|
||||
Some(computed::Image::LinearGradient(ref gradient)) => {
|
||||
self.build_display_list_for_background_linear_gradient(display_list,
|
||||
level,
|
||||
absolute_bounds,
|
||||
|
@ -371,7 +372,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
gradient,
|
||||
style)
|
||||
}
|
||||
Some(Image::Url(ref image_url)) => {
|
||||
Some(computed::Image::Url(ref image_url)) => {
|
||||
self.build_display_list_for_background_image(style,
|
||||
display_list,
|
||||
layout_context,
|
||||
|
@ -386,7 +387,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
fn compute_background_image_size(&self,
|
||||
style: &ComputedValues,
|
||||
bounds: &Rect<Au>,
|
||||
image: &png::Image)
|
||||
image: &Image)
|
||||
-> Size2D<Au> {
|
||||
// If `image_aspect_ratio` < `bounds_aspect_ratio`, the image is tall; otherwise, it is
|
||||
// wide.
|
||||
|
@ -1111,10 +1112,11 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
&*self.style,
|
||||
Cursor::DefaultCursor),
|
||||
(*clip).clone()),
|
||||
image: Arc::new(png::Image {
|
||||
image: Arc::new(Image {
|
||||
width: width as u32,
|
||||
height: height as u32,
|
||||
pixels: PixelsByColorType::RGBA8(canvas_data),
|
||||
format: PixelFormat::RGBA8,
|
||||
bytes: canvas_data,
|
||||
}),
|
||||
stretch_size: stacking_relative_content_box.size,
|
||||
image_rendering: image_rendering::T::Auto,
|
||||
|
|
|
@ -50,7 +50,6 @@ extern crate gfx_traits;
|
|||
extern crate layout_traits;
|
||||
extern crate libc;
|
||||
extern crate msg;
|
||||
extern crate png;
|
||||
extern crate script;
|
||||
extern crate script_traits;
|
||||
extern crate selectors;
|
||||
|
|
|
@ -4,11 +4,25 @@
|
|||
|
||||
use png;
|
||||
use stb_image::image as stb_image2;
|
||||
use std::mem;
|
||||
use util::vec::byte_swap;
|
||||
|
||||
// FIXME: Images must not be copied every frame. Instead we should atomically
|
||||
// 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.
|
||||
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) {
|
||||
match png::load_png_from_memory(buffer) {
|
||||
Ok(mut png_image) => {
|
||||
match png_image.pixels {
|
||||
png::PixelsByColorType::RGB8(ref mut data) => byte_swap(data),
|
||||
png::PixelsByColorType::RGBA8(ref mut data) => {
|
||||
byte_swap_and_premultiply(data)
|
||||
let (bytes, format) = match png_image.pixels {
|
||||
png::PixelsByColorType::K8(ref mut data) => {
|
||||
(data, PixelFormat::K8)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Some(png_image)
|
||||
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) => {
|
||||
byte_swap_and_premultiply(data);
|
||||
(data, PixelFormat::RGBA8)
|
||||
}
|
||||
};
|
||||
|
||||
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,
|
||||
}
|
||||
|
@ -57,10 +90,11 @@ pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
|
|||
} else {
|
||||
byte_swap(&mut image.data);
|
||||
}
|
||||
Some(png::Image {
|
||||
Some(Image {
|
||||
width: image.width as u32,
|
||||
height: image.height as u32,
|
||||
pixels: png::PixelsByColorType::RGBA8(image.data)
|
||||
format: PixelFormat::RGBA8,
|
||||
bytes: image.data,
|
||||
})
|
||||
}
|
||||
stb_image2::LoadResult::ImageF32(_image) => {
|
||||
|
|
|
@ -48,9 +48,6 @@ git = "https://github.com/servo/rust-selectors"
|
|||
[dependencies.js]
|
||||
git = "https://github.com/servo/rust-mozjs"
|
||||
|
||||
[dependencies.png]
|
||||
git = "https://github.com/servo/rust-png"
|
||||
|
||||
[dependencies.url]
|
||||
version = "0.2.33"
|
||||
features = ["query_encoding"]
|
||||
|
|
|
@ -35,7 +35,7 @@ use canvas_traits::{LineCapStyle, LineJoinStyle, CompositionOrBlending};
|
|||
use canvas::canvas_paint_task::CanvasPaintTask;
|
||||
|
||||
use net_traits::image_cache_task::{ImageCacheChan, ImageResponse};
|
||||
use png::PixelsByColorType;
|
||||
use net_traits::image::base::PixelFormat;
|
||||
|
||||
use num::{Float, ToPrimitive};
|
||||
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_data = match img.pixels {
|
||||
PixelsByColorType::RGBA8(ref pixels) => pixels.to_vec(),
|
||||
PixelsByColorType::K8(_) => panic!("K8 color type not supported"),
|
||||
PixelsByColorType::RGB8(_) => panic!("RGB8 color type not supported"),
|
||||
PixelsByColorType::KA8(_) => panic!("KA8 color type not supported"),
|
||||
let image_data = match img.format {
|
||||
PixelFormat::RGBA8 => img.bytes.to_vec(),
|
||||
PixelFormat::K8 => panic!("K8 color type not supported"),
|
||||
PixelFormat::RGB8 => panic!("RGB8 color type not supported"),
|
||||
PixelFormat::KA8 => panic!("KA8 color type not supported"),
|
||||
};
|
||||
|
||||
return Some((image_data, image_size));
|
||||
|
|
|
@ -48,7 +48,6 @@ extern crate libc;
|
|||
extern crate msg;
|
||||
extern crate net_traits;
|
||||
extern crate num;
|
||||
extern crate png;
|
||||
extern crate rustc_serialize;
|
||||
extern crate time;
|
||||
extern crate canvas;
|
||||
|
|
4
components/servo/Cargo.lock
generated
4
components/servo/Cargo.lock
generated
|
@ -431,14 +431,12 @@ dependencies = [
|
|||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile_traits 0.0.1",
|
||||
"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)",
|
||||
"script_traits 0.0.1",
|
||||
"skia 0.0.20130412 (git+https://github.com/servo/skia)",
|
||||
"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)",
|
||||
"style 0.0.1",
|
||||
"time 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -680,7 +678,6 @@ dependencies = [
|
|||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile_traits 0.0.1",
|
||||
"rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"script 0.0.1",
|
||||
|
@ -1073,7 +1070,6 @@ dependencies = [
|
|||
"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)",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile_traits 0.0.1",
|
||||
"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)",
|
||||
|
|
4
ports/cef/Cargo.lock
generated
4
ports/cef/Cargo.lock
generated
|
@ -430,14 +430,12 @@ dependencies = [
|
|||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile_traits 0.0.1",
|
||||
"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)",
|
||||
"script_traits 0.0.1",
|
||||
"skia 0.0.20130412 (git+https://github.com/servo/skia)",
|
||||
"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)",
|
||||
"style 0.0.1",
|
||||
"time 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -672,7 +670,6 @@ dependencies = [
|
|||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile_traits 0.0.1",
|
||||
"rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"script 0.0.1",
|
||||
|
@ -1053,7 +1050,6 @@ dependencies = [
|
|||
"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)",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile_traits 0.0.1",
|
||||
"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)",
|
||||
|
|
4
ports/gonk/Cargo.lock
generated
4
ports/gonk/Cargo.lock
generated
|
@ -409,14 +409,12 @@ dependencies = [
|
|||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile_traits 0.0.1",
|
||||
"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)",
|
||||
"script_traits 0.0.1",
|
||||
"skia 0.0.20130412 (git+https://github.com/servo/skia)",
|
||||
"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)",
|
||||
"style 0.0.1",
|
||||
"time 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -606,7 +604,6 @@ dependencies = [
|
|||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile_traits 0.0.1",
|
||||
"rustc-serialize 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"script 0.0.1",
|
||||
|
@ -961,7 +958,6 @@ dependencies = [
|
|||
"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)",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile_traits 0.0.1",
|
||||
"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)",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue