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