wined3d: Allow shader_buffer_init() to fail.
[wine] / dlls / wined3d / surface_gdi.c
1 /*
2  * 2D Surface implementation without OpenGL
3  *
4  * Copyright 1997-2000 Marcus Meissner
5  * Copyright 1998-2000 Lionel Ulmer
6  * Copyright 2000-2001 TransGaming Technologies Inc.
7  * Copyright 2002-2005 Jason Edmeades
8  * Copyright 2002-2003 Raphael Junqueira
9  * Copyright 2004 Christian Costa
10  * Copyright 2005 Oliver Stieber
11  * Copyright 2006-2008 Stefan Dösinger
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with this library; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27
28 #include "config.h"
29 #include "wine/port.h"
30 #include "wined3d_private.h"
31
32 #include <stdio.h>
33
34 /* Use the d3d_surface debug channel to have one channel for all surfaces */
35 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
36
37 void surface_gdi_cleanup(IWineD3DSurfaceImpl *This)
38 {
39     TRACE("(%p) : Cleaning up.\n", This);
40
41     if (This->Flags & SFLAG_DIBSECTION)
42     {
43         /* Release the DC. */
44         SelectObject(This->hDC, This->dib.holdbitmap);
45         DeleteDC(This->hDC);
46         /* Release the DIB section. */
47         DeleteObject(This->dib.DIBsection);
48         This->dib.bitmap_data = NULL;
49         This->resource.allocatedMemory = NULL;
50     }
51
52     if (This->Flags & SFLAG_USERPTR) IWineD3DSurface_SetMem((IWineD3DSurface *)This, NULL);
53     if (This->overlay_dest) list_remove(&This->overlay_entry);
54
55     HeapFree(GetProcessHeap(), 0, This->palette9);
56
57     resource_cleanup((IWineD3DResource *)This);
58 }
59
60 /*****************************************************************************
61  * IWineD3DSurface::Release, GDI version
62  *
63  * In general a normal COM Release method, but the GDI version doesn't have
64  * to destroy all the GL things.
65  *
66  *****************************************************************************/
67 static ULONG WINAPI IWineGDISurfaceImpl_Release(IWineD3DSurface *iface) {
68     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
69     ULONG ref = InterlockedDecrement(&This->resource.ref);
70     TRACE("(%p) : Releasing from %d\n", This, ref + 1);
71
72     if (!ref)
73     {
74         surface_gdi_cleanup(This);
75
76         TRACE("(%p) Released.\n", This);
77         HeapFree(GetProcessHeap(), 0, This);
78     }
79
80     return ref;
81 }
82
83 /*****************************************************************************
84  * IWineD3DSurface::PreLoad, GDI version
85  *
86  * This call is unsupported on GDI surfaces, if it's called something went
87  * wrong in the parent library. Write an informative warning
88  *
89  *****************************************************************************/
90 static void WINAPI
91 IWineGDISurfaceImpl_PreLoad(IWineD3DSurface *iface)
92 {
93     ERR("(%p): PreLoad is not supported on X11 surfaces!\n", iface);
94     ERR("(%p): Most likely the parent library did something wrong.\n", iface);
95     ERR("(%p): Please report to wine-devel\n", iface);
96 }
97
98 /*****************************************************************************
99  * IWineD3DSurface::UnLoad, GDI version
100  *
101  * This call is unsupported on GDI surfaces, if it's called something went
102  * wrong in the parent library. Write an informative warning.
103  *
104  *****************************************************************************/
105 static void WINAPI IWineGDISurfaceImpl_UnLoad(IWineD3DSurface *iface)
106 {
107     ERR("(%p): UnLoad is not supported on X11 surfaces!\n", iface);
108     ERR("(%p): Most likely the parent library did something wrong.\n", iface);
109     ERR("(%p): Please report to wine-devel\n", iface);
110 }
111
112 /*****************************************************************************
113  * IWineD3DSurface::LockRect, GDI version
114  *
115  * Locks the surface and returns a pointer to the surface memory
116  *
117  * Params:
118  *  pLockedRect: Address to return the locking info at
119  *  pRect: Rectangle to lock
120  *  Flags: Some flags
121  *
122  * Returns:
123  *  WINED3D_OK on success
124  *  WINED3DERR_INVALIDCALL on errors
125  *
126  *****************************************************************************/
127 static HRESULT WINAPI
128 IWineGDISurfaceImpl_LockRect(IWineD3DSurface *iface,
129                              WINED3DLOCKED_RECT* pLockedRect,
130                              CONST RECT* pRect,
131                              DWORD Flags)
132 {
133     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
134
135     /* Already locked? */
136     if(This->Flags & SFLAG_LOCKED)
137     {
138         WARN("(%p) Surface already locked\n", This);
139         /* What should I return here? */
140         return WINED3DERR_INVALIDCALL;
141     }
142     This->Flags |= SFLAG_LOCKED;
143
144     if(!This->resource.allocatedMemory) {
145         /* This happens on gdi surfaces if the application set a user pointer and resets it.
146          * Recreate the DIB section
147          */
148         IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
149         This->resource.allocatedMemory = This->dib.bitmap_data;
150     }
151
152     return IWineD3DBaseSurfaceImpl_LockRect(iface, pLockedRect, pRect, Flags);
153 }
154
155 /*****************************************************************************
156  * IWineD3DSurface::UnlockRect, GDI version
157  *
158  * Unlocks a surface. This implementation doesn't do much, except updating
159  * the window if the front buffer is unlocked
160  *
161  * Returns:
162  *  WINED3D_OK on success
163  *  WINED3DERR_INVALIDCALL on failure
164  *
165  *****************************************************************************/
166 static HRESULT WINAPI
167 IWineGDISurfaceImpl_UnlockRect(IWineD3DSurface *iface)
168 {
169     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
170     IWineD3DSwapChainImpl *swapchain = NULL;
171     TRACE("(%p)\n", This);
172
173     if (!(This->Flags & SFLAG_LOCKED))
174     {
175         WARN("trying to Unlock an unlocked surf@%p\n", This);
176         return WINEDDERR_NOTLOCKED;
177     }
178
179     /* Can be useful for debugging */
180 #if 0
181         {
182             static unsigned int gen = 0;
183             char buffer[4096];
184             ++gen;
185             if ((gen % 10) == 0) {
186                 snprintf(buffer, sizeof(buffer), "/tmp/surface%p_type%u_level%u_%u.ppm", This, This->glDescription.target, This->glDescription.level, gen);
187                 IWineD3DSurfaceImpl_SaveSnapshot(iface, buffer);
188             }
189             /*
190              * debugging crash code
191             if (gen == 250) {
192               void** test = NULL;
193               *test = 0;
194             }
195             */
196         }
197 #endif
198
199     /* Tell the swapchain to update the screen */
200     if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapchain)))
201     {
202         if(iface == swapchain->frontBuffer)
203         {
204             x11_copy_to_screen(swapchain, &This->lockedRect);
205         }
206         IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
207     }
208
209     This->Flags &= ~SFLAG_LOCKED;
210     memset(&This->lockedRect, 0, sizeof(RECT));
211     return WINED3D_OK;
212 }
213
214 /*****************************************************************************
215  * IWineD3DSurface::Flip, GDI version
216  *
217  * Flips 2 flipping enabled surfaces. Determining the 2 targets is done by
218  * the parent library. This implementation changes the data pointers of the
219  * surfaces and copies the new front buffer content to the screen
220  *
221  * Params:
222  *  override: Flipping target(e.g. back buffer)
223  *
224  * Returns:
225  *  WINED3D_OK on success
226  *
227  *****************************************************************************/
228 static HRESULT WINAPI
229 IWineGDISurfaceImpl_Flip(IWineD3DSurface *iface,
230                          IWineD3DSurface *override,
231                          DWORD Flags)
232 {
233     IWineD3DSwapChainImpl *swapchain = NULL;
234     HRESULT hr;
235
236     if(FAILED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapchain)))
237     {
238         ERR("Flipped surface is not on a swapchain\n");
239         return WINEDDERR_NOTFLIPPABLE;
240     }
241
242     hr = IWineD3DSwapChain_Present((IWineD3DSwapChain *) swapchain, NULL, NULL, 0, NULL, 0);
243     IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
244     return hr;
245 }
246
247 /*****************************************************************************
248  * IWineD3DSurface::LoadTexture, GDI version
249  *
250  * This is mutually unsupported by GDI surfaces
251  *
252  * Returns:
253  *  D3DERR_INVALIDCALL
254  *
255  *****************************************************************************/
256 static HRESULT WINAPI
257 IWineGDISurfaceImpl_LoadTexture(IWineD3DSurface *iface, BOOL srgb_mode)
258 {
259     ERR("Unsupported on X11 surfaces\n");
260     return WINED3DERR_INVALIDCALL;
261 }
262
263 /*****************************************************************************
264  * IWineD3DSurface::SaveSnapshot, GDI version
265  *
266  * This method writes the surface's contents to the in tga format to the
267  * file specified in filename.
268  *
269  * Params:
270  *  filename: File to write to
271  *
272  * Returns:
273  *  WINED3DERR_INVALIDCALL if the file couldn't be opened
274  *  WINED3D_OK on success
275  *
276  *****************************************************************************/
277 static int get_shift(DWORD color_mask) {
278     int shift = 0;
279     while (color_mask > 0xFF) {
280         color_mask >>= 1;
281         shift += 1;
282     }
283     while ((color_mask & 0x80) == 0) {
284         color_mask <<= 1;
285         shift -= 1;
286     }
287     return shift;
288 }
289
290
291 static HRESULT WINAPI
292 IWineGDISurfaceImpl_SaveSnapshot(IWineD3DSurface *iface,
293 const char* filename)
294 {
295     FILE* f = NULL;
296     UINT y = 0, x = 0;
297     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
298     static char *output = NULL;
299     static UINT size = 0;
300     const struct GlPixelFormatDesc *format_desc = This->resource.format_desc;
301
302     if (This->pow2Width > size) {
303         output = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->pow2Width * 3);
304         size = This->pow2Width;
305     }
306
307
308     f = fopen(filename, "w+");
309     if (NULL == f) {
310         ERR("opening of %s failed with\n", filename);
311         return WINED3DERR_INVALIDCALL;
312     }
313     fprintf(f, "P6\n%d %d\n255\n", This->pow2Width, This->pow2Height);
314
315     if (This->resource.format_desc->format == WINED3DFMT_P8)
316     {
317         unsigned char table[256][3];
318         int i;
319
320         if (This->palette == NULL) {
321             fclose(f);
322             return WINED3DERR_INVALIDCALL;
323         }
324         for (i = 0; i < 256; i++) {
325             table[i][0] = This->palette->palents[i].peRed;
326             table[i][1] = This->palette->palents[i].peGreen;
327             table[i][2] = This->palette->palents[i].peBlue;
328         }
329         for (y = 0; y < This->pow2Height; y++) {
330             unsigned char *src = This->resource.allocatedMemory + (y * 1 * IWineD3DSurface_GetPitch(iface));
331             for (x = 0; x < This->pow2Width; x++) {
332                 unsigned char color = *src;
333                 src += 1;
334
335                 output[3 * x + 0] = table[color][0];
336                 output[3 * x + 1] = table[color][1];
337                 output[3 * x + 2] = table[color][2];
338             }
339             fwrite(output, 3 * This->pow2Width, 1, f);
340         }
341     } else {
342         int red_shift, green_shift, blue_shift, pix_width, alpha_shift;
343
344         pix_width = format_desc->byte_count;
345
346         red_shift = get_shift(format_desc->red_mask);
347         green_shift = get_shift(format_desc->green_mask);
348         blue_shift = get_shift(format_desc->blue_mask);
349         alpha_shift = get_shift(format_desc->alpha_mask);
350
351         for (y = 0; y < This->pow2Height; y++) {
352             const unsigned char *src = This->resource.allocatedMemory + (y * 1 * IWineD3DSurface_GetPitch(iface));
353             for (x = 0; x < This->pow2Width; x++) {
354                 unsigned int color;
355                 unsigned int comp;
356                 int i;
357
358                 color = 0;
359                 for (i = 0; i < pix_width; i++) {
360                     color |= src[i] << (8 * i);
361                 }
362                 src += 1 * pix_width;
363
364                 comp = color & format_desc->red_mask;
365                 output[3 * x + 0] = red_shift > 0 ? comp >> red_shift : comp << -red_shift;
366                 comp = color & format_desc->green_mask;
367                 output[3 * x + 1] = green_shift > 0 ? comp >> green_shift : comp << -green_shift;
368                 comp = color & format_desc->alpha_mask;
369                 output[3 * x + 2] = alpha_shift > 0 ? comp >> alpha_shift : comp << -alpha_shift;
370             }
371             fwrite(output, 3 * This->pow2Width, 1, f);
372         }
373     }
374     fclose(f);
375     return WINED3D_OK;
376 }
377
378 static HRESULT WINAPI IWineGDISurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) {
379     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
380     WINED3DLOCKED_RECT lock;
381     HRESULT hr;
382     RGBQUAD col[256];
383
384     TRACE("(%p)->(%p)\n",This,pHDC);
385
386     if(This->Flags & SFLAG_USERPTR) {
387         ERR("Not supported on surfaces with an application-provided surfaces\n");
388         return WINEDDERR_NODC;
389     }
390
391     /* Give more detailed info for ddraw */
392     if (This->Flags & SFLAG_DCINUSE)
393         return WINEDDERR_DCALREADYCREATED;
394
395     /* Can't GetDC if the surface is locked */
396     if (This->Flags & SFLAG_LOCKED)
397         return WINED3DERR_INVALIDCALL;
398
399     memset(&lock, 0, sizeof(lock)); /* To be sure */
400
401     /* Should have a DIB section already */
402
403     /* Lock the surface */
404     hr = IWineD3DSurface_LockRect(iface,
405                                   &lock,
406                                   NULL,
407                                   0);
408     if(FAILED(hr)) {
409         ERR("IWineD3DSurface_LockRect failed with hr = %08x\n", hr);
410         /* keep the dib section */
411         return hr;
412     }
413
414     if (This->resource.format_desc->format == WINED3DFMT_P8
415             || This->resource.format_desc->format == WINED3DFMT_A8P8)
416     {
417         unsigned int n;
418         const PALETTEENTRY *pal = NULL;
419
420         if(This->palette) {
421             pal = This->palette->palents;
422         } else {
423             IWineD3DSurfaceImpl *dds_primary;
424             IWineD3DSwapChainImpl *swapchain;
425             swapchain = (IWineD3DSwapChainImpl *)This->resource.wineD3DDevice->swapchains[0];
426             dds_primary = (IWineD3DSurfaceImpl *)swapchain->frontBuffer;
427             if (dds_primary && dds_primary->palette)
428                 pal = dds_primary->palette->palents;
429         }
430
431         if (pal) {
432             for (n=0; n<256; n++) {
433                 col[n].rgbRed   = pal[n].peRed;
434                 col[n].rgbGreen = pal[n].peGreen;
435                 col[n].rgbBlue  = pal[n].peBlue;
436                 col[n].rgbReserved = 0;
437             }
438             SetDIBColorTable(This->hDC, 0, 256, col);
439         }
440     }
441
442     *pHDC = This->hDC;
443     TRACE("returning %p\n",*pHDC);
444     This->Flags |= SFLAG_DCINUSE;
445
446     return WINED3D_OK;
447 }
448
449 static HRESULT WINAPI IWineGDISurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC) {
450     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
451
452     TRACE("(%p)->(%p)\n",This,hDC);
453
454     if (!(This->Flags & SFLAG_DCINUSE))
455         return WINEDDERR_NODC;
456
457     if (This->hDC !=hDC) {
458         WARN("Application tries to release an invalid DC(%p), surface dc is %p\n", hDC, This->hDC);
459         return WINEDDERR_NODC;
460     }
461
462     /* we locked first, so unlock now */
463     IWineD3DSurface_UnlockRect(iface);
464
465     This->Flags &= ~SFLAG_DCINUSE;
466
467     return WINED3D_OK;
468 }
469
470 static HRESULT WINAPI IWineGDISurfaceImpl_RealizePalette(IWineD3DSurface *iface) {
471     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
472     RGBQUAD col[256];
473     IWineD3DPaletteImpl *pal = This->palette;
474     unsigned int n;
475     IWineD3DSwapChainImpl *swapchain;
476     TRACE("(%p)\n", This);
477
478     if (!pal) return WINED3D_OK;
479
480     if(This->Flags & SFLAG_DIBSECTION) {
481         TRACE("(%p): Updating the hdc's palette\n", This);
482         for (n=0; n<256; n++) {
483             col[n].rgbRed   = pal->palents[n].peRed;
484             col[n].rgbGreen = pal->palents[n].peGreen;
485             col[n].rgbBlue  = pal->palents[n].peBlue;
486             col[n].rgbReserved = 0;
487         }
488         SetDIBColorTable(This->hDC, 0, 256, col);
489     }
490
491     /* Update the image because of the palette change. Some games like e.g Red Alert
492        call SetEntries a lot to implement fading. */
493     /* Tell the swapchain to update the screen */
494     if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapchain)))
495     {
496         if(iface == swapchain->frontBuffer)
497         {
498             x11_copy_to_screen(swapchain, NULL);
499         }
500         IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
501     }
502
503     return WINED3D_OK;
504 }
505
506 /*****************************************************************************
507  * IWineD3DSurface::PrivateSetup, GDI version
508  *
509  * Initializes the GDI surface, aka creates the DIB section we render to
510  * The DIB section creation is done by calling GetDC, which will create the
511  * section and releasing the dc to allow the app to use it. The dib section
512  * will stay until the surface is released
513  *
514  * GDI surfaces do not need to be a power of 2 in size, so the pow2 sizes
515  * are set to the real sizes to save memory. The NONPOW2 flag is unset to
516  * avoid confusion in the shared surface code.
517  *
518  * Returns:
519  *  WINED3D_OK on success
520  *  The return values of called methods on failure
521  *
522  *****************************************************************************/
523 static HRESULT WINAPI
524 IWineGDISurfaceImpl_PrivateSetup(IWineD3DSurface *iface)
525 {
526     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
527
528     if(This->resource.usage & WINED3DUSAGE_OVERLAY)
529     {
530         ERR("(%p) Overlays not yet supported by GDI surfaces\n", This);
531         return WINED3DERR_INVALIDCALL;
532     }
533     /* Sysmem textures have memory already allocated -
534      * release it, this avoids an unnecessary memcpy
535      */
536     HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
537     This->resource.allocatedMemory = NULL;
538     This->resource.heapMemory = NULL;
539
540     /* We don't mind the nonpow2 stuff in GDI */
541     This->pow2Width = This->currentDesc.Width;
542     This->pow2Height = This->currentDesc.Height;
543
544     IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
545     This->resource.allocatedMemory = This->dib.bitmap_data;
546
547     return WINED3D_OK;
548 }
549
550 static void WINAPI IWineGDISurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription) {
551     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
552     FIXME("(%p) : Should not be called on a GDI surface\n", This);
553     *glDescription = NULL;
554 }
555
556 static HRESULT WINAPI IWineGDISurfaceImpl_SetMem(IWineD3DSurface *iface, void *Mem) {
557     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
558
559     /* Render targets depend on their hdc, and we can't create an hdc on a user pointer */
560     if(This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
561         ERR("Not supported on render targets\n");
562         return WINED3DERR_INVALIDCALL;
563     }
564
565     if(This->Flags & (SFLAG_LOCKED | SFLAG_DCINUSE)) {
566         WARN("Surface is locked or the HDC is in use\n");
567         return WINED3DERR_INVALIDCALL;
568     }
569
570     if(Mem && Mem != This->resource.allocatedMemory) {
571         void *release = NULL;
572
573         /* Do I have to copy the old surface content? */
574         if(This->Flags & SFLAG_DIBSECTION) {
575                 /* Release the DC. No need to hold the critical section for the update
576             * Thread because this thread runs only on front buffers, but this method
577             * fails for render targets in the check above.
578                 */
579             SelectObject(This->hDC, This->dib.holdbitmap);
580             DeleteDC(This->hDC);
581             /* Release the DIB section */
582             DeleteObject(This->dib.DIBsection);
583             This->dib.bitmap_data = NULL;
584             This->resource.allocatedMemory = NULL;
585             This->hDC = NULL;
586             This->Flags &= ~SFLAG_DIBSECTION;
587         } else if(!(This->Flags & SFLAG_USERPTR)) {
588             release = This->resource.allocatedMemory;
589         }
590         This->resource.allocatedMemory = Mem;
591         This->Flags |= SFLAG_USERPTR | SFLAG_INSYSMEM;
592
593         /* Now free the old memory if any */
594         HeapFree(GetProcessHeap(), 0, release);
595     } else if(This->Flags & SFLAG_USERPTR) {
596         /* LockRect and GetDC will re-create the dib section and allocated memory */
597         This->resource.allocatedMemory = NULL;
598         This->Flags &= ~SFLAG_USERPTR;
599     }
600     return WINED3D_OK;
601 }
602
603 /***************************
604  *
605  ***************************/
606 static void WINAPI IWineGDISurfaceImpl_ModifyLocation(IWineD3DSurface *iface, DWORD flag, BOOL persistent) {
607     TRACE("(%p)->(%s, %s)\n", iface,
608           flag == SFLAG_INSYSMEM ? "SFLAG_INSYSMEM" : flag == SFLAG_INDRAWABLE ? "SFLAG_INDRAWABLE" : "SFLAG_INTEXTURE",
609           persistent ? "TRUE" : "FALSE");
610     /* GDI surfaces can be in system memory only */
611     if(flag != SFLAG_INSYSMEM) {
612         ERR("GDI Surface requested in gl %s memory\n", flag == SFLAG_INDRAWABLE ? "drawable" : "texture");
613     }
614 }
615
616 static HRESULT WINAPI IWineGDISurfaceImpl_LoadLocation(IWineD3DSurface *iface, DWORD flag, const RECT *rect) {
617     if(flag != SFLAG_INSYSMEM) {
618         ERR("GDI Surface requested to be copied to gl %s\n", flag == SFLAG_INTEXTURE ? "texture" : "drawable");
619     } else {
620         TRACE("Surface requested in surface memory\n");
621     }
622     return WINED3D_OK;
623 }
624
625 static WINED3DSURFTYPE WINAPI IWineGDISurfaceImpl_GetImplType(IWineD3DSurface *iface) {
626     return SURFACE_GDI;
627 }
628
629 static HRESULT WINAPI IWineGDISurfaceImpl_DrawOverlay(IWineD3DSurface *iface) {
630     FIXME("GDI surfaces can't draw overlays yet\n");
631     return E_FAIL;
632 }
633
634 /* FIXME: This vtable should not use any IWineD3DSurface* implementation functions,
635  * only IWineD3DBaseSurface and IWineGDISurface ones.
636  */
637 const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl =
638 {
639     /* IUnknown */
640     IWineD3DBaseSurfaceImpl_QueryInterface,
641     IWineD3DBaseSurfaceImpl_AddRef,
642     IWineGDISurfaceImpl_Release,
643     /* IWineD3DResource */
644     IWineD3DBaseSurfaceImpl_GetParent,
645     IWineD3DBaseSurfaceImpl_GetDevice,
646     IWineD3DBaseSurfaceImpl_SetPrivateData,
647     IWineD3DBaseSurfaceImpl_GetPrivateData,
648     IWineD3DBaseSurfaceImpl_FreePrivateData,
649     IWineD3DBaseSurfaceImpl_SetPriority,
650     IWineD3DBaseSurfaceImpl_GetPriority,
651     IWineGDISurfaceImpl_PreLoad,
652     IWineGDISurfaceImpl_UnLoad,
653     IWineD3DBaseSurfaceImpl_GetType,
654     /* IWineD3DSurface */
655     IWineD3DBaseSurfaceImpl_GetContainer,
656     IWineD3DBaseSurfaceImpl_GetDesc,
657     IWineGDISurfaceImpl_LockRect,
658     IWineGDISurfaceImpl_UnlockRect,
659     IWineGDISurfaceImpl_GetDC,
660     IWineGDISurfaceImpl_ReleaseDC,
661     IWineGDISurfaceImpl_Flip,
662     IWineD3DBaseSurfaceImpl_Blt,
663     IWineD3DBaseSurfaceImpl_GetBltStatus,
664     IWineD3DBaseSurfaceImpl_GetFlipStatus,
665     IWineD3DBaseSurfaceImpl_IsLost,
666     IWineD3DBaseSurfaceImpl_Restore,
667     IWineD3DBaseSurfaceImpl_BltFast,
668     IWineD3DBaseSurfaceImpl_GetPalette,
669     IWineD3DBaseSurfaceImpl_SetPalette,
670     IWineGDISurfaceImpl_RealizePalette,
671     IWineD3DBaseSurfaceImpl_SetColorKey,
672     IWineD3DBaseSurfaceImpl_GetPitch,
673     IWineGDISurfaceImpl_SetMem,
674     IWineD3DBaseSurfaceImpl_SetOverlayPosition,
675     IWineD3DBaseSurfaceImpl_GetOverlayPosition,
676     IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder,
677     IWineD3DBaseSurfaceImpl_UpdateOverlay,
678     IWineD3DBaseSurfaceImpl_SetClipper,
679     IWineD3DBaseSurfaceImpl_GetClipper,
680     /* Internal use: */
681     IWineGDISurfaceImpl_LoadTexture,
682     IWineD3DBaseSurfaceImpl_BindTexture,
683     IWineGDISurfaceImpl_SaveSnapshot,
684     IWineD3DBaseSurfaceImpl_SetContainer,
685     IWineGDISurfaceImpl_GetGlDesc,
686     IWineD3DBaseSurfaceImpl_GetData,
687     IWineD3DBaseSurfaceImpl_SetFormat,
688     IWineGDISurfaceImpl_PrivateSetup,
689     IWineGDISurfaceImpl_ModifyLocation,
690     IWineGDISurfaceImpl_LoadLocation,
691     IWineGDISurfaceImpl_GetImplType,
692     IWineGDISurfaceImpl_DrawOverlay
693 };