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"
37 #include "dsurface/main.h"
38 #include "dsurface/dib.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
43 extern HBITMAP DIB_CreateDIBSection( HDC hdc, const BITMAPINFO *bmi, UINT usage, VOID **bits,
44 HANDLE section, DWORD offset, DWORD ovr_pitch );
46 static const IDirectDrawSurface7Vtbl DIB_IDirectDrawSurface7_VTable;
48 /* Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned. */
49 inline static int get_dib_width_bytes( int width, int depth )
55 case 1: words = (width + 31) / 32; break;
56 case 4: words = (width + 7) / 8; break;
57 case 8: words = (width + 3) / 4; break;
59 case 16: words = (width + 1) / 2; break;
60 case 24: words = (width * 3 + 3)/4; break;
62 WARN("(%d): Unsupported depth\n", depth );
64 case 32: words = width; break;
70 static HRESULT create_dib(IDirectDrawSurfaceImpl* This)
75 DIB_DirectDrawSurfaceImpl* priv = This->private;
77 assert(This->surface_desc.lpSurface != NULL);
79 switch (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount)
83 /* Allocate extra space to store the RGB bit masks. */
84 b_info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
85 sizeof(BITMAPINFOHEADER) + 3 * sizeof(DWORD));
89 b_info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
90 sizeof(BITMAPINFOHEADER));
94 /* Allocate extra space for a palette. */
95 b_info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
96 sizeof(BITMAPINFOHEADER)
98 * (1 << This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount));
102 b_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
103 b_info->bmiHeader.biWidth = This->surface_desc.dwWidth;
104 b_info->bmiHeader.biHeight = -This->surface_desc.dwHeight;
105 b_info->bmiHeader.biPlanes = 1;
106 b_info->bmiHeader.biBitCount = This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount;
108 if ((This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount != 16)
109 && (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount != 32))
110 b_info->bmiHeader.biCompression = BI_RGB;
112 b_info->bmiHeader.biCompression = BI_BITFIELDS;
114 b_info->bmiHeader.biSizeImage
115 = (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount / 8)
116 * This->surface_desc.dwWidth * This->surface_desc.dwHeight;
118 b_info->bmiHeader.biXPelsPerMeter = 0;
119 b_info->bmiHeader.biYPelsPerMeter = 0;
120 b_info->bmiHeader.biClrUsed = 0;
121 b_info->bmiHeader.biClrImportant = 0;
123 if (!This->surface_desc.u1.lPitch) {
124 /* This can't happen, right? */
125 /* or use GDI_GetObj to get it from the created DIB? */
126 This->surface_desc.u1.lPitch = get_dib_width_bytes(b_info->bmiHeader.biWidth, b_info->bmiHeader.biBitCount);
127 This->surface_desc.dwFlags |= DDSD_PITCH;
130 switch (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount)
135 DWORD *masks = (DWORD *) &(b_info->bmiColors);
138 masks[0] = This->surface_desc.u4.ddpfPixelFormat.u2.dwRBitMask;
139 masks[1] = This->surface_desc.u4.ddpfPixelFormat.u3.dwGBitMask;
140 masks[2] = This->surface_desc.u4.ddpfPixelFormat.u4.dwBBitMask;
146 usage = DIB_RGB_COLORS;
150 /* Don't know palette */
155 ddc = CreateDCA("DISPLAY", NULL, NULL, NULL);
158 HeapFree(GetProcessHeap(), 0, b_info);
159 return HRESULT_FROM_WIN32(GetLastError());
163 = DIB_CreateDIBSection(ddc, b_info, usage, &(priv->dib.bitmap_data), 0,
164 (DWORD)This->surface_desc.lpSurface,
165 This->surface_desc.u1.lPitch);
167 if (!priv->dib.DIBsection) {
168 ERR("CreateDIBSection failed!\n");
169 HeapFree(GetProcessHeap(), 0, b_info);
170 return HRESULT_FROM_WIN32(GetLastError());
173 TRACE("DIBSection at : %p\n", priv->dib.bitmap_data);
175 if (!This->surface_desc.lpSurface) {
176 This->surface_desc.lpSurface = priv->dib.bitmap_data;
177 This->surface_desc.dwFlags |= DDSD_LPSURFACE;
180 HeapFree(GetProcessHeap(), 0, b_info);
182 /* I don't think it's worth checking for this. */
183 if (priv->dib.bitmap_data != This->surface_desc.lpSurface)
184 ERR("unexpected error creating DirectDrawSurface DIB section\n");
186 /* this seems like a good place to put the handle for HAL driver use */
187 This->global_more.hKernelSurface = (ULONG_PTR)priv->dib.DIBsection;
192 void DIB_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
194 DIB_DirectDrawSurfaceImpl* priv = This->private;
196 DeleteObject(priv->dib.DIBsection);
198 if (!priv->dib.client_memory)
199 VirtualFree(This->surface_desc.lpSurface, 0, MEM_RELEASE);
201 Main_DirectDrawSurface_final_release(This);
204 HRESULT DIB_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,
205 LPDIRECTDRAWSURFACE7* ppDup)
207 return DIB_DirectDrawSurface_Create(This->ddraw_owner,
208 &This->surface_desc, ppDup, NULL);
211 HRESULT DIB_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
212 IDirectDrawImpl *pDD,
213 const DDSURFACEDESC2 *pDDSD)
216 DIB_DirectDrawSurfaceImpl* priv = This->private;
218 TRACE("(%p)->(%p,%p)\n",This,pDD,pDDSD);
219 hr = Main_DirectDrawSurface_Construct(This, pDD, pDDSD);
220 if (FAILED(hr)) return hr;
222 ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,
223 DIB_IDirectDrawSurface7_VTable);
225 This->final_release = DIB_DirectDrawSurface_final_release;
226 This->duplicate_surface = DIB_DirectDrawSurface_duplicate_surface;
227 This->flip_data = DIB_DirectDrawSurface_flip_data;
229 This->get_dc = DIB_DirectDrawSurface_get_dc;
230 This->release_dc = DIB_DirectDrawSurface_release_dc;
233 This->set_palette = DIB_DirectDrawSurface_set_palette;
234 This->update_palette = DIB_DirectDrawSurface_update_palette;
236 TRACE("(%ldx%ld, pitch=%ld)\n",
237 This->surface_desc.dwWidth, This->surface_desc.dwHeight,
238 This->surface_desc.u1.lPitch);
239 /* XXX load dwWidth and dwHeight from pDD if they are not specified? */
241 if (This->surface_desc.dwFlags & DDSD_LPSURFACE)
243 /* "Client memory": it is managed by the application. */
244 /* XXX What if lPitch is not set? Use dwWidth or fail? */
246 priv->dib.client_memory = TRUE;
250 if (!(This->surface_desc.dwFlags & DDSD_PITCH))
252 int pitch = This->surface_desc.u1.lPitch;
254 pitch += 8 - (pitch % 8);
256 /* XXX else: how should lPitch be verified? */
258 This->surface_desc.dwFlags |= DDSD_LPSURFACE;
260 /* Ensure that DDSD_PITCH is respected for DDPF_FOURCC surfaces too */
261 if (This->surface_desc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC && !(This->surface_desc.dwFlags & DDSD_PITCH)) {
262 This->surface_desc.lpSurface
263 = VirtualAlloc(NULL, This->surface_desc.u1.dwLinearSize, MEM_COMMIT, PAGE_READWRITE);
264 This->surface_desc.dwFlags |= DDSD_LINEARSIZE;
266 This->surface_desc.lpSurface
267 = VirtualAlloc(NULL, This->surface_desc.u1.lPitch
268 * This->surface_desc.dwHeight + 4, /* The + 4 here is for dumb games reading after the end of the surface
269 when reading the last byte / half using word access */
270 MEM_COMMIT, PAGE_READWRITE);
271 This->surface_desc.dwFlags |= DDSD_PITCH;
274 if (This->surface_desc.lpSurface == NULL)
276 Main_DirectDrawSurface_final_release(This);
277 return HRESULT_FROM_WIN32(GetLastError());
280 priv->dib.client_memory = FALSE;
283 hr = create_dib(This);
286 if (!priv->dib.client_memory)
287 VirtualFree(This->surface_desc.lpSurface, 0, MEM_RELEASE);
289 Main_DirectDrawSurface_final_release(This);
298 HRESULT DIB_DirectDrawSurface_Create(IDirectDrawImpl *pDD,
299 const DDSURFACEDESC2 *pDDSD,
300 LPDIRECTDRAWSURFACE7 *ppSurf,
303 IDirectDrawSurfaceImpl* This;
305 assert(pUnkOuter == NULL);
307 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
308 sizeof(*This) + sizeof(DIB_DirectDrawSurfaceImpl));
309 if (This == NULL) return E_OUTOFMEMORY;
311 This->private = (DIB_DirectDrawSurfaceImpl*)(This+1);
313 hr = DIB_DirectDrawSurface_Construct(This, pDD, pDDSD);
315 HeapFree(GetProcessHeap(), 0, This);
317 *ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);
323 /* AddAttachedSurface: generic */
324 /* AddOverlayDirtyRect: generic, unimplemented */
326 static HRESULT _Blt_ColorFill(
327 LPBYTE buf, int width, int height, int bpp, LONG lPitch, DWORD color
334 #define COLORFILL_ROW(type) { \
335 type *d = (type *) buf; \
336 for (x = 0; x < width; x++) \
337 d[x] = (type) color; \
342 case 1: COLORFILL_ROW(BYTE)
343 case 2: COLORFILL_ROW(WORD)
344 case 3: { BYTE *d = (BYTE *) buf;
345 for (x = 0; x < width; x++,d+=3) {
346 d[0] = (color ) & 0xFF;
347 d[1] = (color>> 8) & 0xFF;
348 d[2] = (color>>16) & 0xFF;
351 case 4: COLORFILL_ROW(DWORD)
353 FIXME("Color fill not implemented for bpp %d!\n", bpp*8);
354 return DDERR_UNSUPPORTED;
359 /* Now copy first row */
361 for (y = 1; y < height; y++) {
363 memcpy(buf, first, width * bpp);
368 static void ComputeShifts(DWORD mask, DWORD* lshift, DWORD* rshift)
378 while(!(mask & (1 << pos)))
381 while(mask & (1 << (pos+bits)))
388 /* This is used to factorize the decompression between the Blt and BltFast code */
389 static void DoDXTCDecompression(const DDSURFACEDESC2 *sdesc, const DDSURFACEDESC2 *ddesc)
396 if (!s3tc_initialized) {
397 /* FIXME: We may fake this by rendering the texture into the framebuffer using OpenGL functions and reading back
398 * the framebuffer. This will be slow and somewhat ugly. */
399 FIXME("Manual S3TC decompression is not supported in native mode\n");
403 rm = ddesc->u4.ddpfPixelFormat.u2.dwRBitMask;
404 ComputeShifts(rm, &rs, &rb);
405 gm = ddesc->u4.ddpfPixelFormat.u3.dwGBitMask;
406 ComputeShifts(gm, &gs, &gb);
407 bm = ddesc->u4.ddpfPixelFormat.u4.dwBBitMask;
408 ComputeShifts(bm, &bs, &bb);
409 am = ddesc->u4.ddpfPixelFormat.u5.dwRGBAlphaBitMask;
410 ComputeShifts(am, &as, &ab);
411 if (sdesc->u4.ddpfPixelFormat.dwFourCC == MAKE_FOURCC('D','X','T','1')) {
412 int is16 = ddesc->u4.ddpfPixelFormat.u1.dwRGBBitCount == 16;
413 int pitch = ddesc->u1.lPitch;
414 int width = ddesc->dwWidth;
415 int height = ddesc->dwHeight;
417 char* dst = (char*) ddesc->lpSurface;
418 char* src = (char*) sdesc->lpSurface;
419 for (x = 0; x < width; x++)
420 for (y =0; y < height; y++) {
423 (*fetch_2d_texel_rgba_dxt1)(width, src, x, y, data);
425 pixel |= ((data[0] >> rb) << rs) & rm;
426 pixel |= ((data[1] >> gb) << gs) & gm;
427 pixel |= ((data[2] >> bb) << bs) & bm;
428 pixel |= ((data[3] >> ab) << as) & am;
430 *((WORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
432 *((DWORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
434 } else if (sdesc->u4.ddpfPixelFormat.dwFourCC == MAKE_FOURCC('D','X','T','3')) {
435 int is16 = ddesc->u4.ddpfPixelFormat.u1.dwRGBBitCount == 16;
436 int pitch = ddesc->u1.lPitch;
437 int width = ddesc->dwWidth;
438 int height = ddesc->dwHeight;
440 char* dst = (char*) ddesc->lpSurface;
441 char* src = (char*) sdesc->lpSurface;
442 for (x = 0; x < width; x++)
443 for (y =0; y < height; y++) {
446 (*fetch_2d_texel_rgba_dxt3)(width, src, x, y, data);
448 pixel |= ((data[0] >> rb) << rs) & rm;
449 pixel |= ((data[1] >> gb) << gs) & gm;
450 pixel |= ((data[2] >> bb) << bs) & bm;
451 pixel |= ((data[3] >> ab) << as) & am;
453 *((WORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
455 *((DWORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
457 } else if (sdesc->u4.ddpfPixelFormat.dwFourCC == MAKE_FOURCC('D','X','T','5')) {
458 int is16 = ddesc->u4.ddpfPixelFormat.u1.dwRGBBitCount == 16;
459 int pitch = ddesc->u1.lPitch;
460 int width = ddesc->dwWidth;
461 int height = ddesc->dwHeight;
463 char* dst = (char*) ddesc->lpSurface;
464 char* src = (char*) sdesc->lpSurface;
465 for (x = 0; x < width; x++)
466 for (y =0; y < height; y++) {
469 (*fetch_2d_texel_rgba_dxt5)(width, src, x, y, data);
471 pixel |= ((data[0] >> rb) << rs) & rm;
472 pixel |= ((data[1] >> gb) << gs) & gm;
473 pixel |= ((data[2] >> bb) << bs) & bm;
474 pixel |= ((data[3] >> ab) << as) & am;
476 *((WORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
478 *((DWORD*)(dst+y*pitch+x*(is16?2:4))) = pixel;
481 #if 0 /* Usefull for debugging */
486 sprintf(texname, "dxt_%d.pnm", idx++);
487 f = fopen(texname,"w");
488 DDRAW_dump_surface_to_disk(This, f, 1);
495 DIB_DirectDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rdst,
496 LPDIRECTDRAWSURFACE7 src, LPRECT rsrc,
497 DWORD dwFlags, LPDDBLTFX lpbltfx)
499 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
501 DDSURFACEDESC2 ddesc,sdesc;
503 int bpp, srcheight, srcwidth, dstheight, dstwidth, width;
507 TRACE("(%p)->(%p,%p,%p,%08lx,%p)\n", This,rdst,src,rsrc,dwFlags,lpbltfx);
509 if (TRACE_ON(ddraw)) {
510 if (rdst) TRACE("\tdestrect :%ldx%ld-%ldx%ld\n",rdst->left,rdst->top,rdst->right,rdst->bottom);
511 if (rsrc) TRACE("\tsrcrect :%ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
513 DDRAW_dump_DDBLT(dwFlags);
514 if (dwFlags & DDBLT_DDFX) {
516 DDRAW_dump_DDBLTFX(lpbltfx->dwDDFX);
520 if ((This->locked) || ((src != NULL) && (((IDirectDrawSurfaceImpl *)src)->locked))) {
521 WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
522 return DDERR_SURFACEBUSY;
525 /* First, check if the possible override function handles this case */
526 if (This->aux_blt != NULL) {
527 if (This->aux_blt(This, rdst, src, rsrc, dwFlags, lpbltfx) == DD_OK) return DD_OK;
530 DD_STRUCT_INIT(&ddesc);
531 DD_STRUCT_INIT(&sdesc);
533 sdesc.dwSize = sizeof(sdesc);
534 ddesc.dwSize = sizeof(ddesc);
537 IDirectDrawSurface7_Lock(iface, NULL, &ddesc, 0, 0);
538 DD_STRUCT_COPY_BYSIZE(&sdesc, &ddesc);
540 if (src) IDirectDrawSurface7_Lock(src, NULL, &sdesc, DDLOCK_READONLY, 0);
541 IDirectDrawSurface7_Lock(iface,NULL,&ddesc,DDLOCK_WRITEONLY,0);
544 if ((sdesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) &&
545 (ddesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC)) {
546 if (sdesc.u4.ddpfPixelFormat.dwFourCC != sdesc.u4.ddpfPixelFormat.dwFourCC) {
547 FIXME("FOURCC->FOURCC copy only supported for the same type of surface\n");
548 ret = DDERR_INVALIDPIXELFORMAT;
551 memcpy(ddesc.lpSurface, sdesc.lpSurface, ddesc.u1.dwLinearSize);
555 if ((sdesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) &&
556 (!(ddesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC))) {
557 DoDXTCDecompression(&sdesc, &ddesc);
562 memcpy(&xdst,rdst,sizeof(xdst));
565 xdst.bottom = ddesc.dwHeight;
567 xdst.right = ddesc.dwWidth;
571 memcpy(&xsrc,rsrc,sizeof(xsrc));
575 xsrc.bottom = sdesc.dwHeight;
577 xsrc.right = sdesc.dwWidth;
579 memset(&xsrc,0,sizeof(xsrc));
583 /* First check for the validity of source / destination rectangles. This was
584 verified using a test application + by MSDN.
587 ((xsrc.bottom > sdesc.dwHeight) || (xsrc.bottom < 0) ||
588 (xsrc.top > sdesc.dwHeight) || (xsrc.top < 0) ||
589 (xsrc.left > sdesc.dwWidth) || (xsrc.left < 0) ||
590 (xsrc.right > sdesc.dwWidth) || (xsrc.right < 0) ||
591 (xsrc.right < xsrc.left) || (xsrc.bottom < xsrc.top))) {
592 WARN("Application gave us bad source rectangle for Blt.\n");
593 ret = DDERR_INVALIDRECT;
596 /* For the Destination rect, it can be out of bounds on the condition that a clipper
597 is set for the given surface.
599 if ((This->clipper == NULL) &&
600 ((xdst.bottom > ddesc.dwHeight) || (xdst.bottom < 0) ||
601 (xdst.top > ddesc.dwHeight) || (xdst.top < 0) ||
602 (xdst.left > ddesc.dwWidth) || (xdst.left < 0) ||
603 (xdst.right > ddesc.dwWidth) || (xdst.right < 0) ||
604 (xdst.right < xdst.left) || (xdst.bottom < xdst.top))) {
605 WARN("Application gave us bad destination rectangle for Blt without a clipper set.\n");
606 ret = DDERR_INVALIDRECT;
610 /* Now handle negative values in the rectangles. Warning: only supported for now
611 in the 'simple' cases (ie not in any stretching / rotation cases).
613 First, the case where nothing is to be done.
615 if (((xdst.bottom <= 0) || (xdst.right <= 0) || (xdst.top >= (int) ddesc.dwHeight) || (xdst.left >= (int) ddesc.dwWidth)) ||
617 ((xsrc.bottom <= 0) || (xsrc.right <= 0) || (xsrc.top >= (int) sdesc.dwHeight) || (xsrc.left >= (int) sdesc.dwWidth))))
619 TRACE("Nothing to be done !\n");
623 /* The easy case : the source-less blits.... */
626 RECT temp_rect; /* No idea if intersect rect can be the same as one of the source rect */
630 full_rect.right = ddesc.dwWidth;
631 full_rect.bottom = ddesc.dwHeight;
632 IntersectRect(&temp_rect, &full_rect, &xdst);
635 /* Only handle clipping on the destination rectangle */
636 int clip_horiz = (xdst.left < 0) || (xdst.right > (int) ddesc.dwWidth );
637 int clip_vert = (xdst.top < 0) || (xdst.bottom > (int) ddesc.dwHeight);
638 if (clip_vert || clip_horiz) {
639 /* Now check if this is a special case or not... */
640 if ((((xdst.bottom - xdst.top ) != (xsrc.bottom - xsrc.top )) && clip_vert ) ||
641 (((xdst.right - xdst.left) != (xsrc.right - xsrc.left)) && clip_horiz) ||
642 (dwFlags & DDBLT_DDFX)) {
643 WARN("Out of screen rectangle in special case. Not handled right now.\n");
648 if (xdst.left < 0) { xsrc.left -= xdst.left; xdst.left = 0; }
649 if (xdst.right > ddesc.dwWidth) { xsrc.right -= (xdst.right - (int) ddesc.dwWidth); xdst.right = (int) ddesc.dwWidth; }
652 if (xdst.top < 0) { xsrc.top -= xdst.top; xdst.top = 0; }
653 if (xdst.bottom > ddesc.dwHeight) { xsrc.bottom -= (xdst.bottom - (int) ddesc.dwHeight); xdst.bottom = (int) ddesc.dwHeight; }
655 /* And check if after clipping something is still to be done... */
656 if ((xdst.bottom <= 0) || (xdst.right <= 0) || (xdst.top >= (int) ddesc.dwHeight) || (xdst.left >= (int) ddesc.dwWidth) ||
657 (xsrc.bottom <= 0) || (xsrc.right <= 0) || (xsrc.top >= (int) sdesc.dwHeight) || (xsrc.left >= (int) sdesc.dwWidth)) {
658 TRACE("Nothing to be done after clipping !\n");
664 bpp = GET_BPP(ddesc);
665 srcheight = xsrc.bottom - xsrc.top;
666 srcwidth = xsrc.right - xsrc.left;
667 dstheight = xdst.bottom - xdst.top;
668 dstwidth = xdst.right - xdst.left;
669 width = (xdst.right - xdst.left) * bpp;
671 assert(width <= ddesc.u1.lPitch);
673 dbuf = (BYTE*)ddesc.lpSurface+(xdst.top*ddesc.u1.lPitch)+(xdst.left*bpp);
675 if (dwFlags & (DDBLT_WAIT|DDBLT_ASYNC))
677 static BOOL displayed = FALSE;
680 FIXME("dwFlags DDBLT_WAIT and/or DDBLT_ASYNC: can't handle right now.\n");
683 dwFlags &= ~(DDBLT_WAIT|DDBLT_ASYNC);
686 /* First, all the 'source-less' blits */
687 if (dwFlags & DDBLT_COLORFILL) {
688 ret = _Blt_ColorFill(dbuf, dstwidth, dstheight, bpp,
689 ddesc.u1.lPitch, lpbltfx->u5.dwFillColor);
690 dwFlags &= ~DDBLT_COLORFILL;
693 if (dwFlags & DDBLT_DEPTHFILL)
694 FIXME("DDBLT_DEPTHFILL needs to be implemented!\n");
695 if (dwFlags & DDBLT_ROP) {
696 /* Catch some degenerate cases here */
697 switch(lpbltfx->dwROP) {
699 ret = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,ddesc.u1.lPitch,0);
701 case 0xAA0029: /* No-op */
704 ret = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,ddesc.u1.lPitch,~0);
706 case SRCCOPY: /* well, we do that below ? */
709 FIXME("Unsupported raster op: %08lx Pattern: %p\n", lpbltfx->dwROP, lpbltfx->u5.lpDDSPattern);
712 dwFlags &= ~DDBLT_ROP;
714 if (dwFlags & DDBLT_DDROPS) {
715 FIXME("\tDdraw Raster Ops: %08lx Pattern: %p\n", lpbltfx->dwDDROP, lpbltfx->u5.lpDDSPattern);
717 /* Now the 'with source' blits */
720 int sx, xinc, sy, yinc;
722 if (!dstwidth || !dstheight) /* hmm... stupid program ? */
724 sbase = (BYTE*)sdesc.lpSurface+(xsrc.top*sdesc.u1.lPitch)+xsrc.left*bpp;
725 xinc = (srcwidth << 16) / dstwidth;
726 yinc = (srcheight << 16) / dstheight;
729 /* No effects, we can cheat here */
730 if (dstwidth == srcwidth) {
731 if (dstheight == srcheight) {
732 /* No stretching in either direction. This needs to be as
733 * fast as possible */
736 /* check for overlapping surfaces */
737 if (src != iface || xdst.top < xsrc.top ||
738 xdst.right <= xsrc.left || xsrc.right <= xdst.left)
740 /* no overlap, or dst above src, so copy from top downwards */
741 for (y = 0; y < dstheight; y++)
743 memcpy(dbuf, sbuf, width);
744 sbuf += sdesc.u1.lPitch;
745 dbuf += ddesc.u1.lPitch;
748 else if (xdst.top > xsrc.top) /* copy from bottom upwards */
750 sbuf += (sdesc.u1.lPitch*dstheight);
751 dbuf += (ddesc.u1.lPitch*dstheight);
752 for (y = 0; y < dstheight; y++)
754 sbuf -= sdesc.u1.lPitch;
755 dbuf -= ddesc.u1.lPitch;
756 memcpy(dbuf, sbuf, width);
759 else /* src and dst overlapping on the same line, use memmove */
761 for (y = 0; y < dstheight; y++)
763 memmove(dbuf, sbuf, width);
764 sbuf += sdesc.u1.lPitch;
765 dbuf += ddesc.u1.lPitch;
769 /* Stretching in Y direction only */
770 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
771 sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
772 memcpy(dbuf, sbuf, width);
773 dbuf += ddesc.u1.lPitch;
777 /* Stretching in X direction */
779 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
780 sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
782 if ((sy >> 16) == (last_sy >> 16)) {
783 /* this sourcerow is the same as last sourcerow -
784 * copy already stretched row
786 memcpy(dbuf, dbuf - ddesc.u1.lPitch, width);
788 #define STRETCH_ROW(type) { \
789 type *s = (type *) sbuf, *d = (type *) dbuf; \
790 for (x = sx = 0; x < dstwidth; x++, sx += xinc) \
791 d[x] = s[sx >> 16]; \
795 case 1: STRETCH_ROW(BYTE)
796 case 2: STRETCH_ROW(WORD)
797 case 4: STRETCH_ROW(DWORD)
800 for (x = sx = 0; x < dstwidth; x++, sx+= xinc) {
804 pixel = s[0]|(s[1]<<8)|(s[2]<<16);
805 d[0] = (pixel )&0xff;
806 d[1] = (pixel>> 8)&0xff;
807 d[2] = (pixel>>16)&0xff;
813 FIXME("Stretched blit not implemented for bpp %d!\n", bpp*8);
814 ret = DDERR_UNSUPPORTED;
819 dbuf += ddesc.u1.lPitch;
824 LONG dstyinc = ddesc.u1.lPitch, dstxinc = bpp;
825 DWORD keylow = 0, keyhigh = 0;
826 if (dwFlags & (DDBLT_KEYSRC | DDBLT_KEYDEST | DDBLT_KEYSRCOVERRIDE | DDBLT_KEYDESTOVERRIDE)) {
828 if (dwFlags & DDBLT_KEYSRC) {
829 keylow = sdesc.ddckCKSrcBlt.dwColorSpaceLowValue;
830 keyhigh = sdesc.ddckCKSrcBlt.dwColorSpaceHighValue;
831 } else if (dwFlags & DDBLT_KEYDEST){
832 keylow = ddesc.ddckCKDestBlt.dwColorSpaceLowValue;
833 keyhigh = ddesc.ddckCKDestBlt.dwColorSpaceHighValue;
834 } else if (dwFlags & DDBLT_KEYSRCOVERRIDE) {
835 keylow = lpbltfx->ddckSrcColorkey.dwColorSpaceLowValue;
836 keyhigh = lpbltfx->ddckSrcColorkey.dwColorSpaceHighValue;
838 keylow = lpbltfx->ddckDestColorkey.dwColorSpaceLowValue;
839 keyhigh = lpbltfx->ddckDestColorkey.dwColorSpaceHighValue;
841 dwFlags &= ~(DDBLT_KEYSRC | DDBLT_KEYDEST | DDBLT_KEYSRCOVERRIDE | DDBLT_KEYDESTOVERRIDE);
844 if (dwFlags & DDBLT_DDFX) {
845 LPBYTE dTopLeft, dTopRight, dBottomLeft, dBottomRight, tmp;
848 dTopRight = dbuf+((dstwidth-1)*bpp);
849 dBottomLeft = dTopLeft+((dstheight-1)*ddesc.u1.lPitch);
850 dBottomRight = dBottomLeft+((dstwidth-1)*bpp);
852 if (lpbltfx->dwDDFX & DDBLTFX_ARITHSTRETCHY){
853 /* I don't think we need to do anything about this flag */
854 WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_ARITHSTRETCHY\n");
856 if (lpbltfx->dwDDFX & DDBLTFX_MIRRORLEFTRIGHT) {
858 dTopRight = dTopLeft;
861 dBottomRight = dBottomLeft;
863 dstxinc = dstxinc *-1;
865 if (lpbltfx->dwDDFX & DDBLTFX_MIRRORUPDOWN) {
867 dTopLeft = dBottomLeft;
870 dTopRight = dBottomRight;
872 dstyinc = dstyinc *-1;
874 if (lpbltfx->dwDDFX & DDBLTFX_NOTEARING) {
875 /* I don't think we need to do anything about this flag */
876 WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_NOTEARING\n");
878 if (lpbltfx->dwDDFX & DDBLTFX_ROTATE180) {
880 dBottomRight = dTopLeft;
883 dBottomLeft = dTopRight;
885 dstxinc = dstxinc * -1;
886 dstyinc = dstyinc * -1;
888 if (lpbltfx->dwDDFX & DDBLTFX_ROTATE270) {
890 dTopLeft = dBottomLeft;
891 dBottomLeft = dBottomRight;
892 dBottomRight = dTopRight;
897 dstxinc = dstxinc * -1;
899 if (lpbltfx->dwDDFX & DDBLTFX_ROTATE90) {
901 dTopLeft = dTopRight;
902 dTopRight = dBottomRight;
903 dBottomRight = dBottomLeft;
908 dstyinc = dstyinc * -1;
910 if (lpbltfx->dwDDFX & DDBLTFX_ZBUFFERBASEDEST) {
911 /* I don't think we need to do anything about this flag */
912 WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_ZBUFFERBASEDEST\n");
915 dwFlags &= ~(DDBLT_DDFX);
918 #define COPY_COLORKEY_FX(type) { \
919 type *s, *d = (type *) dbuf, *dx, tmp; \
920 for (y = sy = 0; y < dstheight; y++, sy += yinc) { \
921 s = (type*)(sbase + (sy >> 16) * sdesc.u1.lPitch); \
923 for (x = sx = 0; x < dstwidth; x++, sx += xinc) { \
925 if (tmp < keylow || tmp > keyhigh) dx[0] = tmp; \
926 dx = (type*)(((LPBYTE)dx)+dstxinc); \
928 d = (type*)(((LPBYTE)d)+dstyinc); \
933 case 1: COPY_COLORKEY_FX(BYTE)
934 case 2: COPY_COLORKEY_FX(WORD)
935 case 4: COPY_COLORKEY_FX(DWORD)
936 case 3: {LPBYTE s,d = dbuf, dx;
937 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
938 sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
940 for (x = sx = 0; x < dstwidth; x++, sx+= xinc) {
943 pixel = s[0]|(s[1]<<8)|(s[2]<<16);
944 if (pixel < keylow || pixel > keyhigh){
945 dx[0] = (pixel )&0xff;
946 dx[1] = (pixel>> 8)&0xff;
947 dx[2] = (pixel>>16)&0xff;
955 FIXME("%s color-keyed blit not implemented for bpp %d!\n",
956 (dwFlags & DDBLT_KEYSRC) ? "Source" : "Destination", bpp*8);
957 ret = DDERR_UNSUPPORTED;
959 #undef COPY_COLORKEY_FX
965 if (dwFlags && FIXME_ON(ddraw)) {
966 FIXME("\tUnsupported flags: ");
967 DDRAW_dump_DDBLT(dwFlags);
971 IDirectDrawSurface7_Unlock(iface,NULL);
972 if (src && src != iface) IDirectDrawSurface7_Unlock(src,NULL);
976 /* BltBatch: generic, unimplemented */
979 DIB_DirectDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface, DWORD dstx,
980 DWORD dsty, LPDIRECTDRAWSURFACE7 src,
981 LPRECT rsrc, DWORD trans)
983 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
985 DDSURFACEDESC2 ddesc,sdesc;
989 RECT lock_src, lock_dst, lock_union;
991 if (TRACE_ON(ddraw)) {
992 TRACE("(%p)->(%ld,%ld,%p,%p,%08lx)\n",
993 This,dstx,dsty,src,rsrc,trans
997 DDRAW_dump_DDBLTFAST(trans);
999 TRACE("\tsrcrect: %ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
1001 TRACE(" srcrect: NULL\n");
1004 if ((This->locked) || ((src != NULL) && (((IDirectDrawSurfaceImpl *)src)->locked))) {
1005 WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
1006 return DDERR_SURFACEBUSY;
1009 /* First, check if the possible override function handles this case */
1010 if (This->aux_bltfast != NULL) {
1011 if (This->aux_bltfast(This, dstx, dsty, src, rsrc, trans) == DD_OK) return DD_OK;
1014 /* Get the surface description without locking to first compute the width / height */
1015 ddesc = This->surface_desc;
1016 sdesc = (ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, src))->surface_desc;
1019 WARN("rsrc is NULL!\n");
1021 rsrc->left = rsrc->top = 0;
1022 rsrc->right = sdesc.dwWidth;
1023 rsrc->bottom = sdesc.dwHeight;
1026 /* Check source rect for validity. Copied from normal Blt. Fixes Baldur's Gate.*/
1027 if ((rsrc->bottom > sdesc.dwHeight) || (rsrc->bottom < 0) ||
1028 (rsrc->top > sdesc.dwHeight) || (rsrc->top < 0) ||
1029 (rsrc->left > sdesc.dwWidth) || (rsrc->left < 0) ||
1030 (rsrc->right > sdesc.dwWidth) || (rsrc->right < 0) ||
1031 (rsrc->right < rsrc->left) || (rsrc->bottom < rsrc->top)) {
1032 WARN("Application gave us bad source rectangle for BltFast.\n");
1033 return DDERR_INVALIDRECT;
1036 h=rsrc->bottom-rsrc->top;
1037 if (h>ddesc.dwHeight-dsty) h=ddesc.dwHeight-dsty;
1038 if (h>sdesc.dwHeight-rsrc->top) h=sdesc.dwHeight-rsrc->top;
1039 if (h<=0) return DDERR_INVALIDRECT;
1041 w=rsrc->right-rsrc->left;
1042 if (w>ddesc.dwWidth-dstx) w=ddesc.dwWidth-dstx;
1043 if (w>sdesc.dwWidth-rsrc->left) w=sdesc.dwWidth-rsrc->left;
1044 if (w<=0) return DDERR_INVALIDRECT;
1046 /* Now compute the locking rectangle... */
1047 lock_src.left = rsrc->left;
1048 lock_src.top = rsrc->top;
1049 lock_src.right = lock_src.left + w;
1050 lock_src.bottom = lock_src.top + h;
1052 lock_dst.left = dstx;
1053 lock_dst.top = dsty;
1054 lock_dst.right = dstx + w;
1055 lock_dst.bottom = dsty + h;
1057 bpp = GET_BPP(This->surface_desc);
1059 /* We need to lock the surfaces, or we won't get refreshes when done. */
1063 UnionRect(&lock_union, &lock_src, &lock_dst);
1065 /* Lock the union of the two rectangles */
1066 IDirectDrawSurface7_Lock(iface, &lock_union, &ddesc, 0, 0);
1068 pitch = This->surface_desc.u1.lPitch;
1070 /* Since sdesc was originally copied from this surface's description, we can just reuse it */
1071 sdesc.lpSurface = (BYTE *)This->surface_desc.lpSurface + lock_src.top * pitch + lock_src.left * bpp;
1072 ddesc.lpSurface = (BYTE *)This->surface_desc.lpSurface + lock_dst.top * pitch + lock_dst.left * bpp;
1074 sdesc.dwSize = sizeof(sdesc);
1075 IDirectDrawSurface7_Lock(src, &lock_src, &sdesc, DDLOCK_READONLY, 0);
1076 ddesc.dwSize = sizeof(ddesc);
1077 IDirectDrawSurface7_Lock(iface, &lock_dst, &ddesc, DDLOCK_WRITEONLY, 0);
1080 /* Handle first the FOURCC surfaces... */
1081 if ((sdesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) && (ddesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC)) {
1083 FIXME("trans arg not supported when a FOURCC surface is involved\n");
1085 FIXME("offset for destination surface is not supported\n");
1086 if (sdesc.u4.ddpfPixelFormat.dwFourCC != sdesc.u4.ddpfPixelFormat.dwFourCC) {
1087 FIXME("FOURCC->FOURCC copy only supported for the same type of surface\n");
1088 ret = DDERR_INVALIDPIXELFORMAT;
1091 memcpy(ddesc.lpSurface, sdesc.lpSurface, ddesc.u1.dwLinearSize);
1094 if ((sdesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC) &&
1095 (!(ddesc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC))) {
1096 DoDXTCDecompression(&sdesc, &ddesc);
1100 sbuf = (BYTE *) sdesc.lpSurface;
1101 dbuf = (BYTE *) ddesc.lpSurface;
1103 if (trans & (DDBLTFAST_SRCCOLORKEY | DDBLTFAST_DESTCOLORKEY)) {
1104 DWORD keylow, keyhigh;
1105 if (trans & DDBLTFAST_SRCCOLORKEY) {
1106 keylow = sdesc.ddckCKSrcBlt.dwColorSpaceLowValue;
1107 keyhigh = sdesc.ddckCKSrcBlt.dwColorSpaceHighValue;
1109 /* I'm not sure if this is correct */
1110 FIXME("DDBLTFAST_DESTCOLORKEY not fully supported yet.\n");
1111 keylow = ddesc.ddckCKDestBlt.dwColorSpaceLowValue;
1112 keyhigh = ddesc.ddckCKDestBlt.dwColorSpaceHighValue;
1115 #define COPYBOX_COLORKEY(type) { \
1117 s = (type *) sdesc.lpSurface; \
1118 d = (type *) ddesc.lpSurface; \
1119 for (y = 0; y < h; y++) { \
1120 for (x = 0; x < w; x++) { \
1122 if (tmp < keylow || tmp > keyhigh) d[x] = tmp; \
1124 s = (type *)((BYTE *)s + sdesc.u1.lPitch); \
1125 d = (type *)((BYTE *)d + ddesc.u1.lPitch); \
1131 case 1: COPYBOX_COLORKEY(BYTE)
1132 case 2: COPYBOX_COLORKEY(WORD)
1133 case 4: COPYBOX_COLORKEY(DWORD)
1138 s = (BYTE *) sdesc.lpSurface;
1139 d = (BYTE *) ddesc.lpSurface;
1140 for (y = 0; y < h; y++) {
1141 for (x = 0; x < w * 3; x += 3) {
1142 tmp = (DWORD)s[x] + ((DWORD)s[x + 1] << 8) + ((DWORD)s[x + 2] << 16);
1143 if (tmp < keylow || tmp > keyhigh) {
1144 d[x + 0] = s[x + 0];
1145 d[x + 1] = s[x + 1];
1146 d[x + 2] = s[x + 2];
1149 s += sdesc.u1.lPitch;
1150 d += ddesc.u1.lPitch;
1155 FIXME("Source color key blitting not supported for bpp %d\n",bpp*8);
1156 ret = DDERR_UNSUPPORTED;
1159 #undef COPYBOX_COLORKEY
1161 int width = w * bpp;
1163 for (y = 0; y < h; y++) {
1164 memcpy(dbuf, sbuf, width);
1165 sbuf += sdesc.u1.lPitch;
1166 dbuf += ddesc.u1.lPitch;
1172 IDirectDrawSurface7_Unlock(iface, &lock_union);
1174 IDirectDrawSurface7_Unlock(iface, &lock_dst);
1175 IDirectDrawSurface7_Unlock(src, &lock_src);
1181 /* ChangeUniquenessValue: generic */
1182 /* DeleteAttachedSurface: generic */
1183 /* EnumAttachedSurfaces: generic */
1184 /* EnumOverlayZOrders: generic, unimplemented */
1186 BOOL DIB_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl* front,
1187 IDirectDrawSurfaceImpl* back,
1190 DIB_DirectDrawSurfaceImpl* front_priv = front->private;
1191 DIB_DirectDrawSurfaceImpl* back_priv = back->private;
1193 TRACE("(%p,%p)\n",front,back);
1197 tmp = front_priv->dib.DIBsection;
1198 front_priv->dib.DIBsection = back_priv->dib.DIBsection;
1199 back_priv->dib.DIBsection = tmp;
1204 tmp = front_priv->dib.bitmap_data;
1205 front_priv->dib.bitmap_data = back_priv->dib.bitmap_data;
1206 back_priv->dib.bitmap_data = tmp;
1208 tmp = front->surface_desc.lpSurface;
1209 front->surface_desc.lpSurface = back->surface_desc.lpSurface;
1210 back->surface_desc.lpSurface = tmp;
1213 /* client_memory should not be different, but just in case */
1216 tmp = front_priv->dib.client_memory;
1217 front_priv->dib.client_memory = back_priv->dib.client_memory;
1218 back_priv->dib.client_memory = tmp;
1221 return Main_DirectDrawSurface_flip_data(front, back, dwFlags);
1225 /* FreePrivateData: generic */
1226 /* GetAttachedSurface: generic */
1227 /* GetBltStatus: generic */
1228 /* GetCaps: generic (Returns the caps from This->surface_desc.) */
1229 /* GetClipper: generic */
1230 /* GetColorKey: generic */
1232 HRESULT DIB_DirectDrawSurface_alloc_dc(IDirectDrawSurfaceImpl* This, HDC* phDC)
1234 DIB_PRIV_VAR(priv, This);
1237 TRACE("Grabbing a DC for surface: %p\n", This);
1239 hDC = CreateCompatibleDC(0);
1240 priv->dib.holdbitmap = SelectObject(hDC, priv->dib.DIBsection);
1242 SelectPalette(hDC, This->palette->hpal, FALSE);
1249 HRESULT DIB_DirectDrawSurface_free_dc(IDirectDrawSurfaceImpl* This, HDC hDC)
1251 DIB_PRIV_VAR(priv, This);
1253 TRACE("Releasing DC for surface: %p\n", This);
1255 SelectObject(hDC, priv->dib.holdbitmap);
1261 HRESULT DIB_DirectDrawSurface_get_dc(IDirectDrawSurfaceImpl* This, HDC* phDC)
1263 return DIB_DirectDrawSurface_alloc_dc(This, phDC);
1266 HRESULT DIB_DirectDrawSurface_release_dc(IDirectDrawSurfaceImpl* This, HDC hDC)
1268 return DIB_DirectDrawSurface_free_dc(This, hDC);
1271 /* GetDDInterface: generic */
1272 /* GetFlipStatus: generic */
1273 /* GetLOD: generic */
1274 /* GetOverlayPosition: generic */
1275 /* GetPalette: generic */
1276 /* GetPixelFormat: generic */
1277 /* GetPriority: generic */
1278 /* GetPrivateData: generic */
1279 /* GetSurfaceDesc: generic */
1280 /* GetUniquenessValue: generic */
1281 /* Initialize: generic */
1282 /* IsLost: generic */
1283 /* Lock: generic with callback? */
1284 /* PageLock: generic */
1285 /* PageUnlock: generic */
1288 DIB_DirectDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface)
1290 TRACE("(%p)\n",iface);
1291 return DD_OK; /* ??? */
1294 /* SetClipper: generic */
1295 /* SetColorKey: generic */
1296 /* SetLOD: generic */
1297 /* SetOverlayPosition: generic */
1299 void DIB_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl* This,
1300 IDirectDrawPaletteImpl* pal)
1303 if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
1304 This->update_palette(This, pal,
1305 0, pal->palNumEntries,
1309 void DIB_DirectDrawSurface_update_palette(IDirectDrawSurfaceImpl* This,
1310 IDirectDrawPaletteImpl* pal,
1311 DWORD dwStart, DWORD dwCount,
1312 LPPALETTEENTRY palent)
1318 TRACE("updating primary palette\n");
1319 for (n=0; n<dwCount; n++) {
1320 col[n].rgbRed = palent[n].peRed;
1321 col[n].rgbGreen = palent[n].peGreen;
1322 col[n].rgbBlue = palent[n].peBlue;
1323 col[n].rgbReserved = 0;
1325 This->get_dc(This, &dc);
1326 SetDIBColorTable(dc, dwStart, dwCount, col);
1327 This->release_dc(This, dc);
1329 /* Propagate change to backbuffers if there are any */
1330 /* Basically this is a modification of the Flip code to find the backbuffer */
1331 /* and duplicate the palette update there as well */
1332 if ((This->surface_desc.ddsCaps.dwCaps&(DDSCAPS_FLIP|DDSCAPS_FRONTBUFFER))
1333 == (DDSCAPS_FLIP|DDSCAPS_FRONTBUFFER))
1335 static DDSCAPS2 back_caps = { DDSCAPS_BACKBUFFER };
1336 LPDIRECTDRAWSURFACE7 tgt;
1338 HRESULT hr = IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This,IDirectDrawSurface7),
1342 IDirectDrawSurfaceImpl* target = ICOM_OBJECT(IDirectDrawSurfaceImpl,
1343 IDirectDrawSurface7,tgt);
1344 IDirectDrawSurface7_Release(tgt);
1345 target->get_dc(target, &dc);
1346 SetDIBColorTable(dc, dwStart, dwCount, col);
1347 target->release_dc(target, dc);
1352 /* SetPalette: generic */
1353 /* SetPriority: generic */
1354 /* SetPrivateData: generic */
1357 DIB_DirectDrawSurface_SetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
1358 LPDDSURFACEDESC2 pDDSD, DWORD dwFlags)
1360 IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
1361 DIB_PRIV_VAR(priv, This);
1363 DWORD flags = pDDSD->dwFlags;
1365 if (TRACE_ON(ddraw)) {
1366 TRACE("(%p)->(%p,%08lx)\n",iface,pDDSD,dwFlags);
1367 DDRAW_dump_surface_desc(pDDSD);
1370 if (pDDSD->dwFlags & DDSD_PIXELFORMAT) {
1371 flags &= ~DDSD_PIXELFORMAT;
1372 if (flags & DDSD_LPSURFACE) {
1373 This->surface_desc.u4.ddpfPixelFormat = pDDSD->u4.ddpfPixelFormat;
1375 FIXME("Change of pixel format without surface re-allocation is not supported !\n");
1378 if (pDDSD->dwFlags & DDSD_LPSURFACE) {
1379 HBITMAP oldbmp = priv->dib.DIBsection;
1380 LPVOID oldsurf = This->surface_desc.lpSurface;
1381 BOOL oldc = priv->dib.client_memory;
1383 flags &= ~DDSD_LPSURFACE;
1385 TRACE("new lpSurface=%p\n",pDDSD->lpSurface);
1386 This->surface_desc.lpSurface = pDDSD->lpSurface;
1387 priv->dib.client_memory = TRUE;
1389 hr = create_dib(This);
1392 priv->dib.DIBsection = oldbmp;
1393 This->surface_desc.lpSurface = oldsurf;
1394 priv->dib.client_memory = oldc;
1398 DeleteObject(oldbmp);
1401 VirtualFree(oldsurf, 0, MEM_RELEASE);
1404 WARN("Unhandled flags : %08lx\n", flags);
1409 /* Unlock: ???, need callback */
1410 /* UpdateOverlay: generic */
1411 /* UpdateOverlayDisplay: generic */
1412 /* UpdateOverlayZOrder: generic */
1414 static const IDirectDrawSurface7Vtbl DIB_IDirectDrawSurface7_VTable =
1416 Main_DirectDrawSurface_QueryInterface,
1417 Main_DirectDrawSurface_AddRef,
1418 Main_DirectDrawSurface_Release,
1419 Main_DirectDrawSurface_AddAttachedSurface,
1420 Main_DirectDrawSurface_AddOverlayDirtyRect,
1421 DIB_DirectDrawSurface_Blt,
1422 Main_DirectDrawSurface_BltBatch,
1423 DIB_DirectDrawSurface_BltFast,
1424 Main_DirectDrawSurface_DeleteAttachedSurface,
1425 Main_DirectDrawSurface_EnumAttachedSurfaces,
1426 Main_DirectDrawSurface_EnumOverlayZOrders,
1427 Main_DirectDrawSurface_Flip,
1428 Main_DirectDrawSurface_GetAttachedSurface,
1429 Main_DirectDrawSurface_GetBltStatus,
1430 Main_DirectDrawSurface_GetCaps,
1431 Main_DirectDrawSurface_GetClipper,
1432 Main_DirectDrawSurface_GetColorKey,
1433 Main_DirectDrawSurface_GetDC,
1434 Main_DirectDrawSurface_GetFlipStatus,
1435 Main_DirectDrawSurface_GetOverlayPosition,
1436 Main_DirectDrawSurface_GetPalette,
1437 Main_DirectDrawSurface_GetPixelFormat,
1438 Main_DirectDrawSurface_GetSurfaceDesc,
1439 Main_DirectDrawSurface_Initialize,
1440 Main_DirectDrawSurface_IsLost,
1441 Main_DirectDrawSurface_Lock,
1442 Main_DirectDrawSurface_ReleaseDC,
1443 DIB_DirectDrawSurface_Restore,
1444 Main_DirectDrawSurface_SetClipper,
1445 Main_DirectDrawSurface_SetColorKey,
1446 Main_DirectDrawSurface_SetOverlayPosition,
1447 Main_DirectDrawSurface_SetPalette,
1448 Main_DirectDrawSurface_Unlock,
1449 Main_DirectDrawSurface_UpdateOverlay,
1450 Main_DirectDrawSurface_UpdateOverlayDisplay,
1451 Main_DirectDrawSurface_UpdateOverlayZOrder,
1452 Main_DirectDrawSurface_GetDDInterface,
1453 Main_DirectDrawSurface_PageLock,
1454 Main_DirectDrawSurface_PageUnlock,
1455 DIB_DirectDrawSurface_SetSurfaceDesc,
1456 Main_DirectDrawSurface_SetPrivateData,
1457 Main_DirectDrawSurface_GetPrivateData,
1458 Main_DirectDrawSurface_FreePrivateData,
1459 Main_DirectDrawSurface_GetUniquenessValue,
1460 Main_DirectDrawSurface_ChangeUniquenessValue,
1461 Main_DirectDrawSurface_SetPriority,
1462 Main_DirectDrawSurface_GetPriority,
1463 Main_DirectDrawSurface_SetLOD,
1464 Main_DirectDrawSurface_GetLOD