src/hb-coretext.cc | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
New commits: commit 81b8d9777b9c38c7e6408591763a4cac6de18e4b Author: Behdad Esfahbod <[email protected]> Date: Tue Aug 12 15:49:47 2014 -0400 [coretext] Fix buffer resizing Was very broken. Now fixed and tested. diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index 0301c4a..fe5f31b 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -659,15 +659,24 @@ resize_and_retry: CFRelease (line); string_ref = NULL; line = NULL; + + /* Get previous start-of-scratch-area, that we use later for readjusting + * our existing scratch arrays. */ + unsigned int old_scratch_used; + hb_buffer_t::scratch_buffer_t *old_scratch; + old_scratch = buffer->get_scratch_buffer (&old_scratch_used); + old_scratch_used = scratch - old_scratch; + if (unlikely (!buffer->ensure (buffer->allocated * 2))) FAIL ("Buffer resize failed"); - /* Adjust scratch, pchars, and log_cluster arrays. This is ugly, but really the cleanest way to do without - * completely restructuring the rest of this shaper. */ - hb_buffer_t::scratch_buffer_t *old_scratch = scratch; + /* Adjust scratch, pchars, and log_cluster arrays. This is ugly, but really the + * cleanest way to do without completely restructuring the rest of this shaper. */ scratch = buffer->get_scratch_buffer (&scratch_size); pchars = reinterpret_cast<UniChar *> (((char *) scratch + ((char *) pchars - (char *) old_scratch))); log_clusters = reinterpret_cast<unsigned int *> (((char *) scratch + ((char *) log_clusters - (char *) old_scratch))); + scratch += old_scratch_used; + scratch_size -= old_scratch_used; } retry: { @@ -864,7 +873,7 @@ retry: if (num_glyphs == 0) continue; - if (!buffer->ensure (buffer->len + num_glyphs)) + if (!buffer->ensure_inplace (buffer->len + num_glyphs)) goto resize_and_retry; hb_glyph_info_t *run_info = buffer->info + buffer->len; commit c3e924fb9e0e2d4003790817655efd9c5688c7e1 Author: Behdad Esfahbod <[email protected]> Date: Tue Aug 12 14:25:11 2014 -0400 [coretext] Rewind scratch-allocated arrays when not needed anymore diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index 7353411..0301c4a 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -874,8 +874,19 @@ retry: * have it that this changed in OS X 10.10 Yosemite, and NULL is returned * frequently. At any rate, we can test that codepath by setting USE_PTR * to false. */ + #define USE_PTR true + +#define SCRATCH_SAVE() \ + unsigned int scratch_size_saved = scratch_size; \ + hb_buffer_t::scratch_buffer_t *scratch_saved = scratch + +#define SCRATCH_RESTORE() \ + scratch_size = scratch_size_saved; \ + scratch = scratch_saved; + { + SCRATCH_SAVE(); const CGGlyph* glyphs = USE_PTR ? CTRunGetGlyphsPtr (run) : NULL; if (!glyphs) { ALLOCATE_ARRAY (CGGlyph, glyph_buf, num_glyphs, goto resize_and_retry); @@ -895,8 +906,10 @@ retry: info->cluster = log_clusters[string_indices[j]]; info++; } + SCRATCH_RESTORE(); } { + SCRATCH_SAVE(); const CGPoint* positions = USE_PTR ? CTRunGetPositionsPtr (run) : NULL; if (!positions) { ALLOCATE_ARRAY (CGPoint, position_buf, num_glyphs, goto resize_and_retry); @@ -929,7 +942,10 @@ retry: info++; } } + SCRATCH_RESTORE(); } +#undef SCRATCH_RESTORE +#undef SCRATCH_SAVE #undef USE_PTR #undef ALLOCATE_ARRAY _______________________________________________ HarfBuzz mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/harfbuzz
