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