Fixed some issues found by winapi_check.
[wine] / dlls / ddraw / dsurface / dib.c
1 /*              DIBSection DirectDrawSurface driver
2  *
3  * Copyright 1997-2000 Marcus Meissner
4  * Copyright 1998-2000 Lionel Ulmer
5  * Copyright 2000-2001 TransGaming Technologies Inc.
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "config.h"
23
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "winerror.h"
28 #include "bitmap.h"
29 #include "wine/debug.h"
30 #include "ddraw_private.h"
31 #include "dsurface/main.h"
32 #include "dsurface/dib.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
35
36 static ICOM_VTABLE(IDirectDrawSurface7) DIB_IDirectDrawSurface7_VTable;
37
38 /* Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned. */
39 inline static int get_dib_width_bytes( int width, int depth )
40 {
41     int words;
42
43     switch(depth)
44     {
45     case 1:  words = (width + 31) / 32; break;
46     case 4:  words = (width + 7) / 8; break;
47     case 8:  words = (width + 3) / 4; break;
48     case 15:
49     case 16: words = (width + 1) / 2; break;
50     case 24: words = (width * 3 + 3)/4; break;
51     default:
52         WARN("(%d): Unsupported depth\n", depth );
53         /* fall through */
54     case 32: words = width; break;
55     }
56     return 4 * words;
57 }
58
59
60 static HRESULT create_dib(IDirectDrawSurfaceImpl* This)
61 {
62     BITMAPINFO* b_info;
63     UINT usage;
64     HDC ddc;
65     DIB_DirectDrawSurfaceImpl* priv = This->private;
66
67     assert(This->surface_desc.lpSurface != NULL);
68
69     switch (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount)
70     {
71     case 16:
72     case 32:
73         /* Allocate extra space to store the RGB bit masks. */
74         b_info = (BITMAPINFO*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
75                                         sizeof(BITMAPINFOHEADER)
76                                         + 3 * sizeof(DWORD));
77         break;
78
79     case 24:
80         b_info = (BITMAPINFO*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
81                                         sizeof(BITMAPINFOHEADER));
82         break;
83
84     default:
85         /* Allocate extra space for a palette. */
86         b_info = (BITMAPINFO*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
87                                         sizeof(BITMAPINFOHEADER)
88                                         + sizeof(RGBQUAD)
89                                         * (1 << This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount));
90         break;
91     }
92
93     b_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
94     b_info->bmiHeader.biWidth = This->surface_desc.dwWidth;
95     b_info->bmiHeader.biHeight = -This->surface_desc.dwHeight;
96     b_info->bmiHeader.biPlanes = 1;
97     b_info->bmiHeader.biBitCount = This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount;
98
99     if ((This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount != 16)
100         && (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount != 32))
101         b_info->bmiHeader.biCompression = BI_RGB;
102     else
103         b_info->bmiHeader.biCompression = BI_BITFIELDS;
104
105     b_info->bmiHeader.biSizeImage
106         = (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount / 8)
107         * This->surface_desc.dwWidth * This->surface_desc.dwHeight;
108
109     b_info->bmiHeader.biXPelsPerMeter = 0;
110     b_info->bmiHeader.biYPelsPerMeter = 0;
111     b_info->bmiHeader.biClrUsed = 0;
112     b_info->bmiHeader.biClrImportant = 0;
113
114     switch (This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount)
115     {
116     case 16:
117     case 32:
118     {
119         DWORD *masks = (DWORD *) &(b_info->bmiColors);
120
121         usage = 0;
122         masks[0] = This->surface_desc.u4.ddpfPixelFormat.u2.dwRBitMask;
123         masks[1] = This->surface_desc.u4.ddpfPixelFormat.u3.dwGBitMask;
124         masks[2] = This->surface_desc.u4.ddpfPixelFormat.u4.dwBBitMask;
125     }
126     break;
127
128     case 24:
129         /* Nothing to do */
130         usage = DIB_RGB_COLORS;
131         break;
132
133     default:
134         /* Don't know palette */
135         usage = 0;
136         break;
137     }
138
139     ddc = CreateDCA("DISPLAY", NULL, NULL, NULL);
140     if (ddc == 0)
141     {
142         HeapFree(GetProcessHeap(), 0, b_info);
143         return HRESULT_FROM_WIN32(GetLastError());
144     }
145
146     priv->dib.DIBsection
147         = DIB_CreateDIBSection(ddc, b_info, usage, &(priv->dib.bitmap_data), 0,
148                                (DWORD)This->surface_desc.lpSurface,
149                                This->surface_desc.u1.lPitch);
150     DeleteDC(ddc);
151     if (!priv->dib.DIBsection) {
152         ERR("CreateDIBSection failed!\n");
153         HeapFree(GetProcessHeap(), 0, b_info);
154         return HRESULT_FROM_WIN32(GetLastError());
155     }
156
157     TRACE("DIBSection at : %p\n", priv->dib.bitmap_data);
158     if (!This->surface_desc.u1.lPitch) {
159         /* This can't happen, right? */
160         /* or use GDI_GetObj to get it from the created DIB? */
161         This->surface_desc.u1.lPitch = get_dib_width_bytes(b_info->bmiHeader.biWidth, b_info->bmiHeader.biBitCount);
162         This->surface_desc.dwFlags |= DDSD_PITCH;
163     }
164
165     if (!This->surface_desc.lpSurface) {
166         This->surface_desc.lpSurface = priv->dib.bitmap_data;
167         This->surface_desc.dwFlags |= DDSD_LPSURFACE;
168     }
169
170     HeapFree(GetProcessHeap(), 0, b_info);
171
172     /* I don't think it's worth checking for this. */
173     if (priv->dib.bitmap_data != This->surface_desc.lpSurface)
174         ERR("unexpected error creating DirectDrawSurface DIB section\n");
175
176     /* this seems like a good place to put the handle for HAL driver use */
177     This->global_more.hKernelSurface = priv->dib.DIBsection;
178
179     return S_OK;
180 }
181
182 void DIB_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
183 {
184     DIB_DirectDrawSurfaceImpl* priv = This->private;
185
186     DeleteObject(priv->dib.DIBsection);
187
188     if (!priv->dib.client_memory)
189         VirtualFree(This->surface_desc.lpSurface, 0, MEM_RELEASE);
190
191     Main_DirectDrawSurface_final_release(This);
192 }
193
194 HRESULT DIB_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,
195                                                 LPDIRECTDRAWSURFACE7* ppDup)
196 {
197     return DIB_DirectDrawSurface_Create(This->ddraw_owner,
198                                         &This->surface_desc, ppDup, NULL);
199 }
200
201 HRESULT DIB_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
202                                         IDirectDrawImpl *pDD,
203                                         const DDSURFACEDESC2 *pDDSD)
204 {
205     HRESULT hr;
206     DIB_DirectDrawSurfaceImpl* priv = This->private;
207
208     TRACE("(%p)->(%p,%p)\n",This,pDD,pDDSD);
209     hr = Main_DirectDrawSurface_Construct(This, pDD, pDDSD);
210     if (FAILED(hr)) return hr;
211
212     ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,
213                         DIB_IDirectDrawSurface7_VTable);
214
215     This->final_release = DIB_DirectDrawSurface_final_release;
216     This->duplicate_surface = DIB_DirectDrawSurface_duplicate_surface;
217     This->flip_data = DIB_DirectDrawSurface_flip_data;
218
219     This->get_dc     = DIB_DirectDrawSurface_get_dc;
220     This->release_dc = DIB_DirectDrawSurface_release_dc;
221     This->hDC = (HDC)NULL;
222
223     This->set_palette    = DIB_DirectDrawSurface_set_palette;
224     This->update_palette = DIB_DirectDrawSurface_update_palette;
225
226     TRACE("(%ldx%ld, pitch=%ld)\n",
227           This->surface_desc.dwWidth, This->surface_desc.dwHeight,
228           This->surface_desc.u1.lPitch);
229     /* XXX load dwWidth and dwHeight from pDD if they are not specified? */
230
231     if (This->surface_desc.dwFlags & DDSD_LPSURFACE)
232     {
233         /* "Client memory": it is managed by the application. */
234         /* XXX What if lPitch is not set? Use dwWidth or fail? */
235
236         priv->dib.client_memory = TRUE;
237     }
238     else
239     {
240         if (!(This->surface_desc.dwFlags & DDSD_PITCH))
241         {
242             int pitch = This->surface_desc.u1.lPitch;
243             if (pitch % 8 != 0)
244                 pitch += 8 - (pitch % 8);
245         }
246         /* XXX else: how should lPitch be verified? */
247
248         This->surface_desc.dwFlags |= DDSD_PITCH|DDSD_LPSURFACE;
249
250         This->surface_desc.lpSurface
251             = VirtualAlloc(NULL, This->surface_desc.u1.lPitch
252                            * This->surface_desc.dwHeight,
253                            MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
254
255         if (This->surface_desc.lpSurface == NULL)
256         {
257             Main_DirectDrawSurface_final_release(This);
258             return HRESULT_FROM_WIN32(GetLastError());
259         }
260
261         priv->dib.client_memory = FALSE;
262     }
263
264     hr = create_dib(This);
265     if (FAILED(hr))
266     {
267         if (!priv->dib.client_memory)
268             VirtualFree(This->surface_desc.lpSurface, 0, MEM_RELEASE);
269
270         Main_DirectDrawSurface_final_release(This);
271
272         return hr;
273     }
274
275     return DD_OK;
276 }
277
278 /* Not an API */
279 HRESULT DIB_DirectDrawSurface_Create(IDirectDrawImpl *pDD,
280                                      const DDSURFACEDESC2 *pDDSD,
281                                      LPDIRECTDRAWSURFACE7 *ppSurf,
282                                      IUnknown *pUnkOuter)
283 {
284     IDirectDrawSurfaceImpl* This;
285     HRESULT hr;
286     assert(pUnkOuter == NULL);
287
288     This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
289                      sizeof(*This) + sizeof(DIB_DirectDrawSurfaceImpl));
290     if (This == NULL) return E_OUTOFMEMORY;
291
292     This->private = (DIB_DirectDrawSurfaceImpl*)(This+1);
293
294     hr = DIB_DirectDrawSurface_Construct(This, pDD, pDDSD);
295     if (FAILED(hr))
296         HeapFree(GetProcessHeap(), 0, This);
297     else
298         *ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);
299
300     return hr;
301
302 }
303
304 /* AddAttachedSurface: generic */
305 /* AddOverlayDirtyRect: generic, unimplemented */
306
307 static HRESULT _Blt_ColorFill(
308     LPBYTE buf, int width, int height, int bpp, LONG lPitch, DWORD color
309 ) {
310     int x, y;
311     LPBYTE first;
312
313     /* Do first row */
314
315 #define COLORFILL_ROW(type) { \
316     type *d = (type *) buf; \
317     for (x = 0; x < width; x++) \
318         d[x] = (type) color; \
319     break; \
320 }
321
322     switch(bpp) {
323     case 1: COLORFILL_ROW(BYTE)
324     case 2: COLORFILL_ROW(WORD)
325     case 4: COLORFILL_ROW(DWORD)
326     default:
327         FIXME("Color fill not implemented for bpp %d!\n", bpp*8);
328         return DDERR_UNSUPPORTED;
329     }
330
331 #undef COLORFILL_ROW
332
333     /* Now copy first row */
334     first = buf;
335     for (y = 1; y < height; y++) {
336         buf += lPitch;
337         memcpy(buf, first, width * bpp);
338     }
339     return DD_OK;
340 }
341
342 HRESULT WINAPI
343 DIB_DirectDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rdst,
344                           LPDIRECTDRAWSURFACE7 src, LPRECT rsrc,
345                           DWORD dwFlags, LPDDBLTFX lpbltfx)
346 {
347     ICOM_THIS(IDirectDrawSurfaceImpl,iface);
348     RECT                xdst,xsrc;
349     DDSURFACEDESC2      ddesc,sdesc;
350     HRESULT             ret = DD_OK;
351     int bpp, srcheight, srcwidth, dstheight, dstwidth, width;
352     int x, y;
353     LPBYTE dbuf, sbuf;
354
355     TRACE("(%p)->(%p,%p,%p,%08lx,%p)\n", This,rdst,src,rsrc,dwFlags,lpbltfx);
356
357     DD_STRUCT_INIT(&ddesc);
358     DD_STRUCT_INIT(&sdesc);
359
360     sdesc.dwSize = sizeof(sdesc);
361     if (src) IDirectDrawSurface7_Lock(src, NULL, &sdesc, DDLOCK_READONLY, 0);
362     ddesc.dwSize = sizeof(ddesc);
363     IDirectDrawSurface7_Lock(iface,NULL,&ddesc,DDLOCK_WRITEONLY,0);
364
365     if (TRACE_ON(ddraw)) {
366         if (rdst) TRACE("\tdestrect :%dx%d-%dx%d\n",rdst->left,rdst->top,rdst->right,rdst->bottom);
367         if (rsrc) TRACE("\tsrcrect  :%dx%d-%dx%d\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
368         TRACE("\tflags: ");
369         DDRAW_dump_DDBLT(dwFlags);
370         if (dwFlags & DDBLT_DDFX) {
371             TRACE("\tblitfx: ");
372             DDRAW_dump_DDBLTFX(lpbltfx->dwDDFX);
373         }
374     }
375
376     if (rdst) {
377         memcpy(&xdst,rdst,sizeof(xdst));
378     } else {
379         xdst.top        = 0;
380         xdst.bottom     = ddesc.dwHeight;
381         xdst.left       = 0;
382         xdst.right      = ddesc.dwWidth;
383     }
384
385     if (rsrc) {
386         memcpy(&xsrc,rsrc,sizeof(xsrc));
387     } else {
388         if (src) {
389             xsrc.top    = 0;
390             xsrc.bottom = sdesc.dwHeight;
391             xsrc.left   = 0;
392             xsrc.right  = sdesc.dwWidth;
393         } else {
394             memset(&xsrc,0,sizeof(xsrc));
395         }
396     }
397
398     if (src) assert((xsrc.bottom-xsrc.top) <= sdesc.dwHeight);
399     assert((xdst.bottom-xdst.top) <= ddesc.dwHeight);
400
401     /* Now handle negative values in the rectangles. Warning: only supported for now
402        in the 'simple' cases (ie not in any stretching / rotation cases).
403
404        First, the case where nothing is to be done.
405     */
406     if (((xdst.bottom <= 0) || (xdst.right <= 0) || (xdst.top >= (int) ddesc.dwHeight) || (xdst.left >= (int) ddesc.dwWidth)) ||
407         ((src != NULL) &&
408          ((xsrc.bottom <= 0) || (xsrc.right <= 0) || (xsrc.top >= (int) sdesc.dwHeight) || (xsrc.left >= (int) sdesc.dwWidth))))
409     {
410         TRACE("Nothing to be done !\n");
411         goto release;
412     }
413
414     /* The easy case : the source-less blits.... */
415     if (src == NULL) {
416         RECT full_rect;
417         RECT temp_rect; /* No idea if intersect rect can be the same as one of the source rect */
418
419         full_rect.left   = 0;
420         full_rect.top    = 0;
421         full_rect.right  = ddesc.dwWidth;
422         full_rect.bottom = ddesc.dwHeight;
423         IntersectRect(&temp_rect, &full_rect, &xdst);
424         xdst = temp_rect;
425     } else {
426         /* This is trickier as any update to one rectangle need to be propagated to the other */
427         int clip_horiz = (xdst.left < 0) || (xdst.right  > (int) ddesc.dwWidth ) || (xsrc.left < 0) || (xsrc.right  > (int) sdesc.dwWidth );
428         int clip_vert  = (xdst.top  < 0) || (xdst.bottom > (int) ddesc.dwHeight) || (xsrc.top  < 0) || (xsrc.bottom > (int) sdesc.dwHeight);
429         if (clip_vert || clip_horiz) {
430             /* Now check if this is a special case or not... */
431             if ((((xdst.bottom - xdst.top ) != (xsrc.bottom - xsrc.top )) && clip_vert ) ||
432                 (((xdst.right  - xdst.left) != (xsrc.right  - xsrc.left)) && clip_horiz) ||
433                 (dwFlags & DDBLT_DDFX)) {
434                 WARN("Out of screen rectangle in special case. Not handled right now.\n");
435                 goto release;
436             }
437
438             if (clip_horiz) {
439               if (xsrc.left < 0) { xdst.left -= xsrc.left; xsrc.left = 0; }
440               if (xdst.left < 0) { xsrc.left -= xdst.left; xdst.left = 0; }
441               if (xsrc.right > sdesc.dwWidth) { xdst.right -= (xsrc.right - (int) sdesc.dwWidth); xsrc.right = (int) sdesc.dwWidth; }
442               if (xdst.right > ddesc.dwWidth) { xsrc.right -= (xdst.right - (int) ddesc.dwWidth); xdst.right = (int) ddesc.dwWidth; }
443             }
444             if (clip_vert) {
445                 if (xsrc.top < 0) { xdst.top -= xsrc.top; xsrc.top = 0; }
446                 if (xdst.top < 0) { xsrc.top -= xdst.top; xdst.top = 0; }
447                 if (xsrc.bottom > sdesc.dwHeight) { xdst.bottom -= (xsrc.bottom - (int) sdesc.dwHeight); xsrc.bottom = (int) sdesc.dwHeight; }
448                 if (xdst.bottom > ddesc.dwHeight) { xsrc.bottom -= (xdst.bottom - (int) ddesc.dwHeight); xdst.bottom = (int) ddesc.dwHeight; }
449             }
450             /* And check if after clipping something is still to be done... */
451             if ((xdst.bottom <= 0) || (xdst.right <= 0) || (xdst.top >= (int) ddesc.dwHeight) || (xdst.left >= (int) ddesc.dwWidth) ||
452                 (xsrc.bottom <= 0) || (xsrc.right <= 0) || (xsrc.top >= (int) sdesc.dwHeight) || (xsrc.left >= (int) sdesc.dwWidth)) {
453                 TRACE("Nothing to be done after clipping !\n");
454                 goto release;
455             }
456         }
457     }
458
459     bpp = GET_BPP(ddesc);
460     srcheight = xsrc.bottom - xsrc.top;
461     srcwidth = xsrc.right - xsrc.left;
462     dstheight = xdst.bottom - xdst.top;
463     dstwidth = xdst.right - xdst.left;
464     width = (xdst.right - xdst.left) * bpp;
465
466     assert(width <= ddesc.u1.lPitch);
467
468     dbuf = (BYTE*)ddesc.lpSurface+(xdst.top*ddesc.u1.lPitch)+(xdst.left*bpp);
469
470     if (dwFlags & (DDBLT_WAIT|DDBLT_ASYNC))
471     {
472         static BOOL displayed = FALSE;
473         if (!displayed)
474         {
475             FIXME("dwFlags DDBLT_WAIT and/or DDBLT_ASYNC: can't handle right now.\n");
476             displayed = TRUE;
477         }
478         dwFlags &= ~(DDBLT_WAIT|DDBLT_ASYNC);
479     }
480
481     /* First, all the 'source-less' blits */
482     if (dwFlags & DDBLT_COLORFILL) {
483         ret = _Blt_ColorFill(dbuf, dstwidth, dstheight, bpp,
484                              ddesc.u1.lPitch, lpbltfx->u5.dwFillColor);
485         dwFlags &= ~DDBLT_COLORFILL;
486     }
487
488     if (dwFlags & DDBLT_DEPTHFILL)
489         FIXME("DDBLT_DEPTHFILL needs to be implemented!\n");
490     if (dwFlags & DDBLT_ROP) {
491         /* Catch some degenerate cases here */
492         switch(lpbltfx->dwROP) {
493         case BLACKNESS:
494             ret = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,ddesc.u1.lPitch,0);
495             break;
496         case 0xAA0029: /* No-op */
497             break;
498         case WHITENESS:
499             ret = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,ddesc.u1.lPitch,~0);
500             break;
501         case SRCCOPY: /* well, we do that below ? */
502             break;
503         default:
504             FIXME("Unsupported raster op: %08lx  Pattern: %p\n", lpbltfx->dwROP, lpbltfx->u5.lpDDSPattern);
505             goto error;
506         }
507         dwFlags &= ~DDBLT_ROP;
508     }
509     if (dwFlags & DDBLT_DDROPS) {
510         FIXME("\tDdraw Raster Ops: %08lx  Pattern: %p\n", lpbltfx->dwDDROP, lpbltfx->u5.lpDDSPattern);
511     }
512     /* Now the 'with source' blits */
513     if (src) {
514         LPBYTE sbase;
515         int sx, xinc, sy, yinc;
516
517         if (!dstwidth || !dstheight) /* hmm... stupid program ? */
518             goto release;
519         sbase = (BYTE*)sdesc.lpSurface+(xsrc.top*sdesc.u1.lPitch)+xsrc.left*bpp;
520         xinc = (srcwidth << 16) / dstwidth;
521         yinc = (srcheight << 16) / dstheight;
522
523         if (!dwFlags) {
524             /* No effects, we can cheat here */
525             if (dstwidth == srcwidth) {
526                 if (dstheight == srcheight) {
527                     /* No stretching in either direction. This needs to be as
528                      * fast as possible */
529                     sbuf = sbase;
530
531                     /* check for overlapping surfaces */
532                     if (src != iface || xdst.top < xsrc.top ||
533                         xdst.right <= xsrc.left || xsrc.right <= xdst.left)
534                     {
535                         /* no overlap, or dst above src, so copy from top downwards */
536                         for (y = 0; y < dstheight; y++)
537                         {
538                             memcpy(dbuf, sbuf, width);
539                             sbuf += sdesc.u1.lPitch;
540                             dbuf += ddesc.u1.lPitch;
541                         }
542                     }
543                     else if (xdst.top > xsrc.top)  /* copy from bottom upwards */
544                     {
545                         sbuf += (sdesc.u1.lPitch*dstheight);
546                         dbuf += (ddesc.u1.lPitch*dstheight);
547                         for (y = 0; y < dstheight; y++)
548                         {
549                             sbuf -= sdesc.u1.lPitch;
550                             dbuf -= ddesc.u1.lPitch;
551                             memcpy(dbuf, sbuf, width);
552                         }
553                     }
554                     else /* src and dst overlapping on the same line, use memmove */
555                     {
556                         for (y = 0; y < dstheight; y++)
557                         {
558                             memmove(dbuf, sbuf, width);
559                             sbuf += sdesc.u1.lPitch;
560                             dbuf += ddesc.u1.lPitch;
561                         }
562                     }
563                 } else {
564                     /* Stretching in Y direction only */
565                     for (y = sy = 0; y < dstheight; y++, sy += yinc) {
566                         sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
567                         memcpy(dbuf, sbuf, width);
568                         dbuf += ddesc.u1.lPitch;
569                     }
570                 }
571             } else {
572                 /* Stretching in X direction */
573                 int last_sy = -1;
574                 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
575                     sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
576
577                     if ((sy >> 16) == (last_sy >> 16)) {
578                         /* this sourcerow is the same as last sourcerow -
579                          * copy already stretched row
580                          */
581                         memcpy(dbuf, dbuf - ddesc.u1.lPitch, width);
582                     } else {
583 #define STRETCH_ROW(type) { \
584                     type *s = (type *) sbuf, *d = (type *) dbuf; \
585                     for (x = sx = 0; x < dstwidth; x++, sx += xinc) \
586                     d[x] = s[sx >> 16]; \
587                     break; }
588
589                     switch(bpp) {
590                     case 1: STRETCH_ROW(BYTE)
591                     case 2: STRETCH_ROW(WORD)
592                     case 4: STRETCH_ROW(DWORD)
593                     case 3: {
594                         LPBYTE s,d = dbuf;
595                         for (x = sx = 0; x < dstwidth; x++, sx+= xinc) {
596                             DWORD pixel;
597
598                             s = sbuf+3*(sx>>16);
599                             pixel = (s[0]<<16)|(s[1]<<8)|s[2];
600                             d[0] = (pixel>>16)&0xff;
601                             d[1] = (pixel>> 8)&0xff;
602                             d[2] = (pixel    )&0xff;
603                             d+=3;
604                         }
605                         break;
606                     }
607                     default:
608                         FIXME("Stretched blit not implemented for bpp %d!\n", bpp*8);
609                         ret = DDERR_UNSUPPORTED;
610                         goto error;
611                     }
612 #undef STRETCH_ROW
613                     }
614                     dbuf += ddesc.u1.lPitch;
615                     last_sy = sy;
616                 }
617             }
618         } else {
619            LONG dstyinc = ddesc.u1.lPitch, dstxinc = bpp;
620            DWORD keylow = 0, keyhigh = 0;
621            if (dwFlags & (DDBLT_KEYSRC | DDBLT_KEYDEST | DDBLT_KEYSRCOVERRIDE | DDBLT_KEYDESTOVERRIDE)) {
622
623               if (dwFlags & DDBLT_KEYSRC) {
624                  keylow  = sdesc.ddckCKSrcBlt.dwColorSpaceLowValue;
625                  keyhigh = sdesc.ddckCKSrcBlt.dwColorSpaceHighValue;
626               } else if (dwFlags & DDBLT_KEYDEST){
627                  keylow  = ddesc.ddckCKDestBlt.dwColorSpaceLowValue;
628                  keyhigh = ddesc.ddckCKDestBlt.dwColorSpaceHighValue;
629               } else if (dwFlags & DDBLT_KEYSRCOVERRIDE) {
630                  keylow  = lpbltfx->ddckSrcColorkey.dwColorSpaceLowValue;
631                  keyhigh = lpbltfx->ddckSrcColorkey.dwColorSpaceHighValue;
632               } else {
633                  keylow  = lpbltfx->ddckDestColorkey.dwColorSpaceLowValue;
634                  keyhigh = lpbltfx->ddckDestColorkey.dwColorSpaceHighValue;
635               }
636               dwFlags &= ~(DDBLT_KEYSRC | DDBLT_KEYDEST | DDBLT_KEYSRCOVERRIDE | DDBLT_KEYDESTOVERRIDE);
637            }
638
639            if (dwFlags & DDBLT_DDFX)  {
640               LPBYTE dTopLeft, dTopRight, dBottomLeft, dBottomRight, tmp;
641               LONG tmpxy;
642               dTopLeft     = dbuf;
643               dTopRight    = dbuf+((dstwidth-1)*bpp);
644               dBottomLeft  = dTopLeft+((dstheight-1)*ddesc.u1.lPitch);
645               dBottomRight = dBottomLeft+((dstwidth-1)*bpp);
646
647               if (lpbltfx->dwDDFX & DDBLTFX_ARITHSTRETCHY){
648                  /* I don't think we need to do anything about this flag */
649                  WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_ARITHSTRETCHY\n");
650               }
651               if (lpbltfx->dwDDFX & DDBLTFX_MIRRORLEFTRIGHT) {
652                  tmp          = dTopRight;
653                  dTopRight    = dTopLeft;
654                  dTopLeft     = tmp;
655                  tmp          = dBottomRight;
656                  dBottomRight = dBottomLeft;
657                  dBottomLeft  = tmp;
658                  dstxinc = dstxinc *-1;
659               }
660               if (lpbltfx->dwDDFX & DDBLTFX_MIRRORUPDOWN) {
661                  tmp          = dTopLeft;
662                  dTopLeft     = dBottomLeft;
663                  dBottomLeft  = tmp;
664                  tmp          = dTopRight;
665                  dTopRight    = dBottomRight;
666                  dBottomRight = tmp;
667                  dstyinc = dstyinc *-1;
668               }
669               if (lpbltfx->dwDDFX & DDBLTFX_NOTEARING) {
670                  /* I don't think we need to do anything about this flag */
671                  WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_NOTEARING\n");
672               }
673               if (lpbltfx->dwDDFX & DDBLTFX_ROTATE180) {
674                  tmp          = dBottomRight;
675                  dBottomRight = dTopLeft;
676                  dTopLeft     = tmp;
677                  tmp          = dBottomLeft;
678                  dBottomLeft  = dTopRight;
679                  dTopRight    = tmp;
680                  dstxinc = dstxinc * -1;
681                  dstyinc = dstyinc * -1;
682               }
683               if (lpbltfx->dwDDFX & DDBLTFX_ROTATE270) {
684                  tmp          = dTopLeft;
685                  dTopLeft     = dBottomLeft;
686                  dBottomLeft  = dBottomRight;
687                  dBottomRight = dTopRight;
688                  dTopRight    = tmp;
689                  tmpxy   = dstxinc;
690                  dstxinc = dstyinc;
691                  dstyinc = tmpxy;
692                  dstxinc = dstxinc * -1;
693               }
694               if (lpbltfx->dwDDFX & DDBLTFX_ROTATE90) {
695                  tmp          = dTopLeft;
696                  dTopLeft     = dTopRight;
697                  dTopRight    = dBottomRight;
698                  dBottomRight = dBottomLeft;
699                  dBottomLeft  = tmp;
700                  tmpxy   = dstxinc;
701                  dstxinc = dstyinc;
702                  dstyinc = tmpxy;
703                  dstyinc = dstyinc * -1;
704               }
705               if (lpbltfx->dwDDFX & DDBLTFX_ZBUFFERBASEDEST) {
706                  /* I don't think we need to do anything about this flag */
707                  WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_ZBUFFERBASEDEST\n");
708               }
709               dbuf = dTopLeft;
710               dwFlags &= ~(DDBLT_DDFX);
711            }
712
713 #define COPY_COLORKEY_FX(type) { \
714             type *s = (type *) sbuf, *d = (type *) dbuf, *dx, tmp; \
715             for (y = sy = 0; y < dstheight; y++, sy += yinc) { \
716                (LPBYTE)s = sbase + (sy >> 16) * sdesc.u1.lPitch; \
717                (LPBYTE)dx = d; \
718                for (x = sx = 0; x < dstwidth; x++, sx += xinc) { \
719                   tmp = s[sx >> 16]; \
720                   if (tmp < keylow || tmp > keyhigh) dx[0] = tmp; \
721                   (LPBYTE)dx += dstxinc; \
722                   } \
723                (LPBYTE)d += dstyinc; \
724             } \
725             break; }
726
727             switch (bpp) {
728             case 1: COPY_COLORKEY_FX(BYTE)
729             case 2: COPY_COLORKEY_FX(WORD)
730             case 4: COPY_COLORKEY_FX(DWORD)
731             case 3: {LPBYTE s,d = dbuf, dx;
732                 for (y = sy = 0; y < dstheight; y++, sy += yinc) {
733                     sbuf = sbase + (sy >> 16) * sdesc.u1.lPitch;
734                     dx = d;
735                     for (x = sx = 0; x < dstwidth; x++, sx+= xinc) {
736                         DWORD pixel;
737                         s = sbuf+3*(sx>>16);
738                         pixel = (s[0]<<16)|(s[1]<<8)|s[2];
739                         if (pixel < keylow || pixel > keyhigh){
740                             dx[0] = (pixel>>16)&0xff;
741                             dx[1] = (pixel>> 8)&0xff;
742                             dx[2] = (pixel    )&0xff;
743                         }
744                         dx+= dstxinc;
745                     }
746                     d += dstyinc;
747                 }
748                 break;}
749             default:
750                FIXME("%s color-keyed blit not implemented for bpp %d!\n",
751                   (dwFlags & DDBLT_KEYSRC) ? "Source" : "Destination", bpp*8);
752                   ret = DDERR_UNSUPPORTED;
753                   goto error;
754 #undef COPY_COLORKEY_FX
755             }
756         }
757     }
758
759 error:
760     if (dwFlags && FIXME_ON(ddraw)) {
761         FIXME("\tUnsupported flags: ");
762         DDRAW_dump_DDBLT(dwFlags);
763     }
764
765 release:
766     IDirectDrawSurface7_Unlock(iface,NULL);
767     if (src) IDirectDrawSurface7_Unlock(src,NULL);
768     return DD_OK;
769 }
770
771 /* BltBatch: generic, unimplemented */
772
773 HRESULT WINAPI
774 DIB_DirectDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface, DWORD dstx,
775                               DWORD dsty, LPDIRECTDRAWSURFACE7 src,
776                               LPRECT rsrc, DWORD trans)
777 {
778     ICOM_THIS(IDirectDrawSurfaceImpl,iface);
779     int                 bpp, w, h, x, y;
780     DDSURFACEDESC2      ddesc,sdesc;
781     HRESULT             ret = DD_OK;
782     LPBYTE              sbuf, dbuf;
783     RECT                rsrc2;
784
785
786     if (TRACE_ON(ddraw)) {
787         FIXME("(%p)->(%ld,%ld,%p,%p,%08lx)\n",
788                 This,dstx,dsty,src,rsrc,trans
789         );
790         FIXME("\ttrans:");
791         if (FIXME_ON(ddraw))
792           DDRAW_dump_DDBLTFAST(trans);
793         if (rsrc)
794           FIXME("\tsrcrect: %dx%d-%dx%d\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
795         else
796           FIXME(" srcrect: NULL\n");
797     }
798
799     /* We need to lock the surfaces, or we won't get refreshes when done. */
800     sdesc.dwSize = sizeof(sdesc);
801     IDirectDrawSurface7_Lock(src, NULL,&sdesc,DDLOCK_READONLY, 0);
802     ddesc.dwSize = sizeof(ddesc);
803     IDirectDrawSurface7_Lock(iface,NULL,&ddesc,DDLOCK_WRITEONLY,0);
804
805    if (!rsrc) {
806            WARN("rsrc is NULL!\n");
807            rsrc = &rsrc2;
808            rsrc->left = rsrc->top = 0;
809            rsrc->right = sdesc.dwWidth;
810            rsrc->bottom = sdesc.dwHeight;
811    }
812
813     bpp = GET_BPP(This->surface_desc);
814     sbuf = (BYTE *)sdesc.lpSurface+(rsrc->top*sdesc.u1.lPitch)+rsrc->left*bpp;
815     dbuf = (BYTE *)ddesc.lpSurface+(dsty*ddesc.u1.lPitch)+dstx* bpp;
816
817
818     h=rsrc->bottom-rsrc->top;
819     if (h>ddesc.dwHeight-dsty) h=ddesc.dwHeight-dsty;
820     if (h>sdesc.dwHeight-rsrc->top) h=sdesc.dwHeight-rsrc->top;
821     if (h<0) h=0;
822
823     w=rsrc->right-rsrc->left;
824     if (w>ddesc.dwWidth-dstx) w=ddesc.dwWidth-dstx;
825     if (w>sdesc.dwWidth-rsrc->left) w=sdesc.dwWidth-rsrc->left;
826     if (w<0) w=0;
827
828     if (trans & (DDBLTFAST_SRCCOLORKEY | DDBLTFAST_DESTCOLORKEY)) {
829         DWORD keylow, keyhigh;
830         if (trans & DDBLTFAST_SRCCOLORKEY) {
831             keylow  = sdesc.ddckCKSrcBlt.dwColorSpaceLowValue;
832             keyhigh = sdesc.ddckCKSrcBlt.dwColorSpaceHighValue;
833         } else {
834             /* I'm not sure if this is correct */
835             FIXME("DDBLTFAST_DESTCOLORKEY not fully supported yet.\n");
836             keylow  = ddesc.ddckCKDestBlt.dwColorSpaceLowValue;
837             keyhigh = ddesc.ddckCKDestBlt.dwColorSpaceHighValue;
838         }
839
840 #define COPYBOX_COLORKEY(type) { \
841     type *d = (type *)dbuf, *s = (type *)sbuf, tmp; \
842     s = (type *) ((BYTE *) sdesc.lpSurface + (rsrc->top * sdesc.u1.lPitch) + rsrc->left * bpp); \
843     d = (type *) ((BYTE *) ddesc.lpSurface + (dsty * ddesc.u1.lPitch) + dstx * bpp); \
844     for (y = 0; y < h; y++) { \
845         for (x = 0; x < w; x++) { \
846             tmp = s[x]; \
847             if (tmp < keylow || tmp > keyhigh) d[x] = tmp; \
848         } \
849         (LPBYTE)s += sdesc.u1.lPitch; \
850         (LPBYTE)d += ddesc.u1.lPitch; \
851     } \
852     break; \
853 }
854
855         switch (bpp) {
856         case 1: COPYBOX_COLORKEY(BYTE)
857         case 2: COPYBOX_COLORKEY(WORD)
858         case 4: COPYBOX_COLORKEY(DWORD)
859         default:
860             FIXME("Source color key blitting not supported for bpp %d\n",bpp*8);
861             ret = DDERR_UNSUPPORTED;
862             goto error;
863         }
864 #undef COPYBOX_COLORKEY
865     } else {
866         int width = w * bpp;
867
868         for (y = 0; y < h; y++) {
869             memcpy(dbuf, sbuf, width);
870             sbuf += sdesc.u1.lPitch;
871             dbuf += ddesc.u1.lPitch;
872         }
873     }
874 error:
875     IDirectDrawSurface7_Unlock(iface, NULL);
876     IDirectDrawSurface7_Unlock(src, NULL);
877     return ret;
878 }
879
880 /* ChangeUniquenessValue: generic */
881 /* DeleteAttachedSurface: generic */
882 /* EnumAttachedSurfaces: generic */
883 /* EnumOverlayZOrders: generic, unimplemented */
884
885 BOOL DIB_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl* front,
886                                      IDirectDrawSurfaceImpl* back,
887                                      DWORD dwFlags)
888 {
889     DIB_DirectDrawSurfaceImpl* front_priv = front->private;
890     DIB_DirectDrawSurfaceImpl* back_priv = back->private;
891
892     TRACE("(%p,%p)\n",front,back);
893
894     {
895         HBITMAP tmp;
896         tmp = front_priv->dib.DIBsection;
897         front_priv->dib.DIBsection = back_priv->dib.DIBsection;
898         back_priv->dib.DIBsection = tmp;
899     }
900
901     {
902         void* tmp;
903         tmp = front_priv->dib.bitmap_data;
904         front_priv->dib.bitmap_data = back_priv->dib.bitmap_data;
905         back_priv->dib.bitmap_data = tmp;
906
907         tmp = front->surface_desc.lpSurface;
908         front->surface_desc.lpSurface = back->surface_desc.lpSurface;
909         back->surface_desc.lpSurface = tmp;
910     }
911
912     /* client_memory should not be different, but just in case */
913     {
914         BOOL tmp;
915         tmp = front_priv->dib.client_memory;
916         front_priv->dib.client_memory = back_priv->dib.client_memory;
917         back_priv->dib.client_memory = tmp;
918     }
919
920     return Main_DirectDrawSurface_flip_data(front, back, dwFlags);
921 }
922
923 /* Flip: generic */
924 /* FreePrivateData: generic */
925 /* GetAttachedSurface: generic */
926 /* GetBltStatus: generic */
927 /* GetCaps: generic (Returns the caps from This->surface_desc.) */
928 /* GetClipper: generic */
929 /* GetColorKey: generic */
930
931 HRESULT DIB_DirectDrawSurface_alloc_dc(IDirectDrawSurfaceImpl* This, HDC* phDC)
932 {
933     DIB_PRIV_VAR(priv, This);
934     HDC hDC;
935
936     TRACE("Grabbing a DC for surface: %p\n", This);
937
938     hDC = CreateCompatibleDC(0);
939     priv->dib.holdbitmap = SelectObject(hDC, priv->dib.DIBsection);
940     if (This->palette)
941         SelectPalette(hDC, This->palette->hpal, FALSE);
942
943     *phDC = hDC;
944
945     return S_OK;
946 }
947
948 HRESULT DIB_DirectDrawSurface_free_dc(IDirectDrawSurfaceImpl* This, HDC hDC)
949 {
950     DIB_PRIV_VAR(priv, This);
951
952     TRACE("Releasing DC for surface: %p\n", This);
953
954     SelectObject(hDC, priv->dib.holdbitmap);
955     DeleteDC(hDC);
956
957     return S_OK;
958 }
959
960 HRESULT DIB_DirectDrawSurface_get_dc(IDirectDrawSurfaceImpl* This, HDC* phDC)
961 {
962     return DIB_DirectDrawSurface_alloc_dc(This, phDC);
963 }
964
965 HRESULT DIB_DirectDrawSurface_release_dc(IDirectDrawSurfaceImpl* This, HDC hDC)
966 {
967     return DIB_DirectDrawSurface_free_dc(This, hDC);
968 }
969
970 /* GetDDInterface: generic */
971 /* GetFlipStatus: generic */
972 /* GetLOD: generic */
973 /* GetOverlayPosition: generic */
974 /* GetPalette: generic */
975 /* GetPixelFormat: generic */
976 /* GetPriority: generic */
977 /* GetPrivateData: generic */
978 /* GetSurfaceDesc: generic */
979 /* GetUniquenessValue: generic */
980 /* Initialize: generic */
981 /* IsLost: generic */
982 /* Lock: generic with callback? */
983 /* PageLock: generic */
984 /* PageUnlock: generic */
985
986 HRESULT WINAPI
987 DIB_DirectDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface)
988 {
989     TRACE("(%p)\n",iface);
990     return DD_OK;       /* ??? */
991 }
992
993 /* SetClipper: generic */
994 /* SetColorKey: generic */
995 /* SetLOD: generic */
996 /* SetOverlayPosition: generic */
997
998 void DIB_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl* This,
999                                        IDirectDrawPaletteImpl* pal)
1000 {
1001     if (!pal) return;
1002     if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
1003         This->update_palette(This, pal,
1004                              0, pal->palNumEntries,
1005                              pal->palents);
1006 }
1007
1008 void DIB_DirectDrawSurface_update_palette(IDirectDrawSurfaceImpl* This,
1009                                           IDirectDrawPaletteImpl* pal,
1010                                           DWORD dwStart, DWORD dwCount,
1011                                           LPPALETTEENTRY palent)
1012 {
1013     RGBQUAD col[256];
1014     int n;
1015     HDC dc;
1016
1017     TRACE("updating primary palette\n");
1018     for (n=0; n<dwCount; n++) {
1019       col[n].rgbRed   = palent[n].peRed;
1020       col[n].rgbGreen = palent[n].peGreen;
1021       col[n].rgbBlue  = palent[n].peBlue;
1022       col[n].rgbReserved = 0;
1023     }
1024     This->get_dc(This, &dc);
1025     SetDIBColorTable(dc, dwStart, dwCount, col);
1026     This->release_dc(This, dc);
1027
1028     /* Propagate change to backbuffers if there are any */
1029     /* Basically this is a modification of the Flip code to find the backbuffer */
1030     /* and duplicate the palette update there as well */
1031     if ((This->surface_desc.ddsCaps.dwCaps&(DDSCAPS_FLIP|DDSCAPS_FRONTBUFFER))
1032         == (DDSCAPS_FLIP|DDSCAPS_FRONTBUFFER))
1033     {
1034         static DDSCAPS2 back_caps = { DDSCAPS_BACKBUFFER };
1035         LPDIRECTDRAWSURFACE7 tgt;
1036
1037         HRESULT hr = IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This,IDirectDrawSurface7),
1038                                                             &back_caps, &tgt);
1039         if (!FAILED(hr))
1040         {
1041             IDirectDrawSurfaceImpl* target = ICOM_OBJECT(IDirectDrawSurfaceImpl,
1042                                                          IDirectDrawSurface7,tgt);
1043             IDirectDrawSurface7_Release(tgt);
1044             target->get_dc(target, &dc);
1045             SetDIBColorTable(dc, dwStart, dwCount, col);
1046             target->release_dc(target, dc);
1047         }
1048     }
1049 }
1050
1051 /* SetPalette: generic */
1052 /* SetPriority: generic */
1053 /* SetPrivateData: generic */
1054
1055 HRESULT WINAPI
1056 DIB_DirectDrawSurface_SetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
1057                                      LPDDSURFACEDESC2 pDDSD, DWORD dwFlags)
1058 {
1059     ICOM_THIS(IDirectDrawSurfaceImpl,iface);
1060     DIB_PRIV_VAR(priv, This);
1061     HRESULT hr = DD_OK;
1062     DWORD flags = pDDSD->dwFlags;
1063
1064     if (TRACE_ON(ddraw)) {
1065         TRACE("(%p)->(%p,%08lx)\n",iface,pDDSD,dwFlags);
1066         DDRAW_dump_surface_desc(pDDSD);
1067     }
1068
1069     if (pDDSD->dwFlags & DDSD_PIXELFORMAT) {
1070         flags &= ~DDSD_PIXELFORMAT;
1071         if (flags & DDSD_LPSURFACE) {
1072             This->surface_desc.u4.ddpfPixelFormat = pDDSD->u4.ddpfPixelFormat;
1073         } else {
1074             FIXME("Change of pixel format without surface re-allocation is not supported !\n");
1075         }
1076     }
1077     if (pDDSD->dwFlags & DDSD_LPSURFACE) {
1078         HBITMAP oldbmp = priv->dib.DIBsection;
1079         LPVOID oldsurf = This->surface_desc.lpSurface;
1080         BOOL oldc = priv->dib.client_memory;
1081
1082         flags &= ~DDSD_LPSURFACE;
1083
1084         TRACE("new lpSurface=%p\n",pDDSD->lpSurface);
1085         This->surface_desc.lpSurface = pDDSD->lpSurface;
1086         priv->dib.client_memory = TRUE;
1087
1088         hr = create_dib(This);
1089         if (FAILED(hr))
1090         {
1091             priv->dib.DIBsection = oldbmp;
1092             This->surface_desc.lpSurface = oldsurf;
1093             priv->dib.client_memory = oldc;
1094             return hr;
1095         }
1096
1097         DeleteObject(oldbmp);
1098
1099         if (!oldc)
1100             VirtualFree(oldsurf, 0, MEM_RELEASE);
1101     }
1102     if (flags) {
1103         WARN("Unhandled flags : %08lx\n", flags);
1104     }
1105     return hr;
1106 }
1107
1108 /* Unlock: ???, need callback */
1109 /* UpdateOverlay: generic */
1110 /* UpdateOverlayDisplay: generic */
1111 /* UpdateOverlayZOrder: generic */
1112
1113 static ICOM_VTABLE(IDirectDrawSurface7) DIB_IDirectDrawSurface7_VTable =
1114 {
1115     Main_DirectDrawSurface_QueryInterface,
1116     Main_DirectDrawSurface_AddRef,
1117     Main_DirectDrawSurface_Release,
1118     Main_DirectDrawSurface_AddAttachedSurface,
1119     Main_DirectDrawSurface_AddOverlayDirtyRect,
1120     DIB_DirectDrawSurface_Blt,
1121     Main_DirectDrawSurface_BltBatch,
1122     DIB_DirectDrawSurface_BltFast,
1123     Main_DirectDrawSurface_DeleteAttachedSurface,
1124     Main_DirectDrawSurface_EnumAttachedSurfaces,
1125     Main_DirectDrawSurface_EnumOverlayZOrders,
1126     Main_DirectDrawSurface_Flip,
1127     Main_DirectDrawSurface_GetAttachedSurface,
1128     Main_DirectDrawSurface_GetBltStatus,
1129     Main_DirectDrawSurface_GetCaps,
1130     Main_DirectDrawSurface_GetClipper,
1131     Main_DirectDrawSurface_GetColorKey,
1132     Main_DirectDrawSurface_GetDC,
1133     Main_DirectDrawSurface_GetFlipStatus,
1134     Main_DirectDrawSurface_GetOverlayPosition,
1135     Main_DirectDrawSurface_GetPalette,
1136     Main_DirectDrawSurface_GetPixelFormat,
1137     Main_DirectDrawSurface_GetSurfaceDesc,
1138     Main_DirectDrawSurface_Initialize,
1139     Main_DirectDrawSurface_IsLost,
1140     Main_DirectDrawSurface_Lock,
1141     Main_DirectDrawSurface_ReleaseDC,
1142     DIB_DirectDrawSurface_Restore,
1143     Main_DirectDrawSurface_SetClipper,
1144     Main_DirectDrawSurface_SetColorKey,
1145     Main_DirectDrawSurface_SetOverlayPosition,
1146     Main_DirectDrawSurface_SetPalette,
1147     Main_DirectDrawSurface_Unlock,
1148     Main_DirectDrawSurface_UpdateOverlay,
1149     Main_DirectDrawSurface_UpdateOverlayDisplay,
1150     Main_DirectDrawSurface_UpdateOverlayZOrder,
1151     Main_DirectDrawSurface_GetDDInterface,
1152     Main_DirectDrawSurface_PageLock,
1153     Main_DirectDrawSurface_PageUnlock,
1154     DIB_DirectDrawSurface_SetSurfaceDesc,
1155     Main_DirectDrawSurface_SetPrivateData,
1156     Main_DirectDrawSurface_GetPrivateData,
1157     Main_DirectDrawSurface_FreePrivateData,
1158     Main_DirectDrawSurface_GetUniquenessValue,
1159     Main_DirectDrawSurface_ChangeUniquenessValue,
1160     Main_DirectDrawSurface_SetPriority,
1161     Main_DirectDrawSurface_GetPriority,
1162     Main_DirectDrawSurface_SetLOD,
1163     Main_DirectDrawSurface_GetLOD
1164 };