freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype][smooth_malloc] 3 commits: Switch to dynamic mem


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype][smooth_malloc] 3 commits: Switch to dynamic memory allocation.
Date: Sat, 07 Oct 2023 03:03:36 +0000

Alexei Podtelezhnikov pushed to branch smooth_malloc at FreeType / FreeType

Commits:

  • 7e7c3489
    by Alexei Podtelezhnikov (Алексей Подтележников) at 2023-10-06T20:08:31-04:00
    Switch to dynamic memory allocation.
    
    This is a proof of concept for benchmarking.
    
    * src/smooth/ftgrays.c (gray_TWorker): Store `memory`.
    (gray_convert_glyph): Allocate memory dynamically and handle errors.
    (gray_raster_render): Set memory.
    
  • b8aae190
    by Alexei Podtelezhnikov (Алексей Подтележников) at 2023-10-06T21:06:27-04:00
    [smooth] Estimate of the rendering pool size.
    
    The estimate is based on the taxi perimeter with extra space added
    for local extrema.
    
    * src/smooth/ftgrays.c (gray_taxi): New function for the perimeter.
    (gray_convert_glyph): Updated, banding suppressed.
    
  • d1016527
    by Alexei Podtelezhnikov (Алексей Подтележников) at 2023-10-06T23:02:16-04:00
    * src/smooth/ftgrays.c (gray_convert_glyph): Limit complexity.
    

1 changed file:

Changes:

  • src/smooth/ftgrays.c
    ... ... @@ -490,6 +490,7 @@ typedef ptrdiff_t FT_PtrDist;
    490 490
       typedef struct  gray_TWorker_
    
    491 491
       {
    
    492 492
         ft_jmp_buf  jump_buffer;
    
    493
    +    FT_Memory   memory;
    
    493 494
     
    
    494 495
         TCoord  min_ex, max_ex;  /* min and max integer pixel coordinates */
    
    495 496
         TCoord  min_ey, max_ey;
    
    ... ... @@ -1934,7 +1935,7 @@ typedef ptrdiff_t FT_PtrDist;
    1934 1935
           if ( continued )
    
    1935 1936
             FT_Trace_Enable();
    
    1936 1937
     
    
    1937
    -      FT_TRACE7(( "band [%d..%d]: %td cell%s remaining/\n",
    
    1938
    +      FT_TRACE7(( "band [%d..%d]: %td cell%s remaining\n",
    
    1938 1939
                       ras.min_ey,
    
    1939 1940
                       ras.max_ey,
    
    1940 1941
                       ras.cell_null - ras.cell_free,
    
    ... ... @@ -1952,15 +1953,57 @@ typedef ptrdiff_t FT_PtrDist;
    1952 1953
       }
    
    1953 1954
     
    
    1954 1955
     
    
    1956
    +  /*
    
    1957
    +   * The taxicab perimeter of the entire outline is used to estimate
    
    1958
    +   * the necessary memory pool or the job size in general.  Clipping
    
    1959
    +   * is ignored because it might hurt the performance.
    
    1960
    +   */
    
    1961
    +  static long
    
    1962
    +  gray_taxi( RAS_ARG )
    
    1963
    +  {
    
    1964
    +    FT_Outline*  outline = &ras.outline;
    
    1965
    +    short        c, p, first, last;
    
    1966
    +    FT_Vector    d, v;
    
    1967
    +    FT_Pos       taxi;
    
    1968
    +
    
    1969
    +
    
    1970
    +    taxi = 0;
    
    1971
    +    last = -1;
    
    1972
    +    for ( c = 0; c < outline->n_contours; c++ )
    
    1973
    +    {
    
    1974
    +      first = last + 1;
    
    1975
    +      last = outline->contours[c];
    
    1976
    +
    
    1977
    +      d = outline->points[last];
    
    1978
    +      for ( p = first; p <= last; p++ )
    
    1979
    +      {
    
    1980
    +        v    = outline->points[p];
    
    1981
    +        d.x -= v.x;
    
    1982
    +        d.y -= v.y;
    
    1983
    +
    
    1984
    +        taxi += FT_ABS( d.x ) + FT_ABS( d.y );
    
    1985
    +
    
    1986
    +        d = v;
    
    1987
    +      }
    
    1988
    +    }
    
    1989
    +
    
    1990
    +    return taxi >> 6;
    
    1991
    +  }
    
    1992
    +
    
    1993
    +
    
    1955 1994
       static int
    
    1956 1995
       gray_convert_glyph( RAS_ARG )
    
    1957 1996
       {
    
    1958 1997
         const TCoord  yMin = ras.min_ey;
    
    1959 1998
         const TCoord  yMax = ras.max_ey;
    
    1960 1999
     
    
    1961
    -    TCell    buffer[FT_MAX_GRAY_POOL];
    
    2000
    +    FT_Error   error = FT_THROW( Ok );
    
    2001
    +    FT_Memory  memory = ras.memory;
    
    2002
    +
    
    2003
    +    TCell*   buffer;
    
    1962 2004
         size_t   height = (size_t)( yMax - yMin );
    
    1963
    -    size_t   n = FT_MAX_GRAY_POOL / 8;
    
    2005
    +    size_t   n;
    
    2006
    +    long     size;
    
    1964 2007
         TCoord   y;
    
    1965 2008
         TCoord   bands[32];  /* enough to accommodate bisections */
    
    1966 2009
         TCoord*  band;
    
    ... ... @@ -1968,8 +2011,25 @@ typedef ptrdiff_t FT_PtrDist;
    1968 2011
         int  continued = 0;
    
    1969 2012
     
    
    1970 2013
     
    
    2014
    +    size = gray_taxi( RAS_VAR );
    
    2015
    +
    
    2016
    +    /* taxicab perimeters in excess of 20 CBox perimeters are    */
    
    2017
    +    /* not rendered unless in direct mode with possible clipping */
    
    2018
    +    if ( !ras.render_span                                     &&
    
    2019
    +         size > 20 * 2 * ( ras.max_ex - ras.min_ex + height ) )
    
    2020
    +      return FT_THROW( Invalid_Outline );
    
    2021
    +
    
    2022
    +    size += height * sizeof ( PCell ) / sizeof ( TCell ) +
    
    2023
    +            9;  /* empirical extra for local extrema */
    
    2024
    +
    
    2025
    +    if ( FT_QNEW_ARRAY( buffer, size ) )
    
    2026
    +      return error;
    
    2027
    +
    
    2028
    +    FT_TRACE7(( "Allocated %ld cells (%ld bytes)\n",
    
    2029
    +                size, size * sizeof ( TCell ) ));
    
    2030
    +
    
    1971 2031
         /* Initialize the null cell at the end of the poll. */
    
    1972
    -    ras.cell_null        = buffer + FT_MAX_GRAY_POOL - 1;
    
    2032
    +    ras.cell_null        = buffer + size - 1;
    
    1973 2033
         ras.cell_null->x     = CELL_MAX_X_VALUE;
    
    1974 2034
         ras.cell_null->area  = 0;
    
    1975 2035
         ras.cell_null->cover = 0;
    
    ... ... @@ -1978,13 +2038,6 @@ typedef ptrdiff_t FT_PtrDist;
    1978 2038
         /* set up vertical bands */
    
    1979 2039
         ras.ycells     = (PCell*)buffer;
    
    1980 2040
     
    
    1981
    -    if ( height > n )
    
    1982
    -    {
    
    1983
    -      /* two divisions rounded up */
    
    1984
    -      n       = ( height + n - 1 ) / n;
    
    1985
    -      height  = ( height + n - 1 ) / n;
    
    1986
    -    }
    
    1987
    -
    
    1988 2041
         for ( y = yMin; y < yMax; )
    
    1989 2042
         {
    
    1990 2043
           ras.min_ey = y;
    
    ... ... @@ -1999,7 +2052,6 @@ typedef ptrdiff_t FT_PtrDist;
    1999 2052
           {
    
    2000 2053
             TCoord  width = band[0] - band[1];
    
    2001 2054
             TCoord  w;
    
    2002
    -        int     error;
    
    2003 2055
     
    
    2004 2056
     
    
    2005 2057
             for ( w = 0; w < width; ++w )
    
    ... ... @@ -2028,7 +2080,7 @@ typedef ptrdiff_t FT_PtrDist;
    2028 2080
               continue;
    
    2029 2081
             }
    
    2030 2082
             else if ( error != Smooth_Err_Raster_Overflow )
    
    2031
    -          return error;
    
    2083
    +          goto Exit;
    
    2032 2084
     
    
    2033 2085
             /* render pool overflow; we will reduce the render band by half */
    
    2034 2086
             width >>= 1;
    
    ... ... @@ -2037,7 +2089,8 @@ typedef ptrdiff_t FT_PtrDist;
    2037 2089
             if ( width == 0 )
    
    2038 2090
             {
    
    2039 2091
               FT_TRACE7(( "gray_convert_glyph: rotten glyph\n" ));
    
    2040
    -          return FT_THROW( Raster_Overflow );
    
    2092
    +          error = FT_THROW( Raster_Overflow );
    
    2093
    +          goto Exit;
    
    2041 2094
             }
    
    2042 2095
     
    
    2043 2096
             band++;
    
    ... ... @@ -2046,7 +2099,9 @@ typedef ptrdiff_t FT_PtrDist;
    2046 2099
           } while ( band >= bands );
    
    2047 2100
         }
    
    2048 2101
     
    
    2049
    -    return Smooth_Err_Ok;
    
    2102
    +  Exit:
    
    2103
    +    FT_FREE( buffer );
    
    2104
    +    return error;
    
    2050 2105
       }
    
    2051 2106
     
    
    2052 2107
     
    
    ... ... @@ -2132,6 +2187,8 @@ typedef ptrdiff_t FT_PtrDist;
    2132 2187
         if ( ras.max_ex <= ras.min_ex || ras.max_ey <= ras.min_ey )
    
    2133 2188
           return Smooth_Err_Ok;
    
    2134 2189
     
    
    2190
    +    ras.memory = (FT_Memory)((gray_PRaster)raster)->memory;
    
    2191
    +
    
    2135 2192
         return gray_convert_glyph( RAS_VAR );
    
    2136 2193
       }
    
    2137 2194
     
    


  • reply via email to

    [Prev in Thread] Current Thread [Next in Thread]