summaryrefslogtreecommitdiffstats
path: root/win/tkWinPixmap.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2009-04-30 13:48:00 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2009-04-30 13:48:00 (GMT)
commit04b88c812c2e34880eb39a6ee03334dc9b141478 (patch)
treee27d069b7c064b7c1677820801a3d7ca4407c9e6 /win/tkWinPixmap.c
parent554ab376d71ec5c1566db04e0bdadebf3d9dc1a6 (diff)
downloadtk-04b88c812c2e34880eb39a6ee03334dc9b141478.zip
tk-04b88c812c2e34880eb39a6ee03334dc9b141478.tar.gz
tk-04b88c812c2e34880eb39a6ee03334dc9b141478.tar.bz2
Backported fix for [Bug 2080533].
Diffstat (limited to 'win/tkWinPixmap.c')
-rw-r--r--win/tkWinPixmap.c57
1 files changed, 52 insertions, 5 deletions
diff --git a/win/tkWinPixmap.c b/win/tkWinPixmap.c
index 369c25c..6e3331e 100644
--- a/win/tkWinPixmap.c
+++ b/win/tkWinPixmap.c
@@ -9,11 +9,10 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkWinPixmap.c,v 1.7 2007/01/11 15:35:41 dkf Exp $
+ * RCS: @(#) $Id: tkWinPixmap.c,v 1.7.4.1 2009/04/30 13:48:00 dkf Exp $
*/
#include "tkWinInt.h"
-
/*
*----------------------------------------------------------------------
@@ -48,7 +47,7 @@ Tk_GetPixmap(
newTwdPtr = (TkWinDrawable*) ckalloc(sizeof(TkWinDrawable));
newTwdPtr->type = TWD_BITMAP;
newTwdPtr->bitmap.depth = depth;
- twdPtr = (TkWinDrawable *)d;
+ twdPtr = (TkWinDrawable *) d;
if (twdPtr->type != TWD_BITMAP) {
if (twdPtr->window.winPtr == NULL) {
newTwdPtr->bitmap.colormap = DefaultColormap(display,
@@ -68,12 +67,60 @@ Tk_GetPixmap(
newTwdPtr->bitmap.handle =
CreateBitmap(width, height, (DWORD) planes, (DWORD) depth, NULL);
+ /*
+ * CreateBitmap tries to use memory on the graphics card. If it fails,
+ * call CreateDIBSection which uses real memory; slower, but at least
+ * still works. [Bug 2080533]
+ */
+
+ if (newTwdPtr->bitmap.handle == NULL) {
+ static int repeatError = 0;
+ unsigned char *bits = NULL;
+ BITMAPINFO bitmapInfo;
+ HDC dc;
+
+ memset(&bitmapInfo, 0, sizeof(bitmapInfo));
+ bitmapInfo.bmiHeader.biSize = sizeof(bitmapInfo.bmiHeader);
+ bitmapInfo.bmiHeader.biWidth = width;
+ bitmapInfo.bmiHeader.biHeight = height;
+ bitmapInfo.bmiHeader.biPlanes = planes;
+ bitmapInfo.bmiHeader.biBitCount = depth;
+ bitmapInfo.bmiHeader.biCompression = BI_RGB;
+ bitmapInfo.bmiHeader.biSizeImage = 0;
+ dc = GetDC(NULL);
+ newTwdPtr->bitmap.handle = CreateDIBSection(dc, &bitmapInfo,
+ DIB_RGB_COLORS, (void **) &bits, 0, 0);
+ ReleaseDC(NULL, dc);
+
+ /*
+ * Oh no! Things are still going wrong. Pop up a warning message here
+ * (because things will probably crash soon) which will encourage
+ * people to report this as a bug...
+ */
+
+ if (newTwdPtr->bitmap.handle == NULL && !repeatError) {
+ LPVOID lpMsgBuf;
+
+ repeatError = 1;
+ if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &lpMsgBuf, 0, NULL)) {
+ MessageBox(NULL, (LPCTSTR) lpMsgBuf,
+ "Tk_GetPixmap: Error from CreateDIBSection",
+ MB_OK | MB_ICONINFORMATION);
+ LocalFree(lpMsgBuf);
+ }
+ }
+ }
+
if (newTwdPtr->bitmap.handle == NULL) {
ckfree((char *) newTwdPtr);
return None;
}
- return (Pixmap)newTwdPtr;
+ return (Pixmap) newTwdPtr;
}
/*
@@ -102,7 +149,7 @@ Tk_FreePixmap(
display->request++;
if (twdPtr != NULL) {
DeleteObject(twdPtr->bitmap.handle);
- ckfree((char *)twdPtr);
+ ckfree((char *) twdPtr);
}
}