shithub: freetype+ttf2subf

Download patch

ref: a773c3041e024975241d110989f617f032c4b7e3
parent: 8dc863587440d0a1d2eec2a7973a8eda99d2767d
author: Behdad Esfahbod <[email protected]>
date: Wed Jan 14 13:16:20 EST 2015

[raster] Allocate render pool for mono rasterizer on the stack.

Instead of using the `render_pool' member of `FT_Library' that is
provided down to the rasterizer, completely ignore that and allocate
needed objects on the stack instead.

With this patch, rasterizing glyphs from different faces from
different threads doesn't crash in the monochrome rasterizer.

* src/raster/ftraster.c (black_TRaster): Remove `buffer',
`buffer_size', and `worker' members.

(ft_black_render): Create `buffer' locally.
(ft_black_reset): Updated.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
 2015-01-14  Behdad Esfahbod  <[email protected]>
 
+	[raster] Allocate render pool for mono rasterizer on the stack.
+
+	Instead of using the `render_pool' member of `FT_Library' that is
+	provided down to the rasterizer, completely ignore that and allocate
+	needed objects on the stack instead.
+
+	With this patch, rasterizing glyphs from different faces from
+	different threads doesn't crash in the monochrome rasterizer.
+
+	* src/raster/ftraster.c (black_TRaster): Remove `buffer',
+	`buffer_size', and `worker' members.
+
+	(ft_black_render): Create `buffer' locally.
+	(ft_black_reset): Updated.
+
+2015-01-14  Behdad Esfahbod  <[email protected]>
+
 	[raster] Remove 5-level gray AA mode from monochrome rasterizer.
 
 	It was off by default and couldn't be turned on at runtime.  And the
--- a/src/raster/ftraster.c
+++ b/src/raster/ftraster.c
@@ -530,10 +530,7 @@
 
   typedef struct  black_TRaster_
   {
-    char*          buffer;
-    long           buffer_size;
     void*          memory;
-    black_PWorker  worker;
 
   } black_TRaster, *black_PRaster;
 
@@ -3058,25 +3055,9 @@
                   char*          pool_base,
                   long           pool_size )
   {
-    if ( raster )
-    {
-      if ( pool_base && pool_size >= (long)sizeof ( black_TWorker ) + 2048 )
-      {
-        black_PWorker  worker = (black_PWorker)pool_base;
-
-
-        raster->buffer      = pool_base + ( ( sizeof ( *worker ) + 7 ) & ~7 );
-        raster->buffer_size = (long)( pool_base + pool_size -
-                                        (char*)raster->buffer );
-        raster->worker      = worker;
-      }
-      else
-      {
-        raster->buffer      = NULL;
-        raster->buffer_size = 0;
-        raster->worker      = NULL;
-      }
-    }
+    FT_UNUSED( raster );
+    FT_UNUSED( pool_base );
+    FT_UNUSED( pool_size );
   }
 
 
@@ -3099,10 +3080,13 @@
   {
     const FT_Outline*  outline    = (const FT_Outline*)params->source;
     const FT_Bitmap*   target_map = params->target;
-    black_PWorker      worker;
 
+    black_TWorker  worker[1];
 
-    if ( !raster || !raster->buffer || !raster->buffer_size )
+    Long  buffer[FT_MAX( FT_RENDER_POOL_SIZE, 2048 ) / sizeof ( Long )];
+
+
+    if ( !raster )
       return FT_THROW( Not_Ini );
 
     if ( !outline )
@@ -3119,8 +3103,6 @@
            outline->contours[outline->n_contours - 1] + 1 )
       return FT_THROW( Invalid );
 
-    worker = raster->worker;
-
     /* this version of the raster does not support direct rendering, sorry */
     if ( params->flags & FT_RASTER_FLAG_DIRECT )
       return FT_THROW( Unsupported );
@@ -3138,9 +3120,8 @@
     ras.outline = *outline;
     ras.target  = *target_map;
 
-    worker->buff       = (PLong) raster->buffer;
-    worker->sizeBuff   = worker->buff +
-                           raster->buffer_size / sizeof ( Long );
+    worker->buff     = buffer;
+    worker->sizeBuff = (&buffer)[1]; /* Points to right after buffer. */
 
     return Render_Glyph( RAS_VAR );
   }