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
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
35 #include "ddraw_private.h"
36 #include "d3d_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
41 extern HBITMAP DIB_CreateDIBSection( HDC hdc, const BITMAPINFO *bmi, UINT usage, VOID **bits,
42 HANDLE section, DWORD offset, DWORD ovr_pitch );
44 static const IDirectDrawSurface7Vtbl DIB_IDirectDrawSurface7_VTable;
46 /* Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned. */
47 inline static int get_dib_width_bytes( int width, int depth )
53 case 1: words = (width + 31) / 32; break;
54 case 4: words = (width + 7) / 8; break;
55 case 8: words = (width + 3) / 4; break;
57 case 16: words = (width + 1) / 2; break;
58 case 24: words = (width * 3 + 3)/4; break;
60 WARN("(%d): Unsupported depth\n", depth );
62 case 32: words = width; break;
68 static HRESULT create_dib(IDirectDrawSurfaceImpl* This)
73 DIB_DirectDrawSurfaceImpl* priv = This->private;
75 assert(This->surface_desc.lpSurface != NULL);
77 switch (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount)
81 /* Allocate extra space to store the RGB bit masks. */
82 b_info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
83 sizeof(BITMAPINFOHEADER) + 3 * sizeof(DWORD));
87 b_info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
88 sizeof(BITMAPINFOHEADER));
92 /* Allocate extra space for a palette. */
93 b_info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
94 sizeof(BITMAPINFOHEADER)
96 * (1 << This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount));
100 b_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
101 b_info->bmiHeader.biWidth = This->surface_desc.dwWidth;
102 b_info->bmiHeader.biHeight = -This->surface_desc.dwHeight;
103 b_info->bmiHeader.biPlanes = 1;
104 b_info->bmiHeader.biBitCount = This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount;
106 if ((This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount != 16)
107 && (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount != 32))
108 b_info->bmiHeader.biCompression = BI_RGB;
110 b_info->bmiHeader.biCompression = BI_BITFIELDS;
112 b_info->bmiHeader.biSizeImage
113 = (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount / 8)
114 * This->surface_desc.dwWidth * This->surface_desc.dwHeight;
116 b_info->bmiHeader.biXPelsPerMeter = 0;
117 b_info->bmiHeader.biYPelsPerMeter = 0;
118 b_info->bmiHeader.biClrUsed = 0;
119 b_info->bmiHeader.biClrImportant = 0;
121 if (!This->surface_desc.u1.lPitch) {
122 /* This can't happen, right? */
123 /* or use GDI_GetObj to get it from the created DIB? */
124 This->surface_desc.u1.lPitch = get_dib_width_bytes(b_info->bmiHeader.biWidth, b_info->bmiHeader.biBitCount);
125 This->surface_desc.dwFlags |= DDSD_PITCH;
128 switch (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount)
133 DWORD *masks = (DWORD *) &(b_info->bmiColors);
136 masks[0] = This->surface_desc.u4.ddpfPixelFormat.u2.dwRBitMask;
137 masks[1] = This->surface_desc.u4.ddpfPixelFormat.u3.dwGBitMask;
138 masks[2] = This->surface_desc.u4.ddpfPixelFormat.u4.dwBBitMask;
144 usage = DIB_RGB_COLORS;
148 /* Don't know palette */
153 ddc = CreateDCA("DISPLAY", NULL, NULL, NULL);
156 HeapFree(GetProcessHeap(), 0, b_info);
157 return HRESULT_FROM_WIN32(GetLastError());
161 = DIB_CreateDIBSection(ddc, b_info, usage, &(priv->dib.bitmap_data), 0,
162 (DWORD)This->surface_desc.lpSurface,
163 This->surface_desc.u1.lPitch);
165 if (!priv->dib.DIBsection) {
166 ERR("CreateDIBSection failed!\n");
167 HeapFree(GetProcessHeap(), 0, b_info);
168 return HRESULT_FROM_WIN32(GetLastError());
171 TRACE("DIBSection at : %p\n", priv->dib.bitmap_data);
173 if (!This->surface_desc.lpSurface) {
174 This->surface_desc.lpSurface = priv->dib.bitmap_data;
175 This->surface_desc.dwFlags |= DDSD_LPSURFACE;
178 HeapFree(GetProcessHeap(), 0, b_info);
180 /* I don't think it's worth checking for this. */
181 if (priv->dib.bitmap_data != This->surface_desc.lpSurface)
182 ERR("unexpected error creating DirectDrawSurface DIB section\n");
184 /* this seems like a good place to put the handle for HAL driver use */
185 This->global_more.hKernelSurface = (ULONG_PTR)priv->dib.DIBsection;
190 void DIB_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
192 DIB_DirectDrawSurfaceImpl* priv = This->private;
194 DeleteObject(priv->dib.DIBsection);
196 if (!priv->dib.client_memory)
197 VirtualFree(This->surface_desc.lpSurface, 0, MEM_RELEASE);
199 Main_DirectDrawSurface_final_release(This);
202 HRESULT DIB_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,
203 LPDIRECTDRAWSURFACE7* ppDup)
205 return DIB_DirectDrawSurface_Create(This->ddraw_owner,
206 &This->surface_desc, ppDup, NULL);
209 HRESULT DIB_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
210 IDirectDrawImpl *pDD,
211 const DDSURFACEDESC2 *pDDSD)
214 DIB_DirectDrawSurfaceImpl* priv = This->private;
216 TRACE("(%p)->(%p,%p)\n",This,pDD,pDDSD);
217 hr = Main_DirectDrawSurface_Construct(This, pDD, pDDSD);
218 if (FAILED(hr)) return hr;
220 ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,
221 DIB_IDirectDrawSurface7_VTable);
223 This->final_release = DIB_DirectDrawSurface_final_release;
224 This->duplicate_surface = DIB_DirectDrawSurface_duplicate_surface;
225 This->flip_data = DIB_DirectDrawSurface_flip_data;
227 This->get_dc = DIB_DirectDrawSurface_get_dc;
228 This->release_dc = DIB_DirectDrawSurface_release_dc;
231 This->set_palette = DIB_DirectDrawSurface_set_palette;
232 This->update_palette = DIB_DirectDrawSurface_update_palette;
234 TRACE("(%ldx%ld, pitch=%ld)\n",
235 This->surface_desc.dwWidth, This->surface_desc.dwHeight,
236 This->surface_desc.u1.lPitch);
237 /* XXX load dwWidth and dwHeight from pDD if they are not specified? */
239 if (This->surface_desc.dwFlags & DDSD_LPSURFACE)
241 /* "Client memory": it is managed by the application. */
242 /* XXX What if lPitch is not set? Use dwWidth or fail? */
244 priv->dib.client_memory = TRUE;
248 if (!(This->surface_desc.dwFlags & DDSD_PITCH))
250 int pitch = This->surface_desc.u1.lPitch;
252 pitch += 8 - (pitch % 8);
254 /* XXX else: how should lPitch be verified? */
256 This->surface_desc.dwFlags |= DDSD_LPSURFACE;
258 /* Ensure that DDSD_PITCH is respected for DDPF_FOURCC surfaces too */
259 if (This->surface_desc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC && !(This->surface_desc.dwFlags & DDSD_PITCH)) {
260 This->surface_desc.lpSurface
261 = VirtualAlloc(NULL, This->surface_desc.u1.dwLinearSize, MEM_COMMIT, PAGE_READWRITE);
262 This->surface_desc.dwFlags |= DDSD_LINEARSIZE;
264 This->surface_desc.lpSurface
265 = VirtualAlloc(NULL, This->surface_desc.u1.lPitch
266 * This->surface_desc.dwHeight + 4, /* The + 4 here is for dumb games reading after the end of the surface
267 when reading the last byte / half using word access */
268 MEM_COMMIT, PAGE_READWRITE);
269 This->surface_desc.dwFlags |= DDSD_PITCH;
272 if (This->surface_desc.lpSurface == NULL)
274 Main_DirectDrawSurface_final_release(This);
275 return HRESULT_FROM_WIN32(GetLastError());
278 priv->dib.client_memory = FALSE;
281 hr = create_dib(This);
284 if (!priv->dib.client_memory)
285 VirtualFree(This->surface_desc.lpSurface, 0, MEM_RELEASE);
287 Main_DirectDrawSurface_final_release(This);
296 HRESULT DIB_DirectDrawSurface_Create(IDirectDrawImpl *pDD,
297 const DDSURFACEDESC2 *pDDSD,
298 LPDIRECTDRAWSURFACE7 *ppSurf,
301 IDirectDrawSurfaceImpl* This;
303 assert(pUnkOuter == NULL);
305 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
306 sizeof(*This) + sizeof(DIB_DirectDrawSurfaceImpl));
307 if (This == NULL) return E_OUTOFMEMORY;
309 This->private = (DIB_DirectDrawSurfaceImpl*)(This+1);
311 hr = DIB_DirectDrawSurface_Construct(This, pDD, pDDSD);
313 HeapFree(GetProcessHeap(), 0, This);
315 *ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);
321 /* AddAttachedSurface: generic */
322 /* AddOverlayDirtyRect: generic, unimplemented */
324 static HRESULT _Blt_ColorFill(
325 LPBYTE buf, int width, int height, int bpp, LONG lPitch, DWORD color
332 #define COLORFILL_ROW(type) { \
333 type *d = (type *) buf; \
334 for (x = 0; x < width; x++) \
335 d[x] = (type) color; \
340 case 1: COLORFILL_ROW(BYTE)
341 case 2: COLORFILL_ROW(WORD)
342 case 3: { BYTE *d = (BYTE *) buf;
343 for (x = 0; x < width; x++,d+=3) {
344 d[0] = (color ) & 0xFF;
345 d[1] = (color>> 8) & 0xFF;
346 d[2] = (color>>16) & 0xFF;
349 case 4: COLORFILL_ROW(DWORD)
351 FIXME("Color fill not implemented for bpp %d!\n", bpp*8);
352 return DDERR_UNSUPPORTED;
357 /* Now copy first row */
359 for (y = 1; y < height; y++) {
361 memcpy(buf, first, width * bpp);
366 static void ComputeShifts(DWORD mask, DWORD* lshift, DWORD* rshift)
376 while(!(mask & (1 << pos)))
379 while(mask & (1 << (pos+bits)))
386 /* This is used to factorize the decompression between the Blt and BltFast code */
387 static void DoDXTCDecompression(const DDSURFACEDESC2 *sdesc, const DDSURFACEDESC2 *ddesc)
394 if (!s3tc_initialized) {
395 /* FIXME: We may fake this by rendering the texture into the framebuffer using OpenGL functions and reading back
396 * the framebuffer. This will be slow and somewhat ugly. */
397 FIXME("Manual S3TC decompression is not supported in native mode\n");
401 rm = ddesc->u4.ddpfPixelFormat.u2.dwRBitMask;
402 ComputeShifts(rm, &rs, &rb);
403 gm = ddesc->u4.ddpfPixelFormat.u3.dwGBitMask;
404 ComputeShifts(gm, &gs, &gb);
405 bm = ddesc->u4.ddpfPixelFormat.u4.dwBBitMask;
406 ComputeShifts(bm, &bs, &bb);
407 am = ddesc->u4.ddpfPixelFormat.u5.dwRGBAlphaBitMask;
408 ComputeShifts(am, &as, &ab);
409 if (sdesc->u4.ddpfPixelFormat.dwFourCC == MAKE_FOURCC('D','X','T','1')) {
410 int is16 = ddesc->u4.ddpfPixelFormat.u1.dwRGBBitCount == 16;
411 int pitch = ddesc->u1.lPitch;
412 int width = ddesc->dwWidth;
413 int height = ddesc->dwHeight;
415 char* dst = (char*) ddesc->lpSurface;
416 char* src = (char*) sdesc->lpSurface;
417 for (x = 0; x < width; x++)
418 for (y =0; y < height; y++) {
421 (*fetch_2d_texel_rgba_dxt1)(width, src, x, y, data);
423 pixel |= ((data[0] >> rb) << rs) & rm;
424 pixel |= ((data[1] >> gb) << gs) & gm;
425 pixel |= ((data[2] >> bb) << bs) & bm;
426 pixel |= ((data[3] >> ab) << as) & am;
428 *((WORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
430 *((DWORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
432 } else if (sdesc->u4.ddpfPixelFormat.dwFourCC == MAKE_FOURCC('D','X','T','3')) {
433 int is16 = ddesc->u4.ddpfPixelFormat.u1.dwRGBBitCount == 16;
434 int pitch = ddesc->u1.lPitch;
435 int width = ddesc->dwWidth;
436 int height = ddesc->dwHeight;
438 char* dst = (char*) ddesc->lpSurface;
439 char* src = (char*) sdesc->lpSurface;
440 for (x = 0; x < width; x++)
441 for (y =0; y < height; y++) {
444 (*fetch_2d_texel_rgba_dxt3)(width, src, x, y, data);
446 pixel |= ((data[0] >> rb) << rs) & rm;
447 pixel |= ((data[1] >> gb) << gs) & gm;
448 pixel |= ((data[2] >> bb) << bs) & bm;
449 pixel |= ((data[3] >> ab) << as) & am;
451 *((WORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
453 *((DWORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
455 } else if (sdesc->u4.ddpfPixelFormat.dwFourCC == MAKE_FOURCC('D','X','T','5')) {
456 int is16 = ddesc->u4.ddpfPixelFormat.u1.dwRGBBitCount == 16;
457 int pitch = ddesc->u1.lPitch;
458 int width = ddesc->dwWidth;
459 int height = ddesc->dwHeight;
461 char* dst = (char*) ddesc->lpSurface;
462 char* src = (char*) sdesc->lpSurface;
463 for (x = 0; x < width; x++)
464 for (y =0; y < height; y++) {
467 (*fetch_2d_texel_rgba_dxt5)(width, src, x, y, data);
469 pixel |= ((data[0] >> rb) << rs) & rm;
470 pixel |= ((data[1] >> gb) << gs) & gm;
471 pixel |= ((data[2] >> bb) << bs) & bm;
472 pixel |= ((data[3] >> ab) << as) & am;
474 *((WORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
476 *((DWORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
479 #if 0 /* Usefull for debugging */
484 sprintf(texname, "dxt_%d.pnm", idx++);
485 f = fopen(texname,"w");
486 DDRAW_dump_surface_to_disk(This, f, 1);
493 DIB_DirectDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rdst,
494 LPDIRECTDRAWSURFACE7 src, LPRECT rsrc,
495 DWORD dwFlags, LPDDBLTFX lpbltfx)
497 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
499 DDSURFACEDESC2 ddesc,sdesc;
501 int bpp, srcheight, srcwidth, dstheight, dstwidth, width;
505 TRACE("(%p)->(%p,%p,%p,%08lx,%p)\n", This,rdst,src,rsrc,dwFlags,lpbltfx);
507 if (TRACE_ON(ddraw)) {
508 if (rdst) TRACE("\tdestrect :%ldx%ld-%ldx%ld\n",rdst->left,rdst->top,rdst->right,rdst->bottom);
509 if (rsrc) TRACE("\tsrcrect :%ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
511 DDRAW_dump_DDBLT(dwFlags);
512 if (dwFlags & DDBLT_DDFX) {
514 DDRAW_dump_DDBLTFX(lpbltfx->dwDDFX);
518 if ((This->locked) || ((src != NULL) && (((IDirectDrawSurfaceImpl *)src)->locked))) {
519 WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
520 return DDERR_SURFACEBUSY;
523 /* First, check if the possible override function handles this case */
524 if (This->aux_blt != NULL) {
525 if (This->aux_blt(This, rdst, src, rsrc, dwFlags, lpbltfx) == DD_OK) return DD_OK;
528 DD_STRUCT_INIT(&ddesc);
529 DD_STRUCT_INIT(&sdesc);
531 sdesc.dwSize = sizeof(sdesc);
532 ddesc.dwSize = sizeof(ddesc);
535 IDirectDrawSurface7_Lock(iface, NULL, &ddesc, 0, 0);
536 DD_STRUCT_COPY_BYSIZE(&sdesc, &ddesc);
538 if (src) IDirectDrawSurface7_Lock(src, NULL, &sdesc, DDLOCK_READONLY, 0);
539 IDirectDrawSurface7_Lock(iface,NULL,&ddesc,DDLOCK_WRITEONLY,0);
542 if ((sdesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) &&
543 (ddesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC)) {
544 if (sdesc.u4.ddpfPixelFormat.dwFourCC != sdesc.u4.ddpfPixelFormat.dwFourCC) {
545 FIXME("FOURCC->FOURCC copy only supported for the same type of surface\n");
546 ret = DDERR_INVALIDPIXELFORMAT;
549 memcpy(ddesc.lpSurface, sdesc.lpSurface, ddesc.u1.dwLinearSize);
553 if ((sdesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) &&
554 (!(ddesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC))) {
555 DoDXTCDecompression(&sdesc, &ddesc);
560 memcpy(&xdst,rdst,sizeof(xdst));
563 xdst.bottom = ddesc.dwHeight;
565 xdst.right = ddesc.dwWidth;
569 memcpy(&xsrc,rsrc,sizeof(xsrc));
573 xsrc.bottom = sdesc.dwHeight;
575 xsrc.right = sdesc.dwWidth;
577 memset(&xsrc,0,sizeof(xsrc));
581 /* First check for the validity of source / destination rectangles. This was
582 verified using a test application + by MSDN.
585 ((xsrc.bottom > sdesc.dwHeight) || (xsrc.bottom < 0) ||
586 (xsrc.top > sdesc.dwHeight) || (xsrc.top < 0) ||
587 (xsrc.left > sdesc.dwWidth) || (xsrc.left < 0) ||
588 (xsrc.right > sdesc.dwWidth) || (xsrc.right < 0) ||
589 (xsrc.right < xsrc.left) || (xsrc.bottom < xsrc.top))) {
590 WARN("Application gave us bad source rectangle for Blt.\n");
591 ret = DDERR_INVALIDRECT;
594 /* For the Destination rect, it can be out of bounds on the condition that a clipper
595 is set for the given surface.
597 if ((This->clipper == NULL) &&
598 ((xdst.bottom > ddesc.dwHeight) || (xdst.bottom < 0) ||
599 (xdst.top > ddesc.dwHeight) || (xdst.top < 0) ||
600 (xdst.left > ddesc.dwWidth) || (xdst.left < 0) ||
601 (xdst.right > ddesc.dwWidth) || (xdst.right < 0) ||
602 (xdst.right < xdst.left) || (xdst.bottom < xdst.top))) {
603 WARN("Application gave us bad destination rectangle for Blt without a clipper set.\n");
604 ret = DDERR_INVALIDRECT;
608 /* Now handle negative values in the rectangles. Warning: only supported for now
609 in the 'simple' cases (ie not in any stretching / rotation cases).
611 First, the case where nothing is to be done.
613 if (((xdst.bottom <= 0) || (xdst.right <= 0) || (xdst.top >= (int) ddesc.dwHeight) || (xdst.left >= (int) ddesc.dwWidth)) ||
615 ((xsrc.bottom <= 0) || (xsrc.right <= 0) || (xsrc.top >= (int) sdesc.dwHeight) || (xsrc.left >= (int) sdesc.dwWidth))))
617 TRACE("Nothing to be done !\n");
621 /* The easy case : the source-less blits.... */
624 RECT temp_rect; /* No idea if intersect rect can be the same as one of the source rect */
628 full_rect.right = ddesc.dwWidth;
629 full_rect.bottom = ddesc.dwHeight;
630 IntersectRect(&temp_rect, &full_rect, &xdst);
633 /* Only handle clipping on the destination rectangle */
634 int clip_horiz = (xdst.left < 0) || (xdst.right > (int) ddesc.dwWidth );
635 int clip_vert = (xdst.top < 0) || (xdst.bottom > (int) ddesc.dwHeight);
636 if (clip_vert || clip_horiz) {
637 /* Now check if this is a special case or not... */
638 if ((((xdst.bottom - xdst.top ) != (xsrc.bottom - xsrc.top )) && clip_vert ) ||
639 (((xdst.right - xdst.left) != (xsrc.right - xsrc.left)) && clip_horiz) ||
640 (dwFlags & DDBLT_DDFX)) {
641 WARN("Out of screen rectangle in special case. Not handled right now.\n");
646 if (xdst.left < 0) { xsrc.left -= xdst.left; xdst.left = 0; }
647 if (xdst.right > ddesc.dwWidth) { xsrc.right -= (xdst.right - (int) ddesc.dwWidth); xdst.right = (int) ddesc.dwWidth; }
650 if (xdst.top < 0) { xsrc.top -= xdst.top; xdst.top = 0; }
651 if (xdst.bottom > ddesc.dwHeight) { xsrc.bottom -= (xdst.bottom - (int) ddesc.dwHeight); xdst.bottom = (int) ddesc.dwHeight; }
653 /* And check if after clipping something is still to be done... */
654 if ((xdst.bottom <= 0) || (xdst.right <= 0) || (xdst.top >= (int) ddesc.dwHeight) || (xdst.left >= (int) ddesc.dwWidth) ||
655 (xsrc.bottom <= 0) || (xsrc.right <= 0) || (xsrc.top >= (int) sdesc.dwHeight) || (xsrc.left >= (int) sdesc.dwWidth)) {
656 TRACE("Nothing to be done after clipping !\n");
662 bpp = GET_BPP(ddesc);
663 srcheight = xsrc.bottom - xsrc.top;
664 srcwidth = xsrc.right - xsrc.left;
665 dstheight = xdst.bottom - xdst.top;
666 dstwidth = xdst.right - xdst.left;
667 width = (xdst.right - xdst.left) * bpp;
669 assert(width <= ddesc.u1.lPitch);
671 dbuf = (BYTE*)ddesc.lpSurface+(xdst.top*ddesc.u1.lPitch)+(xdst.left*bpp);
673 if (dwFlags & (DDBLT_WAIT|DDBLT_ASYNC))
675 static BOOL displayed = FALSE;
678 FIXME("dwFlags DDBLT_WAIT and/or DDBLT_ASYNC: can't handle right now.\n");
681 dwFlags &= ~(DDBLT_WAIT|DDBLT_ASYNC);
684 /* First, all the 'source-less' blits */
685 if (dwFlags & DDBLT_COLORFILL) {
686 ret = _Blt_ColorFill(dbuf, dstwidth, dstheight, bpp,
687 ddesc.u1.lPitch, lpbltfx->u5.dwFillColor);
688 dwFlags &= ~DDBLT_COLORFILL;
691 if (dwFlags & DDBLT_DEPTHFILL)
692 FIXME("DDBLT_DEPTHFILL needs to be implemented!\n");
693 if (dwFlags & DDBLT_ROP) {
694 /* Catch some degenerate cases here */
695 switch(lpbltfx->dwROP) {
697 ret = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,ddesc.u1.lPitch,0);
699 case 0xAA0029: /* No-op */
702 ret = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,ddesc.u1.lPitch,~0);
704 case SRCCOPY: /* well, we do that below ? */
707 FIXME("Unsupported raster op: %08lx Pattern: %p\n", lpbltfx->dwROP, lpbltfx->u5.lpDDSPattern);
710 dwFlags &= ~DDBLT_ROP;
712 if (dwFlags & DDBLT_DDROPS) {
713 FIXME("\tDdraw Raster Ops: %08lx Pattern: %p\n", lpbltfx->dwDDROP, lpbltfx->u5.lpDDSPattern);
715 /* Now the 'with source' blits */
718 int sx, xinc, sy, yinc;
720 if (!dstwidth || !dstheight) /* hmm... stupid program ? */
722 sbase = (BYTE*)sdesc.lpSurface+(xsrc.top*sdesc.u1.lPitch)+xsrc.left*bpp;
723 xinc = (srcwidth << 16) / dstwidth;
724 yinc = (srcheight << 16) / dstheight;
727 /* No effects, we can cheat here */
728 if (dstwidth == srcwidth) {
729 if (dstheight == srcheight) {
730 /* No stretching in either direction. This needs to be as
731 * fast as possible */
734 /* check for overlapping surfaces */
735 if (src != iface || xdst.top < xsrc.top ||
736 xdst.right <= xsrc.left || xsrc.right <= xdst.left)
738 /* no overlap, or dst above src, so copy from top downwards */
739 for (y = 0; y < dstheight; y++)
741 memcpy(dbuf, sbuf, width);
742 sbuf += sdesc.u1.lPitch;
743 dbuf += ddesc.u1.lPitch;
746 else if (xdst.top > xsrc.top) /* copy from bottom upwards */
748 sbuf += (sdesc.u1.lPitch*dstheight);
749 dbuf += (ddesc.u1.lPitch*dstheight);
750 for (y = 0; y < dstheight; y++)
752 sbuf -= sdesc.u1.lPitch;
753 dbuf -= ddesc.u1.lPitch;
754 memcpy(dbuf, sbuf, width);
757 else /* src and dst overlapping on the same line, use memmove */
759 for (y = 0; y < dstheight; y++)
761 memmove(dbuf, sbuf, width);
762 sbuf += sdesc.u1.lPitch;
763 dbuf += ddesc.u1.lPitch;
767 /* Stretching in Y direction only */
768 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
769 sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
770 memcpy(dbuf, sbuf, width);
771 dbuf += ddesc.u1.lPitch;
775 /* Stretching in X direction */
777 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
778 sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
780 if ((sy >> 16) == (last_sy >> 16)) {
781 /* this sourcerow is the same as last sourcerow -
782 * copy already stretched row
784 memcpy(dbuf, dbuf - ddesc.u1.lPitch, width);
786 #define STRETCH_ROW(type) { \
787 type *s = (type *) sbuf, *d = (type *) dbuf; \
788 for (x = sx = 0; x < dstwidth; x++, sx += xinc) \
789 d[x] = s[sx >> 16]; \
793 case 1: STRETCH_ROW(BYTE)
794 case 2: STRETCH_ROW(WORD)
795 case 4: STRETCH_ROW(DWORD)
798 for (x = sx = 0; x < dstwidth; x++, sx+= xinc) {
802 pixel = s[0]|(s[1]<<8)|(s[2]<<16);
803 d[0] = (pixel )&0xff;
804 d[1] = (pixel>> 8)&0xff;
805 d[2] = (pixel>>16)&0xff;
811 FIXME("Stretched blit not implemented for bpp %d!\n", bpp*8);
812 ret = DDERR_UNSUPPORTED;
817 dbuf += ddesc.u1.lPitch;
822 LONG dstyinc = ddesc.u1.lPitch, dstxinc = bpp;
823 DWORD keylow = 0, keyhigh = 0;
824 if (dwFlags & (DDBLT_KEYSRC | DDBLT_KEYDEST | DDBLT_KEYSRCOVERRIDE | DDBLT_KEYDESTOVERRIDE)) {
826 if (dwFlags & DDBLT_KEYSRC) {
827 keylow = sdesc.ddckCKSrcBlt.dwColorSpaceLowValue;
828 keyhigh = sdesc.ddckCKSrcBlt.dwColorSpaceHighValue;
829 } else if (dwFlags & DDBLT_KEYDEST){
830 keylow = ddesc.ddckCKDestBlt.dwColorSpaceLowValue;
831 keyhigh = ddesc.ddckCKDestBlt.dwColorSpaceHighValue;
832 } else if (dwFlags & DDBLT_KEYSRCOVERRIDE) {
833 keylow = lpbltfx->ddckSrcColorkey.dwColorSpaceLowValue;
834 keyhigh = lpbltfx->ddckSrcColorkey.dwColorSpaceHighValue;
836 keylow = lpbltfx->ddckDestColorkey.dwColorSpaceLowValue;
837 keyhigh = lpbltfx->ddckDestColorkey.dwColorSpaceHighValue;
839 dwFlags &= ~(DDBLT_KEYSRC | DDBLT_KEYDEST | DDBLT_KEYSRCOVERRIDE | DDBLT_KEYDESTOVERRIDE);
842 if (dwFlags & DDBLT_DDFX) {
843 LPBYTE dTopLeft, dTopRight, dBottomLeft, dBottomRight, tmp;
846 dTopRight = dbuf+((dstwidth-1)*bpp);
847 dBottomLeft = dTopLeft+((dstheight-1)*ddesc.u1.lPitch);
848 dBottomRight = dBottomLeft+((dstwidth-1)*bpp);
850 if (lpbltfx->dwDDFX & DDBLTFX_ARITHSTRETCHY){
851 /* I don't think we need to do anything about this flag */
852 WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_ARITHSTRETCHY\n");
854 if (lpbltfx->dwDDFX & DDBLTFX_MIRRORLEFTRIGHT) {
856 dTopRight = dTopLeft;
859 dBottomRight = dBottomLeft;
861 dstxinc = dstxinc *-1;
863 if (lpbltfx->dwDDFX & DDBLTFX_MIRRORUPDOWN) {
865 dTopLeft = dBottomLeft;
868 dTopRight = dBottomRight;
870 dstyinc = dstyinc *-1;
872 if (lpbltfx->dwDDFX & DDBLTFX_NOTEARING) {
873 /* I don't think we need to do anything about this flag */
874 WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_NOTEARING\n");
876 if (lpbltfx->dwDDFX & DDBLTFX_ROTATE180) {
878 dBottomRight = dTopLeft;
881 dBottomLeft = dTopRight;
883 dstxinc = dstxinc * -1;
884 dstyinc = dstyinc * -1;
886 if (lpbltfx->dwDDFX & DDBLTFX_ROTATE270) {
888 dTopLeft = dBottomLeft;
889 dBottomLeft = dBottomRight;
890 dBottomRight = dTopRight;
895 dstxinc = dstxinc * -1;
897 if (lpbltfx->dwDDFX & DDBLTFX_ROTATE90) {
899 dTopLeft = dTopRight;
900 dTopRight = dBottomRight;
901 dBottomRight = dBottomLeft;
906 dstyinc = dstyinc * -1;
908 if (lpbltfx->dwDDFX & DDBLTFX_ZBUFFERBASEDEST) {
909 /* I don't think we need to do anything about this flag */
910 WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_ZBUFFERBASEDEST\n");
913 dwFlags &= ~(DDBLT_DDFX);
916 #define COPY_COLORKEY_FX(type) { \
917 type *s, *d = (type *) dbuf, *dx, tmp; \
918 for (y = sy = 0; y < dstheight; y++, sy += yinc) { \
919 s = (type*)(sbase + (sy >> 16) * sdesc.u1.lPitch); \
921 for (x = sx = 0; x < dstwidth; x++, sx += xinc) { \
923 if (tmp < keylow || tmp > keyhigh) dx[0] = tmp; \
924 dx = (type*)(((LPBYTE)dx)+dstxinc); \
926 d = (type*)(((LPBYTE)d)+dstyinc); \
931 case 1: COPY_COLORKEY_FX(BYTE)
932 case 2: COPY_COLORKEY_FX(WORD)
933 case 4: COPY_COLORKEY_FX(DWORD)
934 case 3: {LPBYTE s,d = dbuf, dx;
935 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
936 sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
938 for (x = sx = 0; x < dstwidth; x++, sx+= xinc) {
941 pixel = s[0]|(s[1]<<8)|(s[2]<<16);
942 if (pixel < keylow || pixel > keyhigh){
943 dx[0] = (pixel )&0xff;
944 dx[1] = (pixel>> 8)&0xff;
945 dx[2] = (pixel>>16)&0xff;
953 FIXME("%s color-keyed blit not implemented for bpp %d!\n",
954 (dwFlags & DDBLT_KEYSRC) ? "Source" : "Destination", bpp*8);
955 ret = DDERR_UNSUPPORTED;
957 #undef COPY_COLORKEY_FX
963 if (dwFlags && FIXME_ON(ddraw)) {
964 FIXME("\tUnsupported flags: ");
965 DDRAW_dump_DDBLT(dwFlags);
969 IDirectDrawSurface7_Unlock(iface,NULL);
970 if (src && src != iface) IDirectDrawSurface7_Unlock(src,NULL);
974 /* BltBatch: generic, unimplemented */
977 DIB_DirectDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface, DWORD dstx,
978 DWORD dsty, LPDIRECTDRAWSURFACE7 src,
979 LPRECT rsrc, DWORD trans)
981 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
983 DDSURFACEDESC2 ddesc,sdesc;
987 RECT lock_src, lock_dst, lock_union;
989 if (TRACE_ON(ddraw)) {
990 TRACE("(%p)->(%ld,%ld,%p,%p,%08lx)\n",
991 This,dstx,dsty,src,rsrc,trans
995 DDRAW_dump_DDBLTFAST(trans);
997 TRACE("\tsrcrect: %ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
999 TRACE(" srcrect: NULL\n");
1002 if ((This->locked) || ((src != NULL) && (((IDirectDrawSurfaceImpl *)src)->locked))) {
1003 WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
1004 return DDERR_SURFACEBUSY;
1007 /* First, check if the possible override function handles this case */
1008 if (This->aux_bltfast != NULL) {
1009 if (This->aux_bltfast(This, dstx, dsty, src, rsrc, trans) == DD_OK) return DD_OK;
1012 /* Get the surface description without locking to first compute the width / height */
1013 ddesc = This->surface_desc;
1014 sdesc = (ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, src))->surface_desc;
1017 WARN("rsrc is NULL!\n");
1019 rsrc->left = rsrc->top = 0;
1020 rsrc->right = sdesc.dwWidth;
1021 rsrc->bottom = sdesc.dwHeight;
1024 /* Check source rect for validity. Copied from normal Blt. Fixes Baldur's Gate.*/
1025 if ((rsrc->bottom > sdesc.dwHeight) || (rsrc->bottom < 0) ||
1026 (rsrc->top > sdesc.dwHeight) || (rsrc->top < 0) ||
1027 (rsrc->left > sdesc.dwWidth) || (rsrc->left < 0) ||
1028 (rsrc->right > sdesc.dwWidth) || (rsrc->right < 0) ||
1029 (rsrc->right < rsrc->left) || (rsrc->bottom < rsrc->top)) {
1030 WARN("Application gave us bad source rectangle for BltFast.\n");
1031 return DDERR_INVALIDRECT;
1034 h=rsrc->bottom-rsrc->top;
1035 if (h>ddesc.dwHeight-dsty) h=ddesc.dwHeight-dsty;
1036 if (h>sdesc.dwHeight-rsrc->top) h=sdesc.dwHeight-rsrc->top;
1037 if (h<=0) return DDERR_INVALIDRECT;
1039 w=rsrc->right-rsrc->left;
1040 if (w>ddesc.dwWidth-dstx) w=ddesc.dwWidth-dstx;
1041 if (w>sdesc.dwWidth-rsrc->left) w=sdesc.dwWidth-rsrc->left;
1042 if (w<=0) return DDERR_INVALIDRECT;
1044 /* Now compute the locking rectangle... */
1045 lock_src.left = rsrc->left;
1046 lock_src.top = rsrc->top;
1047 lock_src.right = lock_src.left + w;
1048 lock_src.bottom = lock_src.top + h;
1050 lock_dst.left = dstx;
1051 lock_dst.top = dsty;
1052 lock_dst.right = dstx + w;
1053 lock_dst.bottom = dsty + h;
1055 bpp = GET_BPP(This->surface_desc);
1057 /* We need to lock the surfaces, or we won't get refreshes when done. */
1061 UnionRect(&lock_union, &lock_src, &lock_dst);
1063 /* Lock the union of the two rectangles */
1064 IDirectDrawSurface7_Lock(iface, &lock_union, &ddesc, 0, 0);
1066 pitch = This->surface_desc.u1.lPitch;
1068 /* Since sdesc was originally copied from this surface's description, we can just reuse it */
1069 sdesc.lpSurface = (BYTE *)This->surface_desc.lpSurface + lock_src.top * pitch + lock_src.left * bpp;
1070 ddesc.lpSurface = (BYTE *)This->surface_desc.lpSurface + lock_dst.top * pitch + lock_dst.left * bpp;
1072 sdesc.dwSize = sizeof(sdesc);
1073 IDirectDrawSurface7_Lock(src, &lock_src, &sdesc, DDLOCK_READONLY, 0);
1074 ddesc.dwSize = sizeof(ddesc);
1075 IDirectDrawSurface7_Lock(iface, &lock_dst, &ddesc, DDLOCK_WRITEONLY, 0);
1078 /* Handle first the FOURCC surfaces... */
1079 if ((sdesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) && (ddesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC)) {
1081 FIXME("trans arg not supported when a FOURCC surface is involved\n");
1083 FIXME("offset for destination surface is not supported\n");
1084 if (sdesc.u4.ddpfPixelFormat.dwFourCC != sdesc.u4.ddpfPixelFormat.dwFourCC) {
1085 FIXME("FOURCC->FOURCC copy only supported for the same type of surface\n");
1086 ret = DDERR_INVALIDPIXELFORMAT;
1089 memcpy(ddesc.lpSurface, sdesc.lpSurface, ddesc.u1.dwLinearSize);
1092 if ((sdesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) &&
1093 (!(ddesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC))) {
1094 DoDXTCDecompression(&sdesc, &ddesc);
1098 sbuf = (BYTE *) sdesc.lpSurface;
1099 dbuf = (BYTE *) ddesc.lpSurface;
1101 if (trans & (DDBLTFAST_SRCCOLORKEY | DDBLTFAST_DESTCOLORKEY)) {
1102 DWORD keylow, keyhigh;
1103 if (trans & DDBLTFAST_SRCCOLORKEY) {
1104 keylow = sdesc.ddckCKSrcBlt.dwColorSpaceLowValue;
1105 keyhigh = sdesc.ddckCKSrcBlt.dwColorSpaceHighValue;
1107 /* I'm not sure if this is correct */
1108 FIXME("DDBLTFAST_DESTCOLORKEY not fully supported yet.\n");
1109 keylow = ddesc.ddckCKDestBlt.dwColorSpaceLowValue;
1110 keyhigh = ddesc.ddckCKDestBlt.dwColorSpaceHighValue;
1113 #define COPYBOX_COLORKEY(type) { \
1115 s = (type *) sdesc.lpSurface; \
1116 d = (type *) ddesc.lpSurface; \
1117 for (y = 0; y < h; y++) { \
1118 for (x = 0; x < w; x++) { \
1120 if (tmp < keylow || tmp > keyhigh) d[x] = tmp; \
1122 s = (type *)((BYTE *)s + sdesc.u1.lPitch); \
1123 d = (type *)((BYTE *)d + ddesc.u1.lPitch); \
1129 case 1: COPYBOX_COLORKEY(BYTE)
1130 case 2: COPYBOX_COLORKEY(WORD)
1131 case 4: COPYBOX_COLORKEY(DWORD)
1136 s = (BYTE *) sdesc.lpSurface;
1137 d = (BYTE *) ddesc.lpSurface;
1138 for (y = 0; y < h; y++) {
1139 for (x = 0; x < w * 3; x += 3) {
1140 tmp = (DWORD)s[x] + ((DWORD)s[x + 1] << 8) + ((DWORD)s[x + 2] << 16);
1141 if (tmp < keylow || tmp > keyhigh) {
1142 d[x + 0] = s[x + 0];
1143 d[x + 1] = s[x + 1];
1144 d[x + 2] = s[x + 2];
1147 s += sdesc.u1.lPitch;
1148 d += ddesc.u1.lPitch;
1153 FIXME("Source color key blitting not supported for bpp %d\n",bpp*8);
1154 ret = DDERR_UNSUPPORTED;
1157 #undef COPYBOX_COLORKEY
1159 int width = w * bpp;
1161 for (y = 0; y < h; y++) {
1162 memcpy(dbuf, sbuf, width);
1163 sbuf += sdesc.u1.lPitch;
1164 dbuf += ddesc.u1.lPitch;
1170 IDirectDrawSurface7_Unlock(iface, &lock_union);
1172 IDirectDrawSurface7_Unlock(iface, &lock_dst);
1173 IDirectDrawSurface7_Unlock(src, &lock_src);
1179 /* ChangeUniquenessValue: generic */
1180 /* DeleteAttachedSurface: generic */
1181 /* EnumAttachedSurfaces: generic */
1182 /* EnumOverlayZOrders: generic, unimplemented */
1184 BOOL DIB_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl* front,
1185 IDirectDrawSurfaceImpl* back,
1188 DIB_DirectDrawSurfaceImpl* front_priv = front->private;
1189 DIB_DirectDrawSurfaceImpl* back_priv = back->private;
1191 TRACE("(%p,%p)\n",front,back);
1195 tmp = front_priv->dib.DIBsection;
1196 front_priv->dib.DIBsection = back_priv->dib.DIBsection;
1197 back_priv->dib.DIBsection = tmp;
1202 tmp = front_priv->dib.bitmap_data;
1203 front_priv->dib.bitmap_data = back_priv->dib.bitmap_data;
1204 back_priv->dib.bitmap_data = tmp;
1206 tmp = front->surface_desc.lpSurface;
1207 front->surface_desc.lpSurface = back->surface_desc.lpSurface;
1208 back->surface_desc.lpSurface = tmp;
1211 /* client_memory should not be different, but just in case */
1214 tmp = front_priv->dib.client_memory;
1215 front_priv->dib.client_memory = back_priv->dib.client_memory;
1216 back_priv->dib.client_memory = tmp;
1219 return Main_DirectDrawSurface_flip_data(front, back, dwFlags);
1223 /* FreePrivateData: generic */
1224 /* GetAttachedSurface: generic */
1225 /* GetBltStatus: generic */
1226 /* GetCaps: generic (Returns the caps from This->surface_desc.) */
1227 /* GetClipper: generic */
1228 /* GetColorKey: generic */
1230 HRESULT DIB_DirectDrawSurface_alloc_dc(IDirectDrawSurfaceImpl* This, HDC* phDC)
1232 DIB_PRIV_VAR(priv, This);
1235 TRACE("Grabbing a DC for surface: %p\n", This);
1237 hDC = CreateCompatibleDC(0);
1238 priv->dib.holdbitmap = SelectObject(hDC, priv->dib.DIBsection);
1240 SelectPalette(hDC, This->palette->hpal, FALSE);
1247 HRESULT DIB_DirectDrawSurface_free_dc(IDirectDrawSurfaceImpl* This, HDC hDC)
1249 DIB_PRIV_VAR(priv, This);
1251 TRACE("Releasing DC for surface: %p\n", This);
1253 SelectObject(hDC, priv->dib.holdbitmap);
1259 HRESULT DIB_DirectDrawSurface_get_dc(IDirectDrawSurfaceImpl* This, HDC* phDC)
1261 return DIB_DirectDrawSurface_alloc_dc(This, phDC);
1264 HRESULT DIB_DirectDrawSurface_release_dc(IDirectDrawSurfaceImpl* This, HDC hDC)
1266 return DIB_DirectDrawSurface_free_dc(This, hDC);
1269 /* GetDDInterface: generic */
1270 /* GetFlipStatus: generic */
1271 /* GetLOD: generic */
1272 /* GetOverlayPosition: generic */
1273 /* GetPalette: generic */
1274 /* GetPixelFormat: generic */
1275 /* GetPriority: generic */
1276 /* GetPrivateData: generic */
1277 /* GetSurfaceDesc: generic */
1278 /* GetUniquenessValue: generic */
1279 /* Initialize: generic */
1280 /* IsLost: generic */
1281 /* Lock: generic with callback? */
1282 /* PageLock: generic */
1283 /* PageUnlock: generic */
1286 DIB_DirectDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface)
1288 TRACE("(%p)\n",iface);
1289 return DD_OK; /* ??? */
1292 /* SetClipper: generic */
1293 /* SetColorKey: generic */
1294 /* SetLOD: generic */
1295 /* SetOverlayPosition: generic */
1297 void DIB_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl* This,
1298 IDirectDrawPaletteImpl* pal)
1301 if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
1302 This->update_palette(This, pal,
1303 0, pal->palNumEntries,
1307 void DIB_DirectDrawSurface_update_palette(IDirectDrawSurfaceImpl* This,
1308 IDirectDrawPaletteImpl* pal,
1309 DWORD dwStart, DWORD dwCount,
1310 LPPALETTEENTRY palent)
1316 TRACE("updating primary palette\n");
1317 for (n=0; n<dwCount; n++) {
1318 col[n].rgbRed = palent[n].peRed;
1319 col[n].rgbGreen = palent[n].peGreen;
1320 col[n].rgbBlue = palent[n].peBlue;
1321 col[n].rgbReserved = 0;
1323 This->get_dc(This, &dc);
1324 SetDIBColorTable(dc, dwStart, dwCount, col);
1325 This->release_dc(This, dc);
1327 /* Propagate change to backbuffers if there are any */
1328 /* Basically this is a modification of the Flip code to find the backbuffer */
1329 /* and duplicate the palette update there as well */
1330 if ((This->surface_desc.ddsCaps.dwCaps&(DDSCAPS_FLIP|DDSCAPS_FRONTBUFFER))
1331 == (DDSCAPS_FLIP|DDSCAPS_FRONTBUFFER))
1333 static DDSCAPS2 back_caps = { DDSCAPS_BACKBUFFER };
1334 LPDIRECTDRAWSURFACE7 tgt;
1336 HRESULT hr = IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This,IDirectDrawSurface7),
1340 IDirectDrawSurfaceImpl* target = ICOM_OBJECT(IDirectDrawSurfaceImpl,
1341 IDirectDrawSurface7,tgt);
1342 IDirectDrawSurface7_Release(tgt);
1343 target->get_dc(target, &dc);
1344 SetDIBColorTable(dc, dwStart, dwCount, col);
1345 target->release_dc(target, dc);
1350 /* SetPalette: generic */
1351 /* SetPriority: generic */
1352 /* SetPrivateData: generic */
1355 DIB_DirectDrawSurface_SetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
1356 LPDDSURFACEDESC2 pDDSD, DWORD dwFlags)
1358 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1359 DIB_PRIV_VAR(priv, This);
1361 DWORD flags = pDDSD->dwFlags;
1363 if (TRACE_ON(ddraw)) {
1364 TRACE("(%p)->(%p,%08lx)\n",iface,pDDSD,dwFlags);
1365 DDRAW_dump_surface_desc(pDDSD);
1368 if (pDDSD->dwFlags & DDSD_PIXELFORMAT) {
1369 flags &= ~DDSD_PIXELFORMAT;
1370 if (flags & DDSD_LPSURFACE) {
1371 This->surface_desc.u4.ddpfPixelFormat = pDDSD->u4.ddpfPixelFormat;
1373 FIXME("Change of pixel format without surface re-allocation is not supported !\n");
1376 if (pDDSD->dwFlags & DDSD_LPSURFACE) {
1377 HBITMAP oldbmp = priv->dib.DIBsection;
1378 LPVOID oldsurf = This->surface_desc.lpSurface;
1379 BOOL oldc = priv->dib.client_memory;
1381 flags &= ~DDSD_LPSURFACE;
1383 TRACE("new lpSurface=%p\n",pDDSD->lpSurface);
1384 This->surface_desc.lpSurface = pDDSD->lpSurface;
1385 priv->dib.client_memory = TRUE;
1387 hr = create_dib(This);
1390 priv->dib.DIBsection = oldbmp;
1391 This->surface_desc.lpSurface = oldsurf;
1392 priv->dib.client_memory = oldc;
1396 DeleteObject(oldbmp);
1399 VirtualFree(oldsurf, 0, MEM_RELEASE);
1402 WARN("Unhandled flags : %08lx\n", flags);
1407 /* Unlock: ???, need callback */
1408 /* UpdateOverlay: generic */
1409 /* UpdateOverlayDisplay: generic */
1410 /* UpdateOverlayZOrder: generic */
1412 static const IDirectDrawSurface7Vtbl DIB_IDirectDrawSurface7_VTable =
1414 Main_DirectDrawSurface_QueryInterface,
1415 Main_DirectDrawSurface_AddRef,
1416 Main_DirectDrawSurface_Release,
1417 Main_DirectDrawSurface_AddAttachedSurface,
1418 Main_DirectDrawSurface_AddOverlayDirtyRect,
1419 DIB_DirectDrawSurface_Blt,
1420 Main_DirectDrawSurface_BltBatch,
1421 DIB_DirectDrawSurface_BltFast,
1422 Main_DirectDrawSurface_DeleteAttachedSurface,
1423 Main_DirectDrawSurface_EnumAttachedSurfaces,
1424 Main_DirectDrawSurface_EnumOverlayZOrders,
1425 Main_DirectDrawSurface_Flip,
1426 Main_DirectDrawSurface_GetAttachedSurface,
1427 Main_DirectDrawSurface_GetBltStatus,
1428 Main_DirectDrawSurface_GetCaps,
1429 Main_DirectDrawSurface_GetClipper,
1430 Main_DirectDrawSurface_GetColorKey,
1431 Main_DirectDrawSurface_GetDC,
1432 Main_DirectDrawSurface_GetFlipStatus,
1433 Main_DirectDrawSurface_GetOverlayPosition,
1434 Main_DirectDrawSurface_GetPalette,
1435 Main_DirectDrawSurface_GetPixelFormat,
1436 Main_DirectDrawSurface_GetSurfaceDesc,
1437 Main_DirectDrawSurface_Initialize,
1438 Main_DirectDrawSurface_IsLost,
1439 Main_DirectDrawSurface_Lock,
1440 Main_DirectDrawSurface_ReleaseDC,
1441 DIB_DirectDrawSurface_Restore,
1442 Main_DirectDrawSurface_SetClipper,
1443 Main_DirectDrawSurface_SetColorKey,
1444 Main_DirectDrawSurface_SetOverlayPosition,
1445 Main_DirectDrawSurface_SetPalette,
1446 Main_DirectDrawSurface_Unlock,
1447 Main_DirectDrawSurface_UpdateOverlay,
1448 Main_DirectDrawSurface_UpdateOverlayDisplay,
1449 Main_DirectDrawSurface_UpdateOverlayZOrder,
1450 Main_DirectDrawSurface_GetDDInterface,
1451 Main_DirectDrawSurface_PageLock,
1452 Main_DirectDrawSurface_PageUnlock,
1453 DIB_DirectDrawSurface_SetSurfaceDesc,
1454 Main_DirectDrawSurface_SetPrivateData,
1455 Main_DirectDrawSurface_GetPrivateData,
1456 Main_DirectDrawSurface_FreePrivateData,
1457 Main_DirectDrawSurface_GetUniquenessValue,
1458 Main_DirectDrawSurface_ChangeUniquenessValue,
1459 Main_DirectDrawSurface_SetPriority,
1460 Main_DirectDrawSurface_GetPriority,
1461 Main_DirectDrawSurface_SetLOD,
1462 Main_DirectDrawSurface_GetLOD