Bug 1491929 - Text is rasterized at the wrong resolution. r=kvark

Differential Revision: https://phabricator.services.mozilla.com/D20276

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Glenn Watson 2019-02-19 20:25:40 +00:00
parent 9303aacdc6
commit 9314a751d7
5 changed files with 33 additions and 8 deletions

View File

@ -161,14 +161,13 @@ VertexInfo write_text_vertex(RectWithSize local_clip_rect,
void main(void) {
int prim_header_address = aData.x;
int glyph_index = aData.y;
int glyph_index = aData.y & 0xffff;
int raster_space = aData.y >> 16;
int resource_address = aData.z;
int subpx_dir = aData.w >> 16;
int color_mode = aData.w & 0xffff;
PrimitiveHeader ph = fetch_prim_header(prim_header_address);
int raster_space = ph.user_data.z;
Transform transform = fetch_transform(ph.transform_id);
ClipArea clip_area = fetch_clip_area(ph.clip_task_index);
PictureTask task = fetch_picture_task(ph.render_task_index);
@ -193,8 +192,10 @@ void main(void) {
RectWithSize glyph_rect = RectWithSize(res.offset + glyph_transform * (text_offset + glyph.offset),
res.uv_rect.zw - res.uv_rect.xy);
#else
float inverse_raster_scale = float(ph.user_data.z) / 65535.0;
// Scale from glyph space to local space.
float scale = res.scale / task.device_pixel_scale;
float scale = inverse_raster_scale * res.scale / task.device_pixel_scale;
// Compute the glyph rect in local space.
RectWithSize glyph_rect = RectWithSize(scale * res.offset + text_offset + glyph.offset,

View File

@ -851,7 +851,7 @@ impl AlphaBatchBuilder {
[
(run.reference_frame_relative_offset.x * 256.0) as i32,
(run.reference_frame_relative_offset.y * 256.0) as i32,
run.raster_space as i32,
(run.inverse_raster_scale * 65535.0).round() as i32,
],
);
let key = BatchKey::new(kind, blend_mode, textures);
@ -866,7 +866,8 @@ impl AlphaBatchBuilder {
for glyph in glyphs {
batch.push(base_instance.build(
glyph.index_in_text_run,
glyph.index_in_text_run |
(run.raster_space as i32) << 16,
glyph.uv_rect_address.as_int(),
(subpx_dir as u32 as i32) << 16 |
(color_mode as u32 as i32),

View File

@ -68,6 +68,7 @@ impl AsInstanceKind<TextRunDataHandle> for TextRunKey {
reference_frame_relative_offset,
shadow: self.shadow,
raster_space: RasterizationSpace::Screen,
inverse_raster_scale: 1.0,
});
PrimitiveInstanceKind::TextRun{ data_handle, run_index }
@ -214,6 +215,7 @@ pub struct TextRunPrimitive {
pub reference_frame_relative_offset: LayoutVector2D,
pub shadow: bool,
pub raster_space: RasterizationSpace,
pub inverse_raster_scale: f32,
}
impl TextRunPrimitive {
@ -225,8 +227,20 @@ impl TextRunPrimitive {
allow_subpixel_aa: bool,
raster_space: RasterSpace,
) -> bool {
// If local raster space is specified, include that in the scale
// of the glyphs that get rasterized.
// TODO(gw): Once we support proper local space raster modes, this
// will implicitly be part of the device pixel ratio for
// the (cached) local space surface, and so this code
// will no longer be required.
let raster_scale = match raster_space {
RasterSpace::Screen => 1.0,
RasterSpace::Local(scale) => scale.max(0.001),
};
self.inverse_raster_scale = 1.0 / raster_scale;
// Get the current font size in device pixels
let device_font_size = specified_font.size.scale_by(device_pixel_scale.0);
let device_font_size = specified_font.size.scale_by(device_pixel_scale.0 * raster_scale);
// Determine if rasterizing glyphs in local or screen space.
// Only support transforms that can be coerced to simple 2D transforms.
@ -337,5 +351,5 @@ fn test_struct_sizes() {
assert_eq!(mem::size_of::<TextRun>(), 88, "TextRun size changed");
assert_eq!(mem::size_of::<TextRunTemplate>(), 104, "TextRunTemplate size changed");
assert_eq!(mem::size_of::<TextRunKey>(), 96, "TextRunKey size changed");
assert_eq!(mem::size_of::<TextRunPrimitive>(), 96, "TextRunPrimitive size changed");
assert_eq!(mem::size_of::<TextRunPrimitive>(), 104, "TextRunPrimitive size changed");
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 61 KiB

View File

@ -17,3 +17,12 @@ root:
origin: 20 50
size: 20
font: "FreeSans.ttf"
- type: stacking-context
transform: scale(5.0) rotate(45)
transform-origin: -80 240
raster-space: local(5.0)
items:
- text: "Local (scaled)"
origin: 20 50
size: 10
font: "FreeSans.ttf"