Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion webrender/src/glyph_rasterizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ impl GlyphRasterizer {
for job in rasterized_glyphs {
let image_id = job.result.and_then(
|glyph| if glyph.width > 0 && glyph.height > 0 {
assert_eq!((glyph.left.fract(), glyph.top.fract()), (0.0, 0.0));
let image_id = texture_cache.insert(
ImageDescriptor {
width: glyph.width,
Expand Down Expand Up @@ -334,7 +335,7 @@ impl GlyphRequest {
point: LayoutPoint,
render_mode: FontRenderMode,
glyph_options: Option<GlyphOptions>,
) -> GlyphRequest {
) -> Self {
GlyphRequest {
key: GlyphKey::new(font_key, size, color, index, point, render_mode),
render_mode,
Expand Down
22 changes: 18 additions & 4 deletions webrender/src/prim_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,24 @@ impl TextRunPrimitiveCpu {
// GPU block.
let first_glyph = glyph_chunk.first().unwrap();
let second_glyph = glyph_chunk.last().unwrap();
request.push([first_glyph.point.x,
first_glyph.point.y,
second_glyph.point.x,
second_glyph.point.y]);
let data = match self.render_mode {
FontRenderMode::Mono |
FontRenderMode::Alpha => [
first_glyph.point.x,
first_glyph.point.y,
second_glyph.point.x,
second_glyph.point.y,
],
// The sub-pixel offset has already been taken into account
// by the glyph rasterizer, thus the truncating here.
FontRenderMode::Subpixel => [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a conditional here, can we do this in the prepare_prim_for_render when the glyph_instances array is created? That would mean only doing it once, not each time it needs to get added to the cache.

first_glyph.point.x.trunc(),
first_glyph.point.y.trunc(),
second_glyph.point.x.trunc(),
second_glyph.point.y.trunc(),
],
};
request.push(data);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions webrender/src/resource_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use texture_cache::{TextureCache, TextureCacheItemId};
use api::{Epoch, FontKey, FontTemplate, GlyphKey, ImageKey, ImageRendering};
use api::{FontRenderMode, ImageData, GlyphDimensions, WebGLContextId};
use api::{DevicePoint, DeviceIntSize, DeviceUintRect, ImageDescriptor, ColorF};
use api::{GlyphOptions, GlyphInstance, TileOffset, TileSize};
use api::{GlyphOptions, GlyphInstance, SubpixelPoint, TileOffset, TileSize};
use api::{BlobImageRenderer, BlobImageDescriptor, BlobImageError, BlobImageRequest, BlobImageData};
use api::BlobImageResources;
use api::{ExternalImageData, ExternalImageType, LayoutPoint};
Expand Down Expand Up @@ -482,21 +482,21 @@ impl ResourceCache {
glyph_options: Option<GlyphOptions>,
mut f: F) -> SourceTexture where F: FnMut(usize, &GpuCacheHandle) {
debug_assert_eq!(self.state, State::QueryResources);
let mut glyph_key = GlyphRequest::new(
let mut glyph_request = GlyphRequest::new(
font_key,
size,
color,
0,
LayoutPoint::new(0.0, 0.0),
LayoutPoint::zero(),
render_mode,
glyph_options
);
let mut texture_id = None;
for (loop_index, glyph_instance) in glyph_instances.iter().enumerate() {
glyph_key.key.index = glyph_instance.index;
glyph_key.key.subpixel_point.set_offset(glyph_instance.point, render_mode);
glyph_request.key.index = glyph_instance.index;
glyph_request.key.subpixel_point = SubpixelPoint::new(glyph_instance.point, render_mode);

let image_id = self.cached_glyphs.get(&glyph_key, self.current_frame_id);
let image_id = self.cached_glyphs.get(&glyph_request, self.current_frame_id);
let cache_item = image_id.map(|image_id| self.texture_cache.get(image_id));
if let Some(cache_item) = cache_item {
f(loop_index, &cache_item.uv_rect_handle);
Expand Down
5 changes: 0 additions & 5 deletions webrender_api/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ impl SubpixelPoint {
pub fn to_f64(&self) -> (f64, f64) {
(self.x.into(), self.y.into())
}

pub fn set_offset(&mut self, point: LayoutPoint, render_mode: FontRenderMode) {
self.x = render_mode.subpixel_quantize_offset(point.x);
self.y = render_mode.subpixel_quantize_offset(point.y);
}
}

#[derive(Clone, Hash, PartialEq, Eq, Debug, Deserialize, Serialize, Ord, PartialOrd)]
Expand Down