1 /* DIBSection DirectDrawSurface driver
3 * Copyright 1997-2000 Marcus Meissner
4 * Copyright 1998-2000 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/debug.h"
30 #include "ddraw_private.h"
31 #include "dsurface/main.h"
32 #include "dsurface/dib.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
36 static ICOM_VTABLE(IDirectDrawSurface7) DIB_IDirectDrawSurface7_VTable;
38 /* Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned. */
39 inline static int get_dib_width_bytes( int width, int depth )
45 case 1: words = (width + 31) / 32; break;
46 case 4: words = (width + 7) / 8; break;
47 case 8: words = (width + 3) / 4; break;
49 case 16: words = (width + 1) / 2; break;
50 case 24: words = (width * 3 + 3)/4; break;
52 WARN("(%d): Unsupported depth\n", depth );
54 case 32: words = width; break;
60 static HRESULT create_dib(IDirectDrawSurfaceImpl* This)
65 DIB_DirectDrawSurfaceImpl* priv = This->private;
67 assert(This->surface_desc.lpSurface != NULL);
69 switch (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount)
73 /* Allocate extra space to store the RGB bit masks. */
74 b_info = (BITMAPINFO*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
75 sizeof(BITMAPINFOHEADER)
80 b_info = (BITMAPINFO*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
81 sizeof(BITMAPINFOHEADER));
85 /* Allocate extra space for a palette. */
86 b_info = (BITMAPINFO*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
87 sizeof(BITMAPINFOHEADER)
89 * (1 << This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount));
93 b_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
94 b_info->bmiHeader.biWidth = This->surface_desc.dwWidth;
95 b_info->bmiHeader.biHeight = -This->surface_desc.dwHeight;
96 b_info->bmiHeader.biPlanes = 1;
97 b_info->bmiHeader.biBitCount = This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount;
99 if ((This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount != 16)
100 && (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount != 32))
101 b_info->bmiHeader.biCompression = BI_RGB;
103 b_info->bmiHeader.biCompression = BI_BITFIELDS;
105 b_info->bmiHeader.biSizeImage
106 = (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount / 8)
107 * This->surface_desc.dwWidth * This->surface_desc.dwHeight;
109 b_info->bmiHeader.biXPelsPerMeter = 0;
110 b_info->bmiHeader.biYPelsPerMeter = 0;
111 b_info->bmiHeader.biClrUsed = 0;
112 b_info->bmiHeader.biClrImportant = 0;
114 switch (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount)
119 DWORD *masks = (DWORD *) &(b_info->bmiColors);
122 masks[0] = This->surface_desc.u4.ddpfPixelFormat.u2.dwRBitMask;
123 masks[1] = This->surface_desc.u4.ddpfPixelFormat.u3.dwGBitMask;
124 masks[2] = This->surface_desc.u4.ddpfPixelFormat.u4.dwBBitMask;
130 usage = DIB_RGB_COLORS;
134 /* Don't know palette */
139 ddc = CreateDCA("DISPLAY", NULL, NULL, NULL);
142 HeapFree(GetProcessHeap(), 0, b_info);
143 return HRESULT_FROM_WIN32(GetLastError());
147 = DIB_CreateDIBSection(ddc, b_info, usage, &(priv->dib.bitmap_data), 0,
148 (DWORD)This->surface_desc.lpSurface,
149 This->surface_desc.u1.lPitch);
151 if (!priv->dib.DIBsection) {
152 ERR("CreateDIBSection failed!\n");
153 HeapFree(GetProcessHeap(), 0, b_info);
154 return HRESULT_FROM_WIN32(GetLastError());
157 TRACE("DIBSection at : %p\n", priv->dib.bitmap_data);
158 if (!This->surface_desc.u1.lPitch) {
159 /* This can't happen, right? */
160 /* or use GDI_GetObj to get it from the created DIB? */
161 This->surface_desc.u1.lPitch = get_dib_width_bytes(b_info->bmiHeader.biWidth, b_info->bmiHeader.biBitCount);
162 This->surface_desc.dwFlags |= DDSD_PITCH;
165 if (!This->surface_desc.lpSurface) {
166 This->surface_desc.lpSurface = priv->dib.bitmap_data;
167 This->surface_desc.dwFlags |= DDSD_LPSURFACE;
170 HeapFree(GetProcessHeap(), 0, b_info);
172 /* I don't think it's worth checking for this. */
173 if (priv->dib.bitmap_data != This->surface_desc.lpSurface)
174 ERR("unexpected error creating DirectDrawSurface DIB section\n");
176 /* this seems like a good place to put the handle for HAL driver use */
177 This->global_more.hKernelSurface = priv->dib.DIBsection;
182 void DIB_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
184 DIB_DirectDrawSurfaceImpl* priv = This->private;
186 DeleteObject(priv->dib.DIBsection);
188 if (!priv->dib.client_memory)
189 VirtualFree(This->surface_desc.lpSurface, 0, MEM_RELEASE);
191 Main_DirectDrawSurface_final_release(This);
194 HRESULT DIB_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,
195 LPDIRECTDRAWSURFACE7* ppDup)
197 return DIB_DirectDrawSurface_Create(This->ddraw_owner,
198 &This->surface_desc, ppDup, NULL);
201 HRESULT DIB_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
202 IDirectDrawImpl *pDD,
203 const DDSURFACEDESC2 *pDDSD)
206 DIB_DirectDrawSurfaceImpl* priv = This->private;
208 TRACE("(%p)->(%p,%p)\n",This,pDD,pDDSD);
209 hr = Main_DirectDrawSurface_Construct(This, pDD, pDDSD);
210 if (FAILED(hr)) return hr;
212 ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,
213 DIB_IDirectDrawSurface7_VTable);
215 This->final_release = DIB_DirectDrawSurface_final_release;
216 This->duplicate_surface = DIB_DirectDrawSurface_duplicate_surface;
217 This->flip_data = DIB_DirectDrawSurface_flip_data;
219 This->get_dc = DIB_DirectDrawSurface_get_dc;
220 This->release_dc = DIB_DirectDrawSurface_release_dc;
221 This->hDC = (HDC)NULL;
223 This->set_palette = DIB_DirectDrawSurface_set_palette;
224 This->update_palette = DIB_DirectDrawSurface_update_palette;
226 TRACE("(%ldx%ld, pitch=%ld)\n",
227 This->surface_desc.dwWidth, This->surface_desc.dwHeight,
228 This->surface_desc.u1.lPitch);
229 /* XXX load dwWidth and dwHeight from pDD if they are not specified? */
231 if (This->surface_desc.dwFlags & DDSD_LPSURFACE)
233 /* "Client memory": it is managed by the application. */
234 /* XXX What if lPitch is not set? Use dwWidth or fail? */
236 priv->dib.client_memory = TRUE;
240 if (!(This->surface_desc.dwFlags & DDSD_PITCH))
242 int pitch = This->surface_desc.u1.lPitch;
244 pitch += 8 - (pitch % 8);
246 /* XXX else: how should lPitch be verified? */
248 This->surface_desc.dwFlags |= DDSD_PITCH|DDSD_LPSURFACE;
250 This->surface_desc.lpSurface
251 = VirtualAlloc(NULL, This->surface_desc.u1.lPitch
252 * This->surface_desc.dwHeight,
253 MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
255 if (This->surface_desc.lpSurface == NULL)
257 Main_DirectDrawSurface_final_release(This);
258 return HRESULT_FROM_WIN32(GetLastError());
261 priv->dib.client_memory = FALSE;
264 hr = create_dib(This);
267 if (!priv->dib.client_memory)
268 VirtualFree(This->surface_desc.lpSurface, 0, MEM_RELEASE);
270 Main_DirectDrawSurface_final_release(This);
279 HRESULT DIB_DirectDrawSurface_Create(IDirectDrawImpl *pDD,
280 const DDSURFACEDESC2 *pDDSD,
281 LPDIRECTDRAWSURFACE7 *ppSurf,
284 IDirectDrawSurfaceImpl* This;
286 assert(pUnkOuter == NULL);
288 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
289 sizeof(*This) + sizeof(DIB_DirectDrawSurfaceImpl));
290 if (This == NULL) return E_OUTOFMEMORY;
292 This->private = (DIB_DirectDrawSurfaceImpl*)(This+1);
294 hr = DIB_DirectDrawSurface_Construct(This, pDD, pDDSD);
296 HeapFree(GetProcessHeap(), 0, This);
298 *ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);
304 /* AddAttachedSurface: generic */
305 /* AddOverlayDirtyRect: generic, unimplemented */
307 static HRESULT _Blt_ColorFill(
308 LPBYTE buf, int width, int height, int bpp, LONG lPitch, DWORD color
315 #define COLORFILL_ROW(type) { \
316 type *d = (type *) buf; \
317 for (x = 0; x < width; x++) \
318 d[x] = (type) color; \
323 case 1: COLORFILL_ROW(BYTE)
324 case 2: COLORFILL_ROW(WORD)
325 case 4: COLORFILL_ROW(DWORD)
327 FIXME("Color fill not implemented for bpp %d!\n", bpp*8);
328 return DDERR_UNSUPPORTED;
333 /* Now copy first row */
335 for (y = 1; y < height; y++) {
337 memcpy(buf, first, width * bpp);
343 DIB_DirectDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rdst,
344 LPDIRECTDRAWSURFACE7 src, LPRECT rsrc,
345 DWORD dwFlags, LPDDBLTFX lpbltfx)
347 ICOM_THIS(IDirectDrawSurfaceImpl,iface);
349 DDSURFACEDESC2 ddesc,sdesc;
351 int bpp, srcheight, srcwidth, dstheight, dstwidth, width;
355 TRACE("(%p)->(%p,%p,%p,%08lx,%p)\n", This,rdst,src,rsrc,dwFlags,lpbltfx);
357 DD_STRUCT_INIT(&ddesc);
358 DD_STRUCT_INIT(&sdesc);
360 sdesc.dwSize = sizeof(sdesc);
361 if (src) IDirectDrawSurface7_Lock(src, NULL, &sdesc, DDLOCK_READONLY, 0);
362 ddesc.dwSize = sizeof(ddesc);
363 IDirectDrawSurface7_Lock(iface,NULL,&ddesc,DDLOCK_WRITEONLY,0);
365 if (TRACE_ON(ddraw)) {
366 if (rdst) TRACE("\tdestrect :%dx%d-%dx%d\n",rdst->left,rdst->top,rdst->right,rdst->bottom);
367 if (rsrc) TRACE("\tsrcrect :%dx%d-%dx%d\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
369 DDRAW_dump_DDBLT(dwFlags);
370 if (dwFlags & DDBLT_DDFX) {
372 DDRAW_dump_DDBLTFX(lpbltfx->dwDDFX);
377 if ((rdst->top < 0) ||
379 (rdst->bottom < 0) ||
381 ERR(" Negative values in LPRECT !!!\n");
384 memcpy(&xdst,rdst,sizeof(xdst));
387 xdst.bottom = ddesc.dwHeight;
389 xdst.right = ddesc.dwWidth;
393 if ((rsrc->top < 0) ||
395 (rsrc->bottom < 0) ||
397 ERR(" Negative values in LPRECT !!!\n");
400 memcpy(&xsrc,rsrc,sizeof(xsrc));
404 xsrc.bottom = sdesc.dwHeight;
406 xsrc.right = sdesc.dwWidth;
408 memset(&xsrc,0,sizeof(xsrc));
411 if (src) assert((xsrc.bottom-xsrc.top) <= sdesc.dwHeight);
412 assert((xdst.bottom-xdst.top) <= ddesc.dwHeight);
414 bpp = GET_BPP(ddesc);
415 srcheight = xsrc.bottom - xsrc.top;
416 srcwidth = xsrc.right - xsrc.left;
417 dstheight = xdst.bottom - xdst.top;
418 dstwidth = xdst.right - xdst.left;
419 width = (xdst.right - xdst.left) * bpp;
421 assert(width <= ddesc.u1.lPitch);
423 dbuf = (BYTE*)ddesc.lpSurface+(xdst.top*ddesc.u1.lPitch)+(xdst.left*bpp);
425 if (dwFlags & (DDBLT_WAIT|DDBLT_ASYNC))
427 static BOOL displayed = FALSE;
430 FIXME("dwFlags DDBLT_WAIT and/or DDBLT_ASYNC: can't handle right now.\n");
433 dwFlags &= ~(DDBLT_WAIT|DDBLT_ASYNC);
436 /* First, all the 'source-less' blits */
437 if (dwFlags & DDBLT_COLORFILL) {
438 ret = _Blt_ColorFill(dbuf, dstwidth, dstheight, bpp,
439 ddesc.u1.lPitch, lpbltfx->u5.dwFillColor);
440 dwFlags &= ~DDBLT_COLORFILL;
443 if (dwFlags & DDBLT_DEPTHFILL)
444 FIXME("DDBLT_DEPTHFILL needs to be implemented!\n");
445 if (dwFlags & DDBLT_ROP) {
446 /* Catch some degenerate cases here */
447 switch(lpbltfx->dwROP) {
449 ret = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,ddesc.u1.lPitch,0);
451 case 0xAA0029: /* No-op */
454 ret = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,ddesc.u1.lPitch,~0);
456 case SRCCOPY: /* well, we do that below ? */
459 FIXME("Unsupported raster op: %08lx Pattern: %p\n", lpbltfx->dwROP, lpbltfx->u5.lpDDSPattern);
462 dwFlags &= ~DDBLT_ROP;
464 if (dwFlags & DDBLT_DDROPS) {
465 FIXME("\tDdraw Raster Ops: %08lx Pattern: %p\n", lpbltfx->dwDDROP, lpbltfx->u5.lpDDSPattern);
467 /* Now the 'with source' blits */
470 int sx, xinc, sy, yinc;
472 if (!dstwidth || !dstheight) /* hmm... stupid program ? */
474 sbase = (BYTE*)sdesc.lpSurface+(xsrc.top*sdesc.u1.lPitch)+xsrc.left*bpp;
475 xinc = (srcwidth << 16) / dstwidth;
476 yinc = (srcheight << 16) / dstheight;
479 /* No effects, we can cheat here */
480 if (dstwidth == srcwidth) {
481 if (dstheight == srcheight) {
482 /* No stretching in either direction. This needs to be as
483 * fast as possible */
485 for (y = 0; y < dstheight; y++) {
486 memcpy(dbuf, sbuf, width);
487 sbuf += sdesc.u1.lPitch;
488 dbuf += ddesc.u1.lPitch;
491 /* Stretching in Y direction only */
492 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
493 sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
494 memcpy(dbuf, sbuf, width);
495 dbuf += ddesc.u1.lPitch;
499 /* Stretching in X direction */
501 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
502 sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
504 if ((sy >> 16) == (last_sy >> 16)) {
505 /* this sourcerow is the same as last sourcerow -
506 * copy already stretched row
508 memcpy(dbuf, dbuf - ddesc.u1.lPitch, width);
510 #define STRETCH_ROW(type) { \
511 type *s = (type *) sbuf, *d = (type *) dbuf; \
512 for (x = sx = 0; x < dstwidth; x++, sx += xinc) \
513 d[x] = s[sx >> 16]; \
517 case 1: STRETCH_ROW(BYTE)
518 case 2: STRETCH_ROW(WORD)
519 case 4: STRETCH_ROW(DWORD)
522 for (x = sx = 0; x < dstwidth; x++, sx+= xinc) {
526 pixel = (s[0]<<16)|(s[1]<<8)|s[2];
527 d[0] = (pixel>>16)&0xff;
528 d[1] = (pixel>> 8)&0xff;
529 d[2] = (pixel )&0xff;
535 FIXME("Stretched blit not implemented for bpp %d!\n", bpp*8);
536 ret = DDERR_UNSUPPORTED;
541 dbuf += ddesc.u1.lPitch;
545 } else if (dwFlags & (DDBLT_KEYSRC | DDBLT_KEYDEST)) {
546 DWORD keylow, keyhigh;
548 if (dwFlags & DDBLT_KEYSRC) {
549 keylow = sdesc.ddckCKSrcBlt.dwColorSpaceLowValue;
550 keyhigh = sdesc.ddckCKSrcBlt.dwColorSpaceHighValue;
552 /* I'm not sure if this is correct */
553 FIXME("DDBLT_KEYDEST not fully supported yet.\n");
554 keylow = ddesc.ddckCKDestBlt.dwColorSpaceLowValue;
555 keyhigh = ddesc.ddckCKDestBlt.dwColorSpaceHighValue;
559 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
560 sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
562 #define COPYROW_COLORKEY(type) { \
563 type *s = (type *) sbuf, *d = (type *) dbuf, tmp; \
564 for (x = sx = 0; x < dstwidth; x++, sx += xinc) { \
566 if (tmp < keylow || tmp > keyhigh) d[x] = tmp; \
571 case 1: COPYROW_COLORKEY(BYTE)
572 case 2: COPYROW_COLORKEY(WORD)
573 case 4: COPYROW_COLORKEY(DWORD)
575 FIXME("%s color-keyed blit not implemented for bpp %d!\n",
576 (dwFlags & DDBLT_KEYSRC) ? "Source" : "Destination", bpp*8);
577 ret = DDERR_UNSUPPORTED;
580 dbuf += ddesc.u1.lPitch;
582 #undef COPYROW_COLORKEY
583 dwFlags &= ~(DDBLT_KEYSRC | DDBLT_KEYDEST);
588 if (dwFlags && FIXME_ON(ddraw)) {
589 FIXME("\tUnsupported flags: ");
590 DDRAW_dump_DDBLT(dwFlags);
594 IDirectDrawSurface7_Unlock(iface,NULL);
595 if (src) IDirectDrawSurface7_Unlock(src,NULL);
599 /* BltBatch: generic, unimplemented */
602 DIB_DirectDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface, DWORD dstx,
603 DWORD dsty, LPDIRECTDRAWSURFACE7 src,
604 LPRECT rsrc, DWORD trans)
606 ICOM_THIS(IDirectDrawSurfaceImpl,iface);
608 DDSURFACEDESC2 ddesc,sdesc;
614 if (TRACE_ON(ddraw)) {
615 FIXME("(%p)->(%ld,%ld,%p,%p,%08lx)\n",
616 This,dstx,dsty,src,rsrc,trans
620 DDRAW_dump_DDBLTFAST(trans);
622 FIXME("\tsrcrect: %dx%d-%dx%d\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
624 FIXME(" srcrect: NULL\n");
627 /* We need to lock the surfaces, or we won't get refreshes when done. */
628 sdesc.dwSize = sizeof(sdesc);
629 IDirectDrawSurface7_Lock(src, NULL,&sdesc,DDLOCK_READONLY, 0);
630 ddesc.dwSize = sizeof(ddesc);
631 IDirectDrawSurface7_Lock(iface,NULL,&ddesc,DDLOCK_WRITEONLY,0);
634 WARN("rsrc is NULL!\n");
636 rsrc->left = rsrc->top = 0;
637 rsrc->right = sdesc.dwWidth;
638 rsrc->bottom = sdesc.dwHeight;
641 bpp = GET_BPP(This->surface_desc);
642 sbuf = (BYTE *)sdesc.lpSurface+(rsrc->top*sdesc.u1.lPitch)+rsrc->left*bpp;
643 dbuf = (BYTE *)ddesc.lpSurface+(dsty*ddesc.u1.lPitch)+dstx* bpp;
646 h=rsrc->bottom-rsrc->top;
647 if (h>ddesc.dwHeight-dsty) h=ddesc.dwHeight-dsty;
648 if (h>sdesc.dwHeight-rsrc->top) h=sdesc.dwHeight-rsrc->top;
651 w=rsrc->right-rsrc->left;
652 if (w>ddesc.dwWidth-dstx) w=ddesc.dwWidth-dstx;
653 if (w>sdesc.dwWidth-rsrc->left) w=sdesc.dwWidth-rsrc->left;
656 if (trans & (DDBLTFAST_SRCCOLORKEY | DDBLTFAST_DESTCOLORKEY)) {
657 DWORD keylow, keyhigh;
658 if (trans & DDBLTFAST_SRCCOLORKEY) {
659 keylow = sdesc.ddckCKSrcBlt.dwColorSpaceLowValue;
660 keyhigh = sdesc.ddckCKSrcBlt.dwColorSpaceHighValue;
662 /* I'm not sure if this is correct */
663 FIXME("DDBLTFAST_DESTCOLORKEY not fully supported yet.\n");
664 keylow = ddesc.ddckCKDestBlt.dwColorSpaceLowValue;
665 keyhigh = ddesc.ddckCKDestBlt.dwColorSpaceHighValue;
668 #define COPYBOX_COLORKEY(type) { \
669 type *d = (type *)dbuf, *s = (type *)sbuf, tmp; \
670 s = (type *) ((BYTE *) sdesc.lpSurface + (rsrc->top * sdesc.u1.lPitch) + rsrc->left * bpp); \
671 d = (type *) ((BYTE *) ddesc.lpSurface + (dsty * ddesc.u1.lPitch) + dstx * bpp); \
672 for (y = 0; y < h; y++) { \
673 for (x = 0; x < w; x++) { \
675 if (tmp < keylow || tmp > keyhigh) d[x] = tmp; \
677 (LPBYTE)s += sdesc.u1.lPitch; \
678 (LPBYTE)d += ddesc.u1.lPitch; \
684 case 1: COPYBOX_COLORKEY(BYTE)
685 case 2: COPYBOX_COLORKEY(WORD)
686 case 4: COPYBOX_COLORKEY(DWORD)
688 FIXME("Source color key blitting not supported for bpp %d\n",bpp*8);
689 ret = DDERR_UNSUPPORTED;
692 #undef COPYBOX_COLORKEY
696 for (y = 0; y < h; y++) {
697 memcpy(dbuf, sbuf, width);
698 sbuf += sdesc.u1.lPitch;
699 dbuf += ddesc.u1.lPitch;
703 IDirectDrawSurface7_Unlock(iface, NULL);
704 IDirectDrawSurface7_Unlock(src, NULL);
708 /* ChangeUniquenessValue: generic */
709 /* DeleteAttachedSurface: generic */
710 /* EnumAttachedSurfaces: generic */
711 /* EnumOverlayZOrders: generic, unimplemented */
713 BOOL DIB_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl* front,
714 IDirectDrawSurfaceImpl* back,
717 DIB_DirectDrawSurfaceImpl* front_priv = front->private;
718 DIB_DirectDrawSurfaceImpl* back_priv = back->private;
720 TRACE("(%p,%p)\n",front,back);
724 tmp = front_priv->dib.DIBsection;
725 front_priv->dib.DIBsection = back_priv->dib.DIBsection;
726 back_priv->dib.DIBsection = tmp;
731 tmp = front_priv->dib.bitmap_data;
732 front_priv->dib.bitmap_data = back_priv->dib.bitmap_data;
733 back_priv->dib.bitmap_data = tmp;
735 tmp = front->surface_desc.lpSurface;
736 front->surface_desc.lpSurface = back->surface_desc.lpSurface;
737 back->surface_desc.lpSurface = tmp;
740 /* client_memory should not be different, but just in case */
743 tmp = front_priv->dib.client_memory;
744 front_priv->dib.client_memory = back_priv->dib.client_memory;
745 back_priv->dib.client_memory = tmp;
748 return Main_DirectDrawSurface_flip_data(front, back, dwFlags);
752 /* FreePrivateData: generic */
753 /* GetAttachedSurface: generic */
754 /* GetBltStatus: generic */
755 /* GetCaps: generic (Returns the caps from This->surface_desc.) */
756 /* GetClipper: generic */
757 /* GetColorKey: generic */
759 HRESULT DIB_DirectDrawSurface_alloc_dc(IDirectDrawSurfaceImpl* This, HDC* phDC)
761 DIB_PRIV_VAR(priv, This);
764 TRACE("Grabbing a DC for surface: %p\n", This);
766 hDC = CreateCompatibleDC(0);
767 priv->dib.holdbitmap = SelectObject(hDC, priv->dib.DIBsection);
769 SelectPalette(hDC, This->palette->hpal, FALSE);
776 HRESULT DIB_DirectDrawSurface_free_dc(IDirectDrawSurfaceImpl* This, HDC hDC)
778 DIB_PRIV_VAR(priv, This);
780 TRACE("Releasing DC for surface: %p\n", This);
782 SelectObject(hDC, priv->dib.holdbitmap);
788 HRESULT DIB_DirectDrawSurface_get_dc(IDirectDrawSurfaceImpl* This, HDC* phDC)
790 return DIB_DirectDrawSurface_alloc_dc(This, phDC);
793 HRESULT DIB_DirectDrawSurface_release_dc(IDirectDrawSurfaceImpl* This, HDC hDC)
795 return DIB_DirectDrawSurface_free_dc(This, hDC);
798 /* GetDDInterface: generic */
799 /* GetFlipStatus: generic */
800 /* GetLOD: generic */
801 /* GetOverlayPosition: generic */
802 /* GetPalette: generic */
803 /* GetPixelFormat: generic */
804 /* GetPriority: generic */
805 /* GetPrivateData: generic */
806 /* GetSurfaceDesc: generic */
807 /* GetUniquenessValue: generic */
808 /* Initialize: generic */
809 /* IsLost: generic */
810 /* Lock: generic with callback? */
811 /* PageLock: generic */
812 /* PageUnlock: generic */
815 DIB_DirectDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface)
817 TRACE("(%p)\n",iface);
818 return DD_OK; /* ??? */
821 /* SetClipper: generic */
822 /* SetColorKey: generic */
823 /* SetLOD: generic */
824 /* SetOverlayPosition: generic */
826 void DIB_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl* This,
827 IDirectDrawPaletteImpl* pal)
830 if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
831 This->update_palette(This, pal,
832 0, pal->palNumEntries,
836 void DIB_DirectDrawSurface_update_palette(IDirectDrawSurfaceImpl* This,
837 IDirectDrawPaletteImpl* pal,
838 DWORD dwStart, DWORD dwCount,
839 LPPALETTEENTRY palent)
845 TRACE("updating primary palette\n");
846 for (n=0; n<dwCount; n++) {
847 col[n].rgbRed = palent[n].peRed;
848 col[n].rgbGreen = palent[n].peGreen;
849 col[n].rgbBlue = palent[n].peBlue;
850 col[n].rgbReserved = 0;
852 This->get_dc(This, &dc);
853 SetDIBColorTable(dc, dwStart, dwCount, col);
854 This->release_dc(This, dc);
856 /* Propagate change to backbuffers if there are any */
857 /* Basically this is a modification of the Flip code to find the backbuffer */
858 /* and duplicate the palette update there as well */
859 if ((This->surface_desc.ddsCaps.dwCaps&(DDSCAPS_FLIP|DDSCAPS_FRONTBUFFER))
860 == (DDSCAPS_FLIP|DDSCAPS_FRONTBUFFER))
862 static DDSCAPS2 back_caps = { DDSCAPS_BACKBUFFER };
863 LPDIRECTDRAWSURFACE7 tgt;
865 HRESULT hr = IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This,IDirectDrawSurface7),
869 IDirectDrawSurfaceImpl* target = ICOM_OBJECT(IDirectDrawSurfaceImpl,
870 IDirectDrawSurface7,tgt);
871 IDirectDrawSurface7_Release(tgt);
872 target->get_dc(target, &dc);
873 SetDIBColorTable(dc, dwStart, dwCount, col);
874 target->release_dc(target, dc);
879 /* SetPalette: generic */
880 /* SetPriority: generic */
881 /* SetPrivateData: generic */
884 DIB_DirectDrawSurface_SetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
885 LPDDSURFACEDESC2 pDDSD, DWORD dwFlags)
887 ICOM_THIS(IDirectDrawSurfaceImpl,iface);
888 DIB_PRIV_VAR(priv, This);
891 TRACE("(%p)->(%p,%08lx)\n",iface,pDDSD,dwFlags);
892 if (pDDSD->dwFlags == DDSD_LPSURFACE) {
893 HBITMAP oldbmp = priv->dib.DIBsection;
894 LPVOID oldsurf = This->surface_desc.lpSurface;
895 BOOL oldc = priv->dib.client_memory;
897 TRACE("new lpSurface=%p\n",pDDSD->lpSurface);
898 This->surface_desc.lpSurface = pDDSD->lpSurface;
899 priv->dib.client_memory = TRUE;
901 hr = create_dib(This);
904 priv->dib.DIBsection = oldbmp;
905 This->surface_desc.lpSurface = oldsurf;
906 priv->dib.client_memory = oldc;
910 DeleteObject(oldbmp);
913 VirtualFree(oldsurf, 0, MEM_RELEASE);
918 FIXME("flags=%08lx\n",pDDSD->dwFlags);
925 /* Unlock: ???, need callback */
926 /* UpdateOverlay: generic */
927 /* UpdateOverlayDisplay: generic */
928 /* UpdateOverlayZOrder: generic */
930 static ICOM_VTABLE(IDirectDrawSurface7) DIB_IDirectDrawSurface7_VTable =
932 Main_DirectDrawSurface_QueryInterface,
933 Main_DirectDrawSurface_AddRef,
934 Main_DirectDrawSurface_Release,
935 Main_DirectDrawSurface_AddAttachedSurface,
936 Main_DirectDrawSurface_AddOverlayDirtyRect,
937 DIB_DirectDrawSurface_Blt,
938 Main_DirectDrawSurface_BltBatch,
939 DIB_DirectDrawSurface_BltFast,
940 Main_DirectDrawSurface_DeleteAttachedSurface,
941 Main_DirectDrawSurface_EnumAttachedSurfaces,
942 Main_DirectDrawSurface_EnumOverlayZOrders,
943 Main_DirectDrawSurface_Flip,
944 Main_DirectDrawSurface_GetAttachedSurface,
945 Main_DirectDrawSurface_GetBltStatus,
946 Main_DirectDrawSurface_GetCaps,
947 Main_DirectDrawSurface_GetClipper,
948 Main_DirectDrawSurface_GetColorKey,
949 Main_DirectDrawSurface_GetDC,
950 Main_DirectDrawSurface_GetFlipStatus,
951 Main_DirectDrawSurface_GetOverlayPosition,
952 Main_DirectDrawSurface_GetPalette,
953 Main_DirectDrawSurface_GetPixelFormat,
954 Main_DirectDrawSurface_GetSurfaceDesc,
955 Main_DirectDrawSurface_Initialize,
956 Main_DirectDrawSurface_IsLost,
957 Main_DirectDrawSurface_Lock,
958 Main_DirectDrawSurface_ReleaseDC,
959 DIB_DirectDrawSurface_Restore,
960 Main_DirectDrawSurface_SetClipper,
961 Main_DirectDrawSurface_SetColorKey,
962 Main_DirectDrawSurface_SetOverlayPosition,
963 Main_DirectDrawSurface_SetPalette,
964 Main_DirectDrawSurface_Unlock,
965 Main_DirectDrawSurface_UpdateOverlay,
966 Main_DirectDrawSurface_UpdateOverlayDisplay,
967 Main_DirectDrawSurface_UpdateOverlayZOrder,
968 Main_DirectDrawSurface_GetDDInterface,
969 Main_DirectDrawSurface_PageLock,
970 Main_DirectDrawSurface_PageUnlock,
971 DIB_DirectDrawSurface_SetSurfaceDesc,
972 Main_DirectDrawSurface_SetPrivateData,
973 Main_DirectDrawSurface_GetPrivateData,
974 Main_DirectDrawSurface_FreePrivateData,
975 Main_DirectDrawSurface_GetUniquenessValue,
976 Main_DirectDrawSurface_ChangeUniquenessValue,
977 Main_DirectDrawSurface_SetPriority,
978 Main_DirectDrawSurface_GetPriority,
979 Main_DirectDrawSurface_SetLOD,
980 Main_DirectDrawSurface_GetLOD