aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/components/main/layout/box.rs3
-rw-r--r--src/components/main/layout/construct.rs2
-rw-r--r--src/components/main/layout/context.rs4
-rw-r--r--src/components/main/layout/layout_task.rs13
-rw-r--r--src/components/net/image/holder.rs22
5 files changed, 30 insertions, 14 deletions
diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs
index 904b5795b83..2b5eec154b0 100644
--- a/src/components/main/layout/box.rs
+++ b/src/components/main/layout/box.rs
@@ -5,6 +5,7 @@
//! The `Box` type, which represents the leaves of the layout tree.
use extra::url::Url;
+use extra::arc::MutexArc;
use geom::{Point2D, Rect, Size2D, SideOffsets2D};
use gfx::color::rgb;
use gfx::display_list::{BaseDisplayItem, BorderDisplayItem, BorderDisplayItemClass};
@@ -98,7 +99,7 @@ impl ImageBoxInfo {
///
/// FIXME(pcwalton): The fact that image boxes store the cache in the box makes little sense to
/// me.
- pub fn new(image_url: Url, local_image_cache: @mut LocalImageCache) -> ImageBoxInfo {
+ pub fn new(image_url: Url, local_image_cache: MutexArc<LocalImageCache>) -> ImageBoxInfo {
ImageBoxInfo {
image: Slot::init(ImageHolder::new(image_url, local_image_cache)),
}
diff --git a/src/components/main/layout/construct.rs b/src/components/main/layout/construct.rs
index 263a8409e23..18ff1654888 100644
--- a/src/components/main/layout/construct.rs
+++ b/src/components/main/layout/construct.rs
@@ -209,7 +209,7 @@ impl<'self> FlowConstructor<'self> {
Some(url) => {
// FIXME(pcwalton): The fact that image boxes store the cache within them makes
// little sense to me.
- Some(ImageBoxInfo::new(url, self.layout_context.image_cache))
+ Some(ImageBoxInfo::new(url, self.layout_context.image_cache.clone()))
}
}
}
diff --git a/src/components/main/layout/context.rs b/src/components/main/layout/context.rs
index c9ef334af43..748ed66d4ad 100644
--- a/src/components/main/layout/context.rs
+++ b/src/components/main/layout/context.rs
@@ -9,9 +9,11 @@ use gfx::font_context::FontContext;
use servo_util::geometry::Au;
use servo_net::local_image_cache::LocalImageCache;
+use extra::arc::MutexArc;
+
/// Data needed by the layout task.
pub struct LayoutContext {
font_ctx: @mut FontContext,
- image_cache: @mut LocalImageCache,
+ image_cache: MutexArc<LocalImageCache>,
screen_size: Rect<Au>
}
diff --git a/src/components/main/layout/layout_task.rs b/src/components/main/layout/layout_task.rs
index a0149bb00eb..899d998293b 100644
--- a/src/components/main/layout/layout_task.rs
+++ b/src/components/main/layout/layout_task.rs
@@ -18,7 +18,7 @@ use layout::flow;
use layout::incremental::{RestyleDamage, BubbleWidths};
use layout::util::{LayoutData, LayoutDataAccess};
-use extra::arc::{Arc, RWArc};
+use extra::arc::{Arc, RWArc, MutexArc};
use geom::point::Point2D;
use geom::rect::Rect;
use geom::size::Size2D;
@@ -75,7 +75,7 @@ struct LayoutTask {
image_cache_task: ImageCacheTask,
/// The local image cache.
- local_image_cache: @mut LocalImageCache,
+ local_image_cache: MutexArc<LocalImageCache>,
/// The local font context.
font_ctx: @mut FontContext,
@@ -239,7 +239,7 @@ impl LayoutTask {
script_chan: script_chan,
render_chan: render_chan,
image_cache_task: image_cache_task.clone(),
- local_image_cache: @mut LocalImageCache(image_cache_task),
+ local_image_cache: MutexArc::new(LocalImageCache(image_cache_task)),
font_ctx: fctx,
screen_size: None,
@@ -259,7 +259,7 @@ impl LayoutTask {
// Create a layout context for use in building display lists, hit testing, &c.
fn build_layout_context(&self) -> LayoutContext {
- let image_cache = self.local_image_cache;
+ let image_cache = self.local_image_cache.clone();
let font_ctx = self.font_ctx;
let screen_size = self.screen_size.unwrap();
@@ -399,7 +399,10 @@ impl LayoutTask {
debug!("{:?}", node.dump());
// Reset the image cache.
- self.local_image_cache.next_round(self.make_on_image_available_cb());
+ unsafe {
+ self.local_image_cache.unsafe_access(
+ |cache| cache.next_round(self.make_on_image_available_cb()));
+ }
let screen_size = Size2D(Au::from_px(data.window_size.width as int),
Au::from_px(data.window_size.height as int));
diff --git a/src/components/net/image/holder.rs b/src/components/net/image/holder.rs
index c394f0f147a..cdaa697fcaf 100644
--- a/src/components/net/image/holder.rs
+++ b/src/components/net/image/holder.rs
@@ -9,7 +9,7 @@ use local_image_cache::LocalImageCache;
use std::util::replace;
use geom::size::Size2D;
use extra::url::Url;
-use extra::arc::Arc;
+use extra::arc::{Arc, MutexArc};
// FIXME: Nasty coupling here This will be a problem if we want to factor out image handling from
// the network stack. This should probably be factored out into an interface and use dependency
@@ -21,11 +21,11 @@ pub struct ImageHolder {
url: Url,
image: Option<Arc<~Image>>,
cached_size: Size2D<int>,
- local_image_cache: @mut LocalImageCache,
+ local_image_cache: MutexArc<LocalImageCache>,
}
impl ImageHolder {
- pub fn new(url: Url, local_image_cache: @mut LocalImageCache) -> ImageHolder {
+ pub fn new(url: Url, local_image_cache: MutexArc<LocalImageCache>) -> ImageHolder {
debug!("ImageHolder::new() {}", url.to_str());
let holder = ImageHolder {
url: url,
@@ -39,8 +39,14 @@ impl ImageHolder {
// but they are intended to be spread out in time. Ideally prefetch
// should be done as early as possible and decode only once we
// are sure that the image will be used.
- local_image_cache.prefetch(&holder.url);
- local_image_cache.decode(&holder.url);
+ //
+ // LocalImageCache isn't Freeze so we have to use unsafe_access.
+ unsafe {
+ holder.local_image_cache.unsafe_access(|cache| {
+ cache.prefetch(&holder.url);
+ cache.decode(&holder.url);
+ });
+ }
holder
}
@@ -71,7 +77,11 @@ impl ImageHolder {
// If this is the first time we've called this function, load
// the image and store it for the future
if self.image.is_none() {
- match self.local_image_cache.get_image(&self.url).recv() {
+ let port = unsafe {
+ self.local_image_cache.unsafe_access(
+ |cache| cache.get_image(&self.url))
+ };
+ match port.recv() {
ImageReady(image) => {
self.image = Some(image);
}