diff options
author | bors-servo <release+servo@mozilla.com> | 2013-10-03 02:45:49 -0700 |
---|---|---|
committer | bors-servo <release+servo@mozilla.com> | 2013-10-03 02:45:49 -0700 |
commit | 5d59c0057592de5f204f1f756dd490f7a23577a0 (patch) | |
tree | 90f65c3df17a68ae23644b078682937c797cf83d | |
parent | d6d2534b562d9e95ce02ede5920b679d53734dcf (diff) | |
parent | 70578e635000509f22cdaf91148a51efedce3b9f (diff) | |
download | servo-5d59c0057592de5f204f1f756dd490f7a23577a0.tar.gz servo-5d59c0057592de5f204f1f756dd490f7a23577a0.zip |
auto merge of #1008 : deokjinkim/servo/glyph_advance_cache, r=jdm
To reduce number of FT_Load_Glyph call, use glyph advance cache.
-rw-r--r-- | src/components/gfx/font.rs | 15 | ||||
-rw-r--r-- | src/components/gfx/platform/android/font.rs | 2 | ||||
-rw-r--r-- | src/components/gfx/platform/linux/font.rs | 2 | ||||
-rw-r--r-- | src/components/gfx/platform/macos/font.rs | 2 | ||||
-rw-r--r-- | src/components/gfx/text/shaping/harfbuzz.rs | 2 |
5 files changed, 14 insertions, 9 deletions
diff --git a/src/components/gfx/font.rs b/src/components/gfx/font.rs index 9dcf7772334..9278cc11041 100644 --- a/src/components/gfx/font.rs +++ b/src/components/gfx/font.rs @@ -49,7 +49,7 @@ pub trait FontHandleMethods { fn clone_with_style(&self, fctx: &FontContextHandle, style: &UsedFontStyle) -> Result<FontHandle, ()>; fn glyph_index(&self, codepoint: char) -> Option<GlyphIndex>; - fn glyph_h_advance(&self, GlyphIndex) -> Option<FractionalPixel>; + fn glyph_h_advance(&mut self, GlyphIndex) -> Option<FractionalPixel>; fn get_metrics(&self) -> FontMetrics; fn get_table_for_tag(&self, FontTableTag) -> Option<FontTable>; } @@ -244,6 +244,7 @@ pub struct Font { backend: BackendType, profiler_chan: ProfilerChan, shape_cache: HashCache<~str, Arc<GlyphStore>>, + glyph_advance_cache: HashCache<u32, FractionalPixel>, } impl Font { @@ -272,6 +273,7 @@ impl Font { backend: backend, profiler_chan: profiler_chan, shape_cache: HashCache::new(), + glyph_advance_cache: HashCache::new(), }); } @@ -289,6 +291,7 @@ impl Font { backend: backend, profiler_chan: profiler_chan, shape_cache: HashCache::new(), + glyph_advance_cache: HashCache::new(), } } @@ -474,10 +477,12 @@ impl Font { self.handle.glyph_index(codepoint) } - pub fn glyph_h_advance(&self, glyph: GlyphIndex) -> FractionalPixel { - match self.handle.glyph_h_advance(glyph) { - Some(adv) => adv, - None => /* FIXME: Need fallback strategy */ 10f as FractionalPixel + pub fn glyph_h_advance(&mut self, glyph: GlyphIndex) -> FractionalPixel { + do self.glyph_advance_cache.find_or_create(&glyph) |glyph| { + match self.handle.glyph_h_advance(*glyph) { + Some(adv) => adv, + None => /* FIXME: Need fallback strategy */ 10f as FractionalPixel + } } } } diff --git a/src/components/gfx/platform/android/font.rs b/src/components/gfx/platform/android/font.rs index b8b08cc9599..a9e20379757 100644 --- a/src/components/gfx/platform/android/font.rs +++ b/src/components/gfx/platform/android/font.rs @@ -198,7 +198,7 @@ impl FontHandleMethods for FontHandle { } #[fixed_stack_segment] - fn glyph_h_advance(&self, + fn glyph_h_advance(&mut self, glyph: GlyphIndex) -> Option<FractionalPixel> { assert!(self.face.is_not_null()); unsafe { diff --git a/src/components/gfx/platform/linux/font.rs b/src/components/gfx/platform/linux/font.rs index b8b08cc9599..a9e20379757 100644 --- a/src/components/gfx/platform/linux/font.rs +++ b/src/components/gfx/platform/linux/font.rs @@ -198,7 +198,7 @@ impl FontHandleMethods for FontHandle { } #[fixed_stack_segment] - fn glyph_h_advance(&self, + fn glyph_h_advance(&mut self, glyph: GlyphIndex) -> Option<FractionalPixel> { assert!(self.face.is_not_null()); unsafe { diff --git a/src/components/gfx/platform/macos/font.rs b/src/components/gfx/platform/macos/font.rs index 08978c5d063..f38d7600bb9 100644 --- a/src/components/gfx/platform/macos/font.rs +++ b/src/components/gfx/platform/macos/font.rs @@ -147,7 +147,7 @@ impl FontHandleMethods for FontHandle { return Some(glyphs[0] as GlyphIndex); } - fn glyph_h_advance(&self, glyph: GlyphIndex) -> Option<FractionalPixel> { + fn glyph_h_advance(&mut self, glyph: GlyphIndex) -> Option<FractionalPixel> { let glyphs = [glyph as CGGlyph]; let advance = self.ctfont.get_advances_for_glyphs(kCTFontDefaultOrientation, &glyphs[0], diff --git a/src/components/gfx/text/shaping/harfbuzz.rs b/src/components/gfx/text/shaping/harfbuzz.rs index 824ccc73e3e..1b3c27af929 100644 --- a/src/components/gfx/text/shaping/harfbuzz.rs +++ b/src/components/gfx/text/shaping/harfbuzz.rs @@ -509,7 +509,7 @@ extern fn glyph_h_advance_func(_: *hb_font_t, glyph: hb_codepoint_t, _: *c_void) -> hb_position_t { - let font: *Font = font_data as *Font; + let font: *mut Font = font_data as *mut Font; assert!(font.is_not_null()); unsafe { |