[HarfBuzz] harfbuzz-ng: Branch 'master' - 2 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Thu Jul 28 13:52:18 PDT 2011


 src/hb-buffer-private.hh           |   26 ++++++----------
 src/hb-buffer.cc                   |   42 ++++++++++++++++++++++++-
 src/hb-ot-layout-gpos-private.hh   |   21 +++++++++---
 src/hb-ot-layout-gsub-private.hh   |   21 ++++++++++++
 src/hb-ot-layout.cc                |    8 +---
 src/hb-ot-shape-complex-arabic.cc  |    6 +++
 src/hb-ot-shape-complex-indic.cc   |    4 +-
 src/hb-ot-shape-complex-private.hh |   10 +++++-
 src/hb-ot-shape.cc                 |   60 ++++++++++++++++++++++---------------
 src/hb-private.hh                  |    1 
 10 files changed, 142 insertions(+), 57 deletions(-)

New commits:
commit b65c06025d2b54a44f716e030d4b10072c65bea8
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu Jul 28 16:48:43 2011 -0400

    Formalize buffer var allocations

diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh
index df8e7ee..8f2095a 100644
--- a/src/hb-buffer-private.hh
+++ b/src/hb-buffer-private.hh
@@ -84,26 +84,10 @@ struct _hb_buffer_t {
   { return have_output? out_len : idx; }
   inline unsigned int next_serial (void) { return serial++; }
 
-
   HB_INTERNAL void allocate_var (unsigned int byte_i, unsigned int count, const char *owner);
   HB_INTERNAL void deallocate_var (unsigned int byte_i, unsigned int count, const char *owner);
   HB_INTERNAL void deallocate_var_all (void);
 
-  inline void allocate_var_8 (unsigned int var_num, unsigned int i, const char *owner)
-  { assert (var_num < 2 && i < 4); allocate_var (var_num * 4 + i, 1, owner); }
-  inline void allocate_var_16 (unsigned int var_num, unsigned int i, const char *owner)
-  { assert (var_num < 2 && i < 2); allocate_var (var_num * 4 + i * 2, 2, owner); }
-  inline void allocate_var_32 (unsigned int var_num, const char *owner)
-  { assert (var_num < 2); allocate_var (var_num * 4, 4, owner); }
-
-  inline void deallocate_var_8 (unsigned int var_num, unsigned int i, const char *owner)
-  { assert (var_num < 2 && i < 4); deallocate_var (var_num * 4 + i, 1, owner); }
-  inline void deallocate_var_16 (unsigned int var_num, unsigned int i, const char *owner)
-  { assert (var_num < 2 && i < 2); deallocate_var (var_num * 4 + i * 2, 2, owner); }
-  inline void deallocate_var_32 (unsigned int var_num, const char *owner)
-  { assert (var_num < 2); deallocate_var (var_num * 4, 4, owner); }
-
-
   HB_INTERNAL void add (hb_codepoint_t  codepoint,
 			hb_mask_t       mask,
 			unsigned int    cluster);
@@ -154,6 +138,15 @@ struct _hb_buffer_t {
 };
 
 
+#define HB_BUFFER_XALLOCATE_VAR(b, func, var, owner) \
+  b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \
+	   sizeof (b->info[0].var), owner)
+#define HB_BUFFER_ALLOCATE_VAR(b, var) \
+	HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var)
+#define HB_BUFFER_DEALLOCATE_VAR(b, var) \
+	HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var)
+
+
 HB_END_DECLS
 
 #endif /* HB_BUFFER_PRIVATE_HH */
diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc
index a587089..ea05307 100644
--- a/src/hb-buffer.cc
+++ b/src/hb-buffer.cc
@@ -398,7 +398,7 @@ dump_var_allocation (const hb_buffer_t *buffer)
 {
   char buf[80];
   for (unsigned int i = 0; i < 8; i++)
-    buf[i] = '0' + buffer->allocated_var_bytes[i];
+    buf[i] = '0' + buffer->allocated_var_bytes[7 - i];
   buf[8] = '\0';
   DEBUG_MSG (BUFFER, buffer,
 	     "Current var allocation: %s",
@@ -407,7 +407,7 @@ dump_var_allocation (const hb_buffer_t *buffer)
 
 void hb_buffer_t::allocate_var (unsigned int byte_i, unsigned int count, const char *owner)
 {
-  assert (byte_i < 8 && byte_i + count < 8);
+  assert (byte_i < 8 && byte_i + count <= 8);
 
   if (DEBUG (BUFFER))
     dump_var_allocation (this);
@@ -424,18 +424,19 @@ void hb_buffer_t::allocate_var (unsigned int byte_i, unsigned int count, const c
 
 void hb_buffer_t::deallocate_var (unsigned int byte_i, unsigned int count, const char *owner)
 {
+  if (DEBUG (BUFFER))
+    dump_var_allocation (this);
+
   DEBUG_MSG (BUFFER, this,
 	     "Deallocating var bytes %d..%d for %s",
 	     byte_i, byte_i + count - 1, owner);
 
-  assert (byte_i < 8 && byte_i + count < 8);
+  assert (byte_i < 8 && byte_i + count <= 8);
   for (unsigned int i = byte_i; i < byte_i + count; i++) {
-    assert (allocated_var_bytes[i] && allocated_var_owner[i] == owner);
+    assert (allocated_var_bytes[i]);
+    assert (0 == strcmp (allocated_var_owner[i], owner));
     allocated_var_bytes[i]--;
   }
-
-  if (DEBUG (BUFFER))
-    dump_var_allocation (this);
 }
 
 void hb_buffer_t::deallocate_var_all (void)
diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh
index 6e1757a..e5edb3c 100644
--- a/src/hb-ot-layout-gpos-private.hh
+++ b/src/hb-ot-layout-gpos-private.hh
@@ -34,7 +34,7 @@
 HB_BEGIN_DECLS
 
 
-/* buffer var allocations */
+/* buffer **position** var allocations */
 #define attach_lookback() var.u16[0] /* number of glyphs to go back to attach this glyph to its base */
 #define cursive_chain() var.i16[1] /* character to which this connects, may be positive or negative */
 
@@ -1569,6 +1569,10 @@ void
 GPOS::position_start (hb_buffer_t *buffer)
 {
   buffer->clear_positions ();
+
+  unsigned int count = buffer->len;
+  for (unsigned int i = 0; i < count; i++)
+    buffer->pos[i].attach_lookback() = buffer->pos[i].cursive_chain() = 0;
 }
 
 void
@@ -1580,15 +1584,15 @@ GPOS::position_finish (hb_buffer_t *buffer)
 
   /* Handle cursive connections */
   for (unsigned int i = 0; i < len; i++)
-  {
     fix_cursive_minor_offset (pos, i, direction);
-  }
 
   /* Handle attachments */
   for (unsigned int i = 0; i < len; i++)
-  {
     fix_mark_attachment (pos, i, direction);
-  }
+
+  HB_BUFFER_DEALLOCATE_VAR (buffer, lig_comp);
+  HB_BUFFER_DEALLOCATE_VAR (buffer, lig_id);
+  HB_BUFFER_DEALLOCATE_VAR (buffer, props_cache);
 }
 
 
diff --git a/src/hb-ot-layout-gsub-private.hh b/src/hb-ot-layout-gsub-private.hh
index e918d0d..88351f7 100644
--- a/src/hb-ot-layout-gsub-private.hh
+++ b/src/hb-ot-layout-gsub-private.hh
@@ -887,8 +887,11 @@ struct GSUB : GSUBGPOS
 void
 GSUB::substitute_start (hb_buffer_t *buffer)
 {
+  HB_BUFFER_ALLOCATE_VAR (buffer, props_cache);
+  HB_BUFFER_ALLOCATE_VAR (buffer, lig_id);
+  HB_BUFFER_ALLOCATE_VAR (buffer, lig_comp);
+
   unsigned int count = buffer->len;
-  /* XXX */
   for (unsigned int i = 0; i < count; i++)
     buffer->info[i].var1.u32 = buffer->info[i].var2.u32 = 0;
 }
diff --git a/src/hb-ot-shape-complex-arabic.cc b/src/hb-ot-shape-complex-arabic.cc
index dc63db2..942edc7 100644
--- a/src/hb-ot-shape-complex-arabic.cc
+++ b/src/hb-ot-shape-complex-arabic.cc
@@ -30,7 +30,7 @@ HB_BEGIN_DECLS
 
 
 /* buffer var allocations */
-#define arabic_shaping_action() var2.u32 /* arabic shaping action */
+#define arabic_shaping_action() complex_var_temporary_u16() /* arabic shaping action */
 
 
 /*
@@ -195,6 +195,8 @@ _hb_ot_shape_complex_setup_masks_arabic (hb_ot_map_t *map, hb_buffer_t *buffer)
   unsigned int count = buffer->len;
   unsigned int prev = 0, state = 0;
 
+  HB_BUFFER_ALLOCATE_VAR (buffer, arabic_shaping_action);
+
   for (unsigned int i = 0; i < count; i++)
   {
     unsigned int this_type = get_joining_type (buffer->info[i].codepoint, (hb_unicode_general_category_t) buffer->info[i].general_category());
@@ -222,6 +224,8 @@ _hb_ot_shape_complex_setup_masks_arabic (hb_ot_map_t *map, hb_buffer_t *buffer)
 
   for (unsigned int i = 0; i < count; i++)
     buffer->info[i].mask |= mask_array[buffer->info[i].arabic_shaping_action()];
+
+  HB_BUFFER_DEALLOCATE_VAR (buffer, arabic_shaping_action);
 }
 
 
diff --git a/src/hb-ot-shape-complex-indic.cc b/src/hb-ot-shape-complex-indic.cc
index cf5a049..494368c 100644
--- a/src/hb-ot-shape-complex-indic.cc
+++ b/src/hb-ot-shape-complex-indic.cc
@@ -30,8 +30,8 @@ HB_BEGIN_DECLS
 
 
 /* buffer var allocations */
-#define indic_category() var2.u8[0] /* indic_category_t */
-#define indic_position() var2.u8[1] /* indic_matra_category_t */
+#define indic_category() complex_var_persistent_u8_0() /* indic_category_t */
+#define indic_position() complex_var_persistent_u8_1() /* indic_matra_category_t */
 
 #define INDIC_TABLE_ELEMENT_TYPE uint8_t
 
diff --git a/src/hb-ot-shape-complex-private.hh b/src/hb-ot-shape-complex-private.hh
index 4bfd855..1aca595 100644
--- a/src/hb-ot-shape-complex-private.hh
+++ b/src/hb-ot-shape-complex-private.hh
@@ -34,10 +34,18 @@
 HB_BEGIN_DECLS
 
 
-/* buffer var allocations, used by all shapers */
+/* buffer var allocations, used during the entire shaping process */
 #define general_category() var1.u8[0] /* unicode general_category (hb_unicode_general_category_t) */
 #define combining_class() var1.u8[1] /* unicode combining_class (uint8_t) */
 
+/* buffer var allocations, used by complex shapers */
+#define complex_var_persistent_u8_0()	var2.u8[0]
+#define complex_var_persistent_u8_1()	var2.u8[1]
+#define complex_var_persistent_u16()	var2.u16[0]
+#define complex_var_temporary_u8_0()	var2.u8[2]
+#define complex_var_temporary_u8_1()	var2.u8[3]
+#define complex_var_temporary_u16()	var2.u16[1]
+
 
 #define HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS \
   HB_COMPLEX_SHAPER_IMPLEMENT (default) /* should be first */ \
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index 9b362bd..1577214 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -115,7 +115,7 @@ hb_ot_shape_setup_masks (hb_ot_shape_context_t *c)
   hb_mask_t global_mask = c->plan->map.get_global_mask ();
   c->buffer->reset_masks (global_mask);
 
-  hb_ot_shape_complex_setup_masks (c->plan->shaper, &c->plan->map, c->buffer); /* BUFFER: Clobbers var2 */
+  hb_ot_shape_complex_setup_masks (c->plan->shaper, &c->plan->map, c->buffer);
 
   for (unsigned int i = 0; i < c->num_user_features; i++)
   {
@@ -225,16 +225,20 @@ hb_map_glyphs (hb_font_t    *font,
 static void
 hb_substitute_default (hb_ot_shape_context_t *c)
 {
+  hb_ot_layout_substitute_start (c->buffer);
+
+  hb_mirror_chars (c);
+
   hb_map_glyphs (c->font, c->buffer);
 }
 
 static void
 hb_ot_substitute_complex (hb_ot_shape_context_t *c)
 {
-  if (!hb_ot_layout_has_substitution (c->face))
-    return;
+  if (hb_ot_layout_has_substitution (c->face))
+    c->plan->map.substitute (c->face, c->buffer);
 
-  c->plan->map.substitute (c->face, c->buffer);
+  hb_ot_layout_substitute_finish (c->buffer);
 
   c->applied_substitute_complex = TRUE;
   return;
@@ -271,24 +275,26 @@ static void
 hb_ot_position_complex (hb_ot_shape_context_t *c)
 {
 
-  if (!hb_ot_layout_has_positioning (c->face))
-    return;
-
-  unsigned int count = c->buffer->len;
-  for (unsigned int i = 0; i < count; i++) {
-    hb_font_add_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
-					    HB_DIRECTION_LTR,
-					    &c->buffer->pos[i].x_offset,
-					    &c->buffer->pos[i].y_offset);
-  }
+  if (hb_ot_layout_has_positioning (c->face))
+  {
+    /* Change glyph origin to what GPOS expects, apply GPOS, change it back. */
+
+    unsigned int count = c->buffer->len;
+    for (unsigned int i = 0; i < count; i++) {
+      hb_font_add_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
+					      HB_DIRECTION_LTR,
+					      &c->buffer->pos[i].x_offset,
+					      &c->buffer->pos[i].y_offset);
+    }
 
-  c->plan->map.position (c->font, c->buffer);
+    c->plan->map.position (c->font, c->buffer);
 
-  for (unsigned int i = 0; i < count; i++) {
-    hb_font_subtract_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
-						 HB_DIRECTION_LTR,
-						 &c->buffer->pos[i].x_offset,
-						 &c->buffer->pos[i].y_offset);
+    for (unsigned int i = 0; i < count; i++) {
+      hb_font_subtract_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
+						   HB_DIRECTION_LTR,
+						   &c->buffer->pos[i].x_offset,
+						   &c->buffer->pos[i].y_offset);
+    }
   }
 
   hb_ot_layout_position_finish (c->buffer);
@@ -341,10 +347,15 @@ hb_position_complex_fallback_visual (hb_ot_shape_context_t *c)
 static void
 hb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
 {
+  c->buffer->deallocate_var_all ();
+
   /* Save the original direction, we use it later. */
   c->target_direction = c->buffer->props.direction;
 
-  _hb_set_unicode_props (c->buffer); /* BUFFER: Set general_category and combining_class in var1 */
+  HB_BUFFER_ALLOCATE_VAR (c->buffer, general_category);
+  HB_BUFFER_ALLOCATE_VAR (c->buffer, combining_class);
+
+  _hb_set_unicode_props (c->buffer); /* BUFFER: Set general_category and combining_class */
 
   hb_form_clusters (c->buffer);
 
@@ -352,12 +363,10 @@ hb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
 
   _hb_ot_shape_normalize (c);
 
-  hb_ot_shape_setup_masks (c); /* BUFFER: Clobbers var2 */
+  hb_ot_shape_setup_masks (c);
 
   /* SUBSTITUTE */
   {
-    hb_mirror_chars (c);
-
     hb_substitute_default (c);
 
     hb_ot_substitute_complex (c);
@@ -383,6 +392,9 @@ hb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
       hb_position_complex_fallback_visual (c);
   }
 
+  HB_BUFFER_DEALLOCATE_VAR (c->buffer, combining_class);
+  HB_BUFFER_DEALLOCATE_VAR (c->buffer, general_category);
+
   c->buffer->props.direction = c->target_direction;
 }
 
diff --git a/src/hb-private.hh b/src/hb-private.hh
index 9482795..6c19d37 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -36,6 +36,7 @@
 #include "hb-common.h"
 
 #include <stdlib.h>
+#include <stddef.h>
 #include <string.h>
 #include <assert.h>
 
commit a9ad3d3460ba863a8d8f3766ccbeab288c3c6822
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu Jul 28 15:42:18 2011 -0400

    Move more code around
    
    Buffer var allocation coming into shape

diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh
index d83d130..df8e7ee 100644
--- a/src/hb-buffer-private.hh
+++ b/src/hb-buffer-private.hh
@@ -87,6 +87,7 @@ struct _hb_buffer_t {
 
   HB_INTERNAL void allocate_var (unsigned int byte_i, unsigned int count, const char *owner);
   HB_INTERNAL void deallocate_var (unsigned int byte_i, unsigned int count, const char *owner);
+  HB_INTERNAL void deallocate_var_all (void);
 
   inline void allocate_var_8 (unsigned int var_num, unsigned int i, const char *owner)
   { assert (var_num < 2 && i < 4); allocate_var (var_num * 4 + i, 1, owner); }
diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc
index 159600e..a587089 100644
--- a/src/hb-buffer.cc
+++ b/src/hb-buffer.cc
@@ -34,6 +34,11 @@
 HB_BEGIN_DECLS
 
 
+#ifndef HB_DEBUG_BUFFER
+#define HB_DEBUG_BUFFER (HB_DEBUG+0)
+#endif
+
+
 static hb_buffer_t _hb_buffer_nil = {
   HB_OBJECT_HEADER_STATIC,
 
@@ -388,10 +393,28 @@ hb_buffer_t::reverse_clusters (void)
   reverse_range (start, i);
 }
 
+static inline void
+dump_var_allocation (const hb_buffer_t *buffer)
+{
+  char buf[80];
+  for (unsigned int i = 0; i < 8; i++)
+    buf[i] = '0' + buffer->allocated_var_bytes[i];
+  buf[8] = '\0';
+  DEBUG_MSG (BUFFER, buffer,
+	     "Current var allocation: %s",
+	     buf);
+}
 
 void hb_buffer_t::allocate_var (unsigned int byte_i, unsigned int count, const char *owner)
 {
   assert (byte_i < 8 && byte_i + count < 8);
+
+  if (DEBUG (BUFFER))
+    dump_var_allocation (this);
+  DEBUG_MSG (BUFFER, this,
+	     "Allocating var bytes %d..%d for %s",
+	     byte_i, byte_i + count - 1, owner);
+
   for (unsigned int i = byte_i; i < byte_i + count; i++) {
     assert (!allocated_var_bytes[i]);
     allocated_var_bytes[i]++;
@@ -401,13 +424,25 @@ void hb_buffer_t::allocate_var (unsigned int byte_i, unsigned int count, const c
 
 void hb_buffer_t::deallocate_var (unsigned int byte_i, unsigned int count, const char *owner)
 {
+  DEBUG_MSG (BUFFER, this,
+	     "Deallocating var bytes %d..%d for %s",
+	     byte_i, byte_i + count - 1, owner);
+
   assert (byte_i < 8 && byte_i + count < 8);
   for (unsigned int i = byte_i; i < byte_i + count; i++) {
     assert (allocated_var_bytes[i] && allocated_var_owner[i] == owner);
     allocated_var_bytes[i]--;
   }
+
+  if (DEBUG (BUFFER))
+    dump_var_allocation (this);
 }
 
+void hb_buffer_t::deallocate_var_all (void)
+{
+  memset (allocated_var_bytes, 0, sizeof (allocated_var_bytes));
+  memset (allocated_var_owner, 0, sizeof (allocated_var_owner));
+}
 
 /* Public API */
 
diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh
index b726f77..6e1757a 100644
--- a/src/hb-ot-layout-gpos-private.hh
+++ b/src/hb-ot-layout-gpos-private.hh
@@ -1507,6 +1507,7 @@ struct GPOS : GSUBGPOS
 			       hb_mask_t     mask) const
   { return get_lookup (lookup_index).apply_string (font, buffer, mask); }
 
+  static inline void position_start (hb_buffer_t *buffer);
   static inline void position_finish (hb_buffer_t *buffer);
 
   inline bool sanitize (hb_sanitize_context_t *c) {
@@ -1565,6 +1566,12 @@ fix_mark_attachment (hb_glyph_position_t *pos, unsigned int i, hb_direction_t di
 }
 
 void
+GPOS::position_start (hb_buffer_t *buffer)
+{
+  buffer->clear_positions ();
+}
+
+void
 GPOS::position_finish (hb_buffer_t *buffer)
 {
   unsigned int len;
diff --git a/src/hb-ot-layout-gsub-private.hh b/src/hb-ot-layout-gsub-private.hh
index b9161bf..e918d0d 100644
--- a/src/hb-ot-layout-gsub-private.hh
+++ b/src/hb-ot-layout-gsub-private.hh
@@ -870,6 +870,9 @@ struct GSUB : GSUBGPOS
 				 hb_mask_t     mask) const
   { return get_lookup (lookup_index).apply_string (face, buffer, mask); }
 
+  static inline void substitute_start (hb_buffer_t *buffer);
+  static inline void substitute_finish (hb_buffer_t *buffer);
+
   inline bool sanitize (hb_sanitize_context_t *c) {
     TRACE_SANITIZE ();
     if (unlikely (!GSUBGPOS::sanitize (c))) return false;
@@ -881,6 +884,21 @@ struct GSUB : GSUBGPOS
 };
 
 
+void
+GSUB::substitute_start (hb_buffer_t *buffer)
+{
+  unsigned int count = buffer->len;
+  /* XXX */
+  for (unsigned int i = 0; i < count; i++)
+    buffer->info[i].var1.u32 = buffer->info[i].var2.u32 = 0;
+}
+
+void
+GSUB::substitute_finish (hb_buffer_t *buffer)
+{
+}
+
+
 /* Out-of-class implementation for methods recursing */
 
 inline bool ExtensionSubst::apply (hb_apply_context_t *c) const
diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc
index 1da4792..5e2d6ac 100644
--- a/src/hb-ot-layout.cc
+++ b/src/hb-ot-layout.cc
@@ -443,10 +443,7 @@ hb_ot_layout_has_substitution (hb_face_t *face)
 void
 hb_ot_layout_substitute_start (hb_buffer_t  *buffer)
 {
-  unsigned int count = buffer->len;
-  /* XXX */
-  for (unsigned int i = 0; i < count; i++)
-    buffer->info[i].var1.u32 = buffer->info[i].var2.u32 = 0;
+  GSUB::substitute_start (buffer);
 }
 
 hb_bool_t
@@ -461,6 +458,7 @@ hb_ot_layout_substitute_lookup (hb_face_t    *face,
 void
 hb_ot_layout_substitute_finish (hb_buffer_t  *buffer HB_UNUSED)
 {
+  GSUB::substitute_finish (buffer);
 }
 
 
@@ -477,7 +475,7 @@ hb_ot_layout_has_positioning (hb_face_t *face)
 void
 hb_ot_layout_position_start (hb_buffer_t  *buffer)
 {
-  buffer->clear_positions ();
+  GPOS::position_start (buffer);
 }
 
 hb_bool_t



More information about the HarfBuzz mailing list