/[freetype]/freetype2/src/cache/ftcsbits.c
ViewVC logotype

Diff of /freetype2/src/cache/ftcsbits.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.57 by freetype, Mon May 23 13:04:53 2005 UTC revision 1.58 by wl, Mon May 23 21:33:02 2005 UTC
# Line 4  Line 4 
4  /*                                                                         */  /*                                                                         */
5  /*    FreeType sbits manager (body).                                       */  /*    FreeType sbits manager (body).                                       */
6  /*                                                                         */  /*                                                                         */
7  /*  Copyright 2000-2001, 2002, 2003, 2004 by                               */  /*  Copyright 2000-2001, 2002, 2003, 2004, 2005 by                         */
8  /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */  /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9  /*                                                                         */  /*                                                                         */
10  /*  This file is part of the FreeType project, and may only be used,       */  /*  This file is part of the FreeType project, and may only be used,       */
# Line 85  Line 85 
85    }    }
86    
87    
88   /* this function tries to load a small bitmap within a given FTC_SNode    /*
89    * note that it will return a non-zero error code _only_ in the case     *  This function tries to load a small bitmap within a given FTC_SNode.
90    * of out-of-memory condition. For all other errors (e.g. corresponding     *  Note that it returns a non-zero error code _only_ in the case of
91    * to a bad font file), this function will mark the sbit as "unavailable"     *  out-of-memory condition.  For all other errors (e.g., corresponding
92    * and return a value of 0.     *  to a bad font file), this function will mark the sbit as `unavailable'
93    *     *  and return a value of 0.
94    * you should also read the comment within the @ftc_snode_compare function     *
95    * below to see how out-of-memory is handled during a lookup     *  You should also read the comment within the @ftc_snode_compare
96    */     *  function below to see how out-of-memory is handled during a lookup.
97       */
98    static FT_Error    static FT_Error
99    ftc_snode_load( FTC_SNode    snode,    ftc_snode_load( FTC_SNode    snode,
100                    FTC_Manager  manager,                    FTC_Manager  manager,
# Line 324  Line 325 
325        FTC_SBit  sbit = snode->sbits + ( gindex - gnode->gindex );        FTC_SBit  sbit = snode->sbits + ( gindex - gnode->gindex );
326    
327    
328       /* the following code illustrates what to do when you want to        /*
329        * perform operations that may fail within a lookup function.         *  The following code illustrates what to do when you want to
330        *         *  perform operations that may fail within a lookup function.
331        * here, we want to load a small bitmap on-demand, we thus         *
332        * need to call the 'ftc_snode_load' function which may return         *  Here, we want to load a small bitmap on-demand; we thus
333        * a non-zero error code only when we're out of memory         *  need to call the `ftc_snode_load' function which may return
334        *         *  a non-zero error code only when we are out of memory (OOM).
335        * the correct thing to do is to use @FTC_CACHE_TRYLOOP and         *
336        * @FTC_CACHE_TRYLOOP_END in order to implement a retry loop         *  The correct thing to do is to use @FTC_CACHE_TRYLOOP and
337        * that is capable of flushing the cache incrementally when         *  @FTC_CACHE_TRYLOOP_END in order to implement a retry loop
338        * OOM errors occur.         *  that is capable of flushing the cache incrementally when
339        *         *  an OOM errors occur.
340        * however, we previously need to 'lock' the node to prevent it         *
341        * from being flushed in the loop.         *  However, we need to `lock' the node before this operation to
342        *         *  prevent it from being flushed within the loop.
343        * when we exit the loop, we unlock the node then check the 'error'         *
344        * variable. If it is non-zero, this means that the cache was         *  When we exit the loop, we unlock the node, then check the `error'
345        * completely flushed and that no usable memory was found to load         *  variable.  If it is non-zero, this means that the cache was
346        * the bitmap.         *  completely flushed and that no usable memory was found to load
347        *         *  the bitmap.
348        * we then prefer to return a value of 0 (i.e. NO MATCH). This         *
349        * will ensure that the caller will try to allocate a new node.         *  We then prefer to return a value of 0 (i.e., NO MATCH).  This
350        * this operation _will_ fail and the lookup function will return         *  ensures that the caller will try to allocate a new node.
351        * the OOM error code appropriately.         *  This operation consequently _fail_ and the lookup function
352        *         *  returns the appropriate OOM error code.
353        * note that 'buffer == NULL && width == 255' is a hack used to         *
354        * tag "unavailable" bitmaps in the array. We should never try         *  Note that `buffer == NULL && width == 255' is a hack used to
355        * to load these.         *  tag `unavailable' bitmaps in the array.  We should never try
356        */         *  to load these.
357           *
358           */
359    
360        if ( sbit->buffer == NULL && sbit->width != 255 )        if ( sbit->buffer == NULL && sbit->width != 255 )
361        {        {
362          FT_ULong  size;          FT_ULong  size;
363          FT_Error  error;          FT_Error  error;
364    
         ftcsnode->ref_count++;  /* lock node, prevent flushing in retry loop */  
365    
366          FTC_CACHE_TRYLOOP(cache)          ftcsnode->ref_count++;  /* lock node to prevent flushing */
367                                    /* in retry loop                 */
368    
369            FTC_CACHE_TRYLOOP( cache )
370          {          {
371            error = ftc_snode_load( snode, cache->manager, gindex, &size );            error = ftc_snode_load( snode, cache->manager, gindex, &size );
372          }          }

Legend:
Removed from v.1.57  
changed lines
  Added in v.1.58

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26