Add reference counters and to FT_Library and FT_Face objects. * include/freetype/freetype.h (FT_Reference_Face): New function. * include/freetype/ftmodapi.h (FT_Rererence_Library): New function. * include/freetype/internal/ftobjs.h (FT_Face_InternalRec, FT_LibraryRec): New field `refcount'. * src/base/ftobjs.c (FT_Open_Face, FT_New_Library): Handle `refcount'. (FT_Reference_Face, FT_Reference_Library): Implement new functions. (FT_Done_Face, FT_Done_Library): Handle `refcount'. * docs/CHANGES: Updated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
diff --git a/ChangeLog b/ChangeLog
index 72d7dd7..54c49b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
2010-07-18 Werner Lemberg <wl@gnu.org>
+ Add reference counters and to FT_Library and FT_Face objects.
+
+ * include/freetype/freetype.h (FT_Reference_Face): New function.
+ * include/freetype/ftmodapi.h (FT_Rererence_Library): New function.
+
+ * include/freetype/internal/ftobjs.h (FT_Face_InternalRec,
+ FT_LibraryRec): New field `refcount'.
+
+ * src/base/ftobjs.c (FT_Open_Face, FT_New_Library): Handle
+ `refcount'.
+ (FT_Reference_Face, FT_Reference_Library): Implement new functions.
+ (FT_Done_Face, FT_Done_Library): Handle `refcount'.
+
+ * docs/CHANGES: Updated.
+
+2010-07-18 Werner Lemberg <wl@gnu.org>
+
* Version 2.4.1 released.
=========================
diff --git a/docs/CHANGES b/docs/CHANGES
index cc38a75..6c952ac 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -1,3 +1,18 @@
+CHANGES BETWEEN 2.4.1 and 2.4.2
+
+ I. MISCELLANEOUS
+
+ - Two new functions, `FT_Reference_Library' (in FT_MODULE_H) and
+ `FT_Reference_Face' (in FT_FREETYPE_H), have been added to
+ simplify life-cycle management. A counter gets initialized to 1
+ at the time an FT_Library (or FT_Face) structure is created.
+ The two new functions increment the respective counter.
+ `FT_Done_Library' and `FT_Done_Face' then only destroy a library
+ or face if the counter is 1, otherwise they simply decrement the
+ counter.
+
+
+======================================================================
CHANGES BETWEEN 2.4.0 and 2.4.1
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index e2ab774..17c8547 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -1952,6 +1952,9 @@ FT_BEGIN_HEADER
/* Each new face object created with this function also owns a */
/* default @FT_Size object, accessible as `face->size'. */
/* */
+ /* See the discussion of reference counters in the description of */
+ /* @FT_Reference_Face. */
+ /* */
FT_EXPORT( FT_Error )
FT_Open_Face( FT_Library library,
const FT_Open_Args* args,
@@ -2019,6 +2022,33 @@ FT_BEGIN_HEADER
/*************************************************************************/
/* */
/* <Function> */
+ /* FT_Reference_Face */
+ /* */
+ /* <Description> */
+ /* A counter gets initialized to~1 at the time an @FT_Face structure */
+ /* is created. This function increments the counter. @FT_Done_Face */
+ /* then only destroys a face if the counter is~1, otherwise it simply */
+ /* decrements the counter. */
+ /* */
+ /* This function helps in managing life-cycles of structures which */
+ /* reference @FT_Face objects. */
+ /* */
+ /* <Input> */
+ /* face :: A handle to a target face object. */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0~means success. */
+ /* */
+ /* <Since> */
+ /* 2.4.2 */
+ /* */
+ FT_EXPORT( FT_Error )
+ FT_Reference_Face( FT_Face face );
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
/* FT_Done_Face */
/* */
/* <Description> */
@@ -2031,6 +2061,10 @@ FT_BEGIN_HEADER
/* <Return> */
/* FreeType error code. 0~means success. */
/* */
+ /* <Note> */
+ /* See the discussion of reference counters in the description of */
+ /* @FT_Reference_Face. */
+ /* */
FT_EXPORT( FT_Error )
FT_Done_Face( FT_Face face );
diff --git a/include/freetype/ftlcdfil.h b/include/freetype/ftlcdfil.h
index e7f5927..0b55ebe 100644
--- a/include/freetype/ftlcdfil.h
+++ b/include/freetype/ftlcdfil.h
@@ -58,7 +58,7 @@ FT_BEGIN_HEADER
/****************************************************************************
*
- * @func:
+ * @enum:
* FT_LcdFilter
*
* @description:
diff --git a/include/freetype/ftmodapi.h b/include/freetype/ftmodapi.h
index 17868b2..8f2e017 100644
--- a/include/freetype/ftmodapi.h
+++ b/include/freetype/ftmodapi.h
@@ -252,6 +252,33 @@ FT_BEGIN_HEADER
/*************************************************************************/
/* */
/* <Function> */
+ /* FT_Reference_Library */
+ /* */
+ /* <Description> */
+ /* A counter gets initialized to~1 at the time an @FT_Library */
+ /* structure is created. This function increments the counter. */
+ /* @FT_Done_Library then only destroys a library if the counter is~1, */
+ /* otherwise it simply decrements the counter. */
+ /* */
+ /* This function helps in managing life-cycles of structures which */
+ /* reference @FT_Library objects. */
+ /* */
+ /* <Input> */
+ /* library :: A handle to a target library object. */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0~means success. */
+ /* */
+ /* <Since> */
+ /* 2.4.2 */
+ /* */
+ FT_EXPORT( FT_Error )
+ FT_Reference_Library( FT_Library library );
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
/* FT_New_Library */
/* */
/* <Description> */
@@ -275,6 +302,10 @@ FT_BEGIN_HEADER
/* <Return> */
/* FreeType error code. 0~means success. */
/* */
+ /* <Note> */
+ /* See the discussion of reference counters in the description of */
+ /* @FT_Reference_Library. */
+ /* */
FT_EXPORT( FT_Error )
FT_New_Library( FT_Memory memory,
FT_Library *alibrary );
@@ -295,6 +326,10 @@ FT_BEGIN_HEADER
/* <Return> */
/* FreeType error code. 0~means success. */
/* */
+ /* <Note> */
+ /* See the discussion of reference counters in the description of */
+ /* @FT_Reference_Library. */
+ /* */
FT_EXPORT( FT_Error )
FT_Done_Library( FT_Library library );
diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h
index 574cf58..670eb78 100644
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -4,7 +4,7 @@
/* */
/* The FreeType private base classes (specification). */
/* */
-/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008 by */
+/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008, 2010 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -311,6 +311,12 @@ FT_BEGIN_HEADER
/* in the case when the unpatented hinter is compiled within the */
/* library. */
/* */
+ /* refcount :: */
+ /* A counter initialized to~1 at the time an @FT_Face structure is */
+ /* created. @FT_Reference_Face increments this counter, and */
+ /* @FT_Done_Face only destroys a face if the counter is~1, */
+ /* otherwise it simply decrements it. */
+ /* */
typedef struct FT_Face_InternalRec_
{
#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
@@ -328,6 +334,7 @@ FT_BEGIN_HEADER
#endif
FT_Bool ignore_unpatented_hinter;
+ FT_UInt refcount;
} FT_Face_InternalRec;
@@ -805,10 +812,28 @@ FT_BEGIN_HEADER
/* */
/* debug_hooks :: XXX */
/* */
+ /* lcd_filter :: If subpixel rendering is activated, the */
+ /* selected LCD filter mode. */
+ /* */
+ /* lcd_extra :: If subpixel rendering is activated, the number */
+ /* of extra pixels needed for the LCD filter. */
+ /* */
+ /* lcd_weights :: If subpixel rendering is activated, the LCD */
+ /* filter weights, if any. */
+ /* */
+ /* lcd_filter_func :: If subpixel rendering is activated, the LCD */
+ /* filtering callback function. */
+ /* */
/* pic_container :: Contains global structs and tables, instead */
/* of defining them globallly. */
/* */
-
+ /* refcount :: A counter initialized to~1 at the time an */
+ /* @FT_Library structure is created. */
+ /* @FT_Reference_Library increments this counter, */
+ /* and @FT_Done_Library only destroys a library */
+ /* if the counter is~1, otherwise it simply */
+ /* decrements it. */
+ /* */
typedef struct FT_LibraryRec_
{
FT_Memory memory; /* library's memory manager */
@@ -843,6 +868,8 @@ FT_BEGIN_HEADER
FT_PIC_Container pic_container;
#endif
+ FT_UInt refcount;
+
} FT_LibraryRec;
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index aa84cf1..9dce576 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -142,7 +142,7 @@
if ( !args )
return FT_Err_Invalid_Argument;
- memory = library->memory;
+ memory = library->memory;
if ( FT_NEW( stream ) )
goto Exit;
@@ -1960,9 +1960,9 @@
FT_Error error;
FT_Driver driver;
FT_Memory memory;
- FT_Stream stream = 0;
- FT_Face face = 0;
- FT_ListNode node = 0;
+ FT_Stream stream = NULL;
+ FT_Face face = NULL;
+ FT_ListNode node = NULL;
FT_Bool external_stream;
FT_Module* cur;
FT_Module* limit;
@@ -2186,6 +2186,8 @@
internal->transform_delta.x = 0;
internal->transform_delta.y = 0;
+
+ internal->refcount = 1;
}
if ( aface )
@@ -2274,6 +2276,17 @@
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
+ FT_Reference_Face( FT_Face face )
+ {
+ face->internal->refcount++;
+
+ return FT_Err_Ok;
+ }
+
+
+ /* documentation is in freetype.h */
+
+ FT_EXPORT_DEF( FT_Error )
FT_Done_Face( FT_Face face )
{
FT_Error error;
@@ -2285,22 +2298,29 @@
error = FT_Err_Invalid_Face_Handle;
if ( face && face->driver )
{
- driver = face->driver;
- memory = driver->root.memory;
-
- /* find face in driver's list */
- node = FT_List_Find( &driver->faces_list, face );
- if ( node )
+ face->internal->refcount--;
+ if ( face->internal->refcount > 0 )
+ error = FT_Err_Ok;
+ else
{
- /* remove face object from the driver's list */
- FT_List_Remove( &driver->faces_list, node );
- FT_FREE( node );
+ driver = face->driver;
+ memory = driver->root.memory;
- /* now destroy the object proper */
- destroy_face( memory, face, driver );
- error = FT_Err_Ok;
+ /* find face in driver's list */
+ node = FT_List_Find( &driver->faces_list, face );
+ if ( node )
+ {
+ /* remove face object from the driver's list */
+ FT_List_Remove( &driver->faces_list, node );
+ FT_FREE( node );
+
+ /* now destroy the object proper */
+ destroy_face( memory, face, driver );
+ error = FT_Err_Ok;
+ }
}
}
+
return error;
}
@@ -4265,10 +4285,21 @@
/* documentation is in ftmodapi.h */
FT_EXPORT_DEF( FT_Error )
+ FT_Reference_Library( FT_Library library )
+ {
+ library->refcount++;
+
+ return FT_Err_Ok;
+ }
+
+
+ /* documentation is in ftmodapi.h */
+
+ FT_EXPORT_DEF( FT_Error )
FT_New_Library( FT_Memory memory,
FT_Library *alibrary )
{
- FT_Library library = 0;
+ FT_Library library = NULL;
FT_Error error;
@@ -4304,6 +4335,8 @@
library->version_minor = FREETYPE_MINOR;
library->version_patch = FREETYPE_PATCH;
+ library->refcount = 1;
+
/* That's ok now */
*alibrary = library;
@@ -4360,6 +4393,10 @@
if ( !library )
return FT_Err_Invalid_Library_Handle;
+ library->refcount--;
+ if ( library->refcount > 0 )
+ goto Exit;
+
memory = library->memory;
/* Discard client-data */
@@ -4435,6 +4472,8 @@
#endif
FT_FREE( library );
+
+ Exit:
return FT_Err_Ok;
}