4 * Started by Robert Pouliot <krynos@clic.net>
11 #include <sys/types.h>
15 #endif /* !defined(__EMX__) */
17 #endif /* defined(HAVE_LIBXXSHM) */
28 typedef enum WING_DITHER_TYPE
30 WING_DISPERSED_4x4, WING_DISPERSED_8x8, WING_CLUSTERED_4x4
33 static int __WinGOK = -1;
36 * WinG DIB bitmaps can be selected into DC and then scribbled upon
37 * by GDI functions. They can also be changed directly. This gives us
39 * - use original WinG 16-bit DLL
40 * requires working 16-bit driver interface
41 * - implement DIB graphics driver from scratch
43 * - use shared pixmaps
44 * won't work with some videocards and/or videomodes
48 static BITMAPINFOHEADER __bmpiWinG = { 0, 1, -1, 1, 8, BI_RGB, 1, 0, 0, 0, 0 };
50 static void __initWinG(void)
55 Status s = TSXShmQueryExtension(display);
58 int i = TSXShmPixmapFormat(display);
59 if( i == ZPixmap && MONITOR_GetDepth(&MONITOR_PrimaryMonitor) == 8 )
65 #endif /* defined(HAVE_LIBXXSHM) */
66 FIXME(wing,"WinG: incorrect depth or unsupported card.\n");
71 /***********************************************************************
72 * WinGCreateDC16 (WING.1001)
74 HDC16 WINAPI WinGCreateDC16(void)
79 return CreateCompatibleDC16(0);
83 /***********************************************************************
84 * WinGRecommendDIBFormat16 (WING.1002)
86 BOOL16 WINAPI WinGRecommendDIBFormat16(BITMAPINFO *fmt)
88 FIXME(wing,"(%p): stub\n", fmt);
90 if( __WinGOK > 0 && fmt )
92 memcpy(&fmt->bmiHeader, &__bmpiWinG, sizeof(BITMAPINFOHEADER));
98 /***********************************************************************
99 * WinGCreateBitmap16 (WING.1003)
101 HBITMAP16 WINAPI WinGCreateBitmap16(HDC16 winDC, BITMAPINFO *header,
104 FIXME(wing,"(%x,%p,%p): empty stub! (expect failure)\n",
105 winDC, header, bits);
106 if( __WinGOK > 0 && header )
108 BITMAPINFOHEADER* bmpi = &header->bmiHeader;
110 FIXME(wing,"bytes=%i,planes=%i,bpp=%i,x=%i,y=%i,rle=0x%08x,size=%i\n",
111 (int)bmpi->biSize, bmpi->biPlanes, bmpi->biBitCount,
112 (int)bmpi->biWidth, (int)bmpi->biHeight,
113 (unsigned)bmpi->biCompression, (int)bmpi->biSizeImage);
115 #ifdef PRELIMINARY_WING16_SUPPORT
116 if( bmpi->biPlanes == __bmpiWinG.biPlanes && bmpi->biBitCount == __bmpiWinG.biBitCount &&
117 bmpi->biCompression == __bmpiWinG.biCompression && (int)bmpi->biHeight < 0 &&
120 unsigned bytes = (bmpi->biWidth + bmpi->biWidth % 2)*(-bmpi->biHeight) * bmpi->biBitCount/8;
121 int key = shmget(IPC_PRIVATE, bytes, IPC_CREAT | 0x01FF);
125 /* Create the BITMAPOBJ
127 * FIXME: A facility to manage shared memory structures
128 * which would clean up when Wine crashes. Perhaps a part of
129 * IPC code can be adapted. Otherwise this code leaves a lot
130 * of junk in shared memory.
133 HBITMAP16 hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
137 __ShmBitmapCtl* p = (__ShmBitmapCtl*)xmalloc(sizeof(__ShmBitmapCtl));
138 #endif /* defined(HAVE_LIBXXSHM) */
139 BITMAPOBJ* bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
141 bmpObjPtr->size.cx = 0;
142 bmpObjPtr->size.cy = 0;
143 bmpObjPtr->bitmap.bmType = 0;
144 bmpObjPtr->bitmap.bmWidth = (INT16)abs(bmpi->biWidth);
145 bmpObjPtr->bitmap.bmHeight = -(INT16)bmpi->biHeight;
146 bmpObjPtr->bitmap.bmPlanes = (BYTE)bmpi->biPlanes;
147 bmpObjPtr->bitmap.bmBitsPixel = (BYTE)bmpi->biBitCount;
148 bmpObjPtr->bitmap.bmWidthBytes =
149 (INT16)BITMAP_WIDTH_BYTES( bmpObjPtr->bitmap.bmWidth, bmpi->biBitCount );
152 bmpObjPtr->bitmap.bmBits = (SEGPTR)p;
155 p->si.shmaddr = shmat(key, NULL, 0);
156 p->si.readOnly = False;
162 TSXShmAttach(display, &p->si);
163 bmpObjPtr->pixmap = TSXShmCreatePixmap(display, rootWindow,
164 p->si.shmaddr, &p->si, bmpObjPtr->bitmap.bmWidth,
165 bmpObjPtr->bitmap.bmHeight, bmpi->biBitCount );
166 if( bmpObjPtr->pixmap )
168 sel = SELECTOR_AllocBlock( p->si.shmaddr, bytes,
169 SEGMENT_DATA, FALSE, FALSE);
170 if (sel) p->bits = PTR_SEG_OFF_TO_SEGPTR(sel,0);
171 else TSXFreePixmap( display, bmpObjPtr->pixmap );
175 shmdt( p->si.shmaddr );
176 p->si.shmaddr = NULL;
181 GDI_FreeObject( hbitmap );
184 #else /* defined(HAVE_LIBXXSHM) */
185 bmpObjPtr->bitmap.bmBits = (SEGPTR) NULL;
186 bmpObjPtr->pixmap = NULL;
187 #endif /* defined(HAVE_LIBXXSHM) */
189 GDI_HEAP_UNLOCK( hbitmap );
193 #endif /* defined(PRELIMINARY_WING16_SUPPORT) */
198 /***********************************************************************
199 * WinGGetDIBPointer (WING.1004)
201 SEGPTR WINAPI WinGGetDIBPointer16(HBITMAP16 hWinGBitmap, BITMAPINFO* bmpi)
203 #ifdef PRELIMINARY_WING16_SUPPORT
205 BITMAPOBJ* bmp = (BITMAPOBJ *) GDI_GetObjPtr( hWinGBitmap, BITMAP_MAGIC );
209 __ShmBitmapCtl* p = (__ShmBitmapCtl*)bmp->bitmap.bmBits;
212 if( bmpi ) memcpy( bmpi, &__bmpiWinG, sizeof(BITMAPINFOHEADER));
213 GDI_HEAP_UNLOCK( hWinGBitmap );
217 #endif /* defined(HAVE_LIBXXSHM) */
218 #endif /* defined(PRELIMINARY_WING16_SUPPORT) */
222 /***********************************************************************
223 * WinGSetDIBColorTable (WING.1004)
225 UINT16 WINAPI WinGSetDIBColorTable16(HDC16 hWinGDC, UINT16 start, UINT16 num,
228 FIXME(wing,"(%x,%d,%d,%p): empty stub!\n",hWinGDC,start,num,pColor);
232 /***********************************************************************
233 * WinGGetDIBColorTable16 (WING.1005)
235 UINT16 WINAPI WinGGetDIBColorTable16(HDC16 winDC, UINT16 start,
236 UINT16 num, RGBQUAD* colors)
238 FIXME(wing,"(%x,%d,%d,%p): empty stub!\n",winDC,start,num,colors);
242 /***********************************************************************
243 * WinGCreateHalfTonePalette16 (WING.1007)
245 HPALETTE16 WINAPI WinGCreateHalfTonePalette16(void)
247 FIXME(wing,"(void): empty stub!\n");
251 /***********************************************************************
252 * WinGCreateHalfToneBrush16 (WING.1008)
254 HPALETTE16 WINAPI WinGCreateHalfToneBrush16(HDC16 winDC, COLORREF col,
255 WING_DITHER_TYPE type)
257 FIXME(wing,"(...): empty stub!\n");
261 /***********************************************************************
262 * WinGStretchBlt16 (WING.1009)
264 BOOL16 WINAPI WinGStretchBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
265 INT16 widDest, INT16 heiDest,
266 HDC16 srcDC, INT16 xSrc, INT16 ySrc,
267 INT16 widSrc, INT16 heiSrc)
270 return StretchBlt16(destDC, xDest, yDest, widDest, heiDest, srcDC, xSrc, ySrc, widSrc, heiSrc, SRCCOPY);
273 /***********************************************************************
274 * WinGBitBlt16 (WING.1010)
276 BOOL16 WINAPI WinGBitBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
277 INT16 widDest, INT16 heiDest, HDC16 srcDC,
278 INT16 xSrc, INT16 ySrc)
280 /* destDC is a display DC, srcDC is a memory DC */
283 X11DRV_PDEVICE *physDevDst, *physDevSrc;
285 if (!(dcDst = (DC *)GDI_GetObjPtr( destDC, DC_MAGIC ))) return FALSE;
286 if (!(dcSrc = (DC *) GDI_GetObjPtr( srcDC, DC_MAGIC ))) return FALSE;
287 physDevDst = (X11DRV_PDEVICE *)dcDst->physDev;
288 physDevSrc = (X11DRV_PDEVICE *)dcSrc->physDev;
290 if (dcDst->w.flags & DC_DIRTY) CLIPPING_UpdateGCRegion( dcDst );
292 xSrc = dcSrc->w.DCOrgX + XLPTODP( dcSrc, xSrc );
293 ySrc = dcSrc->w.DCOrgY + YLPTODP( dcSrc, ySrc );
294 xDest = dcDst->w.DCOrgX + XLPTODP( dcDst, xDest );
295 yDest = dcDst->w.DCOrgY + YLPTODP( dcDst, yDest );
296 widDest = widDest * dcDst->vportExtX / dcDst->wndExtX;
297 heiDest = heiDest * dcDst->vportExtY / dcDst->wndExtY;
300 TSXSetFunction( display, physDevDst->gc, GXcopy );
301 TSXCopyArea( display, physDevSrc->drawable,
302 physDevDst->drawable, physDevDst->gc,
303 xSrc, ySrc, widDest, heiDest, xDest, yDest );