mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
Split the network stuff out of servo-gfx into servo-net
This commit is contained in:
parent
7267f806a7
commit
932070b9e7
26 changed files with 149 additions and 249 deletions
18
Makefile.in
18
Makefile.in
|
@ -168,21 +168,28 @@ DONE_servo_util = $(B)src/servo-util/libservoutil.dummy
|
||||||
|
|
||||||
DEPS_servo_util = $(CRATE_servo_util) $(SRC_servo_util) $(DONE_SUBMODULES)
|
DEPS_servo_util = $(CRATE_servo_util) $(SRC_servo_util) $(DONE_SUBMODULES)
|
||||||
|
|
||||||
RFLAGS_servo_gfx = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/servo-util
|
RFLAGS_servo_net = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/servo-util
|
||||||
|
SRC_servo_net = $(call rwildcard,$(S)src/servo-net/,*.rs)
|
||||||
|
CRATE_servo_net = $(S)src/servo-net/servo_net.rc
|
||||||
|
DONE_servo_net = $(B)src/servo-net/libservonet.dummy
|
||||||
|
|
||||||
|
DEPS_servo_net = $(CRATE_servo_net) $(SRC_servo_net) $(DONE_SUBMODULES) $(DONE_servo_util)
|
||||||
|
|
||||||
|
RFLAGS_servo_gfx = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/servo-util -L $(B)src/servo-net
|
||||||
SRC_servo_gfx = $(call rwildcard,$(S)src/servo-gfx/,*.rs)
|
SRC_servo_gfx = $(call rwildcard,$(S)src/servo-gfx/,*.rs)
|
||||||
CRATE_servo_gfx = $(S)src/servo-gfx/servo_gfx.rc
|
CRATE_servo_gfx = $(S)src/servo-gfx/servo_gfx.rc
|
||||||
DONE_servo_gfx = $(B)src/servo-gfx/libservogfx.dummy
|
DONE_servo_gfx = $(B)src/servo-gfx/libservogfx.dummy
|
||||||
|
|
||||||
DEPS_servo_gfx = $(CRATE_servo_gfx) $(SRC_servo_gfx) $(DONE_SUBMODULES) $(DONE_servo_util)
|
DEPS_servo_gfx = $(CRATE_servo_gfx) $(SRC_servo_gfx) $(DONE_SUBMODULES) $(DONE_servo_util) $(DONE_servo_net)
|
||||||
|
|
||||||
RFLAGS_servo = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/servo-gfx -L $(B)src/servo-util
|
RFLAGS_servo = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/servo-gfx -L $(B)src/servo-util -L $(B)src/servo-net
|
||||||
|
|
||||||
WEBIDL_servo = $(call rwildcard,$(S)src/servo/,*.webidl)
|
WEBIDL_servo = $(call rwildcard,$(S)src/servo/,*.webidl)
|
||||||
AUTOGEN_SRC_servo = $(patsubst %.webidl, %Binding.rs, $(WEBIDL_servo))
|
AUTOGEN_SRC_servo = $(patsubst %.webidl, %Binding.rs, $(WEBIDL_servo))
|
||||||
SRC_servo = $(call rwildcard,$(S)src/servo/,*.rs) $(AUTOGEN_SRC_servo)
|
SRC_servo = $(call rwildcard,$(S)src/servo/,*.rs) $(AUTOGEN_SRC_servo)
|
||||||
CRATE_servo = $(S)src/servo/servo.rc
|
CRATE_servo = $(S)src/servo/servo.rc
|
||||||
|
|
||||||
DEPS_servo = $(CRATE_servo) $(SRC_servo) $(DONE_SUBMODULES) $(DONE_servo_util) $(DONE_servo_gfx)
|
DEPS_servo = $(CRATE_servo) $(SRC_servo) $(DONE_SUBMODULES) $(DONE_servo_util) $(DONE_servo_gfx) $(DONE_servo_net)
|
||||||
|
|
||||||
# rules that depend on having correct meta-target vars (DEPS_CLEAN, DEPS_servo, etc)
|
# rules that depend on having correct meta-target vars (DEPS_CLEAN, DEPS_servo, etc)
|
||||||
include $(S)mk/check.mk
|
include $(S)mk/check.mk
|
||||||
|
@ -197,6 +204,9 @@ all: servo package
|
||||||
$(DONE_servo_util): $(DEPS_servo_util)
|
$(DONE_servo_util): $(DEPS_servo_util)
|
||||||
$(RUSTC) $(RFLAGS_servo_util) -o $@ $< && touch $@
|
$(RUSTC) $(RFLAGS_servo_util) -o $@ $< && touch $@
|
||||||
|
|
||||||
|
$(DONE_servo_net): $(DEPS_servo_net)
|
||||||
|
$(RUSTC) $(RFLAGS_servo_net) -o $@ $< && touch $@
|
||||||
|
|
||||||
$(DONE_servo_gfx): $(DEPS_servo_gfx)
|
$(DONE_servo_gfx): $(DEPS_servo_gfx)
|
||||||
$(RUSTC) $(RFLAGS_servo_gfx) -o $@ $< && touch $@
|
$(RUSTC) $(RFLAGS_servo_gfx) -o $@ $< && touch $@
|
||||||
|
|
||||||
|
|
1
configure
vendored
1
configure
vendored
|
@ -419,6 +419,7 @@ do
|
||||||
done
|
done
|
||||||
|
|
||||||
make_dir ${CFG_BUILD_DIR}src/servo-util
|
make_dir ${CFG_BUILD_DIR}src/servo-util
|
||||||
|
make_dir ${CFG_BUILD_DIR}src/servo-net
|
||||||
make_dir ${CFG_BUILD_DIR}src/servo-gfx
|
make_dir ${CFG_BUILD_DIR}src/servo-gfx
|
||||||
make_dir src/test/ref
|
make_dir src/test/ref
|
||||||
make_dir src/rust
|
make_dir src/rust
|
||||||
|
|
|
@ -4,15 +4,15 @@
|
||||||
|
|
||||||
use color::{Color, rgb};
|
use color::{Color, rgb};
|
||||||
use geometry::Au;
|
use geometry::Au;
|
||||||
use image::base::Image;
|
|
||||||
use render_context::RenderContext;
|
use render_context::RenderContext;
|
||||||
use text::SendableTextRun;
|
use text::SendableTextRun;
|
||||||
use servo_util::range::Range;
|
|
||||||
|
|
||||||
use clone_arc = std::arc::clone;
|
use clone_arc = std::arc::clone;
|
||||||
use geom::Rect;
|
use geom::Rect;
|
||||||
use geom::Point2D;
|
use geom::Point2D;
|
||||||
use std::arc::ARC;
|
use std::arc::ARC;
|
||||||
|
use servo_net::image::base::Image;
|
||||||
|
use servo_util::range::Range;
|
||||||
|
|
||||||
struct DisplayItemData {
|
struct DisplayItemData {
|
||||||
bounds : Rect<Au>, // TODO: whose coordinate system should this use?
|
bounds : Rect<Au>, // TODO: whose coordinate system should this use?
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
use core::io::WriterUtil;
|
|
||||||
use surface;
|
|
||||||
|
|
||||||
fn encode(writer: @io::Writer, surface: &surface::ImageSurface) {
|
|
||||||
assert!(surface.format == surface::fo_rgba_8888);
|
|
||||||
|
|
||||||
writer.write_u8(0u8); // identsize
|
|
||||||
writer.write_u8(0u8); // colourmaptype
|
|
||||||
writer.write_u8(2u8); // imagetype
|
|
||||||
|
|
||||||
writer.write_le_u16(0u16); // colourmapstart
|
|
||||||
writer.write_le_u16(0u16); // colourmaplength
|
|
||||||
writer.write_u8(16u8); // colourmapbits
|
|
||||||
|
|
||||||
writer.write_le_u16(0u16); // xstart
|
|
||||||
writer.write_le_u16(0u16); // ystart
|
|
||||||
writer.write_le_u16(surface.size.width as u16); // width
|
|
||||||
writer.write_le_u16(surface.size.height as u16); // height
|
|
||||||
writer.write_u8(32u8); // bits
|
|
||||||
writer.write_u8(0x30u8); // descriptor
|
|
||||||
|
|
||||||
writer.write(surface.buffer);
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,17 +10,11 @@ use azure::azure_hl::{CoreGraphicsAcceleratedBackend, Direct2DBackend, SkiaBacke
|
||||||
|
|
||||||
pub struct Opts {
|
pub struct Opts {
|
||||||
urls: ~[~str],
|
urls: ~[~str],
|
||||||
render_mode: RenderMode,
|
|
||||||
render_backend: BackendType,
|
render_backend: BackendType,
|
||||||
n_render_threads: uint,
|
n_render_threads: uint,
|
||||||
tile_size: uint,
|
tile_size: uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum RenderMode {
|
|
||||||
Screen,
|
|
||||||
Png(~str)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(non_implicitly_copyable_typarams)]
|
#[allow(non_implicitly_copyable_typarams)]
|
||||||
pub fn from_cmdline_args(args: &[~str]) -> Opts {
|
pub fn from_cmdline_args(args: &[~str]) -> Opts {
|
||||||
use std::getopts;
|
use std::getopts;
|
||||||
|
@ -45,11 +39,6 @@ pub fn from_cmdline_args(args: &[~str]) -> Opts {
|
||||||
copy opt_match.free
|
copy opt_match.free
|
||||||
};
|
};
|
||||||
|
|
||||||
let render_mode = match getopts::opt_maybe_str(&opt_match, ~"o") {
|
|
||||||
Some(output_file) => Png(output_file),
|
|
||||||
None => Screen,
|
|
||||||
};
|
|
||||||
|
|
||||||
let render_backend = match getopts::opt_maybe_str(&opt_match, ~"r") {
|
let render_backend = match getopts::opt_maybe_str(&opt_match, ~"r") {
|
||||||
Some(backend_str) => {
|
Some(backend_str) => {
|
||||||
if backend_str == ~"direct2d" {
|
if backend_str == ~"direct2d" {
|
||||||
|
@ -81,7 +70,6 @@ pub fn from_cmdline_args(args: &[~str]) -> Opts {
|
||||||
|
|
||||||
Opts {
|
Opts {
|
||||||
urls: urls,
|
urls: urls,
|
||||||
render_mode: render_mode,
|
|
||||||
render_backend: render_backend,
|
render_backend: render_backend,
|
||||||
n_render_threads: n_render_threads,
|
n_render_threads: n_render_threads,
|
||||||
tile_size: tile_size,
|
tile_size: tile_size,
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
use compositor::LayerBuffer;
|
use compositor::LayerBuffer;
|
||||||
use font_context::FontContext;
|
use font_context::FontContext;
|
||||||
use geometry::Au;
|
use geometry::Au;
|
||||||
use image::base::Image;
|
|
||||||
use opts::Opts;
|
use opts::Opts;
|
||||||
|
|
||||||
use azure::azure_hl::{B8G8R8A8, Color, ColorPattern, DrawOptions};
|
use azure::azure_hl::{B8G8R8A8, Color, ColorPattern, DrawOptions};
|
||||||
|
@ -15,6 +14,7 @@ use core::libc::types::common::c99::uint16_t;
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
|
use servo_net::image::base::Image;
|
||||||
use std::arc;
|
use std::arc;
|
||||||
use std::arc::ARC;
|
use std::arc::ARC;
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,13 @@ use geom::matrix2d::Matrix2D;
|
||||||
use opts::Opts;
|
use opts::Opts;
|
||||||
use render_context::RenderContext;
|
use render_context::RenderContext;
|
||||||
use render_layers::{RenderLayer, render_layers};
|
use render_layers::{RenderLayer, render_layers};
|
||||||
use resource::util::spawn_listener;
|
|
||||||
use servo_util::time::time;
|
|
||||||
|
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
use core::comm::{Port, SharedChan};
|
use core::comm::{Port, SharedChan};
|
||||||
use core::task::SingleThreaded;
|
use core::task::SingleThreaded;
|
||||||
use std::task_pool::TaskPool;
|
use std::task_pool::TaskPool;
|
||||||
|
use servo_net::util::spawn_listener;
|
||||||
|
use servo_util::time::time;
|
||||||
|
|
||||||
pub enum Msg {
|
pub enum Msg {
|
||||||
RenderMsg(RenderLayer),
|
RenderMsg(RenderLayer),
|
||||||
|
|
|
@ -13,6 +13,7 @@ extern mod geom;
|
||||||
extern mod http_client;
|
extern mod http_client;
|
||||||
extern mod stb_image;
|
extern mod stb_image;
|
||||||
extern mod std;
|
extern mod std;
|
||||||
|
extern mod servo_net;
|
||||||
extern mod servo_util (name = "servo_util");
|
extern mod servo_util (name = "servo_util");
|
||||||
|
|
||||||
// Eventually we would like the shaper to be pluggable, as many operating systems have their own
|
// Eventually we would like the shaper to be pluggable, as many operating systems have their own
|
||||||
|
@ -57,22 +58,7 @@ pub mod opts;
|
||||||
#[path="platform/mod.rs"]
|
#[path="platform/mod.rs"]
|
||||||
pub mod platform;
|
pub mod platform;
|
||||||
|
|
||||||
// Images
|
|
||||||
pub mod image {
|
|
||||||
pub mod base;
|
|
||||||
pub mod holder;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
#[path = "text/mod.rs"]
|
#[path = "text/mod.rs"]
|
||||||
pub mod text;
|
pub mod text;
|
||||||
|
|
||||||
// FIXME: Blech. This does not belong in the GFX module.
|
|
||||||
pub mod resource {
|
|
||||||
pub mod file_loader;
|
|
||||||
pub mod http_loader;
|
|
||||||
pub mod image_cache_task;
|
|
||||||
pub mod local_image_cache;
|
|
||||||
pub mod resource_task;
|
|
||||||
pub mod util;
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,16 +2,17 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use core::task::spawn;
|
use resource_task::{Done, LoaderTask, Payload};
|
||||||
use resource::resource_task::{Payload, Done, LoaderTask};
|
|
||||||
use core::io::{file_reader, ReaderUtil};
|
use core::io::{ReaderUtil, file_reader};
|
||||||
|
use core::task;
|
||||||
|
|
||||||
static READ_SIZE: uint = 1024;
|
static READ_SIZE: uint = 1024;
|
||||||
|
|
||||||
pub fn factory() -> LoaderTask {
|
pub fn factory() -> LoaderTask {
|
||||||
let f: LoaderTask = |url, progress_chan| {
|
let f: LoaderTask = |url, progress_chan| {
|
||||||
assert!(url.scheme == ~"file");
|
assert!("file" == url.scheme);
|
||||||
do spawn {
|
do task::spawn {
|
||||||
// FIXME: Resolve bug prevents us from moving the path out of the URL.
|
// FIXME: Resolve bug prevents us from moving the path out of the URL.
|
||||||
match file_reader(&Path(url.path)) {
|
match file_reader(&Path(url.path)) {
|
||||||
Ok(reader) => {
|
Ok(reader) => {
|
|
@ -2,18 +2,19 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use resource_task::{Payload, Done, LoaderTask};
|
||||||
|
|
||||||
use core::comm::SharedChan;
|
use core::comm::SharedChan;
|
||||||
use core::task::spawn;
|
use core::task;
|
||||||
use resource::resource_task::{Payload, Done, LoaderTask};
|
use http_client::uv_http_request;
|
||||||
use http_client;
|
use http_client;
|
||||||
use http_client::{uv_http_request};
|
|
||||||
|
|
||||||
pub fn factory() -> LoaderTask {
|
pub fn factory() -> LoaderTask {
|
||||||
let f: LoaderTask = |url, progress_chan| {
|
let f: LoaderTask = |url, progress_chan| {
|
||||||
assert!(url.scheme == ~"http");
|
assert!(url.scheme == ~"http");
|
||||||
|
|
||||||
let progress_chan = SharedChan::new(progress_chan);
|
let progress_chan = SharedChan::new(progress_chan);
|
||||||
do spawn {
|
do task::spawn {
|
||||||
debug!("http_loader: requesting via http: %?", url.clone());
|
debug!("http_loader: requesting via http: %?", url.clone());
|
||||||
let mut request = uv_http_request(url.clone());
|
let mut request = uv_http_request(url.clone());
|
||||||
let errored = @mut false;
|
let errored = @mut false;
|
|
@ -20,7 +20,6 @@ pub fn test_image_bin() -> ~[u8] {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
|
pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
|
||||||
|
|
||||||
// Can't remember why we do this. Maybe it's what cairo wants
|
// Can't remember why we do this. Maybe it's what cairo wants
|
||||||
static FORCE_DEPTH: uint = 4;
|
static FORCE_DEPTH: uint = 4;
|
||||||
|
|
|
@ -3,21 +3,20 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use image::base::Image;
|
use image::base::Image;
|
||||||
use resource::image_cache_task::{ImageReady, ImageNotReady, ImageFailed};
|
use image_cache_task::{ImageReady, ImageNotReady, ImageFailed};
|
||||||
use resource::local_image_cache::LocalImageCache;
|
use local_image_cache::LocalImageCache;
|
||||||
|
|
||||||
use core::util::replace;
|
use core::util::replace;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
use std::net::url::Url;
|
use std::net::url::Url;
|
||||||
use std::arc::{ARC, clone, get};
|
use std::arc::{ARC, clone, get};
|
||||||
|
|
||||||
// FIXME: Nasty coupling to resource here. This should probably be factored out into an interface
|
// FIXME: Nasty coupling here This will be a problem if we want to factor out image handling from
|
||||||
// and use dependency injection.
|
// the network stack. This should probably be factored out into an interface and use dependency
|
||||||
|
// injection.
|
||||||
|
|
||||||
/** A struct to store image data. The image will be loaded once, the
|
/// A struct to store image data. The image will be loaded once the first time it is requested,
|
||||||
first time it is requested, and an arc will be stored. Clones of
|
/// and an ARC will be stored. Clones of this ARC are given out on demand.
|
||||||
this arc are given out on demand.
|
|
||||||
*/
|
|
||||||
pub struct ImageHolder {
|
pub struct ImageHolder {
|
||||||
url: Url,
|
url: Url,
|
||||||
image: Option<ARC<~Image>>,
|
image: Option<ARC<~Image>>,
|
||||||
|
@ -46,18 +45,16 @@ pub impl ImageHolder {
|
||||||
holder
|
holder
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// This version doesn't perform any computation, but may be stale w.r.t. newly-available image
|
||||||
This version doesn't perform any computation, but may be stale w.r.t.
|
/// data that determines size.
|
||||||
newly-available image data that determines size.
|
///
|
||||||
|
/// The intent is that the impure version is used during layout when dimensions are used for
|
||||||
The intent is that the impure version is used during layout when
|
/// computing layout.
|
||||||
dimensions are used for computing layout.
|
|
||||||
*/
|
|
||||||
fn size(&self) -> Size2D<int> {
|
fn size(&self) -> Size2D<int> {
|
||||||
self.cached_size
|
self.cached_size
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Query and update current image size */
|
/// Query and update the current image size.
|
||||||
fn get_size(&mut self) -> Option<Size2D<int>> {
|
fn get_size(&mut self) -> Option<Size2D<int>> {
|
||||||
debug!("get_size() %?", self.url);
|
debug!("get_size() %?", self.url);
|
||||||
match self.get_image() {
|
match self.get_image() {
|
||||||
|
@ -103,3 +100,4 @@ pub impl ImageHolder {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
|
@ -3,46 +3,46 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use image::base::{Image, load_from_memory};
|
use image::base::{Image, load_from_memory};
|
||||||
use resource::resource_task;
|
use resource_task;
|
||||||
use resource::resource_task::ResourceTask;
|
use resource_task::ResourceTask;
|
||||||
use servo_util::url::{UrlMap, url_map};
|
use servo_util::url::{UrlMap, url_map};
|
||||||
|
|
||||||
use clone_arc = std::arc::clone;
|
use clone_arc = std::arc::clone;
|
||||||
|
use core::cell::Cell;
|
||||||
use core::comm::{Chan, Port, SharedChan, stream};
|
use core::comm::{Chan, Port, SharedChan, stream};
|
||||||
use core::task::spawn;
|
use core::task::spawn;
|
||||||
use core::to_str::ToStr;
|
use core::to_str::ToStr;
|
||||||
use core::util::replace;
|
use core::util::replace;
|
||||||
use std::arc::ARC;
|
use std::arc::ARC;
|
||||||
use std::net::url::Url;
|
use std::net::url::Url;
|
||||||
use core::cell::Cell;
|
|
||||||
|
|
||||||
pub enum Msg {
|
pub enum Msg {
|
||||||
/// Tell the cache that we may need a particular image soon. Must be posted
|
/// Tell the cache that we may need a particular image soon. Must be posted
|
||||||
/// before Decode
|
/// before Decode
|
||||||
pub Prefetch(Url),
|
Prefetch(Url),
|
||||||
|
|
||||||
// FIXME: We can probably get rid of this Cell now
|
// FIXME: We can probably get rid of this Cell now
|
||||||
/// Used be the prefetch tasks to post back image binaries
|
/// Used be the prefetch tasks to post back image binaries
|
||||||
priv StorePrefetchedImageData(Url, Result<Cell<~[u8]>, ()>),
|
priv StorePrefetchedImageData(Url, Result<Cell<~[u8]>, ()>),
|
||||||
|
|
||||||
/// Tell the cache to decode an image. Must be posted before GetImage/WaitForImage
|
/// Tell the cache to decode an image. Must be posted before GetImage/WaitForImage
|
||||||
pub Decode(Url),
|
Decode(Url),
|
||||||
|
|
||||||
/// Used by the decoder tasks to post decoded images back to the cache
|
/// Used by the decoder tasks to post decoded images back to the cache
|
||||||
priv StoreImage(Url, Option<ARC<~Image>>),
|
priv StoreImage(Url, Option<ARC<~Image>>),
|
||||||
|
|
||||||
/// Request an Image object for a URL. If the image is not is not immediately
|
/// Request an Image object for a URL. If the image is not is not immediately
|
||||||
/// available then ImageNotReady is returned.
|
/// available then ImageNotReady is returned.
|
||||||
pub GetImage(Url, Chan<ImageResponseMsg>),
|
GetImage(Url, Chan<ImageResponseMsg>),
|
||||||
|
|
||||||
/// Wait for an image to become available (or fail to load).
|
/// Wait for an image to become available (or fail to load).
|
||||||
pub WaitForImage(Url, Chan<ImageResponseMsg>),
|
WaitForImage(Url, Chan<ImageResponseMsg>),
|
||||||
|
|
||||||
/// For testing
|
/// For testing
|
||||||
priv OnMsg(~fn(msg: &Msg)),
|
priv OnMsg(~fn(msg: &Msg)),
|
||||||
|
|
||||||
/// Clients must wait for a response before shutting down the ResourceTask
|
/// Clients must wait for a response before shutting down the ResourceTask
|
||||||
pub Exit(Chan<()>)
|
Exit(Chan<()>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ImageResponseMsg {
|
pub enum ImageResponseMsg {
|
||||||
|
@ -54,9 +54,9 @@ pub enum ImageResponseMsg {
|
||||||
impl ImageResponseMsg {
|
impl ImageResponseMsg {
|
||||||
fn clone(&self) -> ImageResponseMsg {
|
fn clone(&self) -> ImageResponseMsg {
|
||||||
match *self {
|
match *self {
|
||||||
ImageReady(ref img) => ImageReady(clone_arc(img)),
|
ImageReady(ref img) => ImageReady(clone_arc(img)),
|
||||||
ImageNotReady => ImageNotReady,
|
ImageNotReady => ImageNotReady,
|
||||||
ImageFailed => ImageFailed
|
ImageFailed => ImageFailed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,17 +65,16 @@ impl Eq for ImageResponseMsg {
|
||||||
fn eq(&self, other: &ImageResponseMsg) -> bool {
|
fn eq(&self, other: &ImageResponseMsg) -> bool {
|
||||||
// FIXME: Bad copies
|
// FIXME: Bad copies
|
||||||
match (self.clone(), other.clone()) {
|
match (self.clone(), other.clone()) {
|
||||||
(ImageReady(*), ImageReady(*)) => fail!(~"unimplemented comparison"),
|
(ImageReady(*), ImageReady(*)) => fail!(~"unimplemented comparison"),
|
||||||
(ImageNotReady, ImageNotReady) => true,
|
(ImageNotReady, ImageNotReady) => true,
|
||||||
(ImageFailed, ImageFailed) => true,
|
(ImageFailed, ImageFailed) => true,
|
||||||
|
|
||||||
(ImageReady(*), _)
|
(ImageReady(*), _) | (ImageNotReady, _) | (ImageFailed, _) => false
|
||||||
| (ImageNotReady, _)
|
|
||||||
| (ImageFailed, _) => false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ne(&self, other: &ImageResponseMsg) -> bool {
|
fn ne(&self, other: &ImageResponseMsg) -> bool {
|
||||||
return !(*self).eq(other);
|
!(*self).eq(other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,9 +86,8 @@ pub fn ImageCacheTask(resource_task: ResourceTask) -> ImageCacheTask {
|
||||||
ImageCacheTask_(resource_task, default_decoder_factory)
|
ImageCacheTask_(resource_task, default_decoder_factory)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ImageCacheTask_(resource_task: ResourceTask,
|
pub fn ImageCacheTask_(resource_task: ResourceTask, decoder_factory: DecoderFactory)
|
||||||
decoder_factory: DecoderFactory)
|
-> ImageCacheTask {
|
||||||
-> ImageCacheTask {
|
|
||||||
// FIXME: Doing some dancing to avoid copying decoder_factory, our test
|
// FIXME: Doing some dancing to avoid copying decoder_factory, our test
|
||||||
// version of which contains an uncopyable type which rust will currently
|
// version of which contains an uncopyable type which rust will currently
|
||||||
// copy unsoundly
|
// copy unsoundly
|
||||||
|
@ -140,7 +138,7 @@ fn SyncImageCacheTask(resource_task: ResourceTask) -> ImageCacheTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return SharedChan::new(chan);
|
SharedChan::new(chan)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ImageCache {
|
struct ImageCache {
|
||||||
|
@ -175,9 +173,7 @@ enum AfterPrefetch {
|
||||||
|
|
||||||
#[allow(non_implicitly_copyable_typarams)]
|
#[allow(non_implicitly_copyable_typarams)]
|
||||||
impl ImageCache {
|
impl ImageCache {
|
||||||
|
|
||||||
pub fn run(&mut self) {
|
pub fn run(&mut self) {
|
||||||
|
|
||||||
let mut msg_handlers: ~[~fn(msg: &Msg)] = ~[];
|
let mut msg_handlers: ~[~fn(msg: &Msg)] = ~[];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -397,26 +393,12 @@ impl ImageCache {
|
||||||
|
|
||||||
priv fn get_image(&self, url: Url, response: Chan<ImageResponseMsg>) {
|
priv fn get_image(&self, url: Url, response: Chan<ImageResponseMsg>) {
|
||||||
match self.get_state(copy url) {
|
match self.get_state(copy url) {
|
||||||
Init => fail!(~"request for image before prefetch"),
|
Init => fail!(~"request for image before prefetch"),
|
||||||
|
Prefetching(DoDecode) => response.send(ImageNotReady),
|
||||||
Prefetching(DoDecode) => {
|
Prefetching(DoNotDecode) | Prefetched(*) => fail!(~"request for image before decode"),
|
||||||
response.send(ImageNotReady);
|
Decoding => response.send(ImageNotReady),
|
||||||
}
|
Decoded(image) => response.send(ImageReady(clone_arc(image))),
|
||||||
|
Failed => response.send(ImageFailed),
|
||||||
Prefetching(DoNotDecode)
|
|
||||||
| Prefetched(*) => fail!(~"request for image before decode"),
|
|
||||||
|
|
||||||
Decoding => {
|
|
||||||
response.send(ImageNotReady)
|
|
||||||
}
|
|
||||||
|
|
||||||
Decoded(image) => {
|
|
||||||
response.send(ImageReady(clone_arc(image)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Failed => {
|
|
||||||
response.send(ImageFailed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,7 +487,6 @@ fn mock_resource_task(on_load: ~fn(resource: Chan<resource_task::ProgressMsg>))
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_exit_on_request() {
|
fn should_exit_on_request() {
|
||||||
|
|
||||||
let mock_resource_task = mock_resource_task(|_response| () );
|
let mock_resource_task = mock_resource_task(|_response| () );
|
||||||
|
|
||||||
let image_cache_task = ImageCacheTask(mock_resource_task);
|
let image_cache_task = ImageCacheTask(mock_resource_task);
|
||||||
|
@ -518,7 +499,6 @@ fn should_exit_on_request() {
|
||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn should_fail_if_unprefetched_image_is_requested() {
|
fn should_fail_if_unprefetched_image_is_requested() {
|
||||||
|
|
||||||
let mock_resource_task = mock_resource_task(|_response| () );
|
let mock_resource_task = mock_resource_task(|_response| () );
|
||||||
|
|
||||||
let image_cache_task = ImageCacheTask(mock_resource_task);
|
let image_cache_task = ImageCacheTask(mock_resource_task);
|
||||||
|
@ -552,7 +532,6 @@ fn should_request_url_from_resource_task_on_prefetch() {
|
||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn should_fail_if_requesting_decode_of_an_unprefetched_image() {
|
fn should_fail_if_requesting_decode_of_an_unprefetched_image() {
|
||||||
|
|
||||||
let mock_resource_task = mock_resource_task(|_response| () );
|
let mock_resource_task = mock_resource_task(|_response| () );
|
||||||
|
|
||||||
let image_cache_task = ImageCacheTask(mock_resource_task);
|
let image_cache_task = ImageCacheTask(mock_resource_task);
|
||||||
|
@ -565,7 +544,6 @@ fn should_fail_if_requesting_decode_of_an_unprefetched_image() {
|
||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn should_fail_if_requesting_image_before_requesting_decode() {
|
fn should_fail_if_requesting_image_before_requesting_decode() {
|
||||||
|
|
||||||
let mock_resource_task = do mock_resource_task |response| {
|
let mock_resource_task = do mock_resource_task |response| {
|
||||||
response.send(resource_task::Done(result::Ok(())));
|
response.send(resource_task::Done(result::Ok(())));
|
||||||
};
|
};
|
||||||
|
@ -606,7 +584,6 @@ fn should_not_request_url_from_resource_task_on_multiple_prefetches() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_image_not_ready_if_data_has_not_arrived() {
|
fn should_return_image_not_ready_if_data_has_not_arrived() {
|
||||||
|
|
||||||
let (wait_chan, wait_port) = pipes::stream();
|
let (wait_chan, wait_port) = pipes::stream();
|
||||||
|
|
||||||
let mock_resource_task = do mock_resource_task |response| {
|
let mock_resource_task = do mock_resource_task |response| {
|
||||||
|
@ -632,7 +609,6 @@ fn should_return_image_not_ready_if_data_has_not_arrived() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_decoded_image_data_if_data_has_arrived() {
|
fn should_return_decoded_image_data_if_data_has_arrived() {
|
||||||
|
|
||||||
let mock_resource_task = do mock_resource_task |response| {
|
let mock_resource_task = do mock_resource_task |response| {
|
||||||
response.send(resource_task::Payload(test_image_bin()));
|
response.send(resource_task::Payload(test_image_bin()));
|
||||||
response.send(resource_task::Done(result::Ok(())));
|
response.send(resource_task::Done(result::Ok(())));
|
||||||
|
@ -670,7 +646,6 @@ fn should_return_decoded_image_data_if_data_has_arrived() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_decoded_image_data_for_multiple_requests() {
|
fn should_return_decoded_image_data_for_multiple_requests() {
|
||||||
|
|
||||||
let mock_resource_task = do mock_resource_task |response| {
|
let mock_resource_task = do mock_resource_task |response| {
|
||||||
response.send(resource_task::Payload(test_image_bin()));
|
response.send(resource_task::Payload(test_image_bin()));
|
||||||
response.send(resource_task::Done(result::Ok(())));
|
response.send(resource_task::Done(result::Ok(())));
|
||||||
|
@ -710,7 +685,6 @@ fn should_return_decoded_image_data_for_multiple_requests() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_not_request_image_from_resource_task_if_image_is_already_available() {
|
fn should_not_request_image_from_resource_task_if_image_is_already_available() {
|
||||||
|
|
||||||
let image_bin_sent = comm::Port();
|
let image_bin_sent = comm::Port();
|
||||||
let image_bin_sent_chan = image_bin_sent.chan();
|
let image_bin_sent_chan = image_bin_sent.chan();
|
||||||
|
|
||||||
|
@ -755,7 +729,6 @@ fn should_not_request_image_from_resource_task_if_image_is_already_available() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_not_request_image_from_resource_task_if_image_fetch_already_failed() {
|
fn should_not_request_image_from_resource_task_if_image_fetch_already_failed() {
|
||||||
|
|
||||||
let image_bin_sent = comm::Port();
|
let image_bin_sent = comm::Port();
|
||||||
let image_bin_sent_chan = image_bin_sent.chan();
|
let image_bin_sent_chan = image_bin_sent.chan();
|
||||||
|
|
||||||
|
@ -802,7 +775,6 @@ fn should_not_request_image_from_resource_task_if_image_fetch_already_failed() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_failed_if_image_bin_cannot_be_fetched() {
|
fn should_return_failed_if_image_bin_cannot_be_fetched() {
|
||||||
|
|
||||||
let mock_resource_task = do mock_resource_task |response| {
|
let mock_resource_task = do mock_resource_task |response| {
|
||||||
response.send(resource_task::Payload(test_image_bin()));
|
response.send(resource_task::Payload(test_image_bin()));
|
||||||
// ERROR fetching image
|
// ERROR fetching image
|
||||||
|
@ -841,7 +813,6 @@ fn should_return_failed_if_image_bin_cannot_be_fetched() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_failed_for_multiple_get_image_requests_if_image_bin_cannot_be_fetched() {
|
fn should_return_failed_for_multiple_get_image_requests_if_image_bin_cannot_be_fetched() {
|
||||||
|
|
||||||
let mock_resource_task = do mock_resource_task |response | {
|
let mock_resource_task = do mock_resource_task |response | {
|
||||||
response.send(resource_task::Payload(test_image_bin()));
|
response.send(resource_task::Payload(test_image_bin()));
|
||||||
// ERROR fetching image
|
// ERROR fetching image
|
||||||
|
@ -888,7 +859,6 @@ fn should_return_failed_for_multiple_get_image_requests_if_image_bin_cannot_be_f
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_not_ready_if_image_is_still_decoding() {
|
fn should_return_not_ready_if_image_is_still_decoding() {
|
||||||
|
|
||||||
let (wait_to_decode_chan, wait_to_decode_port) = pipes::stream();
|
let (wait_to_decode_chan, wait_to_decode_port) = pipes::stream();
|
||||||
|
|
||||||
let mock_resource_task = do mock_resource_task |response| {
|
let mock_resource_task = do mock_resource_task |response| {
|
||||||
|
@ -943,7 +913,6 @@ fn should_return_not_ready_if_image_is_still_decoding() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_failed_if_image_decode_fails() {
|
fn should_return_failed_if_image_decode_fails() {
|
||||||
|
|
||||||
let mock_resource_task = do mock_resource_task |response| {
|
let mock_resource_task = do mock_resource_task |response| {
|
||||||
// Bogus data
|
// Bogus data
|
||||||
response.send(resource_task::Payload(~[]));
|
response.send(resource_task::Payload(~[]));
|
||||||
|
@ -984,7 +953,6 @@ fn should_return_failed_if_image_decode_fails() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_image_on_wait_if_image_is_already_loaded() {
|
fn should_return_image_on_wait_if_image_is_already_loaded() {
|
||||||
|
|
||||||
let mock_resource_task = do mock_resource_task |response| {
|
let mock_resource_task = do mock_resource_task |response| {
|
||||||
response.send(resource_task::Payload(test_image_bin()));
|
response.send(resource_task::Payload(test_image_bin()));
|
||||||
response.send(resource_task::Done(result::Ok(())));
|
response.send(resource_task::Done(result::Ok(())));
|
||||||
|
@ -1022,7 +990,6 @@ fn should_return_image_on_wait_if_image_is_already_loaded() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_image_on_wait_if_image_is_not_yet_loaded() {
|
fn should_return_image_on_wait_if_image_is_not_yet_loaded() {
|
||||||
|
|
||||||
let (wait_chan, wait_port) = pipes::stream();
|
let (wait_chan, wait_port) = pipes::stream();
|
||||||
|
|
||||||
let mock_resource_task = do mock_resource_task |response| {
|
let mock_resource_task = do mock_resource_task |response| {
|
||||||
|
@ -1053,7 +1020,6 @@ fn should_return_image_on_wait_if_image_is_not_yet_loaded() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_image_failed_on_wait_if_image_fails_to_load() {
|
fn should_return_image_failed_on_wait_if_image_fails_to_load() {
|
||||||
|
|
||||||
let (wait_chan, wait_port) = pipes::stream();
|
let (wait_chan, wait_port) = pipes::stream();
|
||||||
|
|
||||||
let mock_resource_task = do mock_resource_task |response| {
|
let mock_resource_task = do mock_resource_task |response| {
|
||||||
|
@ -1105,3 +1071,4 @@ fn sync_cache_should_wait_for_images() {
|
||||||
image_cache_task.exit();
|
image_cache_task.exit();
|
||||||
mock_resource_task.send(resource_task::Exit);
|
mock_resource_task.send(resource_task::Exit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,13 @@ extra message traffic, it also avoids waiting on the same image
|
||||||
multiple times and thus triggering reflows multiple times.
|
multiple times and thus triggering reflows multiple times.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use image_cache_task::{Decode, GetImage, ImageCacheTask, ImageFailed, ImageNotReady, ImageReady};
|
||||||
|
use image_cache_task::{ImageResponseMsg, Prefetch, WaitForImage};
|
||||||
|
|
||||||
use clone_arc = std::arc::clone;
|
use clone_arc = std::arc::clone;
|
||||||
use std::net::url::Url;
|
|
||||||
use core::comm::Port;
|
use core::comm::Port;
|
||||||
use resource::image_cache_task::{ImageCacheTask, ImageResponseMsg, Prefetch, Decode, GetImage};
|
|
||||||
use resource::image_cache_task::{ WaitForImage, ImageReady, ImageNotReady, ImageFailed};
|
|
||||||
use servo_util::url::{UrlMap, url_map};
|
use servo_util::url::{UrlMap, url_map};
|
||||||
|
use std::net::url::Url;
|
||||||
|
|
||||||
pub fn LocalImageCache(image_cache_task: ImageCacheTask) -> LocalImageCache {
|
pub fn LocalImageCache(image_cache_task: ImageCacheTask) -> LocalImageCache {
|
||||||
LocalImageCache {
|
LocalImageCache {
|
|
@ -2,17 +2,15 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
/*!
|
//! A task that takes a URL and streams back the binary data.
|
||||||
|
|
||||||
A task that takes a URL and streams back the binary data
|
use file_loader;
|
||||||
|
use http_loader;
|
||||||
*/
|
|
||||||
|
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
use core::comm::{Chan, Port, SharedChan};
|
use core::comm::{Chan, Port, SharedChan};
|
||||||
use resource::util::spawn_listener;
|
|
||||||
use std::net::url::{Url, to_str};
|
use std::net::url::{Url, to_str};
|
||||||
use super::{file_loader, http_loader};
|
use util::spawn_listener;
|
||||||
|
|
||||||
pub enum ControlMsg {
|
pub enum ControlMsg {
|
||||||
/// Request the data associated with a particular URL
|
/// Request the data associated with a particular URL
|
33
src/servo-net/servo_net.rc
Normal file
33
src/servo-net/servo_net.rc
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#[link(name = "servo_net",
|
||||||
|
vers = "0.1",
|
||||||
|
uuid = "69c2b7b7-0d7d-4514-a48a-0eed61476039",
|
||||||
|
url = "http://servo.org/")];
|
||||||
|
#[crate_type = "lib"];
|
||||||
|
|
||||||
|
extern mod geom;
|
||||||
|
extern mod http_client;
|
||||||
|
extern mod servo_util;
|
||||||
|
extern mod stb_image;
|
||||||
|
extern mod std;
|
||||||
|
|
||||||
|
/// Image handling.
|
||||||
|
///
|
||||||
|
/// It may be surprising that this goes in the network crate as opposed to the graphics crate.
|
||||||
|
/// However, image handling is generally very integrated with the network stack (especially where
|
||||||
|
/// caching is involved) and as a result it must live in here.
|
||||||
|
pub mod image {
|
||||||
|
pub mod base;
|
||||||
|
pub mod holder;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod file_loader;
|
||||||
|
pub mod http_loader;
|
||||||
|
pub mod image_cache_task;
|
||||||
|
pub mod local_image_cache;
|
||||||
|
pub mod resource_task;
|
||||||
|
pub mod util;
|
||||||
|
|
|
@ -17,15 +17,13 @@ use layout::layout_task;
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
use core::comm::{Port, SharedChan};
|
use core::comm::{Port, SharedChan};
|
||||||
use core::either;
|
use core::either;
|
||||||
use core::io::{println, read_whole_file};
|
use core::io::read_whole_file;
|
||||||
use core::pipes::select2i;
|
use core::pipes::select2i;
|
||||||
use core::ptr::null;
|
use core::ptr::null;
|
||||||
use core::task::{SingleThreaded, task};
|
use core::task::{SingleThreaded, task};
|
||||||
use core::util::replace;
|
use core::util::replace;
|
||||||
use dom;
|
use dom;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
use gfx::resource::image_cache_task::ImageCacheTask;
|
|
||||||
use gfx::resource::resource_task::ResourceTask;
|
|
||||||
use html;
|
use html;
|
||||||
use js::JSVAL_NULL;
|
use js::JSVAL_NULL;
|
||||||
use js::global::{global_class, debug_fns};
|
use js::global::{global_class, debug_fns};
|
||||||
|
@ -34,6 +32,8 @@ use js::jsapi::JSContext;
|
||||||
use js::jsapi::bindgen::{JS_CallFunctionValue, JS_GetContextPrivate};
|
use js::jsapi::bindgen::{JS_CallFunctionValue, JS_GetContextPrivate};
|
||||||
use js::rust::{Compartment, Cx};
|
use js::rust::{Compartment, Cx};
|
||||||
use jsrt = js::rust::rt;
|
use jsrt = js::rust::rt;
|
||||||
|
use servo_net::image_cache_task::ImageCacheTask;
|
||||||
|
use servo_net::resource_task::ResourceTask;
|
||||||
use servo_util::tree::TreeNodeRef;
|
use servo_util::tree::TreeNodeRef;
|
||||||
use std::net::url::Url;
|
use std::net::url::Url;
|
||||||
use url_to_str = std::net::url::to_str;
|
use url_to_str = std::net::url::to_str;
|
||||||
|
|
|
@ -8,9 +8,6 @@ use content::content_task;
|
||||||
use dom::event::Event;
|
use dom::event::Event;
|
||||||
use layout::layout_task;
|
use layout::layout_task;
|
||||||
use layout::layout_task::LayoutTask;
|
use layout::layout_task::LayoutTask;
|
||||||
use resource::image_cache_task::{ImageCacheTask, ImageCacheTaskClient};
|
|
||||||
use resource::resource_task::ResourceTask;
|
|
||||||
use resource::resource_task;
|
|
||||||
use util::task::spawn_listener;
|
use util::task::spawn_listener;
|
||||||
|
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
|
@ -18,6 +15,9 @@ use core::comm::{Chan, Port, SharedChan};
|
||||||
use gfx::opts::Opts;
|
use gfx::opts::Opts;
|
||||||
use gfx::render_task::RenderTask;
|
use gfx::render_task::RenderTask;
|
||||||
use gfx::render_task;
|
use gfx::render_task;
|
||||||
|
use servo_net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient};
|
||||||
|
use servo_net::resource_task::ResourceTask;
|
||||||
|
use servo_net::resource_task;
|
||||||
use std::net::url::Url;
|
use std::net::url::Url;
|
||||||
|
|
||||||
pub type EngineTask = Chan<Msg>;
|
pub type EngineTask = Chan<Msg>;
|
||||||
|
|
|
@ -2,17 +2,14 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
/*!
|
/// Some little helpers for hooking up the HTML parser with the CSS parser.
|
||||||
Some little helpers for hooking up the HTML parser with the CSS parser
|
|
||||||
*/
|
|
||||||
|
|
||||||
use resource::resource_task::{ResourceTask, ProgressMsg, Load, Payload, Done};
|
|
||||||
|
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
use core::comm::Port;
|
use core::comm::Port;
|
||||||
use core::str;
|
use core::str;
|
||||||
use newcss::stylesheet::Stylesheet;
|
use newcss::stylesheet::Stylesheet;
|
||||||
use newcss::util::DataStream;
|
use newcss::util::DataStream;
|
||||||
|
use servo_net::resource_task::{ResourceTask, ProgressMsg, Load, Payload, Done};
|
||||||
use std::net::url::Url;
|
use std::net::url::Url;
|
||||||
|
|
||||||
/// Where a style sheet comes from.
|
/// Where a style sheet comes from.
|
||||||
|
|
|
@ -6,15 +6,15 @@ use dom::element::*;
|
||||||
use dom::node::{AbstractNode, Comment, Doctype, Element, ElementNodeTypeId, Node, Text};
|
use dom::node::{AbstractNode, Comment, Doctype, Element, ElementNodeTypeId, Node, Text};
|
||||||
use html::cssparse::{InlineProvenance, StylesheetProvenance, UrlProvenance, spawn_css_parser};
|
use html::cssparse::{InlineProvenance, StylesheetProvenance, UrlProvenance, spawn_css_parser};
|
||||||
use newcss::stylesheet::Stylesheet;
|
use newcss::stylesheet::Stylesheet;
|
||||||
use resource::image_cache_task::ImageCacheTask;
|
|
||||||
use resource::image_cache_task;
|
|
||||||
use resource::resource_task::{Done, Load, Payload, ResourceTask};
|
|
||||||
use util::task::spawn_conversation;
|
use util::task::spawn_conversation;
|
||||||
|
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
use core::comm::{Chan, Port, SharedChan};
|
use core::comm::{Chan, Port, SharedChan};
|
||||||
use core::str::eq_slice;
|
use core::str::eq_slice;
|
||||||
use hubbub::hubbub;
|
use hubbub::hubbub;
|
||||||
|
use servo_net::image_cache_task::ImageCacheTask;
|
||||||
|
use servo_net::image_cache_task;
|
||||||
|
use servo_net::resource_task::{Done, Load, Payload, ResourceTask};
|
||||||
use servo_util::tree::TreeUtils;
|
use servo_util::tree::TreeUtils;
|
||||||
use servo_util::url::make_url;
|
use servo_util::url::make_url;
|
||||||
use std::net::url::Url;
|
use std::net::url::Url;
|
||||||
|
|
|
@ -19,8 +19,6 @@ use geom::{Point2D, Rect, Size2D};
|
||||||
use gfx::display_list::{DisplayItem, DisplayList};
|
use gfx::display_list::{DisplayItem, DisplayList};
|
||||||
use gfx::font::{FontStyle, FontWeight300};
|
use gfx::font::{FontStyle, FontWeight300};
|
||||||
use gfx::geometry::Au;
|
use gfx::geometry::Au;
|
||||||
use gfx::image::holder::ImageHolder;
|
|
||||||
use gfx::resource::local_image_cache::LocalImageCache;
|
|
||||||
use newcss::color::rgb;
|
use newcss::color::rgb;
|
||||||
use newcss::complete::CompleteStyle;
|
use newcss::complete::CompleteStyle;
|
||||||
use newcss::units::{Cursive, Em, Fantasy, Length, Monospace, Pt, Px, SansSerif, Serif};
|
use newcss::units::{Cursive, Em, Fantasy, Length, Monospace, Pt, Px, SansSerif, Serif};
|
||||||
|
@ -28,6 +26,8 @@ use newcss::values::{CSSBorderWidthLength, CSSBorderWidthMedium};
|
||||||
use newcss::values::{CSSFontFamilyFamilyName, CSSFontFamilyGenericFamily};
|
use newcss::values::{CSSFontFamilyFamilyName, CSSFontFamilyGenericFamily};
|
||||||
use newcss::values::{CSSFontSizeLength, CSSFontStyleItalic, CSSFontStyleNormal};
|
use newcss::values::{CSSFontSizeLength, CSSFontStyleItalic, CSSFontStyleNormal};
|
||||||
use newcss::values::{CSSFontStyleOblique, CSSTextAlign};
|
use newcss::values::{CSSFontStyleOblique, CSSTextAlign};
|
||||||
|
use servo_net::image::holder::ImageHolder;
|
||||||
|
use servo_net::local_image_cache::LocalImageCache;
|
||||||
use servo_util::range::*;
|
use servo_util::range::*;
|
||||||
use std::arc;
|
use std::arc;
|
||||||
use std::cmp::FuzzyEq;
|
use std::cmp::FuzzyEq;
|
||||||
|
|
|
@ -2,14 +2,15 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
//! Data needed by the layout task.
|
||||||
|
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use gfx::font_context::FontContext;
|
use gfx::font_context::FontContext;
|
||||||
use gfx::geometry::Au;
|
use gfx::geometry::Au;
|
||||||
use gfx::resource::local_image_cache::LocalImageCache;
|
use servo_net::local_image_cache::LocalImageCache;
|
||||||
use std::net::url::Url;
|
use std::net::url::Url;
|
||||||
|
|
||||||
/* Represents layout task context. */
|
/// Data needed by the layout task.
|
||||||
|
|
||||||
pub struct LayoutContext {
|
pub struct LayoutContext {
|
||||||
font_ctx: @mut FontContext,
|
font_ctx: @mut FontContext,
|
||||||
image_cache: @mut LocalImageCache,
|
image_cache: @mut LocalImageCache,
|
||||||
|
|
|
@ -15,8 +15,6 @@ use layout::context::LayoutContext;
|
||||||
use layout::debug::{BoxedMutDebugMethods, DebugMethods};
|
use layout::debug::{BoxedMutDebugMethods, DebugMethods};
|
||||||
use layout::display_list_builder::{DisplayListBuilder, FlowDisplayListBuilderMethods};
|
use layout::display_list_builder::{DisplayListBuilder, FlowDisplayListBuilderMethods};
|
||||||
use layout::flow::FlowContext;
|
use layout::flow::FlowContext;
|
||||||
use resource::image_cache_task::{ImageCacheTask, ImageResponseMsg};
|
|
||||||
use resource::local_image_cache::LocalImageCache;
|
|
||||||
use util::task::spawn_listener;
|
use util::task::spawn_listener;
|
||||||
use util::time::time;
|
use util::time::time;
|
||||||
|
|
||||||
|
@ -34,6 +32,8 @@ use gfx::render_task::{RenderMsg, RenderTask};
|
||||||
use newcss::select::SelectCtx;
|
use newcss::select::SelectCtx;
|
||||||
use newcss::stylesheet::Stylesheet;
|
use newcss::stylesheet::Stylesheet;
|
||||||
use newcss::types::OriginAuthor;
|
use newcss::types::OriginAuthor;
|
||||||
|
use servo_net::image_cache_task::{ImageCacheTask, ImageResponseMsg};
|
||||||
|
use servo_net::local_image_cache::LocalImageCache;
|
||||||
use servo_util::tree::TreeUtils;
|
use servo_util::tree::TreeUtils;
|
||||||
use std::net::url::Url;
|
use std::net::url::Url;
|
||||||
|
|
||||||
|
|
|
@ -11,19 +11,18 @@
|
||||||
#[license = "MPL"];
|
#[license = "MPL"];
|
||||||
#[crate_type = "lib"];
|
#[crate_type = "lib"];
|
||||||
|
|
||||||
#[legacy_records];
|
|
||||||
|
|
||||||
extern mod azure;
|
extern mod azure;
|
||||||
extern mod geom;
|
extern mod geom;
|
||||||
extern mod gfx (name = "servo_gfx");
|
extern mod gfx (name = "servo_gfx");
|
||||||
extern mod servo_util (name = "servo_util");
|
|
||||||
extern mod glut;
|
extern mod glut;
|
||||||
extern mod http_client;
|
extern mod http_client;
|
||||||
extern mod hubbub;
|
extern mod hubbub;
|
||||||
extern mod js;
|
extern mod js;
|
||||||
extern mod layers;
|
extern mod layers;
|
||||||
extern mod opengles;
|
|
||||||
extern mod newcss (name = "css");
|
extern mod newcss (name = "css");
|
||||||
|
extern mod opengles;
|
||||||
|
extern mod servo_net;
|
||||||
|
extern mod servo_util (name = "servo_util");
|
||||||
extern mod sharegl;
|
extern mod sharegl;
|
||||||
extern mod stb_image;
|
extern mod stb_image;
|
||||||
extern mod std;
|
extern mod std;
|
||||||
|
@ -36,10 +35,12 @@ extern mod core_text;
|
||||||
use compositing::{AddKeyHandler, CompositorImpl};
|
use compositing::{AddKeyHandler, CompositorImpl};
|
||||||
use engine::{Engine, LoadUrlMsg};
|
use engine::{Engine, LoadUrlMsg};
|
||||||
|
|
||||||
pub use gfx::opts::{Opts, Png, Screen}; // FIXME: Do we really want "Screen" and "Png" visible?
|
use core::comm::SharedChan;
|
||||||
pub use gfx::resource;
|
use gfx::opts;
|
||||||
pub use gfx::resource::image_cache_task::ImageCacheTask;
|
use servo_net::image_cache_task::ImageCacheTask;
|
||||||
pub use gfx::resource::resource_task::ResourceTask;
|
use servo_net::resource_task::ResourceTask;
|
||||||
|
|
||||||
|
pub use gfx::opts::Opts;
|
||||||
pub use gfx::text;
|
pub use gfx::text;
|
||||||
pub use servo_util::url::make_url;
|
pub use servo_util::url::make_url;
|
||||||
|
|
||||||
|
@ -122,27 +123,12 @@ pub mod platform;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
run(&opts::from_cmdline_args(os::args()))
|
||||||
run(&gfx::opts::from_cmdline_args(args))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_implicitly_copyable_typarams)]
|
|
||||||
fn run(opts: &Opts) {
|
fn run(opts: &Opts) {
|
||||||
match &opts.render_mode {
|
|
||||||
&Screen => run_pipeline_screen(opts),
|
|
||||||
&Png(ref outfile) => {
|
|
||||||
assert!(!opts.urls.is_empty());
|
|
||||||
if opts.urls.len() > 1u {
|
|
||||||
fail!(~"servo asks that you stick to a single URL in PNG output mode")
|
|
||||||
}
|
|
||||||
run_pipeline_png(opts, *outfile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run_pipeline_screen(opts: &Opts) {
|
|
||||||
let (dom_event_port, dom_event_chan) = comm::stream();
|
let (dom_event_port, dom_event_chan) = comm::stream();
|
||||||
let dom_event_chan = comm::SharedChan::new(dom_event_chan);
|
let dom_event_chan = SharedChan::new(dom_event_chan);
|
||||||
|
|
||||||
// The platform event handler thread
|
// The platform event handler thread
|
||||||
let compositor = CompositorImpl::new(dom_event_chan.clone(), copy *opts);
|
let compositor = CompositorImpl::new(dom_event_chan.clone(), copy *opts);
|
||||||
|
@ -163,14 +149,15 @@ fn run_pipeline_screen(opts: &Opts) {
|
||||||
|
|
||||||
for opts.urls.each |filename| {
|
for opts.urls.each |filename| {
|
||||||
let url = make_url(copy *filename, None);
|
let url = make_url(copy *filename, None);
|
||||||
|
|
||||||
debug!("master: Sending url `%s`", url.to_str());
|
debug!("master: Sending url `%s`", url.to_str());
|
||||||
engine_task.send(LoadUrlMsg(url));
|
engine_task.send(LoadUrlMsg(url));
|
||||||
debug!("master: Waiting for keypress");
|
|
||||||
|
|
||||||
|
debug!("master: Waiting for keypress");
|
||||||
match keypress_from_compositor.try_recv() {
|
match keypress_from_compositor.try_recv() {
|
||||||
Some(*) => { }
|
Some(*) => {}
|
||||||
None => { error!("keypress stream closed unexpectedly") }
|
None => error!("keypress stream closed unexpectedly"),
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shut everything down
|
// Shut everything down
|
||||||
|
@ -182,43 +169,3 @@ fn run_pipeline_screen(opts: &Opts) {
|
||||||
compositor.chan.send(compositing::Exit);
|
compositor.chan.send(compositing::Exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_pipeline_png(_opts: &Opts, _outfile: &str) {
|
|
||||||
fail!(~"PNG compositor is broken");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(broken)]
|
|
||||||
fn run_pipeline_png(url: ~str, outfile: &str) {
|
|
||||||
// Use a PNG encoder as the graphics compositor
|
|
||||||
use gfx::png_compositor;
|
|
||||||
use png_compositor::PngCompositor;
|
|
||||||
use io::{Writer, buffered_file_writer};
|
|
||||||
use resource::resource_task::ResourceTask;
|
|
||||||
use resource::image_cache_task::SyncImageCacheTask;
|
|
||||||
|
|
||||||
listen(|pngdata_from_compositor| {
|
|
||||||
let (dom_event_port, dom_event_chan) = comm::stream();
|
|
||||||
let dom_event_chan = comm::SharedChan(dom_event_chan);
|
|
||||||
|
|
||||||
let compositor = PngCompositor(pngdata_from_compositor);
|
|
||||||
let resource_task = ResourceTask();
|
|
||||||
// For the PNG pipeline we are using a synchronous image task so that all images will be
|
|
||||||
// fulfilled before the first paint.
|
|
||||||
let image_cache_task = SyncImageCacheTask(resource_task);
|
|
||||||
let engine_task = Engine(copy compositor,
|
|
||||||
dom_event_port,
|
|
||||||
dom_event_chan,
|
|
||||||
resource_task,
|
|
||||||
image_cache_task);
|
|
||||||
engine_task.send(LoadUrlMsg(make_url(copy url, None)));
|
|
||||||
|
|
||||||
match buffered_file_writer(&Path(outfile)) {
|
|
||||||
Ok(writer) => writer.write(pngdata_from_compositor.recv()),
|
|
||||||
Err(e) => fail!(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
let (exit_chan, exit_response_from_engine) = comm::stream();
|
|
||||||
engine_task.send(engine::ExitMsg(exit_chan));
|
|
||||||
exit_response_from_engine.recv();
|
|
||||||
compositor.send(png_compositor::Exit);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue