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