aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/canvasrenderingcontext2d.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2015-04-03 14:24:22 -0700
committerPatrick Walton <pcwalton@mimiga.net>2015-05-20 12:00:33 -0700
commit7e7675c1dcbd8148527d018b56883c6d83886fec (patch)
tree61b10d83aa20cbdbd3e2d601e47edb5193eff3e0 /components/script/dom/canvasrenderingcontext2d.rs
parente52197d1261055527a838f74b353a1124d6b077a (diff)
downloadservo-7e7675c1dcbd8148527d018b56883c6d83886fec.tar.gz
servo-7e7675c1dcbd8148527d018b56883c6d83886fec.zip
net: Don't load the placeholder image for background images, only for
image fragments. This also changes the way the placeholder is handled in the image cache task to decode it up front instead of each time an image fails to load, both because it was more convenient to implement that way and because it saves CPU cycles to do so. This matches the behavior of Gecko and WebKit. It improves the look of our cached copy of Wikipedia.
Diffstat (limited to 'components/script/dom/canvasrenderingcontext2d.rs')
-rw-r--r--components/script/dom/canvasrenderingcontext2d.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs
index 6353479b116..ad49955c64f 100644
--- a/components/script/dom/canvasrenderingcontext2d.rs
+++ b/components/script/dom/canvasrenderingcontext2d.rs
@@ -33,14 +33,12 @@ use canvas::canvas_paint_task::{CanvasPaintTask, FillOrStrokeStyle};
use canvas::canvas_paint_task::{LinearGradientStyle, RadialGradientStyle};
use canvas::canvas_paint_task::{LineCapStyle, LineJoinStyle, CompositionOrBlending};
-use net_traits::image::base::Image;
-use net_traits::image_cache_task::ImageCacheChan;
+use net_traits::image_cache_task::{ImageCacheChan, ImageResponse};
use png::PixelsByColorType;
use num::{Float, ToPrimitive};
use std::borrow::ToOwned;
use std::cell::RefCell;
-use std::sync::{Arc};
use std::sync::mpsc::{channel, Sender};
use util::str::DOMString;
@@ -260,8 +258,8 @@ impl CanvasRenderingContext2D {
};
let img = match self.request_image_from_cache(url) {
- Some(img) => img,
- None => return None,
+ ImageResponse::Loaded(img) => img,
+ ImageResponse::PlaceholderLoaded(_) | ImageResponse::None => return None,
};
let image_size = Size2D(img.width as f64, img.height as f64);
@@ -277,7 +275,7 @@ impl CanvasRenderingContext2D {
return Some((image_data, image_size));
}
- fn request_image_from_cache(&self, url: Url) -> Option<Arc<Image>> {
+ fn request_image_from_cache(&self, url: Url) -> ImageResponse {
let canvas = self.canvas.root();
let window = window_from_node(canvas.r()).root();
let window = window.r();
@@ -285,7 +283,7 @@ impl CanvasRenderingContext2D {
let (response_chan, response_port) = channel();
image_cache.request_image(url, ImageCacheChan(response_chan), None);
let result = response_port.recv().unwrap();
- result.image
+ result.image_response
}
fn create_drawable_rect(&self, x: f64, y: f64, w: f64, h: f64) -> Option<Rect<f32>> {