f6a988faa662acfe85ba71159ef63b0c9769e24d
[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 /* 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
72
73 /* surface more struct */
74 memset(&This->More, 0, sizeof(DDRAWI_DDRAWSURFACE_MORE));
75 This->More.dwSize = sizeof(DDRAWI_DDRAWSURFACE_MORE);
76
77 /* surface local struct */
78
79 memset(&This->Local, 0, sizeof(DDRAWI_DDRAWSURFACE_LCL));
80 This->Local.lpGbl = &This->Global;
81 This->Local.lpSurfMore = &This->More;
82
83
84 /* FIXME do a memcopy */
85 This->Local.ddsCaps = *(DDSCAPS*)&This->ddsd.ddsCaps;
86
87 /* for the double pointer below */
88 This->pLocal[0] = &This->Local;
89 This->pLocal[1] = NULL;
90
91 /* the parameter struct */
92 DDHAL_CREATESURFACEDATA CreateData;
93 memset(&CreateData, 0, sizeof(DDHAL_CREATESURFACEDATA));
94 CreateData.lpDD = &This->owner->DirectDrawGlobal;
95 CreateData.lpDDSurfaceDesc = (LPDDSURFACEDESC) &This->ddsd;
96 CreateData.dwSCnt = 1;
97 CreateData.lplpSList = This->pLocal;
98 CreateData.ddRVal = DD_FALSE;
99
100 /* this is the call we were waiting for */
101 if(This->owner->DirectDrawGlobal.lpDDCBtmp->HALDD.CreateSurface(&CreateData) == DDHAL_DRIVER_NOTHANDLED)
102 return DDERR_INVALIDPARAMS;
103
104 /* FIXME remove the if and debug string*/
105 if(CreateData.ddRVal != DD_OK)
106 return CreateData.ddRVal;
107
108 OutputDebugString(L"This does hit By Ati Readon but not for nvida :( ");
109 OutputDebugString(L"Yet ;)");
110
111 return DD_OK;
112 }
113
114
115 HRESULT Hal_DDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rDest,
116 LPDIRECTDRAWSURFACE7 src, LPRECT rSrc, DWORD dwFlags, LPDDBLTFX lpbltfx)
117 {
118 DX_STUB;
119
120 IDirectDrawSurfaceImpl* This = (IDirectDrawSurfaceImpl*)iface;
121 IDirectDrawSurfaceImpl* That = (IDirectDrawSurfaceImpl*)src;
122
123 if (!(This->owner->DirectDrawGlobal.lpDDCBtmp->HALDDSurface.dwFlags & DDHAL_SURFCB32_BLT))
124 {
125 return DDERR_NODRIVERSUPPORT;
126 }
127
128 DDHAL_BLTDATA BltData;
129 BltData.lpDD = &This->owner->DirectDrawGlobal;
130 BltData.dwFlags = dwFlags;
131 BltData.lpDDDestSurface = &This->Local;
132 if(rDest) BltData.rDest = *(RECTL*)rDest;
133 if(rSrc) BltData.rSrc = *(RECTL*)rSrc;
134 if(That) BltData.lpDDSrcSurface = &That->Local;
135 if(lpbltfx) BltData.bltFX = *lpbltfx;
136
137 if (This->owner->DirectDrawGlobal.lpDDCBtmp->HALDDSurface.Blt(&BltData) != DDHAL_DRIVER_HANDLED)
138 {
139 return DDERR_NODRIVERSUPPORT;
140 }
141
142 return BltData.ddRVal;
143 }