Skip to content

Commit

Permalink
Auto merge of #523 - glennw:resource-list-2, r=pcwalton
Browse files Browse the repository at this point in the history
Remove ResourceList structure and usage.

Previously, a resource list would be built at the start of the
frame. This would allow glyphs missing from the texture cache
to be rasterized.

However, sometimes (e.g. with subpixel antialiasing) it's not possible
to know right at the start of the frame exactly what needs to be
rasterized yet.

Instead, we now allow the resource cache to add requests during
the prepare_prim_for_render() stage. Primitives that request
resources are marked as needing a resolve operation. This allows
primitives that request resources to update their UV coords etc
before batching occurs (since texture IDs for resources must be
known before batching can occur).

This also lays most of the groundwork for running the resource
cache rasterizer as a separate thread in the future. This will be
used to ensure that if too many glyphs are requested in one frame,
WR can continue running without blocking, using older glyphs and
then re-render the scene when newer, high resolution glyphs are
available.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/523)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo authored Nov 4, 2016
2 parents 25f657f + 17a3629 commit e7a66c5
Show file tree
Hide file tree
Showing 12 changed files with 561 additions and 533 deletions.
3 changes: 2 additions & 1 deletion webrender/res/clip_shared.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ void write_clip(ClipInfo clip) {
clip.bottom_right.outer_inner_radius.x,
clip.bottom_left.outer_inner_radius.x);
//TODO: interpolate the final mask UV
vClipMaskUvRect = clip.mask_info.uv_rect;
vec2 texture_size = textureSize(sMask, 0);
vClipMaskUvRect = clip.mask_info.uv_rect / texture_size.xyxy;
vClipMaskLocalRect = clip.mask_info.local_rect; //TODO: transform
}
#endif
Expand Down
4 changes: 0 additions & 4 deletions webrender/res/prim_shared.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ struct Image {
vec4 st_rect; // Location of the image texture in the texture atlas.
vec4 stretch_size_and_tile_spacing; // Size of the actual image and amount of space between
// tiled instances of this image.
bool has_pixel_coords;
};

Image fetch_image(int index) {
Expand All @@ -605,9 +604,6 @@ Image fetch_image(int index) {
image.st_rect = texelFetchOffset(sData32, uv, 0, ivec2(0, 0));
image.stretch_size_and_tile_spacing = texelFetchOffset(sData32, uv, 0, ivec2(1, 0));

image.has_pixel_coords = image.st_rect.z < 0.0;
image.st_rect.z = abs(image.st_rect.z);

return image;
}

Expand Down
11 changes: 3 additions & 8 deletions webrender/res/ps_image.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ void main(void) {
#endif

// vUv will contain how many times this image has wrapped around the image size.
vec2 st0 = image.st_rect.xy;
vec2 st1 = image.st_rect.zw;

if (image.has_pixel_coords) {
vec2 texture_size = vec2(textureSize(sDiffuse, 0));
st0 /= texture_size;
st1 /= texture_size;
}
vec2 texture_size = vec2(textureSize(sDiffuse, 0));
vec2 st0 = image.st_rect.xy / texture_size;
vec2 st1 = image.st_rect.zw / texture_size;

vTextureSize = st1 - st0;
vTextureOffset = st0;
Expand Down
2 changes: 1 addition & 1 deletion webrender/res/shared.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#define varying in

// Uniform inputs
uniform sampler2D sMask;

// Fragment shader outputs
out vec4 oFragColor;
Expand All @@ -35,6 +34,7 @@
// Shared shader uniforms
//======================================================================================
uniform sampler2D sDiffuse;
uniform sampler2D sMask;

//======================================================================================
// Interpolator definitions
Expand Down
18 changes: 0 additions & 18 deletions webrender/src/internal_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,24 +475,6 @@ pub struct PolygonPosColorUv {
pub vertices: Vec<WorkVertex>,
}

#[derive(PartialEq, Eq, Hash)]
pub struct Glyph {
pub size: Au,
pub blur_radius: Au,
pub index: u32,
}

impl Glyph {
#[inline]
pub fn new(size: Au, blur_radius: Au, index: u32) -> Glyph {
Glyph {
size: size,
blur_radius: blur_radius,
index: index,
}
}
}

#[derive(Debug, Clone)]
#[repr(C)]
pub struct PackedVertexForTextureCacheUpdate {
Expand Down
1 change: 0 additions & 1 deletion webrender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ mod profiler;
mod record;
mod render_backend;
mod resource_cache;
mod resource_list;
mod scene;
mod spring;
mod texture_cache;
Expand Down
16 changes: 10 additions & 6 deletions webrender/src/platform/macos/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,18 @@ impl FontContext {
size: Au,
character: u32,
device_pixel_ratio: f32) -> Option<GlyphDimensions> {
self.get_ct_font(font_key, size, device_pixel_ratio).map(|ref ct_font| {
self.get_ct_font(font_key, size, device_pixel_ratio).and_then(|ref ct_font| {
let glyph = character as CGGlyph;
let metrics = get_glyph_metrics(ct_font, glyph);
GlyphDimensions {
left: metrics.rasterized_left,
top: metrics.rasterized_ascent,
width: metrics.rasterized_width as u32,
height: metrics.rasterized_height as u32,
if metrics.rasterized_width == 0 || metrics.rasterized_height == 0 {
None
} else {
Some(GlyphDimensions {
left: metrics.rasterized_left,
top: metrics.rasterized_ascent,
width: metrics.rasterized_width as u32,
height: metrics.rasterized_height as u32,
})
}
})
}
Expand Down
16 changes: 10 additions & 6 deletions webrender/src/platform/unix/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ impl FontContext {
size: Au,
character: u32,
device_pixel_ratio: f32) -> Option<GlyphDimensions> {
self.load_glyph(font_key, size, character, device_pixel_ratio).map(|slot| {
self.load_glyph(font_key, size, character, device_pixel_ratio).and_then(|slot| {
let metrics = unsafe { &(*slot).metrics };
GlyphDimensions {
left: (metrics.horiBearingX >> 6) as i32,
top: (metrics.horiBearingY >> 6) as i32,
width: (metrics.width >> 6) as u32,
height: (metrics.height >> 6) as u32,
if metrics.width == 0 || metrics.height == 0 {
None
} else {
Some(GlyphDimensions {
left: (metrics.horiBearingX >> 6) as i32,
top: (metrics.horiBearingY >> 6) as i32,
width: (metrics.width >> 6) as u32,
height: (metrics.height >> 6) as u32,
})
}
})
}
Expand Down
Loading

0 comments on commit e7a66c5

Please sign in to comment.