mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
gfx: Allow images to be shipped to the WebRender thread without shipping
over the data as well. WebRender doesn't need the data, as it acquires it separately. About a 50%-100% improvement in display list building time on browser.html.
This commit is contained in:
parent
9fcf9215d0
commit
0006c1923a
8 changed files with 151 additions and 70 deletions
|
@ -24,8 +24,9 @@ use euclid::{Matrix2D, Matrix4, Point2D, Rect, SideOffsets2D, Size2D};
|
|||
use fnv::FnvHasher;
|
||||
use gfx_traits::{LayerId, ScrollPolicy};
|
||||
use heapsize::HeapSizeOf;
|
||||
use ipc_channel::ipc::IpcSharedMemory;
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use net_traits::image::base::Image;
|
||||
use net_traits::image::base::{Image, PixelFormat};
|
||||
use paint_context::PaintContext;
|
||||
use range::Range;
|
||||
use serde::de::{self, Deserialize, Deserializer, MapVisitor, Visitor};
|
||||
|
@ -46,7 +47,7 @@ use text::TextRun;
|
|||
use text::glyph::CharIndex;
|
||||
use util::geometry::{self, MAX_RECT, ScreenPx};
|
||||
use util::print_tree::PrintTree;
|
||||
use webrender_traits::WebGLContextId;
|
||||
use webrender_traits::{self, WebGLContextId};
|
||||
|
||||
pub use style::dom::OpaqueNode;
|
||||
|
||||
|
@ -986,8 +987,11 @@ pub enum TextOrientation {
|
|||
#[derive(Clone, HeapSizeOf, Deserialize, Serialize)]
|
||||
pub struct ImageDisplayItem {
|
||||
pub base: BaseDisplayItem,
|
||||
|
||||
pub webrender_image: WebRenderImageInfo,
|
||||
|
||||
#[ignore_heap_size_of = "Because it is non-owning"]
|
||||
pub image: Arc<Image>,
|
||||
pub image_data: Option<Arc<IpcSharedMemory>>,
|
||||
|
||||
/// The dimensions to which the image display item should be stretched. If this is smaller than
|
||||
/// the bounds of this display item, then the image will be repeated in the appropriate
|
||||
|
@ -1203,10 +1207,14 @@ impl DisplayItem {
|
|||
|
||||
DisplayItem::ImageClass(ref image_item) => {
|
||||
debug!("Drawing image at {:?}.", image_item.base.bounds);
|
||||
paint_context.draw_image(&image_item.base.bounds,
|
||||
&image_item.stretch_size,
|
||||
image_item.image.clone(),
|
||||
image_item.image_rendering.clone());
|
||||
paint_context.draw_image(
|
||||
&image_item.base.bounds,
|
||||
&image_item.stretch_size,
|
||||
&image_item.webrender_image,
|
||||
&image_item.image_data
|
||||
.as_ref()
|
||||
.expect("Non-WR painting needs image data!")[..],
|
||||
image_item.image_rendering.clone());
|
||||
}
|
||||
|
||||
DisplayItem::WebGLClass(_) => {
|
||||
|
@ -1390,3 +1398,25 @@ impl StackingContextId {
|
|||
StackingContextId(fragment_type, id)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, HeapSizeOf, Deserialize, Serialize)]
|
||||
pub struct WebRenderImageInfo {
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub format: PixelFormat,
|
||||
#[ignore_heap_size_of = "WebRender traits type, and tiny"]
|
||||
pub key: Option<webrender_traits::ImageKey>,
|
||||
}
|
||||
|
||||
impl WebRenderImageInfo {
|
||||
#[inline]
|
||||
pub fn from_image(image: &Image) -> WebRenderImageInfo {
|
||||
WebRenderImageInfo {
|
||||
width: image.width,
|
||||
height: image.height,
|
||||
format: image.format,
|
||||
key: image.id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ use azure::{AzDrawTargetFillGlyphs, struct__AzGlyphBuffer, struct__AzPoint};
|
|||
use azure::{AzFloat, struct__AzDrawOptions, struct__AzGlyph};
|
||||
use display_list::TextOrientation::{SidewaysLeft, SidewaysRight, Upright};
|
||||
use display_list::{BLUR_INFLATION_FACTOR, BorderRadii, BoxShadowClipMode, ClippingRegion};
|
||||
use display_list::{TextDisplayItem};
|
||||
use display_list::{TextDisplayItem, WebRenderImageInfo};
|
||||
use euclid::matrix2d::Matrix2D;
|
||||
use euclid::point::Point2D;
|
||||
use euclid::rect::{Rect, TypedRect};
|
||||
|
@ -27,10 +27,9 @@ use euclid::size::Size2D;
|
|||
use filters;
|
||||
use font_context::FontContext;
|
||||
use gfx_traits::{color, LayerKind};
|
||||
use net_traits::image::base::{Image, PixelFormat};
|
||||
use net_traits::image::base::PixelFormat;
|
||||
use range::Range;
|
||||
use std::default::Default;
|
||||
use std::sync::Arc;
|
||||
use std::{f32, mem, ptr};
|
||||
use style::computed_values::{border_style, filter, image_rendering, mix_blend_mode};
|
||||
use text::TextRun;
|
||||
|
@ -181,21 +180,22 @@ impl<'a> PaintContext<'a> {
|
|||
pub fn draw_image(&self,
|
||||
bounds: &Rect<Au>,
|
||||
stretch_size: &Size2D<Au>,
|
||||
image: Arc<Image>,
|
||||
image_info: &WebRenderImageInfo,
|
||||
image_data: &[u8],
|
||||
image_rendering: image_rendering::T) {
|
||||
let size = Size2D::new(image.width as i32, image.height as i32);
|
||||
let (pixel_width, source_format) = match image.format {
|
||||
let size = Size2D::new(image_info.width as i32, image_info.height as i32);
|
||||
let (pixel_width, source_format) = match image_info.format {
|
||||
PixelFormat::RGBA8 => (4, SurfaceFormat::B8G8R8A8),
|
||||
PixelFormat::K8 => (1, SurfaceFormat::A8),
|
||||
PixelFormat::RGB8 => panic!("RGB8 color type not supported"),
|
||||
PixelFormat::KA8 => panic!("KA8 color type not supported"),
|
||||
};
|
||||
let stride = image.width * pixel_width;
|
||||
let stride = image_info.width * pixel_width;
|
||||
let scale = self.screen_pixels_per_px();
|
||||
|
||||
self.draw_target.make_current();
|
||||
let draw_target_ref = &self.draw_target;
|
||||
let azure_surface = match draw_target_ref.create_source_surface_from_data(&image.bytes,
|
||||
let azure_surface = match draw_target_ref.create_source_surface_from_data(image_data,
|
||||
size,
|
||||
stride as i32,
|
||||
source_format) {
|
||||
|
@ -204,7 +204,8 @@ impl<'a> PaintContext<'a> {
|
|||
};
|
||||
|
||||
let source_rect = Rect::new(Point2D::new(0.0, 0.0),
|
||||
Size2D::new(image.width as AzFloat, image.height as AzFloat));
|
||||
Size2D::new(image_info.width as AzFloat,
|
||||
image_info.height as AzFloat));
|
||||
let dest_rect = bounds.to_nearest_azure_rect(scale);
|
||||
|
||||
// TODO(pcwalton): According to CSS-IMAGES-3 § 5.3, nearest-neighbor interpolation is a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue