Add support for more than 2 audio channels.
[wine] / dlls / ddraw / dsurface / user.c
1 /*      User-based primary surface driver
2  *
3  * Copyright 2000-2001 TransGaming Technologies Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include "config.h"
21
22 #include <assert.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #define CONST_VTABLE
27
28 #include "winerror.h"
29 #include "wine/debug.h"
30 #include "ddraw_private.h"
31 #include "dsurface/main.h"
32 #include "dsurface/dib.h"
33 #include "dsurface/user.h"
34 #include "dsurface/wndproc.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
37
38 /* if you use OWN_WINDOW, don't use SYNC_UPDATE, or you may get trouble */
39 /* #define SYNC_UPDATE */
40 /*
41  * FIXME: This does not work any more because the created window has its own
42  *        thread queue that cannot be manipulated by application threads.
43  * #define OWN_WINDOW
44  */
45
46 #ifdef OWN_WINDOW
47 static void User_create_own_window(IDirectDrawSurfaceImpl* This);
48 static void User_destroy_own_window(IDirectDrawSurfaceImpl* This);
49 #endif
50 #ifndef SYNC_UPDATE
51 static DWORD CALLBACK User_update_thread(LPVOID);
52 #endif
53 static void User_copy_to_screen(IDirectDrawSurfaceImpl* This, LPCRECT rc);
54
55 static HWND get_display_window(IDirectDrawSurfaceImpl* This, LPPOINT pt);
56
57 static const IDirectDrawSurface7Vtbl User_IDirectDrawSurface7_VTable;
58
59 HRESULT
60 User_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl* This,
61                                  IDirectDrawImpl* pDD,
62                                  const DDSURFACEDESC2* pDDSD)
63 {
64     USER_PRIV_VAR(priv, This);
65     HRESULT hr;
66
67     TRACE("(%p,%p,%p)\n",This,pDD,pDDSD);
68     hr = DIB_DirectDrawSurface_Construct(This, pDD, pDDSD);
69     if (FAILED(hr)) return hr;
70
71     ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,
72                         User_IDirectDrawSurface7_VTable);
73
74     This->final_release = User_DirectDrawSurface_final_release;
75     This->duplicate_surface = User_DirectDrawSurface_duplicate_surface;
76
77     This->lock_update   = User_DirectDrawSurface_lock_update;
78     This->unlock_update = User_DirectDrawSurface_unlock_update;
79
80     This->flip_data   = User_DirectDrawSurface_flip_data;
81     This->flip_update = User_DirectDrawSurface_flip_update;
82
83     This->get_dc     = User_DirectDrawSurface_get_dc;
84     This->release_dc = User_DirectDrawSurface_release_dc;
85
86     This->set_palette    = User_DirectDrawSurface_set_palette;
87     This->update_palette = User_DirectDrawSurface_update_palette;
88
89     This->get_gamma_ramp = User_DirectDrawSurface_get_gamma_ramp;
90     This->set_gamma_ramp = User_DirectDrawSurface_set_gamma_ramp;
91
92     This->get_display_window = User_DirectDrawSurface_get_display_window;
93
94     if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
95     {
96 #ifdef OWN_WINDOW
97         DirectDrawSurface_RegisterClass();
98 #endif
99 #ifndef SYNC_UPDATE
100         InitializeCriticalSection(&priv->user.crit);
101         priv->user.refresh_event = CreateEventW(NULL, TRUE, FALSE, NULL);
102         priv->user.update_event = CreateEventW(NULL, FALSE, FALSE, NULL);
103         priv->user.update_thread = CreateThread(NULL, 0, User_update_thread, This, 0, NULL);
104 #ifdef OWN_WINDOW
105         if (This->ddraw_owner->cooperative_level & DDSCL_FULLSCREEN) {
106             /* wait for window creation (or update thread destruction) */
107             while (WaitForMultipleObjects(1, &priv->user.update_thread, FALSE, 100) == WAIT_TIMEOUT)
108                 if (This->more.lpDDRAWReserved) break;
109             if (!This->more.lpDDRAWReserved) {
110                 ERR("window creation failed\n");
111             }
112         }
113 #endif
114 #else
115 #ifdef OWN_WINDOW
116         User_create_own_window(This);
117 #endif
118 #endif
119         if (!This->more.lpDDRAWReserved)
120             This->more.lpDDRAWReserved = (LPVOID)pDD->window;
121     }
122
123     return DIB_DirectDrawSurface_alloc_dc(This, &priv->user.cached_dc);
124 }
125
126 HRESULT
127 User_DirectDrawSurface_Create(IDirectDrawImpl *pDD,
128                               const DDSURFACEDESC2 *pDDSD,
129                               LPDIRECTDRAWSURFACE7 *ppSurf,
130                               IUnknown *pUnkOuter)
131 {
132     IDirectDrawSurfaceImpl* This;
133     HRESULT hr;
134     assert(pUnkOuter == NULL);
135
136     This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
137                      sizeof(*This) + sizeof(User_DirectDrawSurfaceImpl));
138     if (This == NULL) return E_OUTOFMEMORY;
139
140     This->private = (User_DirectDrawSurfaceImpl*)(This+1);
141
142     hr = User_DirectDrawSurface_Construct(This, pDD, pDDSD);
143     if (FAILED(hr))
144         HeapFree(GetProcessHeap(), 0, This);
145     else
146         *ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);
147
148     return hr;
149 }
150
151 void User_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
152 {
153     USER_PRIV_VAR(priv, This);
154
155     if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
156     {
157 #ifndef SYNC_UPDATE
158         HANDLE event = priv->user.update_event;
159         priv->user.update_event = 0;
160         SetEvent(event);
161         TRACE("waiting for update thread to terminate...\n");
162 #ifdef OWN_WINDOW
163         /* dispatch any waiting sendmessages */
164         {
165             MSG msg;
166             PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
167         }
168         /* to avoid deadlocks, allow SendMessages from update thread
169          * through while we wait for it */
170         while (MsgWaitForMultipleObjects(1, &priv->user.update_thread, FALSE,
171                                          INFINITE, QS_SENDMESSAGE) == WAIT_OBJECT_0+1)
172         {
173             MSG msg;
174             PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
175         }
176 #else
177         WaitForSingleObject(priv->user.update_thread,INFINITE);
178 #endif
179         TRACE("update thread terminated\n");
180         CloseHandle(event);
181         CloseHandle(priv->user.update_thread);
182         CloseHandle(priv->user.refresh_event);
183         DeleteCriticalSection(&priv->user.crit);
184 #else
185 #ifdef OWN_WINDOW
186         User_destroy_own_window(This);
187 #endif
188 #endif
189         This->more.lpDDRAWReserved = 0;
190 #ifdef OWN_WINDOW
191         DirectDrawSurface_UnregisterClass();
192 #endif
193     }
194     DIB_DirectDrawSurface_free_dc(This, priv->user.cached_dc);
195     DIB_DirectDrawSurface_final_release(This);
196 }
197
198 static int User_DirectDrawSurface_init_wait(IDirectDrawSurfaceImpl* This)
199 {
200     USER_PRIV_VAR(priv, This);
201     int need_wait;
202     EnterCriticalSection(&priv->user.crit);
203     priv->user.wait_count++;
204     need_wait = priv->user.in_refresh;
205     LeaveCriticalSection(&priv->user.crit);
206     return need_wait;
207 }
208
209 static void User_DirectDrawSurface_end_wait(IDirectDrawSurfaceImpl* This)
210 {
211     USER_PRIV_VAR(priv, This);
212     EnterCriticalSection(&priv->user.crit);
213     if (!--priv->user.wait_count)
214         ResetEvent(priv->user.refresh_event);
215     LeaveCriticalSection(&priv->user.crit);
216 }
217
218 static void User_DirectDrawSurface_wait_update(IDirectDrawSurfaceImpl* This)
219 {
220     USER_PRIV_VAR(priv, This);
221     if (priv->user.in_refresh) {
222         if (User_DirectDrawSurface_init_wait(This))
223             WaitForSingleObject(priv->user.refresh_event, 2);
224         User_DirectDrawSurface_end_wait(This);
225     }
226 }
227
228 void User_DirectDrawSurface_lock_update(IDirectDrawSurfaceImpl* This,
229                                         LPCRECT pRect, DWORD dwFlags)
230 {
231 #if 0
232     if (!(dwFlags & DDLOCK_WRITEONLY))
233         User_copy_from_screen(This, pRect);
234 #endif
235     if (dwFlags & DDLOCK_WAIT) User_DirectDrawSurface_wait_update(This);
236
237     if (pRect) {
238         This->lastlockrect = *pRect;
239     } else {
240         This->lastlockrect.left = This->lastlockrect.right = 0;
241     }
242 }
243
244 void User_DirectDrawSurface_unlock_update(IDirectDrawSurfaceImpl* This,
245                                           LPCRECT pRect)
246 {
247     if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
248     {
249 #ifdef SYNC_UPDATE
250         User_copy_to_screen(This, pRect);
251 #else
252         USER_PRIV_VAR(priv, This);
253         SetEvent(priv->user.update_event);
254 #endif
255     }
256 }
257
258 void User_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl* This,
259                                         IDirectDrawPaletteImpl* pal)
260 {
261     USER_PRIV_VAR(priv, This);
262
263     if (!pal) {
264         FIXME("selecting null palette\n");
265         /* I don't think selecting GDI object 0 will work, we should select
266          * the original palette, returned by the first SelectPalette */
267         SelectPalette(priv->user.cached_dc, 0, FALSE);
268         return;
269     }
270
271     SelectPalette(priv->user.cached_dc, pal->hpal, FALSE);
272
273     DIB_DirectDrawSurface_set_palette(This, pal);
274 }
275
276 void User_DirectDrawSurface_update_palette(IDirectDrawSurfaceImpl* This,
277                                            IDirectDrawPaletteImpl* pal,
278                                            DWORD dwStart, DWORD dwCount,
279                                            LPPALETTEENTRY palent)
280 {
281 #ifndef SYNC_UPDATE
282     USER_PRIV_VAR(priv, This);
283 #endif
284
285     DIB_DirectDrawSurface_update_palette(This, pal, dwStart, dwCount, palent);
286     /* FIXME: realize palette on display window */
287
288 #ifndef SYNC_UPDATE
289     /* with async updates, it's probably cool to force an update */
290     SetEvent(priv->user.update_event);
291 #endif
292 }
293
294 HRESULT User_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,
295                                                  LPDIRECTDRAWSURFACE7* ppDup)
296 {
297     return User_DirectDrawSurface_Create(This->ddraw_owner,
298                                          &This->surface_desc, ppDup, NULL);
299 }
300
301 BOOL User_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl* front,
302                                       IDirectDrawSurfaceImpl* back,
303                                       DWORD dwFlags)
304 {
305     USER_PRIV_VAR(front_priv, front);
306     USER_PRIV_VAR(back_priv, back);
307
308     {
309         HDC tmp;
310         tmp = front_priv->user.cached_dc;
311         front_priv->user.cached_dc = back_priv->user.cached_dc;
312         back_priv->user.cached_dc = tmp;
313     }
314
315     return DIB_DirectDrawSurface_flip_data(front, back, dwFlags);
316 }
317
318 void User_DirectDrawSurface_flip_update(IDirectDrawSurfaceImpl* This, DWORD dwFlags)
319 {
320 #ifdef SYNC_UPDATE
321     This->lastlockrect.left = This->lastlockrect.right = 0;
322     assert(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE);
323     User_copy_to_screen(This,NULL);
324 #else
325     USER_PRIV_VAR(priv, This);
326     assert(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE);
327     if (dwFlags & DDFLIP_WAIT) User_DirectDrawSurface_wait_update(This);
328     This->lastlockrect.left = This->lastlockrect.right = 0;
329     SetEvent(priv->user.update_event);
330 #endif
331 }
332
333 HRESULT User_DirectDrawSurface_get_dc(IDirectDrawSurfaceImpl* This, HDC* phDC)
334 {
335     USER_PRIV_VAR(priv, This);
336
337     *phDC = priv->user.cached_dc;
338     return S_OK;
339 }
340
341 HRESULT User_DirectDrawSurface_release_dc(IDirectDrawSurfaceImpl* This,
342                                           HDC hDC)
343 {
344     return S_OK;
345 }
346
347 HRESULT User_DirectDrawSurface_get_gamma_ramp(IDirectDrawSurfaceImpl* This,
348                                               DWORD dwFlags,
349                                               LPDDGAMMARAMP lpGammaRamp)
350 {
351     if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
352     {
353         POINT offset;
354         HWND hDisplayWnd;
355         HDC hDisplayDC;
356         HRESULT hr;
357         hDisplayWnd = get_display_window(This, &offset);
358         hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
359         hr = GetDeviceGammaRamp(hDisplayDC, lpGammaRamp) ? DD_OK : DDERR_UNSUPPORTED;
360         ReleaseDC(hDisplayWnd, hDisplayDC);
361         return hr;
362     }
363     return Main_DirectDrawSurface_get_gamma_ramp(This, dwFlags, lpGammaRamp);
364 }
365
366 HRESULT User_DirectDrawSurface_set_gamma_ramp(IDirectDrawSurfaceImpl* This,
367                                               DWORD dwFlags,
368                                               LPDDGAMMARAMP lpGammaRamp)
369 {
370     if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
371     {
372         POINT offset;
373         HWND hDisplayWnd;
374         HDC hDisplayDC;
375         HRESULT hr;
376         hDisplayWnd = get_display_window(This, &offset);
377         hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
378         hr = SetDeviceGammaRamp(hDisplayDC, lpGammaRamp) ? DD_OK : DDERR_UNSUPPORTED;
379         ReleaseDC(hDisplayWnd, hDisplayDC);
380         return hr;
381     }
382     return Main_DirectDrawSurface_set_gamma_ramp(This, dwFlags, lpGammaRamp);
383 }
384
385 /* Returns the window that hosts the display.
386  * *pt is set to the upper left position of the window relative to the
387  * upper left corner of the surface. */
388 static HWND get_display_window(IDirectDrawSurfaceImpl* This, LPPOINT pt)
389 {
390     memset(pt, 0, sizeof(*pt));
391
392     if (This->ddraw_owner->cooperative_level & DDSCL_FULLSCREEN)
393     {
394 #ifdef OWN_WINDOW
395         USER_PRIV_VAR(priv, This);
396 #if 1
397         SetWindowPos(priv->user.window, HWND_TOP, 0, 0, 0, 0,
398                      SWP_DEFERERASE|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|
399                      SWP_NOREDRAW|SWP_NOSENDCHANGING|SWP_NOSIZE);
400 #endif
401         return priv->user.window;
402 #else
403         return This->ddraw_owner->window;
404 #endif
405     }
406     else
407     {
408         if (This->clipper != NULL)
409         {
410             /* looks silly, but since we don't have the clipper locked */
411             HWND hWnd = This->clipper->hWnd;
412
413             if (hWnd != 0)
414             {
415                 ClientToScreen(hWnd, pt);
416                 return hWnd;
417             }
418             else
419             {
420                 static BOOL warn = 0;
421                 if (!warn++) FIXME("clipper clip lists not supported\n");
422
423                 return GetDesktopWindow();
424             }
425         }
426         else
427         {
428             static BOOL warn = 0;
429             if (!warn++) WARN("hosting on root\n");
430
431             return GetDesktopWindow();
432         }
433     }
434 }
435
436 HWND User_DirectDrawSurface_get_display_window(IDirectDrawSurfaceImpl* This)
437 {
438     POINT offset;
439     return get_display_window(This, &offset);
440 }
441
442 #ifdef OWN_WINDOW
443 static void User_create_own_window(IDirectDrawSurfaceImpl* This)
444 {
445     USER_PRIV_VAR(priv, This);
446
447     if (This->ddraw_owner->cooperative_level & DDSCL_FULLSCREEN)
448     {
449         priv->user.window = CreateWindowExA(WS_EX_TOPMOST |
450                                             WS_EX_LAYERED |
451                                             WS_EX_TRANSPARENT,
452                                             "WINE_DDRAW", "DirectDraw",
453                                             WS_POPUP,
454                                             0, 0,
455                                             This->surface_desc.dwWidth,
456                                             This->surface_desc.dwHeight,
457                                             GetDesktopWindow(),
458                                             0, 0, This);
459         This->more.lpDDRAWReserved = (LPVOID)priv->user.window;
460         SetWindowPos(priv->user.window, HWND_TOP, 0, 0, 0, 0,
461                      SWP_DEFERERASE|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|
462                      SWP_NOREDRAW|SWP_NOSENDCHANGING|SWP_NOSIZE|SWP_SHOWWINDOW);
463         UpdateWindow(priv->user.window);
464     }
465 }
466
467 static void User_destroy_own_window(IDirectDrawSurfaceImpl* This)
468 {
469     USER_PRIV_VAR(priv, This);
470
471     if (priv->user.window)
472     {
473         SetWindowPos(priv->user.window, 0, 0, 0, 0, 0,
474                      SWP_DEFERERASE|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|
475                      SWP_NOREDRAW|SWP_NOSENDCHANGING|SWP_NOSIZE|SWP_HIDEWINDOW);
476         This->more.lpDDRAWReserved = NULL;
477         DestroyWindow(priv->user.window);
478         priv->user.window = 0;
479     }
480 }
481 #endif
482
483 #ifndef SYNC_UPDATE
484 static DWORD CALLBACK User_update_thread(LPVOID arg)
485 {
486     IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)arg;
487     USER_PRIV_VAR(priv, This);
488     volatile HANDLE *pActive = (volatile HANDLE *)&priv->user.update_event;
489     HANDLE event = *pActive;
490
491 #ifdef OWN_WINDOW
492     User_create_own_window(This);
493 #endif
494
495     /* the point of this is that many games lock the primary surface
496      * multiple times per frame; this thread will then simply copy as
497      * often as it can without keeping the main thread waiting for
498      * each unlock, thus keeping the frame rate high */
499     do {
500 #ifdef OWN_WINDOW
501         DWORD ret = MsgWaitForMultipleObjects(1, &event, FALSE, INFINITE, QS_ALLINPUT);
502         MSG msg;
503
504         while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
505         {
506             switch (msg.message) {
507             case WM_PAINT:
508                 DispatchMessageA(&msg);
509                 break;
510             default:
511                 /* since we risk getting keyboard messages posted to us,
512                  * repost posted messages to cooperative window */
513                 PostMessageA(This->ddraw_owner->window, msg.message, msg.wParam, msg.lParam);
514             }
515         }
516 #else
517         DWORD ret = WaitForSingleObject(event, INFINITE);
518 #endif
519         if (ret == WAIT_OBJECT_0)
520         {
521             if (*pActive) {
522                 priv->user.in_refresh = TRUE;
523                 User_copy_to_screen(This, NULL);
524                 EnterCriticalSection(&priv->user.crit);
525                 priv->user.in_refresh = FALSE;
526                 if (priv->user.wait_count)
527                     SetEvent(priv->user.refresh_event);
528                 LeaveCriticalSection(&priv->user.crit);
529             } else
530                 break;
531         }
532         else if (ret != WAIT_OBJECT_0+1) break;
533     } while (TRUE);
534
535     SetEvent(priv->user.refresh_event);
536 #ifdef OWN_WINDOW
537     User_destroy_own_window(This);
538 #endif
539
540     return 0;
541 }
542 #endif
543
544 static void User_copy_to_screen(IDirectDrawSurfaceImpl* This, LPCRECT rc)
545 {
546     if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
547     {
548         POINT offset;
549         HWND hDisplayWnd;
550         HDC hDisplayDC;
551         HDC hSurfaceDC;
552         RECT drawrect;
553
554         if (FAILED(This->get_dc(This, &hSurfaceDC)))
555             return;
556
557         hDisplayWnd = get_display_window(This, &offset);
558         hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
559 #if 0
560         /* FIXME: this doesn't work... if users really want to run
561          * X in 8bpp, then we need to call directly into display.drv
562          * (or Wine's equivalent), and force a private colormap
563          * without default entries. */
564         if (This->palette) {
565             SelectPalette(hDisplayDC, This->palette->hpal, FALSE);
566             RealizePalette(hDisplayDC); /* sends messages => deadlocks */
567         }
568 #endif
569         drawrect.left   = 0;
570         drawrect.right  = This->surface_desc.dwWidth;
571         drawrect.top    = 0;
572         drawrect.bottom = This->surface_desc.dwHeight;
573
574         if (This->clipper) {
575             RECT xrc;
576             HWND hwnd = This->clipper->hWnd;
577             if (hwnd && GetClientRect(hwnd,&xrc)) {
578                 OffsetRect(&xrc,offset.x,offset.y);
579                 IntersectRect(&drawrect,&drawrect,&xrc);
580             }
581         }
582         if (rc)
583             IntersectRect(&drawrect,&drawrect,rc);
584         else {
585             /* Only use this if the caller did not pass a rectangle, since
586              * due to double locking this could be the wrong one ... */
587             if (This->lastlockrect.left != This->lastlockrect.right)
588                 IntersectRect(&drawrect,&drawrect,&This->lastlockrect);
589         }
590         BitBlt(hDisplayDC,
591                 drawrect.left-offset.x, drawrect.top-offset.y,
592                 drawrect.right-drawrect.left, drawrect.bottom-drawrect.top,
593                 hSurfaceDC,
594                 drawrect.left, drawrect.top,
595                 SRCCOPY
596         );
597         ReleaseDC(hDisplayWnd, hDisplayDC);
598     }
599 }
600
601 #if 0
602 static void User_copy_from_screen(IDirectDrawSurfaceImpl* This, LPCRECT rc)
603 {
604     if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
605     {
606         POINT offset;
607         HWND hDisplayWnd = get_display_window(This, &offset);
608         HDC hDisplayDC = GetDC(hDisplayWnd);
609         RECT drawrect;
610
611         drawrect.left   = 0;
612         drawrect.right  = This->surface_desc.dwWidth;
613         drawrect.top    = 0;
614         drawrect.bottom = This->surface_desc.dwHeight;
615         if (rc)
616             IntersectRect(&drawrect,&drawrect,rc);
617
618         BitBlt(This->hDC,
619             drawrect.left, drawrect.top,
620             drawrect.right-drawrect.left, drawrect.bottom-drawrect.top,
621             hDisplayDC,
622             drawrect.left+offset.x, drawrect.top+offset.y,
623             SRCCOPY
624         );
625         ReleaseDC(hDisplayWnd, hDisplayDC);
626     }
627 }
628 #endif
629
630 static const IDirectDrawSurface7Vtbl User_IDirectDrawSurface7_VTable =
631 {
632     Main_DirectDrawSurface_QueryInterface,
633     Main_DirectDrawSurface_AddRef,
634     Main_DirectDrawSurface_Release,
635     Main_DirectDrawSurface_AddAttachedSurface,
636     Main_DirectDrawSurface_AddOverlayDirtyRect,
637     DIB_DirectDrawSurface_Blt,
638     Main_DirectDrawSurface_BltBatch,
639     DIB_DirectDrawSurface_BltFast,
640     Main_DirectDrawSurface_DeleteAttachedSurface,
641     Main_DirectDrawSurface_EnumAttachedSurfaces,
642     Main_DirectDrawSurface_EnumOverlayZOrders,
643     Main_DirectDrawSurface_Flip,
644     Main_DirectDrawSurface_GetAttachedSurface,
645     Main_DirectDrawSurface_GetBltStatus,
646     Main_DirectDrawSurface_GetCaps,
647     Main_DirectDrawSurface_GetClipper,
648     Main_DirectDrawSurface_GetColorKey,
649     Main_DirectDrawSurface_GetDC,
650     Main_DirectDrawSurface_GetFlipStatus,
651     Main_DirectDrawSurface_GetOverlayPosition,
652     Main_DirectDrawSurface_GetPalette,
653     Main_DirectDrawSurface_GetPixelFormat,
654     Main_DirectDrawSurface_GetSurfaceDesc,
655     Main_DirectDrawSurface_Initialize,
656     Main_DirectDrawSurface_IsLost,
657     Main_DirectDrawSurface_Lock,
658     Main_DirectDrawSurface_ReleaseDC,
659     DIB_DirectDrawSurface_Restore,
660     Main_DirectDrawSurface_SetClipper,
661     Main_DirectDrawSurface_SetColorKey,
662     Main_DirectDrawSurface_SetOverlayPosition,
663     Main_DirectDrawSurface_SetPalette,
664     Main_DirectDrawSurface_Unlock,
665     Main_DirectDrawSurface_UpdateOverlay,
666     Main_DirectDrawSurface_UpdateOverlayDisplay,
667     Main_DirectDrawSurface_UpdateOverlayZOrder,
668     Main_DirectDrawSurface_GetDDInterface,
669     Main_DirectDrawSurface_PageLock,
670     Main_DirectDrawSurface_PageUnlock,
671     DIB_DirectDrawSurface_SetSurfaceDesc,
672     Main_DirectDrawSurface_SetPrivateData,
673     Main_DirectDrawSurface_GetPrivateData,
674     Main_DirectDrawSurface_FreePrivateData,
675     Main_DirectDrawSurface_GetUniquenessValue,
676     Main_DirectDrawSurface_ChangeUniquenessValue,
677     Main_DirectDrawSurface_SetPriority,
678     Main_DirectDrawSurface_GetPriority,
679     Main_DirectDrawSurface_SetLOD,
680     Main_DirectDrawSurface_GetLOD
681 };