From c5d68380428079bedb4fd56bbcc8c934dc932814 Mon Sep 17 00:00:00 2001 From: Mason Chang Date: Tue, 24 Jan 2017 09:15:00 -0800 Subject: [PATCH] pipe dwrite glyph rendering options to rasterize glyphs --- sample/src/main.rs | 3 ++- webrender/src/frame.rs | 3 ++- webrender/src/platform/macos/font.rs | 5 +++-- webrender/src/platform/unix/font.rs | 5 +++-- webrender/src/platform/windows/font.rs | 5 +++-- webrender/src/prim_store.rs | 8 ++++++-- webrender/src/resource_cache.rs | 27 +++++++++++++++++--------- webrender/src/tiling.rs | 5 ++++- webrender_traits/src/display_list.rs | 5 ++++- webrender_traits/src/types.rs | 8 ++++++++ wrench/src/yaml_frame_reader.rs | 2 +- 11 files changed, 54 insertions(+), 22 deletions(-) diff --git a/sample/src/main.rs b/sample/src/main.rs index 29bf6660d8..dba7be13b1 100644 --- a/sample/src/main.rs +++ b/sample/src/main.rs @@ -227,7 +227,8 @@ fn main() { font_key, ColorF::new(1.0, 1.0, 0.0, 1.0), Au::from_px(32), - Au::from_px(0)); + Au::from_px(0), + None); } builder.pop_stacking_context(); diff --git a/webrender/src/frame.rs b/webrender/src/frame.rs index fdc2faeacc..f30bd433ea 100644 --- a/webrender/src/frame.rs +++ b/webrender/src/frame.rs @@ -554,7 +554,8 @@ impl Frame { text_info.size, text_info.blur_radius, &text_info.color, - text_info.glyphs); + text_info.glyphs, + text_info.glyph_options); } SpecificDisplayItem::Rectangle(ref info) => { context.builder.add_solid_rectangle(&item.rect, diff --git a/webrender/src/platform/macos/font.rs b/webrender/src/platform/macos/font.rs index fba16d676d..accfae2b69 100644 --- a/webrender/src/platform/macos/font.rs +++ b/webrender/src/platform/macos/font.rs @@ -15,7 +15,7 @@ use core_text::font_descriptor::kCTFontDefaultOrientation; use core_text; use std::collections::HashMap; use std::collections::hash_map::Entry; -use webrender_traits::{ColorU, FontKey, FontRenderMode, GlyphDimensions}; +use webrender_traits::{ColorU, FontKey, FontRenderMode, GlyphDimensions, GlyphOptions}; pub type NativeFontHandle = CGFont; @@ -180,7 +180,8 @@ impl FontContext { size: Au, color: ColorU, character: u32, - render_mode: FontRenderMode) -> Option { + render_mode: FontRenderMode, + glyph_options: Option) -> Option { match self.get_ct_font(font_key, size) { Some(ref ct_font) => { let glyph = character as CGGlyph; diff --git a/webrender/src/platform/unix/font.rs b/webrender/src/platform/unix/font.rs index cd7038186e..ba3f3c3701 100644 --- a/webrender/src/platform/unix/font.rs +++ b/webrender/src/platform/unix/font.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use app_units::Au; -use webrender_traits::{FontKey, ColorU, FontRenderMode, GlyphDimensions, NativeFontHandle}; +use webrender_traits::{FontKey, ColorU, FontRenderMode, GlyphDimensions, NativeFontHandle, GlyphOptions}; use freetype::freetype::{FT_Render_Mode, FT_Pixel_Mode}; use freetype::freetype::{FT_Done_FreeType, FT_Library_SetLcdFilter}; @@ -135,7 +135,8 @@ impl FontContext { size: Au, color: ColorU, character: u32, - render_mode: FontRenderMode) -> Option { + render_mode: FontRenderMode, + glyph_options: Option) -> Option { let mut glyph = None; if let Some(slot) = self.load_glyph(font_key, diff --git a/webrender/src/platform/windows/font.rs b/webrender/src/platform/windows/font.rs index 5b0574edc1..d9ca8fd331 100644 --- a/webrender/src/platform/windows/font.rs +++ b/webrender/src/platform/windows/font.rs @@ -4,7 +4,7 @@ use app_units::Au; use std::collections::HashMap; -use webrender_traits::{FontKey, ColorU, FontRenderMode, GlyphDimensions}; +use webrender_traits::{FontKey, ColorU, FontRenderMode, GlyphDimensions, GlyphOptions}; use dwrote; @@ -184,7 +184,8 @@ impl FontContext { size: Au, color: ColorU, glyph: u32, - render_mode: FontRenderMode) -> Option { + render_mode: FontRenderMode, + glyph_options: Option) -> Option { let (_, maybe_glyph) = self.get_glyph_dimensions_and_maybe_rasterize(font_key, size, glyph, Some(render_mode)); maybe_glyph diff --git a/webrender/src/prim_store.rs b/webrender/src/prim_store.rs index c9cf57e3ae..67b4a1033f 100644 --- a/webrender/src/prim_store.rs +++ b/webrender/src/prim_store.rs @@ -19,6 +19,7 @@ use webrender_traits::{device_length, DeviceIntRect, DeviceIntSize}; use webrender_traits::{DeviceRect, DevicePoint, DeviceSize}; use webrender_traits::{LayerRect, LayerSize, LayerPoint}; use webrender_traits::LayerToWorldTransform; +use webrender_traits::{GlyphOptions}; pub const CLIP_DATA_GPU_SIZE: usize = 5; pub const MASK_DATA_GPU_SIZE: usize = 1; @@ -290,6 +291,7 @@ pub struct TextRunPrimitiveCpu { pub color: ColorF, pub render_mode: FontRenderMode, pub resource_address: GpuStoreAddress, + pub glyph_options: Option, } #[derive(Debug, Clone)] @@ -741,7 +743,8 @@ impl PrimitiveStore { font_size_dp, text.color, &text.glyph_indices, - text.render_mode, |index, uv0, uv1| { + text.render_mode, + text.glyph_options, |index, uv0, uv1| { let dest_rect = &mut dest_rects[index]; dest_rect.uv0 = uv0; dest_rect.uv1 = uv1; @@ -1001,7 +1004,8 @@ impl PrimitiveStore { font_size_dp, text.color, &text.glyph_indices, - text.render_mode); + text.render_mode, + text.glyph_options); } PrimitiveKind::Image => { let image_cpu = &mut self.cpu_images[metadata.cpu_prim_index.0]; diff --git a/webrender/src/resource_cache.rs b/webrender/src/resource_cache.rs index 8f6e21c799..2a0a19ac3e 100644 --- a/webrender/src/resource_cache.rs +++ b/webrender/src/resource_cache.rs @@ -22,7 +22,7 @@ use texture_cache::{TextureCache, TextureCacheItemId}; use webrender_traits::{Epoch, FontKey, GlyphKey, ImageKey, ImageFormat, ImageRendering}; use webrender_traits::{FontRenderMode, ImageData, GlyphDimensions, WebGLContextId}; use webrender_traits::{DevicePoint, DeviceIntSize, ImageDescriptor, ColorF}; -use webrender_traits::ExternalImageId; +use webrender_traits::{ExternalImageId, GlyphOptions}; use threadpool::ThreadPool; thread_local!(pub static FONT_CONTEXT: RefCell = RefCell::new(FontContext::new())); @@ -36,7 +36,7 @@ enum GlyphCacheMsg { /// Add a new font. AddFont(FontKey, FontTemplate), /// Request glyphs for a text run. - RequestGlyphs(FontKey, Au, ColorF, Vec, FontRenderMode), + RequestGlyphs(FontKey, Au, ColorF, Vec, FontRenderMode, Option), /// Finished requesting glyphs. Reply with new glyphs. EndFrame, } @@ -66,6 +66,7 @@ pub struct CacheItem { pub struct RenderedGlyphKey { pub key: GlyphKey, pub render_mode: FontRenderMode, + pub glyph_options: Option, } impl RenderedGlyphKey { @@ -73,10 +74,12 @@ impl RenderedGlyphKey { size: Au, color: ColorF, index: u32, - render_mode: FontRenderMode) -> RenderedGlyphKey { + render_mode: FontRenderMode, + glyph_options: Option) -> RenderedGlyphKey { RenderedGlyphKey { key: GlyphKey::new(font_key, size, color, index), render_mode: render_mode, + glyph_options: glyph_options, } } } @@ -328,7 +331,8 @@ impl ResourceCache { size: Au, color: ColorF, glyph_indices: &[u32], - render_mode: FontRenderMode) { + render_mode: FontRenderMode, + glyph_options: Option) { debug_assert!(self.state == State::AddResources); let render_mode = self.get_glyph_render_mode(render_mode); // Immediately request that the glyph cache thread start @@ -338,7 +342,8 @@ impl ResourceCache { size, color, glyph_indices.to_vec(), - render_mode); + render_mode, + glyph_options); self.glyph_cache_tx.send(msg).unwrap(); } @@ -356,6 +361,7 @@ impl ResourceCache { color: ColorF, glyph_indices: &[u32], render_mode: FontRenderMode, + glyph_options: Option, mut f: F) -> SourceTexture where F: FnMut(usize, DevicePoint, DevicePoint) { debug_assert!(self.state == State::QueryResources); let cache = self.cached_glyphs.as_ref().unwrap(); @@ -364,7 +370,8 @@ impl ResourceCache { size, color, 0, - render_mode); + render_mode, + glyph_options); let mut texture_id = None; for (loop_index, glyph_index) in glyph_indices.iter().enumerate() { glyph_key.key.index = *glyph_index; @@ -668,7 +675,7 @@ fn spawn_glyph_cache_thread() -> (Sender, Receiver { + GlyphCacheMsg::RequestGlyphs(key, size, color, indices, render_mode, glyph_options) => { // Request some glyphs for a text run. // For any glyph that isn't currently in the cache, // immeediately push a job to the worker thread pool @@ -680,7 +687,8 @@ fn spawn_glyph_cache_thread() -> (Sender, Receiver (Sender, Receiver) { if color.a == 0.0 { return } @@ -2370,6 +2372,7 @@ impl FrameBuilder { color_texture_id: SourceTexture::Invalid, color: *color, render_mode: render_mode, + glyph_options: glyph_options, resource_address: GpuStoreAddress(0), }; diff --git a/webrender_traits/src/display_list.rs b/webrender_traits/src/display_list.rs index 11dc1de9e3..3ffcddb3fa 100644 --- a/webrender_traits/src/display_list.rs +++ b/webrender_traits/src/display_list.rs @@ -15,6 +15,7 @@ use {PushScrollLayerItem, PushStackingContextDisplayItem, RectangleDisplayItem, use {ScrollPolicy, ServoScrollRootId, SpecificDisplayItem, StackingContext, TextDisplayItem}; use {WebGLContextId, WebGLDisplayItem, YuvImageDisplayItem}; use {LayoutTransform, LayoutPoint, LayoutRect, LayoutSize}; +use {GlyphOptions}; impl BuiltDisplayListDescriptor { pub fn size(&self) -> usize { @@ -154,7 +155,8 @@ impl DisplayListBuilder { font_key: FontKey, color: ColorF, size: Au, - blur_radius: Au) { + blur_radius: Au, + glyph_options: Option) { // Sanity check - anything with glyphs bigger than this // is probably going to consume too much memory to render // efficiently anyway. This is specifically to work around @@ -168,6 +170,7 @@ impl DisplayListBuilder { font_key: font_key, size: size, blur_radius: blur_radius, + glyph_options: glyph_options, }; let display_item = DisplayItem { diff --git a/webrender_traits/src/types.rs b/webrender_traits/src/types.rs index 8522f1265e..55fed76ce7 100644 --- a/webrender_traits/src/types.rs +++ b/webrender_traits/src/types.rs @@ -631,6 +631,13 @@ pub struct StackingContext { pub filters: ItemRange, } +#[derive(Clone, Copy, Debug, Deserialize, Hash, Eq, PartialEq, PartialOrd, Ord, Serialize)] +pub struct GlyphOptions { + // These are currently only used on windows for dwrite fonts. + use_embedded_bitmap: bool, + force_gdi_rendering: bool, +} + #[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)] pub struct TextDisplayItem { pub glyphs: ItemRange, @@ -638,6 +645,7 @@ pub struct TextDisplayItem { pub size: Au, pub color: ColorF, pub blur_radius: Au, + pub glyph_options: Option, } #[derive(Clone, Deserialize, Serialize)] diff --git a/wrench/src/yaml_frame_reader.rs b/wrench/src/yaml_frame_reader.rs index f32154148f..a814af3bb7 100644 --- a/wrench/src/yaml_frame_reader.rs +++ b/wrench/src/yaml_frame_reader.rs @@ -371,7 +371,7 @@ impl YamlFrameReader { }; let clip = self.to_clip_region(&item["clip"], &rect, wrench).unwrap_or(*clip_region); - self.builder().push_text(rect, clip, glyphs, font_key, color, size, blur_radius); + self.builder().push_text(rect, clip, glyphs, font_key, color, size, blur_radius, None); } fn handle_iframe(&mut self, wrench: &mut Wrench, clip_region: &ClipRegion, item: &Yaml)