1 /*
2  * COPYRIGHT:            See COPYING in the top level directory
3  * PROJECT:              ReactOS DirectX
4  * FILE:                 dll/directx/ddraw/Surface/surface_main.c
5  * PURPOSE:              IDirectDrawSurface7 Implementation
6  * PROGRAMMER:           Magnus Olsen, Maarten Bosma
7  *
8  */
9 
10 #include "rosdraw.h"
11 
12 
13 /* FIXME adding hal and hel stub
14     DestroySurface;
15     SetClipList;
16     AddAttachedSurface;
17     GetFlipStatus;
18     SetOverlayPosition;
19     SetPalette;
20 */
21 
22 LPDDRAWI_DDRAWSURFACE_INT
internal_directdrawsurface_int_alloc(LPDDRAWI_DDRAWSURFACE_INT This)23 internal_directdrawsurface_int_alloc(LPDDRAWI_DDRAWSURFACE_INT This)
24 {
25     LPDDRAWI_DDRAWSURFACE_INT  newThis;
26     DxHeapMemAlloc(newThis, sizeof(DDRAWI_DDRAWSURFACE_INT));
27     if (newThis)
28     {
29         newThis->lpLcl = This->lpLcl;
30         newThis->lpLink = This;
31     }
32     return  newThis;
33 }
34 
Main_DDrawSurface_Initialize(LPDDRAWI_DDRAWSURFACE_INT iface,LPDIRECTDRAW pDD,LPDDSURFACEDESC2 pDDSD2)35 HRESULT WINAPI Main_DDrawSurface_Initialize (LPDDRAWI_DDRAWSURFACE_INT iface, LPDIRECTDRAW pDD, LPDDSURFACEDESC2 pDDSD2)
36 {
37     return DDERR_ALREADYINITIALIZED;
38 }
39 
Main_DDrawSurface_AddRef(LPDDRAWI_DDRAWSURFACE_INT This)40 ULONG WINAPI Main_DDrawSurface_AddRef(LPDDRAWI_DDRAWSURFACE_INT This)
41 {
42 
43     DX_WINDBG_trace();
44 
45     if (This!=NULL)
46     {
47         This->dwIntRefCnt++;
48         This->lpLcl->dwLocalRefCnt++;
49 
50         if (This->lpLcl->lpGbl != NULL)
51         {
52             This->lpLcl->lpGbl->dwRefCnt++;
53         }
54     }
55     return This->dwIntRefCnt;
56 
57 }
58 
59 HRESULT WINAPI
Main_DDrawSurface_QueryInterface(LPDDRAWI_DDRAWSURFACE_INT This,REFIID riid,LPVOID * ppObj)60 Main_DDrawSurface_QueryInterface(LPDDRAWI_DDRAWSURFACE_INT This, REFIID riid, LPVOID* ppObj)
61 {
62     HRESULT retVal = DD_OK;
63     *ppObj = NULL;
64 
65     DX_WINDBG_trace();
66 
67     _SEH2_TRY
68     {
69         if (IsEqualGUID(&IID_IDirectDrawSurface7, riid))
70         {
71             if (This->lpVtbl != &DirectDrawSurface7_Vtable)
72             {
73                 This = internal_directdrawsurface_int_alloc(This);
74                 if (!This)
75                 {
76                     retVal = DDERR_OUTOFVIDEOMEMORY;
77                     _SEH2_LEAVE;
78                 }
79             }
80             This->lpVtbl = &DirectDrawSurface7_Vtable;
81             *ppObj = This;
82             Main_DDrawSurface_AddRef(This);
83         }
84         else if (IsEqualGUID(&IID_IDirectDrawSurface4, riid))
85         {
86             if (This->lpVtbl != &DirectDrawSurface4_Vtable)
87             {
88                 This = internal_directdrawsurface_int_alloc(This);
89                 if (!This)
90                 {
91                     retVal = DDERR_OUTOFVIDEOMEMORY;
92                     _SEH2_LEAVE;
93                 }
94             }
95             This->lpVtbl = &DirectDrawSurface4_Vtable;
96             *ppObj = This;
97             Main_DDrawSurface_AddRef(This);
98         }
99         else if (IsEqualGUID(&IID_IDirectDrawSurface3, riid))
100         {
101             if (This->lpVtbl != &DirectDrawSurface3_Vtable)
102             {
103                 This = internal_directdrawsurface_int_alloc(This);
104                 if (!This)
105                 {
106                     retVal = DDERR_OUTOFVIDEOMEMORY;
107                     _SEH2_LEAVE;
108                 }
109             }
110             This->lpVtbl = &DirectDrawSurface3_Vtable;
111             *ppObj = This;
112             Main_DDrawSurface_AddRef(This);
113         }
114         else if (IsEqualGUID(&IID_IDirectDrawSurface2, riid))
115         {
116             if (This->lpVtbl != &DirectDrawSurface2_Vtable)
117             {
118                 This = internal_directdrawsurface_int_alloc(This);
119                 if (!This)
120                 {
121                     retVal = DDERR_OUTOFVIDEOMEMORY;
122                     _SEH2_LEAVE;
123                 }
124             }
125             This->lpVtbl = &DirectDrawSurface2_Vtable;
126             *ppObj = This;
127             Main_DDrawSurface_AddRef(This);
128         }
129         else if (IsEqualGUID(&IID_IDirectDrawSurface, riid))
130         {
131             if (This->lpVtbl != &DirectDrawSurface_Vtable)
132             {
133                 This = internal_directdrawsurface_int_alloc(This);
134                 if (!This)
135                 {
136                     retVal = DDERR_OUTOFVIDEOMEMORY;
137                     _SEH2_LEAVE;
138                 }
139             }
140             This->lpVtbl = &DirectDrawSurface_Vtable;
141             *ppObj = This;
142             Main_DDrawSurface_AddRef(This);
143         }
144         else if (IsEqualGUID(&IID_IDirectDrawColorControl, riid))
145         {
146             if (This->lpVtbl != &DirectDrawColorControl_Vtable)
147             {
148                 This = internal_directdrawsurface_int_alloc(This);
149                 if (!This)
150                 {
151                     retVal = DDERR_OUTOFVIDEOMEMORY;
152                     _SEH2_LEAVE;
153                 }
154             }
155             This->lpVtbl = &DirectDrawColorControl_Vtable;
156             *ppObj = This;
157             Main_DDrawSurface_AddRef(This);
158         }
159         else if (IsEqualGUID(&IID_IDirectDrawGammaControl, riid))
160         {
161             if (This->lpVtbl != &DirectDrawGammaControl_Vtable)
162             {
163                 This = internal_directdrawsurface_int_alloc(This);
164                 if (!This)
165                 {
166                     retVal = DDERR_OUTOFVIDEOMEMORY;
167                     _SEH2_LEAVE;
168                 }
169             }
170             This->lpVtbl = &DirectDrawGammaControl_Vtable;
171             *ppObj = This;
172             Main_DDrawSurface_AddRef(This);
173         }
174         else if (IsEqualGUID(&IID_IDirectDrawSurfaceKernel, riid))
175         {
176             if (This->lpVtbl != &DirectDrawSurfaceKernel_Vtable)
177             {
178                 This = internal_directdrawsurface_int_alloc(This);
179                 if (!This)
180                 {
181                     retVal = DDERR_OUTOFVIDEOMEMORY;
182                     _SEH2_LEAVE;
183                 }
184             }
185             This->lpVtbl = &DirectDrawSurfaceKernel_Vtable;
186             *ppObj = This;
187             Main_DDrawSurface_AddRef(This);
188         }
189         else if (IsEqualGUID(&IID_IDirect3D, riid))
190         {
191             if (This->lpVtbl != &IDirect3D_Vtbl)
192             {
193                 This = internal_directdrawsurface_int_alloc(This);
194                 if (!This)
195                 {
196                     retVal = DDERR_OUTOFVIDEOMEMORY;
197                     _SEH2_LEAVE;
198                 }
199             }
200             This->lpVtbl = &IDirect3D_Vtbl;
201             *ppObj = This;
202             Main_DDrawSurface_AddRef(This);
203         }
204         else if (IsEqualGUID(&IID_IDirect3D2, riid))
205         {
206             if (This->lpVtbl != &IDirect3D2_Vtbl)
207             {
208                 This = internal_directdrawsurface_int_alloc(This);
209                 if (!This)
210                 {
211                     retVal = DDERR_OUTOFVIDEOMEMORY;
212                     _SEH2_LEAVE;
213                 }
214             }
215             This->lpVtbl = &IDirect3D2_Vtbl;
216             *ppObj = This;
217             Main_DDrawSurface_AddRef(This);
218         }
219         else if (IsEqualGUID(&IID_IDirect3D3, riid))
220         {
221             if (This->lpVtbl != &IDirect3D3_Vtbl)
222             {
223                 This = internal_directdrawsurface_int_alloc(This);
224                 if (!This)
225                 {
226                     retVal = DDERR_OUTOFVIDEOMEMORY;
227                     _SEH2_LEAVE;
228                 }
229             }
230             This->lpVtbl = &IDirect3D3_Vtbl;
231             *ppObj = This;
232             Main_DDrawSurface_AddRef(This);
233         }
234         else if (IsEqualGUID(&IID_IDirect3D7, riid))
235         {
236             if (This->lpVtbl != &IDirect3D7_Vtbl)
237             {
238                 This = internal_directdrawsurface_int_alloc(This);
239                 if (!This)
240                 {
241                     retVal = DDERR_OUTOFVIDEOMEMORY;
242                     _SEH2_LEAVE;
243                 }
244             }
245             This->lpVtbl = &IDirect3D7_Vtbl;
246             *ppObj = This;
247             Main_DDrawSurface_AddRef(This);
248         }
249         else
250         {
251             DX_STUB_str("E_NOINTERFACE");
252             retVal = E_NOINTERFACE;
253         }
254     }
255     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
256     {
257     }
258     _SEH2_END;
259     return retVal;
260 }
261 
262 
263 
Main_DDrawSurface_Release(LPDDRAWI_DDRAWSURFACE_INT This)264 ULONG WINAPI Main_DDrawSurface_Release(LPDDRAWI_DDRAWSURFACE_INT This)
265 {
266     /* FIXME
267        This is not right exiame how it should be done
268      */
269     ULONG ret = --This->dwIntRefCnt;
270     if(!ret)
271     {
272         DX_STUB_str("Release is a bit simplistic right now\n");
273         AcquireDDThreadLock();
274         DxHeapMemFree(This);
275         ReleaseDDThreadLock();
276     }
277     return ret;
278 }
279 
Main_DDrawSurface_Release4(LPDDRAWI_DDRAWSURFACE_INT This)280 ULONG WINAPI Main_DDrawSurface_Release4(LPDDRAWI_DDRAWSURFACE_INT This)
281 {
282     ULONG ref = Main_DDrawSurface_Release(This) ;
283 
284     if(ref == 0) Main_DirectDraw_Release(This->lpLcl->lpSurfMore->lpDD_int);
285 
286     return ref;
287 }
288 
Main_DDrawSurface_Blt(LPDDRAWI_DDRAWSURFACE_INT ThisDest,LPRECT rdst,LPDDRAWI_DDRAWSURFACE_INT ThisSrc,LPRECT rsrc,DWORD dwFlags,LPDDBLTFX lpbltfx)289 HRESULT WINAPI Main_DDrawSurface_Blt(LPDDRAWI_DDRAWSURFACE_INT ThisDest, LPRECT rdst,
290                                      LPDDRAWI_DDRAWSURFACE_INT ThisSrc, LPRECT rsrc, DWORD dwFlags, LPDDBLTFX lpbltfx)
291 {
292     DDHAL_BLTDATA mDdBlt;
293 
294     DX_WINDBG_trace();
295 
296     if (ThisDest == NULL)
297     {
298         return DDERR_INVALIDPARAMS;
299     }
300 
301     /* Zero out members in DDHAL_BLTDATA */
302     ZeroMemory(&mDdBlt, sizeof(DDHAL_BLTDATA));
303     ZeroMemory(&mDdBlt.bltFX, sizeof(DDBLTFX));
304 
305     /* Check if we got HAL support for this api */
306     if (( ThisDest->lpLcl->lpGbl->lpDD->lpDDCBtmp->HALDDSurface.dwFlags &
307           DDHAL_SURFCB32_BLT) == DDHAL_SURFCB32_BLT)
308     {
309         mDdBlt.Blt = ThisDest->lpLcl->lpSurfMore->lpDD_lcl->lpGbl->lpDDCBtmp->HALDDSurface.Blt;
310     }
311     /* Check if we got HEL support for this api */
312     else if (( ThisDest->lpLcl->lpGbl->lpDD->lpDDCBtmp->HELDDSurface.dwFlags &
313           DDHAL_SURFCB32_BLT) == DDHAL_SURFCB32_BLT)
314     {
315         mDdBlt.Blt = ThisDest->lpLcl->lpSurfMore->lpDD_lcl->lpGbl->lpDDCBtmp->HELDDSurface.Blt;
316     }
317 
318     if (mDdBlt.Blt == NULL)
319     {
320         /* This API is unsupported */
321         return DDERR_UNSUPPORTED;
322     }
323 
324     /* Prepare for draw, if we do not reset the DdResetVisrgn some graphics card will not draw on the screen */
325     if (!DdResetVisrgn( ThisDest->lpLcl->lpSurfMore->slist[0], NULL))
326     {
327         DX_STUB_str("DdResetVisrgn failed");
328     }
329 
330     mDdBlt.lpDD = ThisDest->lpLcl->lpSurfMore->lpDD_lcl->lpGbl;
331     mDdBlt.lpDDDestSurface = ThisDest->lpLcl->lpSurfMore->slist[0];
332     ThisDest->lpLcl->lpSurfMore->slist[0]->hDC = ThisDest->lpLcl->lpSurfMore->lpDD_lcl->hDC;
333 
334     /* Setup Src */
335     if (( ThisSrc != NULL ) )
336     {
337 
338         mDdBlt.lpDDSrcSurface = ThisSrc->lpLcl->lpSurfMore->slist[0];
339         ThisSrc->lpLcl->lpSurfMore->slist[0]->hDC = ThisSrc->lpLcl->lpSurfMore->lpDD_lcl->hDC;
340 
341         if (rsrc != NULL)
342         {
343             memmove(&mDdBlt.rSrc, rsrc, sizeof (RECTL));
344         }
345         else
346         {
347             if(!GetWindowRect((HWND)ThisSrc->lpLcl->lpSurfMore->lpDD_lcl->hWnd,
348                 (RECT *)&mDdBlt.rSrc))
349             {
350                 DX_STUB_str("GetWindowRect failed");
351             }
352         }
353 
354     /* FIXME
355     *  compare so we do not write too far
356     *  ThisDest->lpLcl->lpGbl->wWidth; <- surface max width
357     *  ThisDest->lpLcl->lpGbl->wHeight <- surface max height
358     *  ThisDest->lpLcl->lpGbl->lPitch  <- surface bpp
359     */
360 
361     }
362 
363     /* Setup dest */
364     if (rdst != NULL)
365     {
366         memmove(&mDdBlt.rDest, rdst, sizeof (RECTL));
367     }
368     else
369     {
370         if (!GetWindowRect((HWND)ThisDest->lpLcl->lpSurfMore->lpDD_lcl->hWnd,
371             (RECT *)&mDdBlt.rDest))
372         {
373             DX_STUB_str("GetWindowRect failed");
374         }
375     }
376 
377     /* FIXME
378     *  compare so we do not write too far
379     *  ThisDest->lpLcl->lpGbl->wWidth; <- surface max width
380     *  ThisDest->lpLcl->lpGbl->wHeight <- surface max height
381     *  ThisDest->lpLcl->lpGbl->lPitch  <- surface bpp
382     */
383 
384 
385     /* setup bltFX */
386     if (lpbltfx != NULL)
387     {
388         memmove(&mDdBlt.bltFX, lpbltfx, sizeof (DDBLTFX));
389     }
390 
391     /* setup value that are not config yet */
392     mDdBlt.dwFlags = dwFlags;
393     mDdBlt.IsClipped = FALSE;
394     mDdBlt.bltFX.dwSize = sizeof(DDBLTFX);
395 
396 
397      /* FIXME
398         BltData.dwRectCnt
399         BltData.dwROPFlags
400         BltData.IsClipped
401         BltData.prDestRects
402         BltData.rOrigDest
403         BltData.rOrigSrc
404         BltData.ddRVal
405     */
406 
407     if (mDdBlt.Blt(&mDdBlt) != DDHAL_DRIVER_HANDLED)
408     {
409         DX_STUB_str("mDdBlt DDHAL_DRIVER_HANDLED");
410         return DDERR_NOBLTHW;
411      }
412 
413     return mDdBlt.ddRVal;
414 }
415 
416 
417 HRESULT WINAPI
Main_DDrawSurface_Lock(LPDDRAWI_DDRAWSURFACE_INT ThisDest,LPRECT prect,LPDDSURFACEDESC2 pDDSD,DWORD flags,HANDLE events)418 Main_DDrawSurface_Lock (LPDDRAWI_DDRAWSURFACE_INT ThisDest, LPRECT prect,
419                         LPDDSURFACEDESC2 pDDSD, DWORD flags, HANDLE events)
420 {
421     DDHAL_LOCKDATA mdLock;
422 
423     DX_WINDBG_trace();
424 
425     DX_WINDBG_trace_res( (DWORD)ThisDest->lpLcl->lpGbl->wWidth, (DWORD)ThisDest->lpLcl->lpGbl->wHeight, (DWORD)ThisDest->lpLcl->lpGbl->lPitch, (DWORD) 0);
426 
427      /* Zero out members in DDHAL_LOCKDATA */
428     ZeroMemory(&mdLock, sizeof(DDHAL_LOCKDATA));
429 
430      /* Check if we got HAL support for this api */
431     if (( ThisDest->lpLcl->lpGbl->lpDD->lpDDCBtmp->HALDDSurface.dwFlags &
432         DDHAL_SURFCB32_LOCK) == DDHAL_SURFCB32_LOCK)
433     {
434         mdLock.Lock = ThisDest->lpLcl->lpSurfMore->lpDD_lcl->lpGbl->lpDDCBtmp->HALDDSurface.Lock;
435     }
436     /* Check if we got HEL support for this api */
437     else if (( ThisDest->lpLcl->lpGbl->lpDD->lpDDCBtmp->HELDDSurface.dwFlags &
438           DDHAL_SURFCB32_LOCK) == DDHAL_SURFCB32_LOCK)
439     {
440         mdLock.Lock = ThisDest->lpLcl->lpSurfMore->lpDD_lcl->lpGbl->lpDDCBtmp->HELDDSurface.Lock;
441     }
442 
443     if (mdLock.Lock == NULL)
444     {
445         /* This api are unsupported */
446         return DDERR_UNSUPPORTED;
447     }
448 
449     if (events != NULL)
450     {
451         return DDERR_INVALIDPARAMS;
452     }
453 
454     /* FIXME add a check see if lock support or not */
455 
456     if (prect!=NULL)
457     {
458         mdLock.bHasRect = TRUE;
459         memcpy(&mdLock.rArea,prect,sizeof(RECTL));
460     }
461     else
462     {
463         mdLock.bHasRect = FALSE;
464     }
465 
466     //FIXME check if it primary or not and use primary or pixelformat data, at moment it is hardcode to primary
467 
468     mdLock.ddRVal = DDERR_CANTLOCKSURFACE;
469     mdLock.dwFlags = flags;
470     mdLock.lpDDSurface = ThisDest->lpLcl->lpSurfMore->slist[0];
471     mdLock.lpDD = ThisDest->lpLcl->lpSurfMore->lpDD_lcl->lpGbl;
472     mdLock.lpSurfData = NULL;
473 
474 
475     if (!DdResetVisrgn(ThisDest->lpLcl->lpSurfMore->slist[0], NULL))
476     {
477       DX_STUB_str("Here DdResetVisrgn lock");
478       // return DDERR_UNSUPPORTED;
479     }
480 
481     if (mdLock.Lock(&mdLock)!= DDHAL_DRIVER_HANDLED)
482     {
483       DX_STUB_str("Here DDHAL_DRIVER_HANDLED lock");
484       return DDERR_UNSUPPORTED;
485     }
486 
487     // FIXME ??? is this right ??
488 
489     if (pDDSD != NULL)
490     {
491         ZeroMemory(pDDSD,sizeof(DDSURFACEDESC2));
492         pDDSD->dwSize = sizeof(DDSURFACEDESC2);
493 
494         //if (pDDSD->dwSize == sizeof(DDSURFACEDESC2))
495         //{
496         //    ZeroMemory(pDDSD,sizeof(DDSURFACEDESC2));
497         //    // FIXME the internal mddsdPrimary shall be DDSURFACEDESC2
498         //    memcpy(pDDSD,&This->Surf->mddsdPrimary,sizeof(DDSURFACEDESC));
499         //    pDDSD->dwSize = sizeof(DDSURFACEDESC2);
500         //}
501         //if (pDDSD->dwSize == sizeof(DDSURFACEDESC))
502         //{
503         //    RtlZeroMemory(pDDSD,sizeof(DDSURFACEDESC));
504         //    memcpy(pDDSD,&This->Surf->mddsdPrimary,sizeof(DDSURFACEDESC));
505         //    pDDSD->dwSize = sizeof(DDSURFACEDESC);
506         //}
507 
508 
509         pDDSD->lpSurface = (LPVOID)  mdLock.lpSurfData;
510 
511         pDDSD->dwHeight = ThisDest->lpLcl->lpGbl->wHeight;
512         pDDSD->dwWidth = ThisDest->lpLcl->lpGbl->wWidth;
513 
514         pDDSD->ddpfPixelFormat.dwRGBBitCount = ThisDest->lpLcl->lpGbl->lpDD->lpModeInfo->dwBPP;// .lpModeInfo->dwBPP; //This->lpLcl->lpGbl->lPitch/ 8;
515         pDDSD->lPitch = ThisDest->lpLcl->lpGbl->lPitch;
516         pDDSD->dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
517     }
518 
519     return mdLock.ddRVal;
520 }
521 
522 
Main_DDrawSurface_Unlock(LPDDRAWI_DDRAWSURFACE_INT This,LPRECT pRect)523 HRESULT WINAPI Main_DDrawSurface_Unlock (LPDDRAWI_DDRAWSURFACE_INT This, LPRECT pRect)
524 {
525     DDHAL_UNLOCKDATA mdUnLock;
526 
527     DX_WINDBG_trace();
528 
529     /* Zero out members in DDHAL_UNLOCKDATA */
530     ZeroMemory(&mdUnLock, sizeof(DDHAL_UNLOCKDATA));
531 
532      /* Check if we got HAL support for this api */
533     if (( This->lpLcl->lpGbl->lpDD->lpDDCBtmp->HALDDSurface.dwFlags &
534         DDHAL_SURFCB32_UNLOCK) == DDHAL_SURFCB32_UNLOCK)
535     {
536         mdUnLock.Unlock = This->lpLcl->lpSurfMore->lpDD_lcl->lpGbl->lpDDCBtmp->HALDDSurface.Unlock;
537     }
538     /* Check if we got HEL support for this api */
539     else if (( This->lpLcl->lpGbl->lpDD->lpDDCBtmp->HELDDSurface.dwFlags &
540           DDHAL_SURFCB32_UNLOCK) == DDHAL_SURFCB32_UNLOCK)
541     {
542         mdUnLock.Unlock = This->lpLcl->lpSurfMore->lpDD_lcl->lpGbl->lpDDCBtmp->HELDDSurface.Unlock;
543     }
544 
545     if (mdUnLock.Unlock == NULL)
546     {
547         /* This api are unsupported */
548         return DDERR_UNSUPPORTED;
549     }
550 
551     mdUnLock.ddRVal = DDERR_NOTPALETTIZED;
552     mdUnLock.lpDD = This->lpLcl->lpSurfMore->lpDD_lcl->lpGbl;
553     mdUnLock.lpDDSurface = This->lpLcl->lpSurfMore->slist[0];
554 
555     if (!DdResetVisrgn( mdUnLock.lpDDSurface, NULL))
556     {
557         DX_STUB_str("DdResetVisrgn fail");
558         //return DDERR_UNSUPPORTED; /* this can fail */
559     }
560 
561     if (mdUnLock.Unlock(&mdUnLock)!= DDHAL_DRIVER_HANDLED)
562     {
563         DX_STUB_str("unLock fail");
564         return DDERR_UNSUPPORTED;
565     }
566 
567     return mdUnLock.ddRVal;
568 }
569 
570 HRESULT WINAPI
Main_DDrawSurface_AddAttachedSurface(LPDDRAWI_DDRAWSURFACE_INT iface,LPDDRAWI_DDRAWSURFACE_INT pAttach)571 Main_DDrawSurface_AddAttachedSurface(LPDDRAWI_DDRAWSURFACE_INT iface,
572 					  LPDDRAWI_DDRAWSURFACE_INT pAttach)
573 {
574 
575    // LPDDRAWI_DDRAWSURFACE_INT This = (LPDDRAWI_DDRAWSURFACE_INT)iface;
576    // LPDDRAWI_DDRAWSURFACE_INT That = (LPDDRAWI_DDRAWSURFACE_INT)pAttach;
577 
578    DX_WINDBG_trace();
579 
580    DX_STUB;
581 }
582 
583 HRESULT WINAPI
Main_DDrawSurface_GetAttachedSurface(LPDDRAWI_DDRAWSURFACE_INT This,LPDDSCAPS2 pCaps,LPDDRAWI_DDRAWSURFACE_INT * ppSurface)584 Main_DDrawSurface_GetAttachedSurface(LPDDRAWI_DDRAWSURFACE_INT This,
585                                      LPDDSCAPS2 pCaps,
586                                      LPDDRAWI_DDRAWSURFACE_INT* ppSurface)
587 {
588     /* FIXME hacked */
589 
590 
591     DX_WINDBG_trace();
592 
593     *ppSurface = This->lpLcl->lpGbl->lpDD->dsList;
594 
595 
596     return DD_OK;
597 }
598 
599 HRESULT WINAPI
Main_DDrawSurface_GetBltStatus(LPDDRAWI_DDRAWSURFACE_INT This,DWORD dwFlags)600 Main_DDrawSurface_GetBltStatus(LPDDRAWI_DDRAWSURFACE_INT This, DWORD dwFlags)
601 {
602 
603 	DX_WINDBG_trace();
604 
605 	if (!(This->lpLcl->lpGbl->lpDD->lpDDCBtmp->cbDDSurfaceCallbacks.dwFlags & DDHAL_SURFCB32_FLIP))
606 	{
607 		return DDERR_GENERIC;
608 	}
609 
610 	DX_STUB;
611 }
612 
613 HRESULT WINAPI
Main_DDrawSurface_GetCaps(LPDDRAWI_DDRAWSURFACE_INT This,LPDDSCAPS2 pCaps)614 Main_DDrawSurface_GetCaps(LPDDRAWI_DDRAWSURFACE_INT This, LPDDSCAPS2 pCaps)
615 {
616 
617 	DX_WINDBG_trace();
618 
619     if (This == NULL)
620     {
621        return DDERR_INVALIDOBJECT;
622     }
623 
624     if (pCaps == NULL)
625     {
626        return DDERR_INVALIDPARAMS;
627     }
628 
629     RtlZeroMemory(pCaps,sizeof(DDSCAPS2));
630 
631 	pCaps->dwCaps = This->lpLcl->ddsCaps.dwCaps;
632 
633     return DD_OK;
634 }
635 
636 HRESULT WINAPI
Main_DDrawSurface_GetClipper(LPDDRAWI_DDRAWSURFACE_INT This,LPDIRECTDRAWCLIPPER * ppClipper)637 Main_DDrawSurface_GetClipper(LPDDRAWI_DDRAWSURFACE_INT This,
638 				  LPDIRECTDRAWCLIPPER* ppClipper)
639 {
640 
641 	DX_WINDBG_trace();
642 
643     if (This == NULL)
644     {
645        return DDERR_INVALIDOBJECT;
646     }
647 
648     if (ppClipper == NULL)
649     {
650        return DDERR_INVALIDPARAMS;
651     }
652 
653     if (This->lpLcl->lp16DDClipper == NULL)
654     {
655         return DDERR_NOCLIPPERATTACHED;
656     }
657 
658     *ppClipper = (LPDIRECTDRAWCLIPPER)This->lpLcl->lp16DDClipper;
659 
660     return DD_OK;
661 }
662 
663 HRESULT WINAPI
Main_DDrawSurface_SetClipper(LPDDRAWI_DDRAWSURFACE_INT This,LPDIRECTDRAWCLIPPER pDDClipper)664 Main_DDrawSurface_SetClipper (LPDDRAWI_DDRAWSURFACE_INT This,
665 				  LPDIRECTDRAWCLIPPER pDDClipper)
666 {
667 
668 	DX_WINDBG_trace();
669 
670     if (This == NULL)
671     {
672        return DDERR_INVALIDOBJECT;
673     }
674 
675     if(pDDClipper == NULL)
676     {
677         if(!This->lpLcl->lp16DDClipper)
678             return DDERR_NOCLIPPERATTACHED;
679 
680         DirectDrawClipper_Release((LPDIRECTDRAWCLIPPER)This->lpLcl->lp16DDClipper);
681         This->lpLcl->lp16DDClipper = NULL;
682         return DD_OK;
683     }
684 
685     // FIXME: Check Surface type and return DDERR_INVALIDSURFACETYPE
686 
687     DirectDrawClipper_AddRef((LPDIRECTDRAWCLIPPER)pDDClipper);
688     This->lpLcl->lp16DDClipper = (LPDDRAWI_DDRAWCLIPPER_INT)pDDClipper;
689 
690     return DD_OK;
691 }
692 
693 HRESULT WINAPI
Main_DDrawSurface_GetDC(LPDDRAWI_DDRAWSURFACE_INT This,HDC * phDC)694 Main_DDrawSurface_GetDC(LPDDRAWI_DDRAWSURFACE_INT This, HDC *phDC)
695 {
696 
697 	DX_WINDBG_trace();
698 
699     if (This == NULL)
700     {
701        return DDERR_INVALIDOBJECT;
702     }
703 
704     if (phDC == NULL)
705     {
706        return DDERR_INVALIDPARAMS;
707     }
708 
709 
710     *phDC = (HDC)This->lpLcl->lpSurfMore->lpDD_lcl->hDC;
711 
712     return DD_OK;
713 }
714 
715 HRESULT WINAPI
Main_DDrawSurface_GetPixelFormat(LPDDRAWI_DDRAWSURFACE_INT This,LPDDPIXELFORMAT pDDPixelFormat)716 Main_DDrawSurface_GetPixelFormat(LPDDRAWI_DDRAWSURFACE_INT This,
717                                  LPDDPIXELFORMAT pDDPixelFormat)
718 {
719     HRESULT retVale = DDERR_INVALIDPARAMS;
720 
721     DX_WINDBG_trace();
722 
723     if (pDDPixelFormat != NULL)
724     {
725         if (This->lpLcl->dwFlags & DDRAWISURF_HASPIXELFORMAT)
726         {
727             memcpy(pDDPixelFormat,&This->lpLcl->lpGbl->ddpfSurface,sizeof(DDPIXELFORMAT));
728         }
729         else
730         {
731             memcpy(pDDPixelFormat,&This->lpLcl->lpSurfMore->
732                               lpDD_lcl->lpGbl->vmiData.ddpfDisplay,sizeof(DDPIXELFORMAT));
733         }
734         retVale = DD_OK;
735     }
736 
737   return retVale;
738 }
739 
740 HRESULT WINAPI
Main_DDrawSurface_GetSurfaceDesc(LPDDRAWI_DDRAWSURFACE_INT This,LPDDSURFACEDESC2 pDDSD)741 Main_DDrawSurface_GetSurfaceDesc(LPDDRAWI_DDRAWSURFACE_INT This,
742 				      LPDDSURFACEDESC2 pDDSD)
743 {
744     DWORD dwSize;
745 
746 	DX_WINDBG_trace();
747 
748     dwSize =  pDDSD->dwSize;
749 
750     if ((dwSize != sizeof(DDSURFACEDESC)) &&
751     	(dwSize != sizeof(DDSURFACEDESC2)))
752     {
753 	   return DDERR_GENERIC;
754     }
755 
756 	ZeroMemory(pDDSD,dwSize);
757 
758 	if (dwSize == sizeof(DDSURFACEDESC))
759 	{
760 		LPDDSURFACEDESC lpDS = (LPDDSURFACEDESC) pDDSD;
761 		memcpy(&lpDS->ddckCKDestBlt, &This->lpLcl->ddckCKDestBlt, sizeof(DDCOLORKEY));
762 		memcpy(&lpDS->ddckCKDestOverlay, &This->lpLcl->ddckCKDestOverlay, sizeof(DDCOLORKEY));
763 		memcpy(&lpDS->ddckCKSrcBlt, &This->lpLcl->ddckCKSrcBlt, sizeof(DDCOLORKEY));
764 		memcpy(&lpDS->ddckCKSrcOverlay, &This->lpLcl->ddckCKSrcOverlay, sizeof(DDCOLORKEY));
765 		memcpy(&lpDS->ddpfPixelFormat, &This->lpLcl->lpGbl->ddpfSurface, sizeof(DDPIXELFORMAT));
766 		memcpy(&lpDS->ddsCaps, &This->lpLcl->ddsCaps, sizeof(DDSCAPS));
767 
768 		lpDS->dwAlphaBitDepth = This->lpLcl->dwAlpha;
769 		lpDS->dwBackBufferCount = This->lpLcl->dwBackBufferCount;
770 
771 		/* FIXME setting the flags right */
772 		// lpDS->dwFlags = This->lpLcl->dwFlags;
773 
774 		lpDS->dwHeight = This->lpLcl->lpGbl->wHeight;
775 		lpDS->dwWidth =  This->lpLcl->lpGbl->wWidth;
776 
777 		/* This two are a union in lpDS  and in This->lpLcl->lpGbl
778 		  so I comment out lPitch
779 		  lpDS->lPitch = This->lpLcl->lpGbl->lPitch;
780 		*/
781 		lpDS->dwLinearSize = This->lpLcl->lpGbl->dwLinearSize;
782 
783 
784 		/* This tree are a union */
785 		//lpDS->dwMipMapCount
786 		//lpDS->dwRefreshRate
787 		//lpDS->dwZBufferBitDepth
788 
789 		/* Unknown */
790 		// lpDS->dwReserved
791 		// lpDS->lpSurface
792 	}
793 	else
794 	{
795 		memcpy(&pDDSD->ddckCKDestBlt, &This->lpLcl->ddckCKDestBlt, sizeof(DDCOLORKEY));
796 
797 		/*
798 		   pDDSD->dwEmptyFaceColor is a union to ddckCKDestOverlay
799         */
800 		memcpy(&pDDSD->ddckCKDestOverlay, &This->lpLcl->ddckCKDestOverlay, sizeof(DDCOLORKEY));
801 		memcpy(&pDDSD->ddckCKSrcBlt, &This->lpLcl->ddckCKSrcBlt, sizeof(DDCOLORKEY));
802 		memcpy(&pDDSD->ddckCKSrcOverlay, &This->lpLcl->ddckCKSrcOverlay, sizeof(DDCOLORKEY));
803 
804 		/*
805 		   pDDSD->dwFVF is a union to ddpfPixelFormat
806 		*/
807 		memcpy(&pDDSD->ddpfPixelFormat, &This->lpLcl->lpGbl->ddpfSurface, sizeof(DDPIXELFORMAT));
808 		memcpy(&pDDSD->ddsCaps, &This->lpLcl->ddsCaps, sizeof(DDSCAPS));
809 
810 
811 		pDDSD->dwAlphaBitDepth = This->lpLcl->dwAlpha;
812 		pDDSD->dwBackBufferCount = This->lpLcl->dwBackBufferCount;
813 
814 		/* FIXME setting the flags right */
815 		// lpDS->dwFlags = This->lpLcl->dwFlags;
816 
817 		pDDSD->dwHeight = This->lpLcl->lpGbl->wHeight;
818 		pDDSD->dwWidth =  This->lpLcl->lpGbl->wWidth;
819 
820 		/* This two are a union in lpDS  and in This->lpLcl->lpGbl
821 		  so I comment out lPitch
822 		  lpDS->lPitch = This->lpLcl->lpGbl->lPitch;
823 		*/
824 		pDDSD->dwLinearSize = This->lpLcl->lpGbl->dwLinearSize;
825 
826 		/* This tree are a union */
827 		// pDDSD->dwMipMapCount
828 		// pDDSD->dwRefreshRate
829 		// pDDSD->dwSrcVBHandle
830 
831 		/* Unknown */
832 		// lpDS->dwReserved
833 		// lpDS->lpSurface
834 		// pDDSD->dwTextureStage
835 	}
836 
837     return DD_OK;
838 }
839 
840 HRESULT WINAPI
Main_DDrawSurface_ReleaseDC(LPDDRAWI_DDRAWSURFACE_INT This,HDC hDC)841 Main_DDrawSurface_ReleaseDC(LPDDRAWI_DDRAWSURFACE_INT This, HDC hDC)
842 {
843 	DX_WINDBG_trace();
844 
845     if (This == NULL)
846     {
847        return DDERR_INVALIDOBJECT;
848     }
849 
850     if (hDC == NULL)
851     {
852        return DDERR_INVALIDPARAMS;
853     }
854 
855     /* FIXME check if surface exits or not */
856 
857 
858     if ((HDC)This->lpLcl->hDC == NULL)
859     {
860         return DDERR_GENERIC;
861     }
862 
863     return DD_OK;
864 }
865 
866 HRESULT WINAPI
Main_DDrawSurface_SetColorKey(LPDDRAWI_DDRAWSURFACE_INT This,DWORD dwFlags,LPDDCOLORKEY pCKey)867 Main_DDrawSurface_SetColorKey (LPDDRAWI_DDRAWSURFACE_INT This,
868 				   DWORD dwFlags, LPDDCOLORKEY pCKey)
869 {
870 
871 	DDHAL_SETCOLORKEYDATA ColorKeyData;
872 
873 	DX_WINDBG_trace();
874 
875     ColorKeyData.ddRVal = DDERR_COLORKEYNOTSET;
876 
877 	if (This->lpLcl->lpGbl->lpDD->lpDDCBtmp->cbDDSurfaceCallbacks.dwFlags & DDHAL_SURFCB32_SETCOLORKEY)
878 	{
879 
880 		ColorKeyData.lpDD = This->lpLcl->lpGbl->lpDD;
881 		ColorKeyData.SetColorKey = 	This->lpLcl->lpGbl->lpDD->lpDDCBtmp->cbDDSurfaceCallbacks.SetColorKey;
882 
883 		//ColorKeyData.lpDDSurface = &This->lpLcl->hDDSurface;
884 		ColorKeyData.dwFlags = dwFlags;
885 		/* FIXME
886 		   ColorKeyData.ckNew = ?
887 		   add / move dwFlags to This->lpLcl->dwFlags ??
888 	     */
889 
890 		if (ColorKeyData.SetColorKey(&ColorKeyData) == DDHAL_DRIVER_HANDLED )
891 		{
892 		    return  ColorKeyData.ddRVal;
893 		}
894 	}
895 	return DDERR_COLORKEYNOTSET;
896 }
897 
898 
899 
900 HRESULT WINAPI
Main_DDrawSurface_SetOverlayPosition(LPDDRAWI_DDRAWSURFACE_INT This,LONG X,LONG Y)901 Main_DDrawSurface_SetOverlayPosition (LPDDRAWI_DDRAWSURFACE_INT This, LONG X, LONG Y)
902 {
903 
904 	DDHAL_SETOVERLAYPOSITIONDATA OverLayPositionData;
905 
906 	DX_WINDBG_trace();
907 
908     OverLayPositionData.ddRVal = DDERR_COLORKEYNOTSET;
909 
910 	if (This->lpLcl->lpGbl->lpDD->lpDDCBtmp->cbDDSurfaceCallbacks.dwFlags & DDHAL_SURFCB32_SETOVERLAYPOSITION)
911 	{
912 
913 		OverLayPositionData.lpDD = This->lpLcl->lpGbl->lpDD;
914 		OverLayPositionData.SetOverlayPosition = This->lpLcl->lpGbl->lpDD->lpDDCBtmp->cbDDSurfaceCallbacks.SetOverlayPosition;
915 
916 		//OverLayPositionData.lpDDSrcSurface = This->lpLcl->lpSurfaceOverlaying->lpLcl->hDDSurface;
917 		//OverLayPositionData.lpDDDestSurface = This->lpLcl->hDDSurface;
918 
919 		OverLayPositionData.lXPos = X;
920 		OverLayPositionData.lYPos = Y;
921 
922 
923 		/* FIXME
924 		   Should X and Y be save ??
925 	     */
926 
927 		if (OverLayPositionData.SetOverlayPosition(&OverLayPositionData) == DDHAL_DRIVER_HANDLED )
928 		{
929 		    return  OverLayPositionData.ddRVal;
930 		}
931 	}
932 
933 	return DDERR_GENERIC;
934 }
935