mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
script: Make the ImageCacheTask
use IPC.
This necessitated getting rid of the boxed trait object that was being be passed between the script task and the image cache task.
This commit is contained in:
parent
380de1ba82
commit
82b53d83ff
11 changed files with 102 additions and 61 deletions
|
@ -28,7 +28,6 @@ use euclid::matrix2d::Matrix2D;
|
|||
use euclid::point::Point2D;
|
||||
use euclid::rect::Rect;
|
||||
use euclid::size::Size2D;
|
||||
use ipc_channel::ipc;
|
||||
|
||||
use canvas_traits::{CanvasMsg, Canvas2dMsg, CanvasCommonMsg};
|
||||
use canvas_traits::{FillOrStrokeStyle, LinearGradientStyle, RadialGradientStyle, RepetitionStyle};
|
||||
|
@ -38,7 +37,7 @@ use msg::constellation_msg::Msg as ConstellationMsg;
|
|||
use net_traits::image_cache_task::{ImageCacheChan, ImageResponse};
|
||||
use net_traits::image::base::PixelFormat;
|
||||
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use num::{Float, ToPrimitive};
|
||||
use std::borrow::ToOwned;
|
||||
use std::cell::RefCell;
|
||||
|
@ -341,7 +340,7 @@ impl CanvasRenderingContext2D {
|
|||
let window = window_from_node(canvas.r());
|
||||
let window = window.r();
|
||||
let image_cache = window.image_cache_task();
|
||||
let (response_chan, response_port) = channel();
|
||||
let (response_chan, response_port) = ipc::channel().unwrap();
|
||||
image_cache.request_image(url, ImageCacheChan(response_chan), None);
|
||||
let result = response_port.recv().unwrap();
|
||||
result.image_response
|
||||
|
|
|
@ -23,9 +23,12 @@ use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
|
|||
use dom::node::{document_from_node, Node, NodeTypeId, NodeHelpers, NodeDamage, window_from_node};
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
use dom::window::WindowHelpers;
|
||||
use script_task::{Runnable, ScriptChan, ScriptMsg};
|
||||
use util::str::DOMString;
|
||||
use string_cache::Atom;
|
||||
|
||||
use ipc_channel::ipc;
|
||||
use ipc_channel::router::ROUTER;
|
||||
use net_traits::image::base::Image;
|
||||
use net_traits::image_cache_task::{ImageResponder, ImageResponse};
|
||||
use url::{Url, UrlParser};
|
||||
|
@ -62,27 +65,27 @@ trait PrivateHTMLImageElementHelpers {
|
|||
fn update_image(self, value: Option<(DOMString, &Url)>);
|
||||
}
|
||||
|
||||
/// This is passed to the image cache when the src attribute
|
||||
/// changes. It is returned via a message to the script task,
|
||||
/// which marks the element as dirty and triggers a reflow.
|
||||
struct Responder {
|
||||
struct ImageResponseHandlerRunnable {
|
||||
element: Trusted<HTMLImageElement>,
|
||||
image: ImageResponse,
|
||||
}
|
||||
|
||||
impl Responder {
|
||||
fn new(element: Trusted<HTMLImageElement>) -> Responder {
|
||||
Responder {
|
||||
element: element
|
||||
impl ImageResponseHandlerRunnable {
|
||||
fn new(element: Trusted<HTMLImageElement>, image: ImageResponse)
|
||||
-> ImageResponseHandlerRunnable {
|
||||
ImageResponseHandlerRunnable {
|
||||
element: element,
|
||||
image: image,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ImageResponder for Responder {
|
||||
fn respond(&self, image: ImageResponse) {
|
||||
impl Runnable for ImageResponseHandlerRunnable {
|
||||
fn handler(self: Box<Self>) {
|
||||
// Update the image field
|
||||
let element = self.element.root();
|
||||
let element_ref = element.r();
|
||||
*element_ref.image.borrow_mut() = match image {
|
||||
*element_ref.image.borrow_mut() = match self.image {
|
||||
ImageResponse::Loaded(image) | ImageResponse::PlaceholderLoaded(image) => {
|
||||
Some(image)
|
||||
}
|
||||
|
@ -130,8 +133,20 @@ impl<'a> PrivateHTMLImageElementHelpers for &'a HTMLImageElement {
|
|||
*self.url.borrow_mut() = Some(img_url.clone());
|
||||
|
||||
let trusted_node = Trusted::new(window.get_cx(), self, window.script_chan());
|
||||
let responder = box Responder::new(trusted_node);
|
||||
image_cache.request_image(img_url, window.image_cache_chan(), Some(responder));
|
||||
let (responder_sender, responder_receiver) = ipc::channel().unwrap();
|
||||
let script_chan = window.script_chan();
|
||||
ROUTER.add_route(responder_receiver.to_opaque(), box move |message| {
|
||||
// Return the image via a message to the script task, which marks the element
|
||||
// as dirty and triggers a reflow.
|
||||
let image_response = message.to().unwrap();
|
||||
script_chan.send(ScriptMsg::RunnableMsg(box ImageResponseHandlerRunnable::new(
|
||||
trusted_node.clone(),
|
||||
image_response))).unwrap();
|
||||
});
|
||||
|
||||
image_cache.request_image(img_url,
|
||||
window.image_cache_chan(),
|
||||
Some(ImageResponder::new(responder_sender)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,12 +53,12 @@ use webdriver_handlers;
|
|||
use devtools_traits::{DevtoolsControlChan, DevtoolsControlPort, DevtoolsPageInfo};
|
||||
use devtools_traits::{DevtoolsControlMsg, DevtoolScriptControlMsg};
|
||||
use devtools_traits::{TimelineMarker, TimelineMarkerType, TracingMetadata};
|
||||
use script_traits::{CompositorEvent, MouseButton};
|
||||
use script_traits::CompositorEvent::{ResizeEvent, ClickEvent};
|
||||
use script_traits::CompositorEvent::{MouseDownEvent, MouseUpEvent};
|
||||
use script_traits::CompositorEvent::{MouseMoveEvent, KeyEvent};
|
||||
use script_traits::{NewLayoutInfo, OpaqueScriptLayoutChannel};
|
||||
use script_traits::CompositorEvent::{ResizeEvent, ClickEvent};
|
||||
use script_traits::{CompositorEvent, MouseButton};
|
||||
use script_traits::{ConstellationControlMsg, ScriptControlChan};
|
||||
use script_traits::{NewLayoutInfo, OpaqueScriptLayoutChannel};
|
||||
use script_traits::{ScriptState, ScriptTaskFactory};
|
||||
use msg::compositor_msg::{LayerId, ScriptListener};
|
||||
use msg::constellation_msg::{ConstellationChan, FocusType};
|
||||
|
@ -517,14 +517,18 @@ impl ScriptTask {
|
|||
}
|
||||
|
||||
let (devtools_sender, devtools_receiver) = channel();
|
||||
let (image_cache_channel, image_cache_port) = channel();
|
||||
|
||||
// Ask the router to proxy IPC messages from the image cache task to us.
|
||||
let (ipc_image_cache_channel, ipc_image_cache_port) = ipc::channel().unwrap();
|
||||
let image_cache_port =
|
||||
ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_image_cache_port);
|
||||
|
||||
ScriptTask {
|
||||
page: DOMRefCell::new(None),
|
||||
incomplete_loads: DOMRefCell::new(vec!()),
|
||||
|
||||
image_cache_task: image_cache_task,
|
||||
image_cache_channel: ImageCacheChan(image_cache_channel),
|
||||
image_cache_channel: ImageCacheChan(ipc_image_cache_channel),
|
||||
image_cache_port: image_cache_port,
|
||||
|
||||
resource_task: resource_task,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue