diff --git a/gfx/wr/webrender/res/ps_text_run.glsl b/gfx/wr/webrender/res/ps_text_run.glsl index e951b0145737..340bdf7b2cef 100644 --- a/gfx/wr/webrender/res/ps_text_run.glsl +++ b/gfx/wr/webrender/res/ps_text_run.glsl @@ -192,10 +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; + float raster_scale = float(ph.user_data.z) / 65535.0; // Scale from glyph space to local space. - float scale = inverse_raster_scale * res.scale / task.device_pixel_scale; + float scale = res.scale / (raster_scale * task.device_pixel_scale); // Compute the glyph rect in local space. RectWithSize glyph_rect = RectWithSize(scale * res.offset + text_offset + glyph.offset, diff --git a/gfx/wr/webrender/src/batch.rs b/gfx/wr/webrender/src/batch.rs index 2642deed4a71..2d398d3b2c73 100644 --- a/gfx/wr/webrender/src/batch.rs +++ b/gfx/wr/webrender/src/batch.rs @@ -5,7 +5,7 @@ use api::{AlphaType, ClipMode, DeviceIntRect, DeviceIntPoint, DeviceIntSize, WorldRect}; use api::{ExternalImageType, FilterOp, ImageRendering, LayoutRect, DeviceRect, DevicePixelScale}; use api::{YuvColorSpace, YuvFormat, PictureRect, ColorDepth, LayoutPoint, DevicePoint, LayoutSize}; -use api::{PremultipliedColorF}; +use api::{PremultipliedColorF, RasterSpace}; use clip::{ClipDataStore, ClipNodeFlags, ClipNodeRange, ClipItem, ClipStore, ClipNodeInstance}; use clip_scroll_tree::{ClipScrollTree, ROOT_SPATIAL_NODE_INDEX, SpatialNodeIndex, CoordinateSystemId}; use glyph_rasterizer::GlyphFormat; @@ -845,13 +845,14 @@ impl AlphaBatchBuilder { } }; + let raster_scale = run.raster_space.local_scale().unwrap_or(1.0).max(0.001); let prim_header_index = prim_headers.push( &prim_header, z_id, [ (run.reference_frame_relative_offset.x * 256.0) as i32, (run.reference_frame_relative_offset.y * 256.0) as i32, - (run.inverse_raster_scale * 65535.0).round() as i32, + (raster_scale * 65535.0).round() as i32, ], ); let key = BatchKey::new(kind, blend_mode, textures); @@ -864,10 +865,14 @@ impl AlphaBatchBuilder { z_id, ); + let rasterization_space = match run.raster_space { + RasterSpace::Screen => RasterizationSpace::Screen, + RasterSpace::Local(..) => RasterizationSpace::Local, + }; for glyph in glyphs { batch.push(base_instance.build( glyph.index_in_text_run | - (run.raster_space as i32) << 16, + (rasterization_space as i32) << 16, glyph.uv_rect_address.as_int(), (subpx_dir as u32 as i32) << 16 | (color_mode as u32 as i32), diff --git a/gfx/wr/webrender/src/prim_store/text_run.rs b/gfx/wr/webrender/src/prim_store/text_run.rs index 40e43e4f05ec..9b13650c3a99 100644 --- a/gfx/wr/webrender/src/prim_store/text_run.rs +++ b/gfx/wr/webrender/src/prim_store/text_run.rs @@ -9,7 +9,6 @@ use display_list_flattener::{CreateShadow, IsVisible}; use frame_builder::{FrameBuildingState, PictureContext}; use glyph_rasterizer::{FontInstance, FontTransform, GlyphKey, FONT_SIZE_LIMIT}; use gpu_cache::GpuCache; -use gpu_types::RasterizationSpace; use intern; use prim_store::{PrimitiveOpacity, PrimitiveSceneData, PrimitiveScratchBuffer}; use prim_store::{PrimitiveStore, PrimKeyCommonData, PrimTemplateCommonData}; @@ -174,8 +173,7 @@ impl InternablePrimitive for TextRun { glyph_keys_range: storage::Range::empty(), reference_frame_relative_offset, shadow: key.shadow, - raster_space: RasterizationSpace::Screen, - inverse_raster_scale: 1.0, + raster_space: RasterSpace::Screen, }); PrimitiveInstanceKind::TextRun{ data_handle, run_index } @@ -213,8 +211,7 @@ pub struct TextRunPrimitive { pub glyph_keys_range: storage::Range, pub reference_frame_relative_offset: LayoutVector2D, pub shadow: bool, - pub raster_space: RasterizationSpace, - pub inverse_raster_scale: f32, + pub raster_space: RasterSpace, } impl TextRunPrimitive { @@ -232,11 +229,7 @@ impl TextRunPrimitive { // 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; + let raster_scale = raster_space.local_scale().unwrap_or(1.0).max(0.001); // Get the current font size in device pixels let device_font_size = specified_font.size.scale_by(device_pixel_scale.0 * raster_scale); @@ -262,11 +255,7 @@ impl TextRunPrimitive { }; // Record the raster space the text needs to be snapped in. - self.raster_space = if raster_space == RasterSpace::Screen { - RasterizationSpace::Screen - } else { - RasterizationSpace::Local - }; + self.raster_space = raster_space; // If the transform or device size is different, then the caller of // this method needs to know to rebuild the glyphs.