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
32 #include "wine/debug.h"
33 #include "ddraw_private.h"
34 #include "d3d_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
39 extern HBITMAP DIB_CreateDIBSection( HDC hdc, const BITMAPINFO *bmi, UINT usage, VOID **bits,
40 HANDLE section, DWORD offset, DWORD ovr_pitch );
42 static const IDirectDrawSurface7Vtbl DIB_IDirectDrawSurface7_VTable;
44 /* Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned. */
45 inline static int get_dib_width_bytes( int width, int depth )
51 case 1: words = (width + 31) / 32; break;
52 case 4: words = (width + 7) / 8; break;
53 case 8: words = (width + 3) / 4; break;
55 case 16: words = (width + 1) / 2; break;
56 case 24: words = (width * 3 + 3)/4; break;
58 WARN("(%d): Unsupported depth\n", depth );
60 case 32: words = width; break;
66 static HRESULT create_dib(IDirectDrawSurfaceImpl* This)
71 DIB_DirectDrawSurfaceImpl* priv = This->private;
73 assert(This->surface_desc.lpSurface != NULL);
75 switch (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount)
79 /* Allocate extra space to store the RGB bit masks. */
80 b_info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
81 sizeof(BITMAPINFOHEADER) + 3 * sizeof(DWORD));
85 b_info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
86 sizeof(BITMAPINFOHEADER));
90 /* Allocate extra space for a palette. */
91 b_info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
92 sizeof(BITMAPINFOHEADER)
94 * (1 << This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount));
98 b_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
99 b_info->bmiHeader.biWidth = This->surface_desc.dwWidth;
100 b_info->bmiHeader.biHeight = -This->surface_desc.dwHeight;
101 b_info->bmiHeader.biPlanes = 1;
102 b_info->bmiHeader.biBitCount = This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount;
104 if ((This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount != 16)
105 && (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount != 32))
106 b_info->bmiHeader.biCompression = BI_RGB;
108 b_info->bmiHeader.biCompression = BI_BITFIELDS;
110 b_info->bmiHeader.biSizeImage
111 = (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount / 8)
112 * This->surface_desc.dwWidth * This->surface_desc.dwHeight;
114 b_info->bmiHeader.biXPelsPerMeter = 0;
115 b_info->bmiHeader.biYPelsPerMeter = 0;
116 b_info->bmiHeader.biClrUsed = 0;
117 b_info->bmiHeader.biClrImportant = 0;
119 if (!This->surface_desc.u1.lPitch) {
120 /* This can't happen, right? */
121 /* or use GDI_GetObj to get it from the created DIB? */
122 This->surface_desc.u1.lPitch = get_dib_width_bytes(b_info->bmiHeader.biWidth, b_info->bmiHeader.biBitCount);
123 This->surface_desc.dwFlags |= DDSD_PITCH;
126 switch (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount)
131 DWORD *masks = (DWORD *) &(b_info->bmiColors);
134 masks[0] = This->surface_desc.u4.ddpfPixelFormat.u2.dwRBitMask;
135 masks[1] = This->surface_desc.u4.ddpfPixelFormat.u3.dwGBitMask;
136 masks[2] = This->surface_desc.u4.ddpfPixelFormat.u4.dwBBitMask;
142 usage = DIB_RGB_COLORS;
146 /* Don't know palette */
151 ddc = CreateDCA("DISPLAY", NULL, NULL, NULL);
154 HeapFree(GetProcessHeap(), 0, b_info);
155 return HRESULT_FROM_WIN32(GetLastError());
159 = DIB_CreateDIBSection(ddc, b_info, usage, &(priv->dib.bitmap_data), 0,
160 (DWORD)This->surface_desc.lpSurface,
161 This->surface_desc.u1.lPitch);
163 if (!priv->dib.DIBsection) {
164 ERR("CreateDIBSection failed!\n");
165 HeapFree(GetProcessHeap(), 0, b_info);
166 return HRESULT_FROM_WIN32(GetLastError());
169 TRACE("DIBSection at : %p\n", priv->dib.bitmap_data);
171 if (!This->surface_desc.lpSurface) {
172 This->surface_desc.lpSurface = priv->dib.bitmap_data;
173 This->surface_desc.dwFlags |= DDSD_LPSURFACE;
176 HeapFree(GetProcessHeap(), 0, b_info);
178 /* I don't think it's worth checking for this. */
179 if (priv->dib.bitmap_data != This->surface_desc.lpSurface)
180 ERR("unexpected error creating DirectDrawSurface DIB section\n");
182 /* this seems like a good place to put the handle for HAL driver use */
183 This->global_more.hKernelSurface = (ULONG_PTR)priv->dib.DIBsection;
188 void DIB_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
190 DIB_DirectDrawSurfaceImpl* priv = This->private;
192 DeleteObject(priv->dib.DIBsection);
194 if (!priv->dib.client_memory)
195 VirtualFree(This->surface_desc.lpSurface, 0, MEM_RELEASE);
197 Main_DirectDrawSurface_final_release(This);
200 HRESULT DIB_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,
201 LPDIRECTDRAWSURFACE7* ppDup)
203 return DIB_DirectDrawSurface_Create(This->ddraw_owner,
204 &This->surface_desc, ppDup, NULL);
207 HRESULT DIB_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
208 IDirectDrawImpl *pDD,
209 const DDSURFACEDESC2 *pDDSD)
212 DIB_DirectDrawSurfaceImpl* priv = This->private;
214 TRACE("(%p)->(%p,%p)\n",This,pDD,pDDSD);
215 hr = Main_DirectDrawSurface_Construct(This, pDD, pDDSD);
216 if (FAILED(hr)) return hr;
218 ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,
219 DIB_IDirectDrawSurface7_VTable);
221 This->final_release = DIB_DirectDrawSurface_final_release;
222 This->duplicate_surface = DIB_DirectDrawSurface_duplicate_surface;
223 This->flip_data = DIB_DirectDrawSurface_flip_data;
225 This->get_dc = DIB_DirectDrawSurface_get_dc;
226 This->release_dc = DIB_DirectDrawSurface_release_dc;
229 This->set_palette = DIB_DirectDrawSurface_set_palette;
230 This->update_palette = DIB_DirectDrawSurface_update_palette;
232 TRACE("(%ldx%ld, pitch=%ld)\n",
233 This->surface_desc.dwWidth, This->surface_desc.dwHeight,
234 This->surface_desc.u1.lPitch);
235 /* XXX load dwWidth and dwHeight from pDD if they are not specified? */
237 if (This->surface_desc.dwFlags & DDSD_LPSURFACE)
239 /* "Client memory": it is managed by the application. */
240 /* XXX What if lPitch is not set? Use dwWidth or fail? */
242 priv->dib.client_memory = TRUE;
246 if (!(This->surface_desc.dwFlags & DDSD_PITCH))
248 int pitch = This->surface_desc.u1.lPitch;
250 pitch += 8 - (pitch % 8);
252 /* XXX else: how should lPitch be verified? */
254 This->surface_desc.dwFlags |= DDSD_LPSURFACE;
256 /* Ensure that DDSD_PITCH is respected for DDPF_FOURCC surfaces too */
257 if (This->surface_desc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC && !(This->surface_desc.dwFlags & DDSD_PITCH)) {
258 This->surface_desc.lpSurface
259 = VirtualAlloc(NULL, This->surface_desc.u1.dwLinearSize, MEM_COMMIT, PAGE_READWRITE);
260 This->surface_desc.dwFlags |= DDSD_LINEARSIZE;
262 This->surface_desc.lpSurface
263 = VirtualAlloc(NULL, This->surface_desc.u1.lPitch
264 * This->surface_desc.dwHeight + 4, /* The + 4 here is for dumb games reading after the end of the surface
265 when reading the last byte / half using word access */
266 MEM_COMMIT, PAGE_READWRITE);
267 This->surface_desc.dwFlags |= DDSD_PITCH;
270 if (This->surface_desc.lpSurface == NULL)
272 Main_DirectDrawSurface_final_release(This);
273 return HRESULT_FROM_WIN32(GetLastError());
276 priv->dib.client_memory = FALSE;
279 hr = create_dib(This);
282 if (!priv->dib.client_memory)
283 VirtualFree(This->surface_desc.lpSurface, 0, MEM_RELEASE);
285 Main_DirectDrawSurface_final_release(This);
294 HRESULT DIB_DirectDrawSurface_Create(IDirectDrawImpl *pDD,
295 const DDSURFACEDESC2 *pDDSD,
296 LPDIRECTDRAWSURFACE7 *ppSurf,
299 IDirectDrawSurfaceImpl* This;
301 assert(pUnkOuter == NULL);
303 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
304 sizeof(*This) + sizeof(DIB_DirectDrawSurfaceImpl));
305 if (This == NULL) return E_OUTOFMEMORY;
307 This->private = (DIB_DirectDrawSurfaceImpl*)(This+1);
309 hr = DIB_DirectDrawSurface_Construct(This, pDD, pDDSD);
311 HeapFree(GetProcessHeap(), 0, This);
313 *ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);
319 /* AddAttachedSurface: generic */
320 /* AddOverlayDirtyRect: generic, unimplemented */
322 static HRESULT _Blt_ColorFill(
323 LPBYTE buf, int width, int height, int bpp, LONG lPitch, DWORD color
330 #define COLORFILL_ROW(type) { \
331 type *d = (type *) buf; \
332 for (x = 0; x < width; x++) \
333 d[x] = (type) color; \
338 case 1: COLORFILL_ROW(BYTE)
339 case 2: COLORFILL_ROW(WORD)
340 case 3: { BYTE *d = (BYTE *) buf;
341 for (x = 0; x < width; x++,d+=3) {
342 d[0] = (color ) & 0xFF;
343 d[1] = (color>> 8) & 0xFF;
344 d[2] = (color>>16) & 0xFF;
347 case 4: COLORFILL_ROW(DWORD)
349 FIXME("Color fill not implemented for bpp %d!\n", bpp*8);
350 return DDERR_UNSUPPORTED;
355 /* Now copy first row */
357 for (y = 1; y < height; y++) {
359 memcpy(buf, first, width * bpp);
364 static void ComputeShifts(DWORD mask, DWORD* lshift, DWORD* rshift)
374 while(!(mask & (1 << pos)))
377 while(mask & (1 << (pos+bits)))
384 /* This is used to factorize the decompression between the Blt and BltFast code */
385 static void DoDXTCDecompression(const DDSURFACEDESC2 *sdesc, const DDSURFACEDESC2 *ddesc)
392 if (!s3tc_initialized) {
393 /* FIXME: We may fake this by rendering the texture into the framebuffer using OpenGL functions and reading back
394 * the framebuffer. This will be slow and somewhat ugly. */
395 FIXME("Manual S3TC decompression is not supported in native mode\n");
399 rm = ddesc->u4.ddpfPixelFormat.u2.dwRBitMask;
400 ComputeShifts(rm, &rs, &rb);
401 gm = ddesc->u4.ddpfPixelFormat.u3.dwGBitMask;
402 ComputeShifts(gm, &gs, &gb);
403 bm = ddesc->u4.ddpfPixelFormat.u4.dwBBitMask;
404 ComputeShifts(bm, &bs, &bb);
405 am = ddesc->u4.ddpfPixelFormat.u5.dwRGBAlphaBitMask;
406 ComputeShifts(am, &as, &ab);
407 if (sdesc->u4.ddpfPixelFormat.dwFourCC == MAKE_FOURCC('D','X','T','1')) {
408 int is16 = ddesc->u4.ddpfPixelFormat.u1.dwRGBBitCount == 16;
409 int pitch = ddesc->u1.lPitch;
410 int width = ddesc->dwWidth;
411 int height = ddesc->dwHeight;
413 char* dst = (char*) ddesc->lpSurface;
414 char* src = (char*) sdesc->lpSurface;
415 for (x = 0; x < width; x++)
416 for (y =0; y < height; y++) {
419 (*fetch_2d_texel_rgba_dxt1)(width, src, x, y, data);
421 pixel |= ((data[0] >> rb) << rs) & rm;
422 pixel |= ((data[1] >> gb) << gs) & gm;
423 pixel |= ((data[2] >> bb) << bs) & bm;
424 pixel |= ((data[3] >> ab) << as) & am;
426 *((WORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
428 *((DWORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
430 } else if (sdesc->u4.ddpfPixelFormat.dwFourCC == MAKE_FOURCC('D','X','T','3')) {
431 int is16 = ddesc->u4.ddpfPixelFormat.u1.dwRGBBitCount == 16;
432 int pitch = ddesc->u1.lPitch;
433 int width = ddesc->dwWidth;
434 int height = ddesc->dwHeight;
436 char* dst = (char*) ddesc->lpSurface;
437 char* src = (char*) sdesc->lpSurface;
438 for (x = 0; x < width; x++)
439 for (y =0; y < height; y++) {
442 (*fetch_2d_texel_rgba_dxt3)(width, src, x, y, data);
444 pixel |= ((data[0] >> rb) << rs) & rm;
445 pixel |= ((data[1] >> gb) << gs) & gm;
446 pixel |= ((data[2] >> bb) << bs) & bm;
447 pixel |= ((data[3] >> ab) << as) & am;
449 *((WORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
451 *((DWORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
453 } else if (sdesc->u4.ddpfPixelFormat.dwFourCC == MAKE_FOURCC('D','X','T','5')) {
454 int is16 = ddesc->u4.ddpfPixelFormat.u1.dwRGBBitCount == 16;
455 int pitch = ddesc->u1.lPitch;
456 int width = ddesc->dwWidth;
457 int height = ddesc->dwHeight;
459 char* dst = (char*) ddesc->lpSurface;
460 char* src = (char*) sdesc->lpSurface;
461 for (x = 0; x < width; x++)
462 for (y =0; y < height; y++) {
465 (*fetch_2d_texel_rgba_dxt5)(width, src, x, y, data);
467 pixel |= ((data[0] >> rb) << rs) & rm;
468 pixel |= ((data[1] >> gb) << gs) & gm;
469 pixel |= ((data[2] >> bb) << bs) & bm;
470 pixel |= ((data[3] >> ab) << as) & am;
472 *((WORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
474 *((DWORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
477 #if 0 /* Useful for debugging */
482 sprintf(texname, "dxt_%d.pnm", idx++);
483 f = fopen(texname,"w");
484 DDRAW_dump_surface_to_disk(This, f, 1);
491 DIB_DirectDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rdst,
492 LPDIRECTDRAWSURFACE7 src, LPRECT rsrc,
493 DWORD dwFlags, LPDDBLTFX lpbltfx)
495 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
497 DDSURFACEDESC2 ddesc,sdesc;
499 int bpp, srcheight, srcwidth, dstheight, dstwidth, width;
503 TRACE("(%p)->(%p,%p,%p,%08lx,%p)\n", This,rdst,src,rsrc,dwFlags,lpbltfx);
505 if (TRACE_ON(ddraw)) {
506 if (rdst) TRACE("\tdestrect :%ldx%ld-%ldx%ld\n",rdst->left,rdst->top,rdst->right,rdst->bottom);
507 if (rsrc) TRACE("\tsrcrect :%ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
509 DDRAW_dump_DDBLT(dwFlags);
510 if (dwFlags & DDBLT_DDFX) {
512 DDRAW_dump_DDBLTFX(lpbltfx->dwDDFX);
516 if ((This->locked) || ((src != NULL) && (((IDirectDrawSurfaceImpl *)src)->locked))) {
517 WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
518 return DDERR_SURFACEBUSY;
521 /* First, check if the possible override function handles this case */
522 if (This->aux_blt != NULL) {
523 if (This->aux_blt(This, rdst, src, rsrc, dwFlags, lpbltfx) == DD_OK) return DD_OK;
526 DD_STRUCT_INIT(&ddesc);
527 DD_STRUCT_INIT(&sdesc);
529 sdesc.dwSize = sizeof(sdesc);
530 ddesc.dwSize = sizeof(ddesc);
533 IDirectDrawSurface7_Lock(iface, NULL, &ddesc, 0, 0);
534 DD_STRUCT_COPY_BYSIZE(&sdesc, &ddesc);
536 if (src) IDirectDrawSurface7_Lock(src, NULL, &sdesc, DDLOCK_READONLY, 0);
537 IDirectDrawSurface7_Lock(iface,NULL,&ddesc,DDLOCK_WRITEONLY,0);
540 if ((sdesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) &&
541 (ddesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC)) {
542 if (sdesc.u4.ddpfPixelFormat.dwFourCC != sdesc.u4.ddpfPixelFormat.dwFourCC) {
543 FIXME("FOURCC->FOURCC copy only supported for the same type of surface\n");
544 ret = DDERR_INVALIDPIXELFORMAT;
547 memcpy(ddesc.lpSurface, sdesc.lpSurface, ddesc.u1.dwLinearSize);
551 if ((sdesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) &&
552 (!(ddesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC))) {
553 DoDXTCDecompression(&sdesc, &ddesc);
558 memcpy(&xdst,rdst,sizeof(xdst));
561 xdst.bottom = ddesc.dwHeight;
563 xdst.right = ddesc.dwWidth;
567 memcpy(&xsrc,rsrc,sizeof(xsrc));
571 xsrc.bottom = sdesc.dwHeight;
573 xsrc.right = sdesc.dwWidth;
575 memset(&xsrc,0,sizeof(xsrc));
579 /* First check for the validity of source / destination rectangles. This was
580 verified using a test application + by MSDN.
583 ((xsrc.bottom > sdesc.dwHeight) || (xsrc.bottom < 0) ||
584 (xsrc.top > sdesc.dwHeight) || (xsrc.top < 0) ||
585 (xsrc.left > sdesc.dwWidth) || (xsrc.left < 0) ||
586 (xsrc.right > sdesc.dwWidth) || (xsrc.right < 0) ||
587 (xsrc.right < xsrc.left) || (xsrc.bottom < xsrc.top))) {
588 WARN("Application gave us bad source rectangle for Blt.\n");
589 ret = DDERR_INVALIDRECT;
592 /* For the Destination rect, it can be out of bounds on the condition that a clipper
593 is set for the given surface.
595 if ((This->clipper == NULL) &&
596 ((xdst.bottom > ddesc.dwHeight) || (xdst.bottom < 0) ||
597 (xdst.top > ddesc.dwHeight) || (xdst.top < 0) ||
598 (xdst.left > ddesc.dwWidth) || (xdst.left < 0) ||
599 (xdst.right > ddesc.dwWidth) || (xdst.right < 0) ||
600 (xdst.right < xdst.left) || (xdst.bottom < xdst.top))) {
601 WARN("Application gave us bad destination rectangle for Blt without a clipper set.\n");
602 ret = DDERR_INVALIDRECT;
606 /* Now handle negative values in the rectangles. Warning: only supported for now
607 in the 'simple' cases (ie not in any stretching / rotation cases).
609 First, the case where nothing is to be done.
611 if (((xdst.bottom <= 0) || (xdst.right <= 0) || (xdst.top >= (int) ddesc.dwHeight) || (xdst.left >= (int) ddesc.dwWidth)) ||
613 ((xsrc.bottom <= 0) || (xsrc.right <= 0) || (xsrc.top >= (int) sdesc.dwHeight) || (xsrc.left >= (int) sdesc.dwWidth))))
615 TRACE("Nothing to be done !\n");
619 /* The easy case : the source-less blits.... */
622 RECT temp_rect; /* No idea if intersect rect can be the same as one of the source rect */
626 full_rect.right = ddesc.dwWidth;
627 full_rect.bottom = ddesc.dwHeight;
628 IntersectRect(&temp_rect, &full_rect, &xdst);
631 /* Only handle clipping on the destination rectangle */
632 int clip_horiz = (xdst.left < 0) || (xdst.right > (int) ddesc.dwWidth );
633 int clip_vert = (xdst.top < 0) || (xdst.bottom > (int) ddesc.dwHeight);
634 if (clip_vert || clip_horiz) {
635 /* Now check if this is a special case or not... */
636 if ((((xdst.bottom - xdst.top ) != (xsrc.bottom - xsrc.top )) && clip_vert ) ||
637 (((xdst.right - xdst.left) != (xsrc.right - xsrc.left)) && clip_horiz) ||
638 (dwFlags & DDBLT_DDFX)) {
639 WARN("Out of screen rectangle in special case. Not handled right now.\n");
644 if (xdst.left < 0) { xsrc.left -= xdst.left; xdst.left = 0; }
645 if (xdst.right > ddesc.dwWidth) { xsrc.right -= (xdst.right - (int) ddesc.dwWidth); xdst.right = (int) ddesc.dwWidth; }
648 if (xdst.top < 0) { xsrc.top -= xdst.top; xdst.top = 0; }
649 if (xdst.bottom > ddesc.dwHeight) { xsrc.bottom -= (xdst.bottom - (int) ddesc.dwHeight); xdst.bottom = (int) ddesc.dwHeight; }
651 /* And check if after clipping something is still to be done... */
652 if ((xdst.bottom <= 0) || (xdst.right <= 0) || (xdst.top >= (int) ddesc.dwHeight) || (xdst.left >= (int) ddesc.dwWidth) ||
653 (xsrc.bottom <= 0) || (xsrc.right <= 0) || (xsrc.top >= (int) sdesc.dwHeight) || (xsrc.left >= (int) sdesc.dwWidth)) {
654 TRACE("Nothing to be done after clipping !\n");
660 bpp = GET_BPP(ddesc);
661 srcheight = xsrc.bottom - xsrc.top;
662 srcwidth = xsrc.right - xsrc.left;
663 dstheight = xdst.bottom - xdst.top;
664 dstwidth = xdst.right - xdst.left;
665 width = (xdst.right - xdst.left) * bpp;
667 assert(width <= ddesc.u1.lPitch);
669 dbuf = (BYTE*)ddesc.lpSurface+(xdst.top*ddesc.u1.lPitch)+(xdst.left*bpp);
671 if (dwFlags & (DDBLT_WAIT|DDBLT_ASYNC))
673 static BOOL displayed = FALSE;
676 FIXME("dwFlags DDBLT_WAIT and/or DDBLT_ASYNC: can't handle right now.\n");
679 dwFlags &= ~(DDBLT_WAIT|DDBLT_ASYNC);
682 /* First, all the 'source-less' blits */
683 if (dwFlags & DDBLT_COLORFILL) {
684 ret = _Blt_ColorFill(dbuf, dstwidth, dstheight, bpp,
685 ddesc.u1.lPitch, lpbltfx->u5.dwFillColor);
686 dwFlags &= ~DDBLT_COLORFILL;
689 if (dwFlags & DDBLT_DEPTHFILL)
690 FIXME("DDBLT_DEPTHFILL needs to be implemented!\n");
691 if (dwFlags & DDBLT_ROP) {
692 /* Catch some degenerate cases here */
693 switch(lpbltfx->dwROP) {
695 ret = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,ddesc.u1.lPitch,0);
697 case 0xAA0029: /* No-op */
700 ret = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,ddesc.u1.lPitch,~0);
702 case SRCCOPY: /* well, we do that below ? */
705 FIXME("Unsupported raster op: %08lx Pattern: %p\n", lpbltfx->dwROP, lpbltfx->u5.lpDDSPattern);
708 dwFlags &= ~DDBLT_ROP;
710 if (dwFlags & DDBLT_DDROPS) {
711 FIXME("\tDdraw Raster Ops: %08lx Pattern: %p\n", lpbltfx->dwDDROP, lpbltfx->u5.lpDDSPattern);
713 /* Now the 'with source' blits */
716 int sx, xinc, sy, yinc;
718 if (!dstwidth || !dstheight) /* hmm... stupid program ? */
720 sbase = (BYTE*)sdesc.lpSurface+(xsrc.top*sdesc.u1.lPitch)+xsrc.left*bpp;
721 xinc = (srcwidth << 16) / dstwidth;
722 yinc = (srcheight << 16) / dstheight;
725 /* No effects, we can cheat here */
726 if (dstwidth == srcwidth) {
727 if (dstheight == srcheight) {
728 /* No stretching in either direction. This needs to be as
729 * fast as possible */
732 /* check for overlapping surfaces */
733 if (src != iface || xdst.top < xsrc.top ||
734 xdst.right <= xsrc.left || xsrc.right <= xdst.left)
736 /* no overlap, or dst above src, so copy from top downwards */
737 for (y = 0; y < dstheight; y++)
739 memcpy(dbuf, sbuf, width);
740 sbuf += sdesc.u1.lPitch;
741 dbuf += ddesc.u1.lPitch;
744 else if (xdst.top > xsrc.top) /* copy from bottom upwards */
746 sbuf += (sdesc.u1.lPitch*dstheight);
747 dbuf += (ddesc.u1.lPitch*dstheight);
748 for (y = 0; y < dstheight; y++)
750 sbuf -= sdesc.u1.lPitch;
751 dbuf -= ddesc.u1.lPitch;
752 memcpy(dbuf, sbuf, width);
755 else /* src and dst overlapping on the same line, use memmove */
757 for (y = 0; y < dstheight; y++)
759 memmove(dbuf, sbuf, width);
760 sbuf += sdesc.u1.lPitch;
761 dbuf += ddesc.u1.lPitch;
765 /* Stretching in Y direction only */
766 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
767 sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
768 memcpy(dbuf, sbuf, width);
769 dbuf += ddesc.u1.lPitch;
773 /* Stretching in X direction */
775 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
776 sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
778 if ((sy >> 16) == (last_sy >> 16)) {
779 /* this sourcerow is the same as last sourcerow -
780 * copy already stretched row
782 memcpy(dbuf, dbuf - ddesc.u1.lPitch, width);
784 #define STRETCH_ROW(type) { \
785 type *s = (type *) sbuf, *d = (type *) dbuf; \
786 for (x = sx = 0; x < dstwidth; x++, sx += xinc) \
787 d[x] = s[sx >> 16]; \
791 case 1: STRETCH_ROW(BYTE)
792 case 2: STRETCH_ROW(WORD)
793 case 4: STRETCH_ROW(DWORD)
796 for (x = sx = 0; x < dstwidth; x++, sx+= xinc) {
800 pixel = s[0]|(s[1]<<8)|(s[2]<<16);
801 d[0] = (pixel )&0xff;
802 d[1] = (pixel>> 8)&0xff;
803 d[2] = (pixel>>16)&0xff;
809 FIXME("Stretched blit not implemented for bpp %d!\n", bpp*8);
810 ret = DDERR_UNSUPPORTED;
815 dbuf += ddesc.u1.lPitch;
820 LONG dstyinc = ddesc.u1.lPitch, dstxinc = bpp;
821 DWORD keylow = 0, keyhigh = 0;
822 if (dwFlags & (DDBLT_KEYSRC | DDBLT_KEYDEST | DDBLT_KEYSRCOVERRIDE | DDBLT_KEYDESTOVERRIDE)) {
824 if (dwFlags & DDBLT_KEYSRC) {
825 keylow = sdesc.ddckCKSrcBlt.dwColorSpaceLowValue;
826 keyhigh = sdesc.ddckCKSrcBlt.dwColorSpaceHighValue;
827 } else if (dwFlags & DDBLT_KEYDEST){
828 keylow = ddesc.ddckCKDestBlt.dwColorSpaceLowValue;
829 keyhigh = ddesc.ddckCKDestBlt.dwColorSpaceHighValue;
830 } else if (dwFlags & DDBLT_KEYSRCOVERRIDE) {
831 keylow = lpbltfx->ddckSrcColorkey.dwColorSpaceLowValue;
832 keyhigh = lpbltfx->ddckSrcColorkey.dwColorSpaceHighValue;
834 keylow = lpbltfx->ddckDestColorkey.dwColorSpaceLowValue;
835 keyhigh = lpbltfx->ddckDestColorkey.dwColorSpaceHighValue;
837 dwFlags &= ~(DDBLT_KEYSRC | DDBLT_KEYDEST | DDBLT_KEYSRCOVERRIDE | DDBLT_KEYDESTOVERRIDE);
840 if (dwFlags & DDBLT_DDFX) {
841 LPBYTE dTopLeft, dTopRight, dBottomLeft, dBottomRight, tmp;
844 dTopRight = dbuf+((dstwidth-1)*bpp);
845 dBottomLeft = dTopLeft+((dstheight-1)*ddesc.u1.lPitch);
846 dBottomRight = dBottomLeft+((dstwidth-1)*bpp);
848 if (lpbltfx->dwDDFX & DDBLTFX_ARITHSTRETCHY){
849 /* I don't think we need to do anything about this flag */
850 WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_ARITHSTRETCHY\n");
852 if (lpbltfx->dwDDFX & DDBLTFX_MIRRORLEFTRIGHT) {
854 dTopRight = dTopLeft;
857 dBottomRight = dBottomLeft;
859 dstxinc = dstxinc *-1;
861 if (lpbltfx->dwDDFX & DDBLTFX_MIRRORUPDOWN) {
863 dTopLeft = dBottomLeft;
866 dTopRight = dBottomRight;
868 dstyinc = dstyinc *-1;
870 if (lpbltfx->dwDDFX & DDBLTFX_NOTEARING) {
871 /* I don't think we need to do anything about this flag */
872 WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_NOTEARING\n");
874 if (lpbltfx->dwDDFX & DDBLTFX_ROTATE180) {
876 dBottomRight = dTopLeft;
879 dBottomLeft = dTopRight;
881 dstxinc = dstxinc * -1;
882 dstyinc = dstyinc * -1;
884 if (lpbltfx->dwDDFX & DDBLTFX_ROTATE270) {
886 dTopLeft = dBottomLeft;
887 dBottomLeft = dBottomRight;
888 dBottomRight = dTopRight;
893 dstxinc = dstxinc * -1;
895 if (lpbltfx->dwDDFX & DDBLTFX_ROTATE90) {
897 dTopLeft = dTopRight;
898 dTopRight = dBottomRight;
899 dBottomRight = dBottomLeft;
904 dstyinc = dstyinc * -1;
906 if (lpbltfx->dwDDFX & DDBLTFX_ZBUFFERBASEDEST) {
907 /* I don't think we need to do anything about this flag */
908 WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_ZBUFFERBASEDEST\n");
911 dwFlags &= ~(DDBLT_DDFX);
914 #define COPY_COLORKEY_FX(type) { \
915 type *s, *d = (type *) dbuf, *dx, tmp; \
916 for (y = sy = 0; y < dstheight; y++, sy += yinc) { \
917 s = (type*)(sbase + (sy >> 16) * sdesc.u1.lPitch); \
919 for (x = sx = 0; x < dstwidth; x++, sx += xinc) { \
921 if (tmp < keylow || tmp > keyhigh) dx[0] = tmp; \
922 dx = (type*)(((LPBYTE)dx)+dstxinc); \
924 d = (type*)(((LPBYTE)d)+dstyinc); \
929 case 1: COPY_COLORKEY_FX(BYTE)
930 case 2: COPY_COLORKEY_FX(WORD)
931 case 4: COPY_COLORKEY_FX(DWORD)
932 case 3: {LPBYTE s,d = dbuf, dx;
933 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
934 sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
936 for (x = sx = 0; x < dstwidth; x++, sx+= xinc) {
939 pixel = s[0]|(s[1]<<8)|(s[2]<<16);
940 if (pixel < keylow || pixel > keyhigh){
941 dx[0] = (pixel )&0xff;
942 dx[1] = (pixel>> 8)&0xff;
943 dx[2] = (pixel>>16)&0xff;
951 FIXME("%s color-keyed blit not implemented for bpp %d!\n",
952 (dwFlags & DDBLT_KEYSRC) ? "Source" : "Destination", bpp*8);
953 ret = DDERR_UNSUPPORTED;
955 #undef COPY_COLORKEY_FX
961 if (dwFlags && FIXME_ON(ddraw)) {
962 FIXME("\tUnsupported flags: ");
963 DDRAW_dump_DDBLT(dwFlags);
967 IDirectDrawSurface7_Unlock(iface,NULL);
968 if (src && src != iface) IDirectDrawSurface7_Unlock(src,NULL);
972 /* BltBatch: generic, unimplemented */
975 DIB_DirectDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface, DWORD dstx,
976 DWORD dsty, LPDIRECTDRAWSURFACE7 src,
977 LPRECT rsrc, DWORD trans)
979 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
981 DDSURFACEDESC2 ddesc,sdesc;
985 RECT lock_src, lock_dst, lock_union;
987 if (TRACE_ON(ddraw)) {
988 TRACE("(%p)->(%ld,%ld,%p,%p,%08lx)\n",
989 This,dstx,dsty,src,rsrc,trans
993 DDRAW_dump_DDBLTFAST(trans);
995 TRACE("\tsrcrect: %ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
997 TRACE(" srcrect: NULL\n");
1000 if ((This->locked) || ((src != NULL) && (((IDirectDrawSurfaceImpl *)src)->locked))) {
1001 WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
1002 return DDERR_SURFACEBUSY;
1005 /* First, check if the possible override function handles this case */
1006 if (This->aux_bltfast != NULL) {
1007 if (This->aux_bltfast(This, dstx, dsty, src, rsrc, trans) == DD_OK) return DD_OK;
1010 /* Get the surface description without locking to first compute the width / height */
1011 ddesc = This->surface_desc;
1012 sdesc = (ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, src))->surface_desc;
1015 WARN("rsrc is NULL!\n");
1017 rsrc->left = rsrc->top = 0;
1018 rsrc->right = sdesc.dwWidth;
1019 rsrc->bottom = sdesc.dwHeight;
1022 /* Check source rect for validity. Copied from normal Blt. Fixes Baldur's Gate.*/
1023 if ((rsrc->bottom > sdesc.dwHeight) || (rsrc->bottom < 0) ||
1024 (rsrc->top > sdesc.dwHeight) || (rsrc->top < 0) ||
1025 (rsrc->left > sdesc.dwWidth) || (rsrc->left < 0) ||
1026 (rsrc->right > sdesc.dwWidth) || (rsrc->right < 0) ||
1027 (rsrc->right < rsrc->left) || (rsrc->bottom < rsrc->top)) {
1028 WARN("Application gave us bad source rectangle for BltFast.\n");
1029 return DDERR_INVALIDRECT;
1032 h=rsrc->bottom-rsrc->top;
1033 if (h>ddesc.dwHeight-dsty) h=ddesc.dwHeight-dsty;
1034 if (h>sdesc.dwHeight-rsrc->top) h=sdesc.dwHeight-rsrc->top;
1035 if (h<=0) return DDERR_INVALIDRECT;
1037 w=rsrc->right-rsrc->left;
1038 if (w>ddesc.dwWidth-dstx) w=ddesc.dwWidth-dstx;
1039 if (w>sdesc.dwWidth-rsrc->left) w=sdesc.dwWidth-rsrc->left;
1040 if (w<=0) return DDERR_INVALIDRECT;
1042 /* Now compute the locking rectangle... */
1043 lock_src.left = rsrc->left;
1044 lock_src.top = rsrc->top;
1045 lock_src.right = lock_src.left + w;
1046 lock_src.bottom = lock_src.top + h;
1048 lock_dst.left = dstx;
1049 lock_dst.top = dsty;
1050 lock_dst.right = dstx + w;
1051 lock_dst.bottom = dsty + h;
1053 bpp = GET_BPP(This->surface_desc);
1055 /* We need to lock the surfaces, or we won't get refreshes when done. */
1059 UnionRect(&lock_union, &lock_src, &lock_dst);
1061 /* Lock the union of the two rectangles */
1062 IDirectDrawSurface7_Lock(iface, &lock_union, &ddesc, 0, 0);
1064 pitch = This->surface_desc.u1.lPitch;
1066 /* Since sdesc was originally copied from this surface's description, we can just reuse it */
1067 sdesc.lpSurface = (BYTE *)This->surface_desc.lpSurface + lock_src.top * pitch + lock_src.left * bpp;
1068 ddesc.lpSurface = (BYTE *)This->surface_desc.lpSurface + lock_dst.top * pitch + lock_dst.left * bpp;
1070 sdesc.dwSize = sizeof(sdesc);
1071 IDirectDrawSurface7_Lock(src, &lock_src, &sdesc, DDLOCK_READONLY, 0);
1072 ddesc.dwSize = sizeof(ddesc);
1073 IDirectDrawSurface7_Lock(iface, &lock_dst, &ddesc, DDLOCK_WRITEONLY, 0);
1076 /* Handle first the FOURCC surfaces... */
1077 if ((sdesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) && (ddesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC)) {
1079 FIXME("trans arg not supported when a FOURCC surface is involved\n");
1081 FIXME("offset for destination surface is not supported\n");
1082 if (sdesc.u4.ddpfPixelFormat.dwFourCC != sdesc.u4.ddpfPixelFormat.dwFourCC) {
1083 FIXME("FOURCC->FOURCC copy only supported for the same type of surface\n");
1084 ret = DDERR_INVALIDPIXELFORMAT;
1087 memcpy(ddesc.lpSurface, sdesc.lpSurface, ddesc.u1.dwLinearSize);
1090 if ((sdesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) &&
1091 (!(ddesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC))) {
1092 DoDXTCDecompression(&sdesc, &ddesc);
1096 sbuf = (BYTE *) sdesc.lpSurface;
1097 dbuf = (BYTE *) ddesc.lpSurface;
1099 if (trans & (DDBLTFAST_SRCCOLORKEY | DDBLTFAST_DESTCOLORKEY)) {
1100 DWORD keylow, keyhigh;
1101 if (trans & DDBLTFAST_SRCCOLORKEY) {
1102 keylow = sdesc.ddckCKSrcBlt.dwColorSpaceLowValue;
1103 keyhigh = sdesc.ddckCKSrcBlt.dwColorSpaceHighValue;
1105 /* I'm not sure if this is correct */
1106 FIXME("DDBLTFAST_DESTCOLORKEY not fully supported yet.\n");
1107 keylow = ddesc.ddckCKDestBlt.dwColorSpaceLowValue;
1108 keyhigh = ddesc.ddckCKDestBlt.dwColorSpaceHighValue;
1111 #define COPYBOX_COLORKEY(type) { \
1113 s = (type *) sdesc.lpSurface; \
1114 d = (type *) ddesc.lpSurface; \
1115 for (y = 0; y < h; y++) { \
1116 for (x = 0; x < w; x++) { \
1118 if (tmp < keylow || tmp > keyhigh) d[x] = tmp; \
1120 s = (type *)((BYTE *)s + sdesc.u1.lPitch); \
1121 d = (type *)((BYTE *)d + ddesc.u1.lPitch); \
1127 case 1: COPYBOX_COLORKEY(BYTE)
1128 case 2: COPYBOX_COLORKEY(WORD)
1129 case 4: COPYBOX_COLORKEY(DWORD)
1134 s = (BYTE *) sdesc.lpSurface;
1135 d = (BYTE *) ddesc.lpSurface;
1136 for (y = 0; y < h; y++) {
1137 for (x = 0; x < w * 3; x += 3) {
1138 tmp = (DWORD)s[x] + ((DWORD)s[x + 1] << 8) + ((DWORD)s[x + 2] << 16);
1139 if (tmp < keylow || tmp > keyhigh) {
1140 d[x + 0] = s[x + 0];
1141 d[x + 1] = s[x + 1];
1142 d[x + 2] = s[x + 2];
1145 s += sdesc.u1.lPitch;
1146 d += ddesc.u1.lPitch;
1151 FIXME("Source color key blitting not supported for bpp %d\n",bpp*8);
1152 ret = DDERR_UNSUPPORTED;
1155 #undef COPYBOX_COLORKEY
1157 int width = w * bpp;
1159 for (y = 0; y < h; y++) {
1160 memcpy(dbuf, sbuf, width);
1161 sbuf += sdesc.u1.lPitch;
1162 dbuf += ddesc.u1.lPitch;
1168 IDirectDrawSurface7_Unlock(iface, &lock_union);
1170 IDirectDrawSurface7_Unlock(iface, &lock_dst);
1171 IDirectDrawSurface7_Unlock(src, &lock_src);
1177 /* ChangeUniquenessValue: generic */
1178 /* DeleteAttachedSurface: generic */
1179 /* EnumAttachedSurfaces: generic */
1180 /* EnumOverlayZOrders: generic, unimplemented */
1182 BOOL DIB_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl* front,
1183 IDirectDrawSurfaceImpl* back,
1186 DIB_DirectDrawSurfaceImpl* front_priv = front->private;
1187 DIB_DirectDrawSurfaceImpl* back_priv = back->private;
1189 TRACE("(%p,%p)\n",front,back);
1193 tmp = front_priv->dib.DIBsection;
1194 front_priv->dib.DIBsection = back_priv->dib.DIBsection;
1195 back_priv->dib.DIBsection = tmp;
1200 tmp = front_priv->dib.bitmap_data;
1201 front_priv->dib.bitmap_data = back_priv->dib.bitmap_data;
1202 back_priv->dib.bitmap_data = tmp;
1204 tmp = front->surface_desc.lpSurface;
1205 front->surface_desc.lpSurface = back->surface_desc.lpSurface;
1206 back->surface_desc.lpSurface = tmp;
1209 /* client_memory should not be different, but just in case */
1212 tmp = front_priv->dib.client_memory;
1213 front_priv->dib.client_memory = back_priv->dib.client_memory;
1214 back_priv->dib.client_memory = tmp;
1217 return Main_DirectDrawSurface_flip_data(front, back, dwFlags);
1221 /* FreePrivateData: generic */
1222 /* GetAttachedSurface: generic */
1223 /* GetBltStatus: generic */
1224 /* GetCaps: generic (Returns the caps from This->surface_desc.) */
1225 /* GetClipper: generic */
1226 /* GetColorKey: generic */
1228 HRESULT DIB_DirectDrawSurface_alloc_dc(IDirectDrawSurfaceImpl* This, HDC* phDC)
1230 DIB_PRIV_VAR(priv, This);
1233 TRACE("Grabbing a DC for surface: %p\n", This);
1235 hDC = CreateCompatibleDC(0);
1236 priv->dib.holdbitmap = SelectObject(hDC, priv->dib.DIBsection);
1238 SelectPalette(hDC, This->palette->hpal, FALSE);
1245 HRESULT DIB_DirectDrawSurface_free_dc(IDirectDrawSurfaceImpl* This, HDC hDC)
1247 DIB_PRIV_VAR(priv, This);
1249 TRACE("Releasing DC for surface: %p\n", This);
1251 SelectObject(hDC, priv->dib.holdbitmap);
1257 HRESULT DIB_DirectDrawSurface_get_dc(IDirectDrawSurfaceImpl* This, HDC* phDC)
1259 return DIB_DirectDrawSurface_alloc_dc(This, phDC);
1262 HRESULT DIB_DirectDrawSurface_release_dc(IDirectDrawSurfaceImpl* This, HDC hDC)
1264 return DIB_DirectDrawSurface_free_dc(This, hDC);
1267 /* GetDDInterface: generic */
1268 /* GetFlipStatus: generic */
1269 /* GetLOD: generic */
1270 /* GetOverlayPosition: generic */
1271 /* GetPalette: generic */
1272 /* GetPixelFormat: generic */
1273 /* GetPriority: generic */
1274 /* GetPrivateData: generic */
1275 /* GetSurfaceDesc: generic */
1276 /* GetUniquenessValue: generic */
1277 /* Initialize: generic */
1278 /* IsLost: generic */
1279 /* Lock: generic with callback? */
1280 /* PageLock: generic */
1281 /* PageUnlock: generic */
1284 DIB_DirectDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface)
1286 TRACE("(%p)\n",iface);
1287 return DD_OK; /* ??? */
1290 /* SetClipper: generic */
1291 /* SetColorKey: generic */
1292 /* SetLOD: generic */
1293 /* SetOverlayPosition: generic */
1295 void DIB_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl* This,
1296 IDirectDrawPaletteImpl* pal)
1299 if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
1300 This->update_palette(This, pal,
1301 0, pal->palNumEntries,
1305 void DIB_DirectDrawSurface_update_palette(IDirectDrawSurfaceImpl* This,
1306 IDirectDrawPaletteImpl* pal,
1307 DWORD dwStart, DWORD dwCount,
1308 LPPALETTEENTRY palent)
1314 TRACE("updating primary palette\n");
1315 for (n=0; n<dwCount; n++) {
1316 col[n].rgbRed = palent[n].peRed;
1317 col[n].rgbGreen = palent[n].peGreen;
1318 col[n].rgbBlue = palent[n].peBlue;
1319 col[n].rgbReserved = 0;
1321 This->get_dc(This, &dc);
1322 SetDIBColorTable(dc, dwStart, dwCount, col);
1323 This->release_dc(This, dc);
1325 /* Propagate change to backbuffers if there are any */
1326 /* Basically this is a modification of the Flip code to find the backbuffer */
1327 /* and duplicate the palette update there as well */
1328 if ((This->surface_desc.ddsCaps.dwCaps&(DDSCAPS_FLIP|DDSCAPS_FRONTBUFFER))
1329 == (DDSCAPS_FLIP|DDSCAPS_FRONTBUFFER))
1331 static DDSCAPS2 back_caps = { DDSCAPS_BACKBUFFER };
1332 LPDIRECTDRAWSURFACE7 tgt;
1334 HRESULT hr = IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This,IDirectDrawSurface7),
1338 IDirectDrawSurfaceImpl* target = ICOM_OBJECT(IDirectDrawSurfaceImpl,
1339 IDirectDrawSurface7,tgt);
1340 IDirectDrawSurface7_Release(tgt);
1341 target->get_dc(target, &dc);
1342 SetDIBColorTable(dc, dwStart, dwCount, col);
1343 target->release_dc(target, dc);
1348 /* SetPalette: generic */
1349 /* SetPriority: generic */
1350 /* SetPrivateData: generic */
1353 DIB_DirectDrawSurface_SetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
1354 LPDDSURFACEDESC2 pDDSD, DWORD dwFlags)
1356 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1357 DIB_PRIV_VAR(priv, This);
1359 DWORD flags = pDDSD->dwFlags;
1361 if (TRACE_ON(ddraw)) {
1362 TRACE("(%p)->(%p,%08lx)\n",iface,pDDSD,dwFlags);
1363 DDRAW_dump_surface_desc(pDDSD);
1366 if (pDDSD->dwFlags & DDSD_PIXELFORMAT) {
1367 flags &= ~DDSD_PIXELFORMAT;
1368 if (flags & DDSD_LPSURFACE) {
1369 This->surface_desc.u4.ddpfPixelFormat = pDDSD->u4.ddpfPixelFormat;
1371 FIXME("Change of pixel format without surface re-allocation is not supported !\n");
1374 if (pDDSD->dwFlags & DDSD_LPSURFACE) {
1375 HBITMAP oldbmp = priv->dib.DIBsection;
1376 LPVOID oldsurf = This->surface_desc.lpSurface;
1377 BOOL oldc = priv->dib.client_memory;
1379 flags &= ~DDSD_LPSURFACE;
1381 TRACE("new lpSurface=%p\n",pDDSD->lpSurface);
1382 This->surface_desc.lpSurface = pDDSD->lpSurface;
1383 priv->dib.client_memory = TRUE;
1385 hr = create_dib(This);
1388 priv->dib.DIBsection = oldbmp;
1389 This->surface_desc.lpSurface = oldsurf;
1390 priv->dib.client_memory = oldc;
1394 DeleteObject(oldbmp);
1397 VirtualFree(oldsurf, 0, MEM_RELEASE);
1400 WARN("Unhandled flags : %08lx\n", flags);
1405 /* Unlock: ???, need callback */
1406 /* UpdateOverlay: generic */
1407 /* UpdateOverlayDisplay: generic */
1408 /* UpdateOverlayZOrder: generic */
1410 static const IDirectDrawSurface7Vtbl DIB_IDirectDrawSurface7_VTable =
1412 Main_DirectDrawSurface_QueryInterface,
1413 Main_DirectDrawSurface_AddRef,
1414 Main_DirectDrawSurface_Release,
1415 Main_DirectDrawSurface_AddAttachedSurface,
1416 Main_DirectDrawSurface_AddOverlayDirtyRect,
1417 DIB_DirectDrawSurface_Blt,
1418 Main_DirectDrawSurface_BltBatch,
1419 DIB_DirectDrawSurface_BltFast,
1420 Main_DirectDrawSurface_DeleteAttachedSurface,
1421 Main_DirectDrawSurface_EnumAttachedSurfaces,
1422 Main_DirectDrawSurface_EnumOverlayZOrders,
1423 Main_DirectDrawSurface_Flip,
1424 Main_DirectDrawSurface_GetAttachedSurface,
1425 Main_DirectDrawSurface_GetBltStatus,
1426 Main_DirectDrawSurface_GetCaps,
1427 Main_DirectDrawSurface_GetClipper,
1428 Main_DirectDrawSurface_GetColorKey,
1429 Main_DirectDrawSurface_GetDC,
1430 Main_DirectDrawSurface_GetFlipStatus,
1431 Main_DirectDrawSurface_GetOverlayPosition,
1432 Main_DirectDrawSurface_GetPalette,
1433 Main_DirectDrawSurface_GetPixelFormat,
1434 Main_DirectDrawSurface_GetSurfaceDesc,
1435 Main_DirectDrawSurface_Initialize,
1436 Main_DirectDrawSurface_IsLost,
1437 Main_DirectDrawSurface_Lock,
1438 Main_DirectDrawSurface_ReleaseDC,
1439 DIB_DirectDrawSurface_Restore,
1440 Main_DirectDrawSurface_SetClipper,
1441 Main_DirectDrawSurface_SetColorKey,
1442 Main_DirectDrawSurface_SetOverlayPosition,
1443 Main_DirectDrawSurface_SetPalette,
1444 Main_DirectDrawSurface_Unlock,
1445 Main_DirectDrawSurface_UpdateOverlay,
1446 Main_DirectDrawSurface_UpdateOverlayDisplay,
1447 Main_DirectDrawSurface_UpdateOverlayZOrder,
1448 Main_DirectDrawSurface_GetDDInterface,
1449 Main_DirectDrawSurface_PageLock,
1450 Main_DirectDrawSurface_PageUnlock,
1451 DIB_DirectDrawSurface_SetSurfaceDesc,
1452 Main_DirectDrawSurface_SetPrivateData,
1453 Main_DirectDrawSurface_GetPrivateData,
1454 Main_DirectDrawSurface_FreePrivateData,
1455 Main_DirectDrawSurface_GetUniquenessValue,
1456 Main_DirectDrawSurface_ChangeUniquenessValue,
1457 Main_DirectDrawSurface_SetPriority,
1458 Main_DirectDrawSurface_GetPriority,
1459 Main_DirectDrawSurface_SetLOD,
1460 Main_DirectDrawSurface_GetLOD