[OT] Gain back some lost speed

This commit is contained in:
Behdad Esfahbod 2012-07-30 02:38:39 -04:00
parent 11f4c87d01
commit f860366456
6 changed files with 114 additions and 44 deletions

View File

@ -1,5 +1,6 @@
/* /*
* Copyright © 2007,2008,2009 Red Hat, Inc. * Copyright © 2007,2008,2009 Red Hat, Inc.
* Copyright © 2012 Google, Inc.
* *
* This is part of HarfBuzz, a text shaping library. * This is part of HarfBuzz, a text shaping library.
* *
@ -22,6 +23,7 @@
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
* *
* Red Hat Author(s): Behdad Esfahbod * Red Hat Author(s): Behdad Esfahbod
* Google Author(s): Behdad Esfahbod
*/ */
#ifndef HB_OT_LAYOUT_PRIVATE_HH #ifndef HB_OT_LAYOUT_PRIVATE_HH
@ -33,9 +35,13 @@
#include "hb-font-private.hh" #include "hb-font-private.hh"
#include "hb-buffer-private.hh" #include "hb-buffer-private.hh"
#include "hb-ot-shape-complex-private.hh"
/* buffer var allocations, used during the GSUB/GPOS processing */
#define props_cache() var1.u16[1] /* GSUB/GPOS glyph_props cache */
#define syllable() var2.u8[0] /* GSUB/GPOS shaping boundaries */
#define lig_props() var2.u8[1] /* GSUB/GPOS ligature tracking */
#define hb_ot_layout_from_face(face) ((hb_ot_layout_t *) face->shaper_data.ot) #define hb_ot_layout_from_face(face) ((hb_ot_layout_t *) face->shaper_data.ot)
/* /*
@ -142,6 +148,25 @@ static inline uint8_t allocate_lig_id (hb_buffer_t *buffer) {
} }
HB_INTERNAL hb_bool_t
hb_ot_layout_would_substitute_lookup_fast (hb_face_t *face,
const hb_codepoint_t *glyphs,
unsigned int glyphs_length,
unsigned int lookup_index);
HB_INTERNAL hb_bool_t
hb_ot_layout_substitute_lookup_fast (hb_face_t *face,
hb_buffer_t *buffer,
unsigned int lookup_index,
hb_mask_t mask);
HB_INTERNAL hb_bool_t
hb_ot_layout_position_lookup_fast (hb_font_t *font,
hb_buffer_t *buffer,
unsigned int lookup_index,
hb_mask_t mask);
/* /*
* hb_ot_layout_t * hb_ot_layout_t
*/ */

View File

