| 1 | #include <os2win.h> | 
|---|
| 2 | #include <stats.h> | 
|---|
| 3 |  | 
|---|
| 4 | #ifdef DEBUG | 
|---|
| 5 |  | 
|---|
| 6 | #define STATS_MAX_OBJECTS        1024 | 
|---|
| 7 |  | 
|---|
| 8 | static DWORD createddc[STATS_MAX_OBJECTS]     = {0}; | 
|---|
| 9 | static DWORD createdfont[STATS_MAX_OBJECTS]   = {0}; | 
|---|
| 10 | static DWORD createdpen[STATS_MAX_OBJECTS]    = {0}; | 
|---|
| 11 | static DWORD createdbrush[STATS_MAX_OBJECTS]  = {0}; | 
|---|
| 12 | static DWORD createdregion[STATS_MAX_OBJECTS] = {0}; | 
|---|
| 13 | static DWORD createdbitmap[STATS_MAX_OBJECTS] = {0}; | 
|---|
| 14 |  | 
|---|
| 15 | static DWORD nrdcscreated        = 0; | 
|---|
| 16 | static DWORD nrfontscreated      = 0; | 
|---|
| 17 | static DWORD nrpenscreated       = 0; | 
|---|
| 18 | static DWORD nrbrushescreated    = 0; | 
|---|
| 19 | static DWORD nrregionscreated    = 0; | 
|---|
| 20 | static DWORD nrbitmapscreated    = 0; | 
|---|
| 21 |  | 
|---|
| 22 |  | 
|---|
| 23 | //****************************************************************************** | 
|---|
| 24 | //****************************************************************************** | 
|---|
| 25 | static void STAT_InsertObject(HANDLE hObject, DWORD *pdwObjects) | 
|---|
| 26 | { | 
|---|
| 27 | for(int i=0;i<STATS_MAX_OBJECTS;i++) { | 
|---|
| 28 | if(pdwObjects[i] == 0) { | 
|---|
| 29 | pdwObjects[i] = hObject; | 
|---|
| 30 | break; | 
|---|
| 31 | } | 
|---|
| 32 | } | 
|---|
| 33 | if(i == STATS_MAX_OBJECTS) { | 
|---|
| 34 | dprintf(("!WARNING! STAT_InsertObject: no room left!!")); | 
|---|
| 35 | } | 
|---|
| 36 | } | 
|---|
| 37 | //****************************************************************************** | 
|---|
| 38 | //****************************************************************************** | 
|---|
| 39 | static void STAT_DeleteObject(HANDLE hObject, DWORD *pdwObjects) | 
|---|
| 40 | { | 
|---|
| 41 | for(int i=0;i<STATS_MAX_OBJECTS;i++) { | 
|---|
| 42 | if(LOWORD(pdwObjects[i]) == LOWORD(hObject)) { | 
|---|
| 43 | pdwObjects[i] = 0; | 
|---|
| 44 | break; | 
|---|
| 45 | } | 
|---|
| 46 | } | 
|---|
| 47 | if(i == STATS_MAX_OBJECTS) { | 
|---|
| 48 | dprintf(("!WARNING! STAT_DeleteObject: %x not found!!", hObject)); | 
|---|
| 49 | } | 
|---|
| 50 | } | 
|---|
| 51 | //****************************************************************************** | 
|---|
| 52 | //****************************************************************************** | 
|---|
| 53 | static void STAT_PrintLeakedObjects(char *szMessage, DWORD *pdwObjects) | 
|---|
| 54 | { | 
|---|
| 55 | for(int i=0;i<STATS_MAX_OBJECTS;i++) { | 
|---|
| 56 | if(pdwObjects[i] != 0) { | 
|---|
| 57 | dprintf(("%s %x", szMessage, pdwObjects[i])); | 
|---|
| 58 | } | 
|---|
| 59 | } | 
|---|
| 60 | } | 
|---|
| 61 | //****************************************************************************** | 
|---|
| 62 | //****************************************************************************** | 
|---|
| 63 | void STATS_CreateFontIndirect(HFONT hFont, LOGFONTA* lplf) | 
|---|
| 64 | { | 
|---|
| 65 | nrfontscreated++; | 
|---|
| 66 | STAT_InsertObject(hFont, createdfont); | 
|---|
| 67 | } | 
|---|
| 68 | //****************************************************************************** | 
|---|
| 69 | //****************************************************************************** | 
|---|
| 70 | void STATS_CreateCompatibleDC(HDC hdc, HDC newHdc) | 
|---|
| 71 | { | 
|---|
| 72 | nrdcscreated++; | 
|---|
| 73 | STAT_InsertObject(newHdc, createddc); | 
|---|
| 74 | } | 
|---|
| 75 | //****************************************************************************** | 
|---|
| 76 | //****************************************************************************** | 
|---|
| 77 | void STATS_DeleteDC(HDC hdc) | 
|---|
| 78 | { | 
|---|
| 79 | nrdcscreated--; | 
|---|
| 80 | STAT_DeleteObject(hdc, createddc); | 
|---|
| 81 | } | 
|---|
| 82 | //****************************************************************************** | 
|---|
| 83 | //****************************************************************************** | 
|---|
| 84 | void STATS_CreatePatternBrush(HBRUSH hBrush, HBITMAP hBitmap) | 
|---|
| 85 | { | 
|---|
| 86 | nrbrushescreated++; | 
|---|
| 87 | STAT_InsertObject(hBrush, createdbrush); | 
|---|
| 88 | } | 
|---|
| 89 | //****************************************************************************** | 
|---|
| 90 | //****************************************************************************** | 
|---|
| 91 | void STATS_CreateDIBPatternBrushPt(HBRUSH hBrush, LPCVOID buffer, DWORD usage) | 
|---|
| 92 | { | 
|---|
| 93 | nrbrushescreated++; | 
|---|
| 94 | STAT_InsertObject(hBrush, createdbrush); | 
|---|
| 95 | } | 
|---|
| 96 | //****************************************************************************** | 
|---|
| 97 | //****************************************************************************** | 
|---|
| 98 | void STATS_CreatePenIndirect(HPEN hPen, const LOGPEN *lplgpn) | 
|---|
| 99 | { | 
|---|
| 100 | nrpenscreated++; | 
|---|
| 101 | STAT_InsertObject(hPen, createdpen); | 
|---|
| 102 | } | 
|---|
| 103 | //****************************************************************************** | 
|---|
| 104 | //****************************************************************************** | 
|---|
| 105 | void STATS_CreatePen(HPEN hPen, int fnPenStyle, int nWidth, COLORREF crColor) | 
|---|
| 106 | { | 
|---|
| 107 | nrpenscreated++; | 
|---|
| 108 | STAT_InsertObject(hPen, createdpen); | 
|---|
| 109 | } | 
|---|
| 110 | //****************************************************************************** | 
|---|
| 111 | //****************************************************************************** | 
|---|
| 112 | void STATS_ExtCreatePen(HPEN hPen, DWORD dwPenStyle, DWORD dwWidth, const LOGBRUSH *lplb, | 
|---|
| 113 | DWORD dwStyleCount, const DWORD *lpStyle) | 
|---|
| 114 | { | 
|---|
| 115 | nrpenscreated++; | 
|---|
| 116 | STAT_InsertObject(hPen, createdpen); | 
|---|
| 117 | } | 
|---|
| 118 | //****************************************************************************** | 
|---|
| 119 | //****************************************************************************** | 
|---|
| 120 | void STATS_CreateBrushIndirect(HBRUSH hBrush, LPLOGBRUSH pLogBrush) | 
|---|
| 121 | { | 
|---|
| 122 | nrbrushescreated++; | 
|---|
| 123 | STAT_InsertObject(hBrush, createdbrush); | 
|---|
| 124 | } | 
|---|
| 125 | //****************************************************************************** | 
|---|
| 126 | //****************************************************************************** | 
|---|
| 127 | void STATS_CreateHatchBrush(HBRUSH hBrush, int fnStyle, COLORREF clrref) | 
|---|
| 128 | { | 
|---|
| 129 | nrbrushescreated++; | 
|---|
| 130 | STAT_InsertObject(hBrush, createdbrush); | 
|---|
| 131 | } | 
|---|
| 132 | //****************************************************************************** | 
|---|
| 133 | //****************************************************************************** | 
|---|
| 134 | void STATS_CreateSolidBrush(HBRUSH hBrush, COLORREF color) | 
|---|
| 135 | { | 
|---|
| 136 | nrbrushescreated++; | 
|---|
| 137 | STAT_InsertObject(hBrush, createdbrush); | 
|---|
| 138 | } | 
|---|
| 139 | //****************************************************************************** | 
|---|
| 140 | //****************************************************************************** | 
|---|
| 141 | void STATS_CreateICA(HDC hdc, LPCSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszOutput, | 
|---|
| 142 | const DEVMODEA *lpdvmInit) | 
|---|
| 143 | { | 
|---|
| 144 | nrdcscreated++; | 
|---|
| 145 | STAT_InsertObject(hdc, createddc); | 
|---|
| 146 | } | 
|---|
| 147 | //****************************************************************************** | 
|---|
| 148 | //****************************************************************************** | 
|---|
| 149 | void STATS_CreateDCA(HDC hdc, LPCSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszOutput, | 
|---|
| 150 | const DEVMODEA *lpdvmInit) | 
|---|
| 151 | { | 
|---|
| 152 | nrdcscreated++; | 
|---|
| 153 | STAT_InsertObject(hdc, createddc); | 
|---|
| 154 | } | 
|---|
| 155 | //****************************************************************************** | 
|---|
| 156 | //****************************************************************************** | 
|---|
| 157 | void STATS_CreatePolyPolygonRgn(HRGN hRgn, const POINT *lppt, const int *pPolyCount, int nCount, int fnPolyFillMode) | 
|---|
| 158 | { | 
|---|
| 159 | nrregionscreated++; | 
|---|
| 160 | STAT_InsertObject(hRgn, createdregion); | 
|---|
| 161 | } | 
|---|
| 162 | //****************************************************************************** | 
|---|
| 163 | //****************************************************************************** | 
|---|
| 164 | void STATS_CreateRectRgn(HRGN hRgn, int left, int top, int right, int bottom) | 
|---|
| 165 | { | 
|---|
| 166 | nrregionscreated++; | 
|---|
| 167 | STAT_InsertObject(hRgn, createdregion); | 
|---|
| 168 | } | 
|---|
| 169 | //****************************************************************************** | 
|---|
| 170 | //****************************************************************************** | 
|---|
| 171 | void STATS_CreateRoundRectRgn(HRGN hRgn, int left, int top, int right, int bottom, int nWidthEllipse, int nHeightEllipse) | 
|---|
| 172 | { | 
|---|
| 173 | nrregionscreated++; | 
|---|
| 174 | STAT_InsertObject(hRgn, createdregion); | 
|---|
| 175 | } | 
|---|
| 176 | //****************************************************************************** | 
|---|
| 177 | //****************************************************************************** | 
|---|
| 178 | void STATS_ExtCreateRegion(HRGN hRgn, PVOID pXform, DWORD count, const RGNDATA * pData) | 
|---|
| 179 | { | 
|---|
| 180 | nrregionscreated++; | 
|---|
| 181 | STAT_InsertObject(hRgn, createdregion); | 
|---|
| 182 | } | 
|---|
| 183 | //****************************************************************************** | 
|---|
| 184 | //****************************************************************************** | 
|---|
| 185 | void STATS_CreateEllipticRgn(HRGN hRgn, int left, int top, int right, int bottom) | 
|---|
| 186 | { | 
|---|
| 187 | nrregionscreated++; | 
|---|
| 188 | STAT_InsertObject(hRgn, createdregion); | 
|---|
| 189 | } | 
|---|
| 190 | //****************************************************************************** | 
|---|
| 191 | //****************************************************************************** | 
|---|
| 192 | void STATS_CreatePolygonRgn(HRGN hRgn, const POINT * lppt, int cPoints, int fnPolyFillMode) | 
|---|
| 193 | { | 
|---|
| 194 | nrregionscreated++; | 
|---|
| 195 | STAT_InsertObject(hRgn, createdregion); | 
|---|
| 196 | } | 
|---|
| 197 | //****************************************************************************** | 
|---|
| 198 | //****************************************************************************** | 
|---|
| 199 | void STATS_CreateDIBitmap(HBITMAP hBitmap,HDC hdc, const BITMAPINFOHEADER *lpbmih, | 
|---|
| 200 | DWORD fdwInit, const void *lpbInit, | 
|---|
| 201 | const BITMAPINFO *lpbmi, UINT fuUsage) | 
|---|
| 202 | { | 
|---|
| 203 | nrbitmapscreated++; | 
|---|
| 204 | STAT_InsertObject(hBitmap, createdbitmap); | 
|---|
| 205 | } | 
|---|
| 206 | //****************************************************************************** | 
|---|
| 207 | //****************************************************************************** | 
|---|
| 208 | void STATS_CreateCompatibleBitmap(HBITMAP hBitmap,HDC hdc, int nWidth, int nHeight) | 
|---|
| 209 | { | 
|---|
| 210 | nrbitmapscreated++; | 
|---|
| 211 | STAT_InsertObject(hBitmap, createdbitmap); | 
|---|
| 212 | } | 
|---|
| 213 | //****************************************************************************** | 
|---|
| 214 | //****************************************************************************** | 
|---|
| 215 | void STATS_CreateBitmap(HBITMAP hBitmap,int nWidth, int nHeight, UINT cPlanes, | 
|---|
| 216 | UINT cBitsPerPel, const void *lpvBits) | 
|---|
| 217 | { | 
|---|
| 218 | nrbitmapscreated++; | 
|---|
| 219 | STAT_InsertObject(hBitmap, createdbitmap); | 
|---|
| 220 | } | 
|---|
| 221 | //****************************************************************************** | 
|---|
| 222 | //****************************************************************************** | 
|---|
| 223 | void STATS_CreateDIBSection(HBITMAP hBitmap,HDC hdc, BITMAPINFO *pbmi, UINT iUsage, | 
|---|
| 224 | VOID **ppvBits, HANDLE hSection, DWORD dwOffset) | 
|---|
| 225 | { | 
|---|
| 226 | nrbitmapscreated++; | 
|---|
| 227 | STAT_InsertObject(hBitmap, createdbitmap); | 
|---|
| 228 | } | 
|---|
| 229 | //****************************************************************************** | 
|---|
| 230 | //****************************************************************************** | 
|---|
| 231 | void STATS_CreateBitmapIndirect(HBITMAP hBitmap, const BITMAP *pBitmap) | 
|---|
| 232 | { | 
|---|
| 233 | nrbitmapscreated++; | 
|---|
| 234 | STAT_InsertObject(hBitmap, createdbitmap); | 
|---|
| 235 | } | 
|---|
| 236 | //****************************************************************************** | 
|---|
| 237 | //****************************************************************************** | 
|---|
| 238 | void STATS_DeleteObject(HANDLE hObj, DWORD objtype) | 
|---|
| 239 | { | 
|---|
| 240 | switch(objtype) { | 
|---|
| 241 | case OBJ_PEN: | 
|---|
| 242 | case OBJ_EXTPEN: | 
|---|
| 243 | nrpenscreated--; | 
|---|
| 244 | STAT_DeleteObject(hObj, createdpen); | 
|---|
| 245 | break; | 
|---|
| 246 | case OBJ_BRUSH: | 
|---|
| 247 | nrbrushescreated--; | 
|---|
| 248 | STAT_DeleteObject(hObj, createdbrush); | 
|---|
| 249 | break; | 
|---|
| 250 | case OBJ_FONT: | 
|---|
| 251 | nrfontscreated--; | 
|---|
| 252 | STAT_DeleteObject(hObj, createdfont); | 
|---|
| 253 | break; | 
|---|
| 254 | case OBJ_REGION: | 
|---|
| 255 | nrregionscreated--; | 
|---|
| 256 | STAT_DeleteObject(hObj, createdregion); | 
|---|
| 257 | break; | 
|---|
| 258 | case OBJ_BITMAP: | 
|---|
| 259 | nrbitmapscreated--; | 
|---|
| 260 | STAT_DeleteObject(hObj, createdbitmap); | 
|---|
| 261 | break; | 
|---|
| 262 |  | 
|---|
| 263 | case OBJ_MEMDC: | 
|---|
| 264 | case OBJ_DC: | 
|---|
| 265 | nrdcscreated--; | 
|---|
| 266 | STAT_DeleteObject(hObj, createddc); | 
|---|
| 267 | break; | 
|---|
| 268 |  | 
|---|
| 269 | case OBJ_PAL: | 
|---|
| 270 | case OBJ_METAFILE: | 
|---|
| 271 | case OBJ_ENHMETADC: | 
|---|
| 272 | case OBJ_ENHMETAFILE: | 
|---|
| 273 | case OBJ_METADC: | 
|---|
| 274 | break; | 
|---|
| 275 | default: | 
|---|
| 276 | dprintf(("!ERROR! Unknown object %x of type %d", hObj, objtype)); | 
|---|
| 277 | break; | 
|---|
| 278 | } | 
|---|
| 279 | } | 
|---|
| 280 | //****************************************************************************** | 
|---|
| 281 | //****************************************************************************** | 
|---|
| 282 | void STATS_DumpStatsGDI32() | 
|---|
| 283 | { | 
|---|
| 284 | dprintf(("*************  GDI32 STATISTICS BEGIN *****************")); | 
|---|
| 285 | dprintf(("Leaked dcs            %d", nrdcscreated)); | 
|---|
| 286 | STAT_PrintLeakedObjects("Leaked DC", createddc); | 
|---|
| 287 | dprintf(("*************  ********************** *****************")); | 
|---|
| 288 | dprintf(("Leaked font objects   %d", nrfontscreated)); | 
|---|
| 289 | STAT_PrintLeakedObjects("Leaked Font", createdfont); | 
|---|
| 290 | dprintf(("*************  ********************** *****************")); | 
|---|
| 291 | dprintf(("Leaked pen objects    %d", nrpenscreated)); | 
|---|
| 292 | STAT_PrintLeakedObjects("Leaked Pen", createdpen); | 
|---|
| 293 | dprintf(("*************  ********************** *****************")); | 
|---|
| 294 | dprintf(("Leaked brush objects  %d", nrbrushescreated)); | 
|---|
| 295 | STAT_PrintLeakedObjects("Leaked Brush", createdbrush); | 
|---|
| 296 | dprintf(("*************  ********************** *****************")); | 
|---|
| 297 | dprintf(("Leaked region objects %d", nrregionscreated)); | 
|---|
| 298 | STAT_PrintLeakedObjects("Leaked Region", createdregion); | 
|---|
| 299 | dprintf(("*************  ********************** *****************")); | 
|---|
| 300 | dprintf(("Leaked bitmap objects %d", nrbitmapscreated)); | 
|---|
| 301 | STAT_PrintLeakedObjects("Leaked Bitmap", createdbitmap); | 
|---|
| 302 | dprintf(("*************  GDI32 STATISTICS END   *****************")); | 
|---|
| 303 | } | 
|---|
| 304 | //****************************************************************************** | 
|---|
| 305 | //****************************************************************************** | 
|---|
| 306 |  | 
|---|
| 307 |  | 
|---|
| 308 | #endif //DEBUG | 
|---|