Fill some structs more correctly.
[reactos.git] / reactos / lib / ddraw / hal / surface_hal.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS
5 * FILE: lib/ddraw/hal/surface.c
6 * PURPOSE: DirectDraw HAL Implementation
7 * PROGRAMMER: Magnus Olsen, Maarten Bosma
8 *
9 */
10
11 #include "rosdraw.h"
12
13 HRESULT Hal_DDrawSurface_Initialize (LPDIRECTDRAWSURFACE7 iface, LPDIRECTDRAW pDD, LPDDSURFACEDESC2 pDDSD2)
14 {
15 IDirectDrawSurfaceImpl* This = (IDirectDrawSurfaceImpl*)iface;
16
17 if(sizeof(DDSURFACEDESC2) != pDDSD2->dwSize)
18 return DDERR_UNSUPPORTED;
19
20 This->owner = (IDirectDrawImpl*)pDD;
21
22 /************ fill the discription of our primary surface ***********************/
23
24 memset (&This->ddsd, 0, sizeof(DDSURFACEDESC));
25 This->ddsd.dwSize = sizeof(DDSURFACEDESC);
26
27 RtlCopyMemory(&This->ddsd.ddckCKDestBlt,&pDDSD2->ddckCKDestBlt,sizeof(This->ddsd.ddckCKDestBlt));
28 RtlCopyMemory(&This->ddsd.ddckCKDestOverlay,&pDDSD2->ddckCKDestOverlay,sizeof(This->ddsd.ddckCKDestOverlay));
29 RtlCopyMemory(&This->ddsd.ddckCKSrcBlt,&pDDSD2->ddckCKSrcBlt,sizeof(This->ddsd.ddckCKSrcBlt));
30 RtlCopyMemory(&This->ddsd.ddckCKSrcOverlay,&pDDSD2->ddckCKSrcOverlay,sizeof(This->ddsd.ddckCKSrcOverlay));
31 RtlCopyMemory(&This->ddsd.ddpfPixelFormat,&pDDSD2->ddpfPixelFormat,sizeof(This->ddsd.ddpfPixelFormat));
32 RtlCopyMemory(&This->ddsd.ddsCaps,&pDDSD2->ddsCaps,sizeof(This->ddsd.ddsCaps));
33
34 This->ddsd.dwAlphaBitDepth = pDDSD2->dwAlphaBitDepth;
35 This->ddsd.dwBackBufferCount = pDDSD2->dwBackBufferCount;
36 This->ddsd.dwFlags = pDDSD2->dwFlags;
37 This->ddsd.dwHeight = pDDSD2->dwHeight;
38 This->ddsd.dwLinearSize = pDDSD2->dwLinearSize;
39 This->ddsd.dwMipMapCount = pDDSD2->dwMipMapCount;
40 This->ddsd.dwRefreshRate = pDDSD2->dwRefreshRate;
41 This->ddsd.dwReserved = pDDSD2->dwReserved;
42 This->ddsd.dwWidth = pDDSD2->dwWidth;
43 This->ddsd.lPitch = pDDSD2->lPitch;
44 This->ddsd.lpSurface = pDDSD2->lpSurface;
45
46 /************ Test see if we can Create Surface ***********************/
47
48 if (This->owner->DirectDrawGlobal.lpDDCBtmp->HALDD.dwFlags & DDHAL_CB32_CANCREATESURFACE)
49 {
50 /* can the driver create the surface */
51 DDHAL_CANCREATESURFACEDATA CanCreateData;
52 memset(&CanCreateData, 0, sizeof(DDHAL_CANCREATESURFACEDATA));
53 CanCreateData.lpDD = &This->owner->DirectDrawGlobal;
54 CanCreateData.lpDDSurfaceDesc = (LPDDSURFACEDESC)&This->ddsd;
55
56 if (This->owner->DirectDrawGlobal.lpDDCBtmp->HALDD.CanCreateSurface(&CanCreateData) == DDHAL_DRIVER_NOTHANDLED)
57 return DDERR_INVALIDPARAMS;
58
59 if(CanCreateData.ddRVal != DD_OK)
60 return CanCreateData.ddRVal;
61 }
62
63 /************ Create Surface ***********************/
64
65 /* surface global struct */
66 memset(&This->Global, 0, sizeof(DDRAWI_DDRAWSURFACE_GBL));
67 This->Global.lpDD = &This->owner->DirectDrawGlobal;
68 This->Global.wHeight = This->owner->DirectDrawGlobal.vmiData.dwDisplayHeight;
69 This->Global.wWidth = This->owner->DirectDrawGlobal.vmiData.dwDisplayWidth;
70 This->Global.dwLinearSize = This->owner->DirectDrawGlobal.vmiData.lDisplayPitch;
71 if(pDDSD2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
72 This->Global.dwGlobalFlags = DDRAWISURFGBL_ISGDISURFACE;
73
74 /* surface more struct */
75 memset(&This->More, 0, sizeof(DDRAWI_DDRAWSURFACE_MORE));
76 This->More.dwSize = sizeof(DDRAWI_DDRAWSURFACE_MORE);
77 This->More.dmiDDrawReserved7.wWidth = This->Global.wWidth;
78 This->More.dmiDDrawReserved7.wHeight = This->Global.wHeight;
79 This->More.dmiDDrawReserved7.wBPP = This->owner->Bpp;
80 //This->More.dmiDDrawReserved7.wRefreshRate = ;
81 //This->More.dmiDDrawReserved7.wMonitorsAttachedToDesktop = 2;
82 /* ToDo: fill ddsCapsEx */
83
84 /* surface local struct */
85 memset(&This->Local, 0, sizeof(DDRAWI_DDRAWSURFACE_LCL));
86 This->Local.lpGbl = &This->Global;
87 This->Local.lpSurfMore = &This->More;
88 This->Local.ddsCaps.dwCaps = pDDSD2->ddsCaps.dwCaps;
89 This->Local.dwProcessId = GetCurrentProcessId();
90
91 /* for the double pointer below */
92 This->pLocal[0] = &This->Local;
93 This->pLocal[1] = NULL;
94
95 /* the parameter struct */
96 DDHAL_CREATESURFACEDATA CreateData;
97 memset(&CreateData, 0, sizeof(DDHAL_CREATESURFACEDATA));
98 CreateData.lpDD = &This->owner->DirectDrawGlobal;
99 CreateData.lpDDSurfaceDesc = (LPDDSURFACEDESC)&This->ddsd;
100 CreateData.dwSCnt = 1;
101 CreateData.lplpSList = This->pLocal;
102 CreateData.ddRVal = DD_FALSE;
103
104 /* this is the call we were waiting for */
105 if(This->owner->DirectDrawGlobal.lpDDCBtmp->HALDD.CreateSurface(&CreateData) == DDHAL_DRIVER_NOTHANDLED)
106 return DDERR_INVALIDPARAMS;
107
108 /* FIXME remove the if and debug string*/
109 if(CreateData.ddRVal != DD_OK)
110 return CreateData.ddRVal;
111
112 OutputDebugString(L"This does hit By Ati Readon but not for nvida :( ");
113 OutputDebugString(L"Yet ;)");
114
115 return DD_OK;
116 }
117
118
119 HRESULT Hal_DDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rDest,
120 LPDIRECTDRAWSURFACE7 src, LPRECT rSrc, DWORD dwFlags, LPDDBLTFX lpbltfx)
121 {
122 DX_STUB;
123
124 IDirectDrawSurfaceImpl* This = (IDirectDrawSurfaceImpl*)iface;
125 IDirectDrawSurfaceImpl* That = (IDirectDrawSurfaceImpl*)src;
126
127 if (!(This->owner->DirectDrawGlobal.lpDDCBtmp->HALDDSurface.dwFlags & DDHAL_SURFCB32_BLT))
128 {
129 return DDERR_NODRIVERSUPPORT;
130 }
131
132 DDHAL_BLTDATA BltData;
133 BltData.lpDD = &This->owner->DirectDrawGlobal;
134 BltData.dwFlags = dwFlags;
135 BltData.lpDDDestSurface = &This->Local;
136 if(rDest) BltData.rDest = *(RECTL*)rDest;
137 if(rSrc) BltData.rSrc = *(RECTL*)rSrc;
138 if(That) BltData.lpDDSrcSurface = &That->Local;
139 if(lpbltfx) BltData.bltFX = *lpbltfx;
140
141 if (This->owner->DirectDrawGlobal.lpDDCBtmp->HALDDSurface.Blt(&BltData) != DDHAL_DRIVER_HANDLED)
142 {
143 return DDERR_NODRIVERSUPPORT;
144 }
145
146 return BltData.ddRVal;
147 }