Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more per-platform font options to FontInstancePlatformOptions #1816

Merged
merged 1 commit into from Oct 6, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

add more per-platform font options to FontInstancePlatformOptions

  • Loading branch information
lsalzman committed Oct 6, 2017
commit e11297a240b29bd57154d37ecb402d0b9aa299e6

Some generated files are not rendered by default. Learn more.

@@ -1,6 +1,6 @@
[package]
name = "webrender"
version = "0.52.0"
version = "0.52.1"
authors = ["Glenn Watson <gw@intuitionlibrary.com>"]
license = "MPL-2.0"
repository = "https://github.com/servo/webrender"
@@ -38,7 +38,7 @@ void main(void) {
// Glyphs size is already in device-pixels.
// The render task origin is in device-pixels. Offset that by
// the glyph offset, relative to its primitive bounding rect.
vec2 size = res.uv_rect.zw - res.uv_rect.xy;
vec2 size = (res.uv_rect.zw - res.uv_rect.xy) * res.scale;
vec2 local_pos = glyph.offset + vec2(res.offset.x, -res.offset.y) / uDevicePixelRatio;
vec2 origin = prim.task.render_target_origin +
uDevicePixelRatio * (local_pos + shadow.offset - shadow_geom.local_rect.p0);
@@ -627,11 +627,12 @@ struct GlyphResource {
vec4 uv_rect;
float layer;
vec2 offset;
float scale;
};

GlyphResource fetch_glyph_resource(int address) {
vec4 data[2] = fetch_from_resource_cache_2(address);
return GlyphResource(data[0], data[1].x, data[1].yz);
return GlyphResource(data[0], data[1].x, data[1].yz, data[1].w);
}

struct ImageResource {
@@ -30,7 +30,7 @@ void main(void) {
vec2(res.offset.x, -res.offset.y) / uDevicePixelRatio;

RectWithSize local_rect = RectWithSize(local_pos,
(res.uv_rect.zw - res.uv_rect.xy) / uDevicePixelRatio);
(res.uv_rect.zw - res.uv_rect.xy) * res.scale / uDevicePixelRatio);

#ifdef WR_FEATURE_TRANSFORM
TransformVertexInfo vi = write_transform_vertex(local_rect,
@@ -57,7 +57,7 @@ void main(void) {
vec2 st0 = res.uv_rect.xy / texture_size;
vec2 st1 = res.uv_rect.zw / texture_size;

vColor = text.color;
vColor = vec4(text.color.rgb * text.color.a, text.color.a);
vUv = vec3(mix(st0, st1, f), res.layer);
vUvBorder = (res.uv_rect + vec4(0.5, 0.5, -0.5, -0.5)) / texture_size.xyxy;
}
@@ -71,13 +71,14 @@ void main(void) {
oFragColor = texture(sColor0, tc);
#else
vec4 color = texture(sColor0, tc) * vColor;
float alpha = 1.0;
#ifdef WR_FEATURE_TRANSFORM
float a = 0.0;
init_transform_fs(vLocalPos, a);
color.a *= a;
alpha *= a;
#endif
color.a = min(color.a, do_clip());
oFragColor = color;
alpha = min(alpha, do_clip());
oFragColor = color * alpha;
#endif
}
#endif
@@ -10,7 +10,7 @@ use api::{GlyphInstance, GlyphOptions, GradientStop, HitTestFlags, HitTestItem,
use api::{ImageKey, ImageRendering, ItemRange, ItemTag, LayerPoint, LayerPrimitiveInfo, LayerRect};
use api::{LayerSize, LayerToScrollTransform, LayerVector2D, LayoutVector2D, LineOrientation};
use api::{LineStyle, LocalClip, POINT_RELATIVE_TO_PIPELINE_VIEWPORT, PipelineId, RepeatMode};
use api::{ScrollSensitivity, SubpixelDirection, Shadow, TileOffset, TransformStyle};
use api::{ScrollSensitivity, Shadow, TileOffset, TransformStyle};
use api::{WorldPixel, WorldPoint, YuvColorSpace, YuvData, device_length};
use app_units::Au;
use border::ImageBorderSegment;
@@ -1132,19 +1132,18 @@ impl FrameBuilder {
// TODO(gw): Use a proper algorithm to select
// whether this item should be rendered with
// subpixel AA!
let mut default_render_mode = self.config
let mut render_mode = self.config
.default_font_render_mode
.limit_by(font.render_mode);
if let Some(options) = glyph_options {
default_render_mode = default_render_mode.limit_by(options.render_mode);
render_mode = render_mode.limit_by(options.render_mode);
}

// There are some conditions under which we can't use
// subpixel text rendering, even if enabled.
let mut normal_render_mode = default_render_mode;
if normal_render_mode == FontRenderMode::Subpixel {
if render_mode == FontRenderMode::Subpixel {
if color.a != 1.0 {
normal_render_mode = FontRenderMode::Alpha;
render_mode = FontRenderMode::Alpha;
}

// text on a stacking context that has filters
@@ -1155,36 +1154,17 @@ impl FrameBuilder {
if let Some(sc_index) = self.stacking_context_stack.last() {
let stacking_context = &self.stacking_context_store[sc_index.0];
if stacking_context.composite_ops.count() > 0 {
normal_render_mode = FontRenderMode::Alpha;
render_mode = FontRenderMode::Alpha;
}
}
}

let color = match font.render_mode {
FontRenderMode::Bitmap => ColorF::new(1.0, 1.0, 1.0, 1.0),
FontRenderMode::Subpixel |
FontRenderMode::Alpha |
FontRenderMode::Mono => *color,
};

// Shadows never use subpixel AA, but need to respect the alpha/mono flag
// for reftests.
let (shadow_render_mode, subpx_dir) = match default_render_mode {
FontRenderMode::Subpixel | FontRenderMode::Alpha => {
// TODO(gw): Expose subpixel direction in API once WR supports
// vertical text runs.
(FontRenderMode::Alpha, font.subpx_dir)
}
FontRenderMode::Mono => (FontRenderMode::Mono, SubpixelDirection::None),
FontRenderMode::Bitmap => (FontRenderMode::Bitmap, font.subpx_dir),
};

let prim_font = FontInstance::new(
font.font_key,
font.size,
color,
normal_render_mode,
subpx_dir,
*color,
render_mode,
font.subpx_dir,
font.platform_options,
font.variations.clone(),
font.synthetic_italics,
@@ -1195,9 +1175,7 @@ impl FrameBuilder {
glyph_count,
glyph_gpu_blocks: Vec::new(),
glyph_keys: Vec::new(),
shadow_render_mode,
offset: run_offset,
color: color,
};

// Text shadows that have a blur radius of 0 need to be rendered as normal
@@ -1215,16 +1193,13 @@ impl FrameBuilder {
let shadow = picture_prim.as_shadow();
if shadow.blur_radius == 0.0 {
let mut text_prim = prim.clone();
if font.render_mode != FontRenderMode::Bitmap {
text_prim.font.color = shadow.color.into();
}
text_prim.font.color = shadow.color.into();
// If we have translucent text, we need to ensure it won't go
// through the subpixel blend mode, which doesn't work with
// traditional alpha blending.
if shadow.color.a != 1.0 {
text_prim.font.render_mode = text_prim.font.render_mode.limit_by(FontRenderMode::Alpha);
}
text_prim.color = shadow.color;
text_prim.offset += shadow.offset;
fast_shadow_prims.push(text_prim);
}
@@ -13,6 +13,7 @@ pub struct CachedGlyphInfo {
pub glyph_bytes: Arc<Vec<u8>>,
pub size: DeviceUintSize,
pub offset: DevicePoint,
pub scale: f32,
}

pub type GlyphKeyCache = ResourceClassCache<GlyphKey, Option<CachedGlyphInfo>>;
@@ -3,10 +3,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#[cfg(test)]
use api::{ColorF, FontRenderMode, IdNamespace, LayoutPoint, SubpixelDirection};
use api::{ColorF, IdNamespace, LayoutPoint};
use api::{DevicePoint, DeviceUintSize, FontInstance};
use api::{FontKey, FontTemplate};
use api::{GlyphDimensions, GlyphKey};
use api::{FontKey, FontTemplate, FontRenderMode, ColorU};
use api::{GlyphDimensions, GlyphKey, SubpixelDirection};
use api::{ImageData, ImageDescriptor, ImageFormat};
#[cfg(test)]
use app_units::Au;
@@ -144,6 +144,29 @@ impl GlyphRasterizer {
self.fonts_to_remove.push(font_key);
}

pub fn prepare_font(&self, font: &mut FontInstance) {
// In alpha/mono mode, the color of the font is irrelevant.
// Forcing it to black in those cases saves rasterizing glyphs
// of different colors when not needed.
match font.render_mode {
FontRenderMode::Mono | FontRenderMode::Bitmap => {
font.color = ColorU::new(255, 255, 255, 255);
// Subpixel positioning is disabled in mono and bitmap modes.
font.subpx_dir = SubpixelDirection::None;
}
FontRenderMode::Alpha => {
font.color = ColorU::new(255, 255, 255, 255);
}
FontRenderMode::Subpixel => {
// In subpixel mode, we only actually need the color if preblending
// is used in the font backend.
if !FontContext::has_gamma_correct_subpixel_aa() {
font.color = ColorU::new(255, 255, 255, 255);
}
}
}
}

pub fn request_glyphs(
&mut self,
glyph_cache: &mut GlyphCache,
@@ -183,7 +206,7 @@ impl GlyphRasterizer {
},
TextureFilter::Linear,
ImageData::Raw(glyph_info.glyph_bytes.clone()),
[glyph_info.offset.x, glyph_info.offset.y],
[glyph_info.offset.x, glyph_info.offset.y, glyph_info.scale],
None,
gpu_cache,
);
@@ -246,10 +269,10 @@ impl GlyphRasterizer {
.get_glyph_dimensions(font, glyph_key)
}

pub fn is_bitmap_font(&self, font_key: FontKey) -> bool {
pub fn is_bitmap_font(&self, font: &FontInstance) -> bool {
self.font_contexts
.lock_shared_context()
.is_bitmap_font(font_key)
.is_bitmap_font(font)
}

pub fn get_glyph_index(&mut self, font_key: FontKey, ch: char) -> Option<u32> {
@@ -312,7 +335,7 @@ impl GlyphRasterizer {
},
TextureFilter::Linear,
ImageData::Raw(glyph_bytes.clone()),
[glyph.left, glyph.top],
[glyph.left, glyph.top, glyph.scale],
None,
gpu_cache,
);
@@ -321,6 +344,7 @@ impl GlyphRasterizer {
glyph_bytes,
size: DeviceUintSize::new(glyph.width, glyph.height),
offset: DevicePoint::new(glyph.left, glyph.top),
scale: glyph.scale,
})
} else {
None
@@ -42,6 +42,7 @@ pub struct RasterizedGlyph {
pub left: f32,
pub width: u32,
pub height: u32,
pub scale: f32,
pub bytes: Vec<u8>,
}

@@ -52,6 +53,7 @@ impl RasterizedGlyph {
left: 0.0,
width: 0,
height: 0,
scale: 1.0,
bytes: vec![],
}
}
@@ -422,18 +424,20 @@ impl FontContext {
}
}

pub fn is_bitmap_font(&mut self, font_key: FontKey) -> bool {
match self.get_ct_font(font_key, Au(16 * 60), &[]) {
pub fn is_bitmap_font(&mut self, font: &FontInstance) -> bool {
match self.get_ct_font(font.font_key, font.size, &font.variations) {
Some(ref ct_font) => {
let traits = ct_font.symbolic_traits();
(traits & kCTFontColorGlyphsTrait) != 0
}
None => {
false
}
None => false,
}
}

pub fn has_gamma_correct_subpixel_aa() -> bool {
true
}

pub fn rasterize_glyph(
&mut self,
font: &FontInstance,
@@ -585,6 +589,7 @@ impl FontContext {
top: metrics.rasterized_ascent as f32,
width: metrics.rasterized_width,
height: metrics.rasterized_height,
scale: 1.0,
bytes: rasterized_pixels,
})
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.