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.
This commit is contained in:
Patrick Walton 2015-04-03 14:24:22 -07:00
parent e52197d126
commit 7e7675c1dc
11 changed files with 135 additions and 38 deletions

View file

@ -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>> {