mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Convert LayoutContext.image_cache from @mut to MutexArc
LocalImageCache isn't Freeze so we have to use unsafe_access, which exists for MutexArc and not RWArc.
This commit is contained in:
parent
94b70e25e1
commit
dda6d2b53c
5 changed files with 30 additions and 14 deletions
|
@ -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)),
|
||||
}
|
||||
|
|
|
@ -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()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue