182aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/***************************************************************************/
282aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*                                                                         */
382aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*  rastpic.c                                                              */
482aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*                                                                         */
582aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*    The FreeType position independent code services for raster module.   */
682aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*                                                                         */
782aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*  Copyright 2009, 2010, 2012, 2013 by                                    */
882aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*  Oran Agra and Mickey Gabel.                                            */
982aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*                                                                         */
1082aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*  This file is part of the FreeType project, and may only be used,       */
1182aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*  modified, and distributed under the terms of the FreeType project      */
1282aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
1382aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*  this file you indicate that you have read the license and              */
1482aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*  understand and accept it fully.                                        */
1582aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/*                                                                         */
1682aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com/***************************************************************************/
179fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed
1882aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com
1982aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com#include "../../include/ft2build.h"
2082aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com#include "../../include/freetype/freetype.h"
2182aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com#include "../../include/freetype/internal/ftobjs.h"
229ea3d57fde28a5fe4487a111dc3dd49418235e5esenorblanco#include "rastpic.h"
239fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#include "rasterrs.h"
248b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org
259fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed
268b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org#ifdef FT_CONFIG_OPTION_PIC
2782aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com
284cb543d6057b692e1099e9f115155f0bf323a0c8senorblanco@chromium.org  /* forward declaration of PIC init functions from ftraster.c */
29ae761f7545d8ebf181d220169afac2056b057b8ccommit-bot@chromium.org  void
301aa68723b8ef4ce0b6db9fe51e7d8051cdd543ffsenorblanco@chromium.org  FT_Init_Class_ft_standard_raster( FT_Raster_Funcs*  funcs );
31b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt
32b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt
331aa68723b8ef4ce0b6db9fe51e7d8051cdd543ffsenorblanco@chromium.org  void
3482aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com  ft_raster1_renderer_class_pic_free( FT_Library  library )
3582aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com  {
3682aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com    FT_PIC_Container*  pic_container = &library->pic_container;
3782aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com    FT_Memory          memory        = library->memory;
3882aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com
3982aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com
4082aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com    if ( pic_container->raster )
4182aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com    {
42      RasterPIC*  container = (RasterPIC*)pic_container->raster;
43
44
45      if ( --container->ref_count )
46        return;
47      FT_FREE( container );
48      pic_container->raster = NULL;
49    }
50  }
51
52
53  FT_Error
54  ft_raster1_renderer_class_pic_init( FT_Library  library )
55  {
56    FT_PIC_Container*  pic_container = &library->pic_container;
57    FT_Error           error         = FT_Err_Ok;
58    RasterPIC*         container     = NULL;
59    FT_Memory          memory        = library->memory;
60
61
62    /* since this function also serves raster5 renderer, */
63    /* it implements reference counting                  */
64    if ( pic_container->raster )
65    {
66      ((RasterPIC*)pic_container->raster)->ref_count++;
67      return error;
68    }
69
70    /* allocate pointer, clear and set global container pointer */
71    if ( FT_ALLOC( container, sizeof ( *container ) ) )
72      return error;
73    FT_MEM_SET( container, 0, sizeof ( *container ) );
74    pic_container->raster = container;
75
76    container->ref_count = 1;
77
78    /* initialize pointer table -                       */
79    /* this is how the module usually expects this data */
80    FT_Init_Class_ft_standard_raster( &container->ft_standard_raster );
81
82    return error;
83  }
84
85
86  /* re-route these init and free functions to the above functions */
87  FT_Error
88  ft_raster5_renderer_class_pic_init( FT_Library  library )
89  {
90    return ft_raster1_renderer_class_pic_init( library );
91  }
92
93
94  void
95  ft_raster5_renderer_class_pic_free( FT_Library  library )
96  {
97    ft_raster1_renderer_class_pic_free( library );
98  }
99
100#endif /* FT_CONFIG_OPTION_PIC */
101
102
103/* END */
104