@ -2,6 +2,7 @@
* Copyright © 1998-2004 David Turner and Werner Lemberg * Copyright © 1998-2004 David Turner and Werner Lemberg
* Copyright © 2006 Behdad Esfahbod * Copyright © 2006 Behdad Esfahbod
* Copyright © 2007,2008,2009 Red Hat, Inc. * Copyright © 2007,2008,2009 Red Hat, Inc.
* Copyright © 2012 Google, Inc.
* *
* This is part of HarfBuzz, a text shaping library. * This is part of HarfBuzz, a text shaping library.
* *
@ -24,6 +25,7 @@
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
* *
* Red Hat Author(s): Behdad Esfahbod * Red Hat Author(s): Behdad Esfahbod
* Google Author(s): Behdad Esfahbod
*/ */
#include "hb-ot-layout-private.hh" #include "hb-ot-layout-private.hh"
@ -93,6 +95,24 @@ _get_gpos (hb_face_t *face)
return *hb_ot_layout_from_face (face)->gpos; return *hb_ot_layout_from_face (face)->gpos;
} }
static inline const GDEF&
_get_gdef_fast (hb_face_t *face)
{
return *hb_ot_layout_from_face (face)->gdef;
}
static inline const GSUB&
_get_gsub_fast (hb_face_t *face)
{
if (unlikely (!hb_ot_layout_ensure (face))) return Null(GSUB);
return *hb_ot_layout_from_face (face)->gsub;
}
static inline const GPOS&
_get_gpos_fast (hb_face_t *face)
{
if (unlikely (!hb_ot_layout_ensure (face))) return Null(GPOS);
return *hb_ot_layout_from_face (face)->gpos;
}
/* /*
* GDEF * GDEF
@ -110,7 +130,7 @@ _hb_ot_layout_get_glyph_property (hb_face_t *face,
{ {
if (!info->props_cache()) if (!info->props_cache())
{ {
const GDEF &gdef = _get_gdef (face); const GDEF &gdef = _get_gdef_fast (face);
info->props_cache() = gdef.get_glyph_props (info->codepoint); info->props_cache() = gdef.get_glyph_props (info->codepoint);
} }
@ -127,7 +147,7 @@ _hb_ot_layout_match_properties_mark (hb_face_t *face,
* lookup_props has the set index. * lookup_props has the set index.
*/ */
if (lookup_props & LookupFlag::UseMarkFilteringSet) if (lookup_props & LookupFlag::UseMarkFilteringSet)
return _get_gdef (face).mark_set_covers (lookup_props >> 16, glyph); return _get_gdef_fast (face).mark_set_covers (lookup_props >> 16, glyph);
/* The second byte of lookup_props has the meaning /* The second byte of lookup_props has the meaning
* "ignore marks of attachment type different than * "ignore marks of attachment type different than
@ -479,6 +499,17 @@ hb_ot_layout_would_substitute_lookup (hb_face_t *face,
return _get_gsub (face).would_substitute_lookup (&c, lookup_index); return _get_gsub (face).would_substitute_lookup (&c, lookup_index);
} }
hb_bool_t
hb_ot_layout_would_substitute_lookup_fast (hb_face_t *face,
const hb_codepoint_t *glyphs,
unsigned int glyphs_length,
unsigned int lookup_index)
{
if (unlikely (glyphs_length < 1 || glyphs_length > 2)) return false;
hb_would_apply_context_t c (face, glyphs[0], glyphs_length == 2 ? glyphs[1] : -1);
return _get_gsub_fast (face).would_substitute_lookup (&c, lookup_index);
}
void void
hb_ot_layout_substitute_start (hb_buffer_t *buffer) hb_ot_layout_substitute_start (hb_buffer_t *buffer)
{ {
@ -495,6 +526,16 @@ hb_ot_layout_substitute_lookup (hb_face_t *face,
return _get_gsub (face).substitute_lookup (&c, lookup_index); return _get_gsub (face).substitute_lookup (&c, lookup_index);
} }
hb_bool_t
hb_ot_layout_substitute_lookup_fast (hb_face_t *face,
hb_buffer_t *buffer,
unsigned int lookup_index,
hb_mask_t mask)
{
hb_apply_context_t c (NULL, face, buffer, mask);
return _get_gsub_fast (face).substitute_lookup (&c, lookup_index);
}
void void
hb_ot_layout_substitute_finish (hb_buffer_t *buffer HB_UNUSED) hb_ot_layout_substitute_finish (hb_buffer_t *buffer HB_UNUSED)
{ {
@ -527,15 +568,25 @@ hb_ot_layout_position_start (hb_buffer_t *buffer)
} }
hb_bool_t hb_bool_t
hb_ot_layout_position_lookup (hb_font_t *font, hb_ot_layout_position_lookup (hb_font_t *font,
hb_buffer_t *buffer, hb_buffer_t *buffer,
unsigned int lookup_index, unsigned int lookup_index,
hb_mask_t mask) hb_mask_t mask)
{ {
hb_apply_context_t c (font, font->face, buffer, mask); hb_apply_context_t c (font, font->face, buffer, mask);
return _get_gpos (font->face).position_lookup (&c, lookup_index); return _get_gpos (font->face).position_lookup (&c, lookup_index);
} }
hb_bool_t
hb_ot_layout_position_lookup_fast (hb_font_t *font,
hb_buffer_t *buffer,
unsigned int lookup_index,
hb_mask_t mask)
{
hb_apply_context_t c (font, font->face, buffer, mask);
return _get_gpos_fast (font->face).position_lookup (&c, lookup_index);
}
void void
hb_ot_layout_position_finish (hb_buffer_t *buffer) hb_ot_layout_position_finish (hb_buffer_t *buffer)
{ {

View File

@ -1,6 +1,6 @@
/* /*
* Copyright © 2009,2010 Red Hat, Inc. * Copyright © 2009,2010 Red Hat, Inc.
* Copyright © 2010,2011 Google, Inc. * Copyright © 2010,2011,2012 Google, Inc.
* *
* This is part of HarfBuzz, a text shaping library. * This is part of HarfBuzz, a text shaping library.
* *
@ -31,8 +31,7 @@
#include "hb-buffer-private.hh" #include "hb-buffer-private.hh"
#include "hb-ot-layout.h" #include "hb-ot-layout-private.hh"
static const hb_tag_t table_tags[2] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS}; static const hb_tag_t table_tags[2] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS};
@ -69,14 +68,9 @@ struct hb_ot_map_t
inline hb_tag_t get_chosen_script (unsigned int table_index) const inline hb_tag_t get_chosen_script (unsigned int table_index) const
{ return chosen_script[table_index]; } { return chosen_script[table_index]; }
inline void substitute (hb_face_t *face, hb_buffer_t *buffer) const HB_INTERNAL void substitute_closure (hb_face_t *face, hb_set_t *glyphs) const;
{ apply (0, (hb_ot_map_t::apply_lookup_func_t) hb_ot_layout_substitute_lookup, face, buffer); } HB_INTERNAL void substitute (hb_face_t *face, hb_buffer_t *buffer) const;
inline void position (hb_font_t *font, hb_buffer_t *buffer) const HB_INTERNAL void position (hb_font_t *font, hb_buffer_t *buffer) const;
{ apply (1, (hb_ot_map_t::apply_lookup_func_t) hb_ot_layout_position_lookup, font, buffer); }
HB_INTERNAL void substitute_closure (hb_face_t *face,
hb_set_t *glyphs) const;
inline void finish (void) { inline void finish (void) {
features.finish (); features.finish ();
@ -119,21 +113,11 @@ struct hb_ot_map_t
pause_callback_t callback; pause_callback_t callback;
}; };
typedef hb_bool_t (*apply_lookup_func_t) (void *face_or_font,
hb_buffer_t *buffer,
unsigned int lookup_index,
hb_mask_t mask);
HB_INTERNAL void add_lookups (hb_face_t *face, HB_INTERNAL void add_lookups (hb_face_t *face,
unsigned int table_index, unsigned int table_index,
unsigned int feature_index, unsigned int feature_index,
hb_mask_t mask); hb_mask_t mask);
HB_INTERNAL void apply (unsigned int table_index,
hb_ot_map_t::apply_lookup_func_t apply_lookup_func,
void *face_or_font,
hb_buffer_t *buffer) const;
hb_mask_t global_mask; hb_mask_t global_mask;
hb_tag_t chosen_script[2]; hb_tag_t chosen_script[2];

View File

@ -31,7 +31,6 @@
#include "hb-ot-shape-private.hh" #include "hb-ot-shape-private.hh"
void void
hb_ot_map_t::add_lookups (hb_face_t *face, hb_ot_map_t::add_lookups (hb_face_t *face,
unsigned int table_index, unsigned int table_index,
@ -76,26 +75,42 @@ void hb_ot_map_builder_t::add_feature (hb_tag_t tag, unsigned int value, bool gl
info->stage[1] = current_stage[1]; info->stage[1] = current_stage[1];
} }
void hb_ot_map_t::apply (unsigned int table_index, /* Keep the next two functions in sync. */
hb_ot_map_t::apply_lookup_func_t apply_lookup_func,
void *face_or_font, void hb_ot_map_t::substitute (hb_face_t *face, hb_buffer_t *buffer) const
hb_buffer_t *buffer) const
{ {
const unsigned int table_index = 0;
unsigned int i = 0; unsigned int i = 0;
for (unsigned int pause_index = 0; pause_index < pauses[table_index].len; pause_index++) { for (unsigned int pause_index = 0; pause_index < pauses[table_index].len; pause_index++) {
const pause_map_t *pause = &pauses[table_index][pause_index]; const pause_map_t *pause = &pauses[table_index][pause_index];
for (; i < pause->num_lookups; i++) for (; i < pause->num_lookups; i++)
apply_lookup_func (face_or_font, buffer, lookups[table_index][i].index, lookups[table_index][i].mask); hb_ot_layout_substitute_lookup_fast (face, buffer, lookups[table_index][i].index, lookups[table_index][i].mask);
if (table_index == 0) buffer->clear_output ();
buffer->clear_output ();
pause->callback.func (this, face_or_font, buffer, pause->callback.user_data); pause->callback.func (this, face, buffer, pause->callback.user_data);
} }
for (; i < lookups[table_index].len; i++) for (; i < lookups[table_index].len; i++)
apply_lookup_func (face_or_font, buffer, lookups[table_index][i].index, lookups[table_index][i].mask); hb_ot_layout_substitute_lookup_fast (face, buffer, lookups[table_index][i].index, lookups[table_index][i].mask);
}
void hb_ot_map_t::position (hb_font_t *font, hb_buffer_t *buffer) const
{
const unsigned int table_index = 1;
unsigned int i = 0;
for (unsigned int pause_index = 0; pause_index < pauses[table_index].len; pause_index++) {
const pause_map_t *pause = &pauses[table_index][pause_index];
for (; i < pause->num_lookups; i++)
hb_ot_layout_position_lookup_fast (font, buffer, lookups[table_index][i].index, lookups[table_index][i].mask);
pause->callback.func (this, font, buffer, pause->callback.user_data);
}
for (; i < lookups[table_index].len; i++)
hb_ot_layout_position_lookup_fast (font, buffer, lookups[table_index][i].index, lookups[table_index][i].mask);
} }
void hb_ot_map_t::substitute_closure (hb_face_t *face, void hb_ot_map_t::substitute_closure (hb_face_t *face,

View File

@ -105,7 +105,7 @@ would_substitute (hb_codepoint_t *glyphs, unsigned int glyphs_count,
lookup_indices); lookup_indices);
for (unsigned int i = 0; i < len; i++) for (unsigned int i = 0; i < len; i++)
if (hb_ot_layout_would_substitute_lookup (face, glyphs, glyphs_count, lookup_indices[i])) if (hb_ot_layout_would_substitute_lookup_fast (face, glyphs, glyphs_count, lookup_indices[i]))
return true; return true;
offset += len; offset += len;

View File

@ -38,11 +38,6 @@
#define unicode_props0() var1.u8[0] #define unicode_props0() var1.u8[0]
#define unicode_props1() var1.u8[1] #define unicode_props1() var1.u8[1]
/* buffer var allocations, used during the GSUB/GPOS processing */
#define props_cache() var1.u16[1] /* GSUB/GPOS glyph_props cache */
#define syllable() var2.u8[0] /* GSUB/GPOS shaping boundaries */
#define lig_props() var2.u8[1] /* GSUB/GPOS ligature tracking */
/* buffer var allocations, used by complex shapers */ /* buffer var allocations, used by complex shapers */
#define complex_var_persistent_u8_0() var2.u8[2] #define complex_var_persistent_u8_0() var2.u8[2]
#define complex_var_persistent_u8_1() var2.u8[3] #define complex_var_persistent_u8_1() var2.u8[3]