split up CreateSurface to hal and hel interface
[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 memset (&This->ddsd, 0, sizeof(DDSURFACEDESC));
24 This->ddsd.dwSize = sizeof(DDSURFACEDESC);
25
26 RtlCopyMemory(&This->ddsd.ddckCKDestBlt,&pDDSD2->ddckCKDestBlt,sizeof(This->ddsd.ddckCKDestBlt));
27 RtlCopyMemory(&This->ddsd.ddckCKDestOverlay,&pDDSD2->ddckCKDestOverlay,sizeof(This->ddsd.ddckCKDestOverlay));
28 RtlCopyMemory(&This->ddsd.ddckCKSrcBlt,&pDDSD2->ddckCKSrcBlt,sizeof(This->ddsd.ddckCKSrcBlt));
29 RtlCopyMemory(&This->ddsd.ddckCKSrcOverlay,&pDDSD2->ddckCKSrcOverlay,sizeof(This->ddsd.ddckCKSrcOverlay));
30 RtlCopyMemory(&This->ddsd.ddpfPixelFormat,&pDDSD2->ddpfPixelFormat,sizeof(This->ddsd.ddpfPixelFormat));
31 RtlCopyMemory(&This->ddsd.ddsCaps,&pDDSD2->ddsCaps,sizeof(This->ddsd.ddsCaps));
32
33 This->ddsd.dwAlphaBitDepth = pDDSD2->dwAlphaBitDepth;
34 This->ddsd.dwBackBufferCount = pDDSD2->dwBackBufferCount;
35 This->ddsd.dwFlags = pDDSD2->dwFlags;
36 This->ddsd.dwHeight = pDDSD2->dwHeight;
37 This->ddsd.dwLinearSize = pDDSD2->dwLinearSize;
38 This->ddsd.dwMipMapCount = pDDSD2->dwMipMapCount;
39 This->ddsd.dwRefreshRate = pDDSD2->dwRefreshRate;
40 This->ddsd.dwReserved = pDDSD2->dwReserved;
41 This->ddsd.dwWidth = pDDSD2->dwWidth;
42 This->ddsd.lPitch = pDDSD2->lPitch;
43 This->ddsd.lpSurface = pDDSD2->lpSurface;
44
45 /************ Test see if we can Create Surface ***********************/
46 if (This->owner->DirectDrawGlobal.lpDDCBtmp->HALDD.dwFlags & DDHAL_CB32_CANCREATESURFACE)
47 {
48 /* can the driver create the surface */
49 DDHAL_CANCREATESURFACEDATA CanCreateData;
50 memset(&CanCreateData, 0, sizeof(DDHAL_CANCREATESURFACEDATA));
51 CanCreateData.lpDD = &This->owner->DirectDrawGlobal;
52 CanCreateData.lpDDSurfaceDesc = (LPDDSURFACEDESC)&This->ddsd;
53
54 if (This->owner->DirectDrawGlobal.lpDDCBtmp->HALDD.CanCreateSurface(&CanCreateData) == DDHAL_DRIVER_NOTHANDLED)
55 return DDERR_INVALIDPARAMS;
56
57 if(CanCreateData.ddRVal != DD_OK)
58 return CanCreateData.ddRVal;
59 }
60
61 /************ Create Surface ***********************/
62
63 /* FIXME we are skipping filling in some data, I do not care for now */
64
65 LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal = &This->owner->DirectDrawGlobal;
66 This->ddsd.dwFlags = DDSD_CAPS;
67 This->ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
68
69 /* surface global struct */
70 memset(&This->Global, 0, sizeof(DDRAWI_DDRAWSURFACE_GBL));
71 This->Global.lpDD = &This->owner->DirectDrawGlobal;
72 This->Global.wHeight = This->owner->DirectDrawGlobal.vmiData.dwDisplayHeight;
73 This->Global.wWidth = This->owner->DirectDrawGlobal.vmiData.dwDisplayWidth;
74 This->Global.dwLinearSize = This->owner->DirectDrawGlobal.vmiData.lDisplayPitch;
75
76
77 /* surface more struct */
78 memset(&This->More, 0, sizeof(DDRAWI_DDRAWSURFACE_MORE));
79 This->More.dwSize = sizeof(DDRAWI_DDRAWSURFACE_MORE);
80
81 /* surface local struct */
82
83 memset(&This->Local, 0, sizeof(DDRAWI_DDRAWSURFACE_LCL));
84 This->Local.lpGbl = &This->Global;
85 This->Local.lpSurfMore = &This->More;
86
87 /* FIXME do a memcopy */
88 This->Local.ddsCaps = *(DDSCAPS*)&This->ddsd.ddsCaps;
89
90 /* for the double pointer below */
91 DDRAWI_DDRAWSURFACE_LCL *pLocal[2];
92 pLocal[0] = &This->Local;
93 pLocal[1] = NULL;
94
95 /* the parameter struct */
96 DDHAL_CREATESURFACEDATA CreateData;
97 memset(&CreateData, 0, sizeof(DDHAL_CREATESURFACEDATA));
98 CreateData.lpDD = pDirectDrawGlobal;
99 CreateData.lpDDSurfaceDesc = (LPDDSURFACEDESC) &This->ddsd;
100 CreateData.dwSCnt = 1;
101 CreateData.lplpSList = 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 }