Ticket #87: 0003-Move-OS-2-module-init-from-cairo-os2-surface.c-to-ca.patch
File 0003-Move-OS-2-module-init-from-cairo-os2-surface.c-to-ca.patch, 8.2 KB (added by , 9 years ago) |
---|
-
src/cairo-os2-surface.c
From 8088aa86ba59fde3f77d9de43a7c28ae65701230 Mon Sep 17 00:00:00 2001 From: Dave Yeo <dave.r.yeo@gmail.com> Date: Tue, 30 Aug 2011 21:15:05 -0700 Subject: [PATCH 3/5] Move OS/2 module init from cairo-os2-surface.c to cairo-system.c. Signed-off-by: Dave Yeo <dave.r.yeo@gmail.com> --- src/cairo-os2-surface.c | 166 ------------------------------------------------ src/cairo-system.c | 129 +++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 166 deletions(-) diff --git a/src/cairo-os2-surface.c b/src/cairo-os2-surface.c index ba46b22..74c0567 100644
a b 42 42 #include "cairo-default-context-private.h" 43 43 #include "cairo-error-private.h" 44 44 45 #if CAIRO_HAS_FC_FONT46 #include <fontconfig/fontconfig.h>47 #endif48 49 #include <float.h>50 #ifdef BUILD_CAIRO_DLL51 # include "cairo-os2.h"52 # ifndef __WATCOMC__53 # include <emx/startup.h>54 # endif55 #endif56 57 /*58 * Here comes the extra API for the OS/2 platform. Currently it consists59 * of two extra functions, the cairo_os2_init() and the60 * cairo_os2_fini(). Both of them are called automatically if61 * Cairo is compiled to be a DLL file, but you have to call them before62 * using the Cairo API if you link to Cairo statically!63 *64 * You'll also find the code in here which deals with DLL initialization65 * and termination, if the code is built to be a DLL.66 * (if BUILD_CAIRO_DLL is defined)67 */68 69 /* Initialization counter: */70 static int cairo_os2_initialization_count = 0;71 72 static inline void73 DisableFPUException (void)74 {75 unsigned short usCW;76 77 /* Some OS/2 PM API calls modify the FPU Control Word,78 * but forget to restore it.79 *80 * This can result in XCPT_FLOAT_INVALID_OPCODE exceptions,81 * so to be sure, we disable Invalid Opcode FPU exception82 * before using FPU stuffs.83 */84 usCW = _control87 (0, 0);85 usCW = usCW | EM_INVALID | 0x80;86 _control87 (usCW, MCW_EM | 0x80);87 }88 89 /**90 * cairo_os2_init:91 *92 * Initializes the Cairo library. This function is automatically called if93 * Cairo was compiled to be a DLL (however it's not a problem if it's called94 * multiple times). But if you link to Cairo statically, you have to call it95 * once to set up Cairo's internal structures and mutexes.96 *97 * Since: 1.498 **/99 cairo_public void100 cairo_os2_init (void)101 {102 /* This may initialize some stuffs, like create mutex semaphores etc.. */103 104 cairo_os2_initialization_count++;105 if (cairo_os2_initialization_count > 1) return;106 107 DisableFPUException ();108 109 #if CAIRO_HAS_FC_FONT110 /* Initialize FontConfig */111 FcInit ();112 #endif113 114 CAIRO_MUTEX_INITIALIZE ();115 }116 117 /**118 * cairo_os2_fini:119 *120 * Uninitializes the Cairo library. This function is automatically called if121 * Cairo was compiled to be a DLL (however it's not a problem if it's called122 * multiple times). But if you link to Cairo statically, you have to call it123 * once to shut down Cairo, to let it free all the resources it has allocated.124 *125 * Since: 1.4126 **/127 cairo_public void128 cairo_os2_fini (void)129 {130 /* This has to uninitialize some stuffs, like destroy mutex semaphores etc.. */131 132 if (cairo_os2_initialization_count <= 0) return;133 cairo_os2_initialization_count--;134 if (cairo_os2_initialization_count > 0) return;135 136 DisableFPUException ();137 138 cairo_debug_reset_static_data ();139 140 #if CAIRO_HAS_FC_FONT141 # if HAVE_FCFINI142 /* Uninitialize FontConfig */143 FcFini ();144 # endif145 #endif146 147 #ifdef __WATCOMC__148 /* It can happen that the libraries we use have memory leaks,149 * so there are still memory chunks allocated at this point.150 * In these cases, Watcom might still have a bigger memory chunk,151 * called "the heap" allocated from the OS.152 * As we want to minimize the memory we lose from the point of153 * view of the OS, we call this function to shrink that heap154 * as much as possible.155 */156 _heapshrink ();157 #else158 /* GCC has a heapmin function that approximately corresponds to159 * what the Watcom function does160 */161 _heapmin ();162 #endif163 }164 165 45 /* 166 46 * This function calls the allocation function depending on which 167 47 * method was compiled into the library: it can be native allocation … … void _buffer_free (void *buffer) 217 97 #endif 218 98 } 219 99 220 /* XXX221 * The cairo_os2_ini() and cairo_os2_fini() functions should be removed and222 * the LibMain code moved to cairo-system.c. It should also call223 * cairo_debug_reset_static_data() instead of duplicating its logic...224 */225 226 #ifdef BUILD_CAIRO_DLL227 /* The main DLL entry for DLL initialization and uninitialization */228 /* Only include this code if we're about to build a DLL. */229 230 #ifdef __WATCOMC__231 unsigned _System232 LibMain (unsigned hmod,233 unsigned termination)234 #else235 unsigned long _System236 _DLL_InitTerm (unsigned long hModule,237 unsigned long termination)238 #endif239 {240 if (termination) {241 /* Unloading the DLL */242 cairo_os2_fini ();243 244 #ifndef __WATCOMC__245 /* Uninitialize RTL of GCC */246 __ctordtorTerm ();247 _CRT_term ();248 #endif249 return 1;250 } else {251 /* Loading the DLL */252 #ifndef __WATCOMC__253 /* Initialize RTL of GCC */254 if (_CRT_init () != 0)255 return 0;256 __ctordtorInit ();257 #endif258 259 cairo_os2_init ();260 return 1;261 }262 }263 264 #endif /* BUILD_CAIRO_DLL */265 266 100 /* 267 101 * The following part of the source file contains the code which might 268 102 * be called the "core" of the OS/2 backend support. This contains the -
src/cairo-system.c
diff --git a/src/cairo-system.c b/src/cairo-system.c index 1ff4d07..c3e2257 100644
a b 34 34 * Owen Taylor <otaylor@redhat.com> 35 35 * Stuart Parmenter <stuart@mozilla.com> 36 36 * Vladimir Vukicevic <vladimir@pobox.com> 37 * Rich Walsh <rich@e-vertise.com> 37 38 */ 38 39 39 40 /* This file should include code that is system-specific, not … … DllMain (HINSTANCE hinstDLL, 95 96 #endif 96 97 #endif 97 98 99 #ifdef __OS2__ 100 101 #include <float.h> 102 #if CAIRO_HAS_FC_FONT 103 #include <fontconfig/fontconfig.h> 104 #endif 105 106 cairo_public void 107 cairo_os2_init (void); 108 cairo_public void 109 cairo_os2_fini (void); 110 111 static int cairo_os2_init_count = 0; 112 113 /** 114 * DLL Initialization/Termination functions - 115 * not used when Cairo is statically linked. 116 * 117 **/ 118 119 #ifdef BUILD_CAIRO_DLL 120 121 #ifdef __WATCOMC__ 122 unsigned _System 123 LibMain (unsigned hmod, 124 unsigned termination) 125 { 126 if (termination) { 127 cairo_os2_fini (); 128 return 1; 129 } 130 131 cairo_os2_init (); 132 return 1; 133 } 134 135 #else 136 137 #include <emx/startup.h> 138 139 unsigned long _System 140 _DLL_InitTerm (unsigned long hmod, 141 unsigned long termination) 142 { 143 if (termination) { 144 cairo_os2_fini (); 145 __ctordtorTerm (); 146 _CRT_term (); 147 return 1; 148 } 149 150 if (_CRT_init ()) 151 return 0; 152 __ctordtorInit (); 153 154 cairo_os2_init (); 155 return 1; 156 } 157 #endif /* __WATCOMC__ */ 158 159 #endif /* BUILD_CAIRO_DLL */ 160 161 /** 162 * cairo_os2_init: 163 * System-specific initialization. 164 * 165 * This is called automatically if Cairo is built as a DLL, but must be 166 * explicitly invoked if Cairo is used as a statically linked library. 167 * 168 * Since: 1.4 169 **/ 170 171 cairo_public void 172 cairo_os2_init (void) 173 { 174 unsigned short usCW; 175 176 cairo_os2_init_count++; 177 if (cairo_os2_init_count > 1) 178 return; 179 180 /* Workaround a bug in some OS/2 PM API calls that 181 * modify the FPU Control Word but fail to restore it. 182 */ 183 usCW = _control87 (0, 0); 184 usCW = usCW | EM_INVALID | 0x80; 185 _control87 (usCW, MCW_EM | 0x80); 186 187 #if CAIRO_HAS_FC_FONT 188 FcInit (); 189 #endif 190 191 CAIRO_MUTEX_INITIALIZE (); 192 } 193 194 195 /** 196 * cairo_os2_fini: 197 * System-specific finalization. 198 * 199 * This is called automatically if Cairo is built as a DLL, but must be 200 * explicitly invoked if Cairo is used as a statically linked library. 201 * 202 * Since: 1.4 203 **/ 204 205 cairo_public void 206 cairo_os2_fini (void) 207 { 208 if (!cairo_os2_init_count) 209 return; 210 cairo_os2_init_count--; 211 if (cairo_os2_init_count) 212 return; 213 214 #if CAIRO_HAS_FC_FONT 215 #if HAVE_FCFINI 216 FcFini (); 217 #endif 218 #endif 219 220 CAIRO_MUTEX_FINALIZE (); 221 222 cairo_debug_reset_static_data (); 223 } 224 225 #endif /* __OS2__ */ 226