ReactOS 0.4.15-dev-5667-ged97270
createsurface.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS DirectX
4 * FILE: dll/directx/ddraw/Surface/createsurface.c
5 * PURPOSE: IDirectDrawSurface Creation
6 * PROGRAMMER: Magnus Olsen
7 *
8 */
9#include "rosdraw.h"
10
11/*
12* All parameters must have been checked if they are valid before they are passed to Internal_CreateSurface.
13* If not please fix the code in the functions which call Internal_CreateSurface.
14* ppSurf,pDDSD,pDDraw are being validated in Internal_CreateSurface.
15 */
16
19 LPDDRAWI_DDRAWSURFACE_INT *ppSurf, IUnknown *pUnkOuter)
20{
21 DDHAL_CANCREATESURFACEDATA mDdCanCreateSurface = { 0 };
22 DDHAL_CREATESURFACEDATA mDdCreateSurface = { 0 };
23
24 LPDDRAWI_DDRAWSURFACE_INT ThisSurfInt;
25 LPDDRAWI_DDRAWSURFACE_LCL ThisSurfLcl;
26 LPDDRAWI_DDRAWSURFACE_GBL ThisSurfGbl;
27 LPDDRAWI_DDRAWSURFACE_MORE ThisSurfMore;
28
29 LPDDRAWI_DDRAWSURFACE_INT * slist_int = NULL;
30 LPDDRAWI_DDRAWSURFACE_LCL * slist_lcl = NULL;
31 LPDDRAWI_DDRAWSURFACE_GBL * slist_gbl = NULL;
32 LPDDRAWI_DDRAWSURFACE_MORE * slist_more = NULL;
33 DWORD num_of_surf=1;
36
38 {
40 }
41
42 if(pUnkOuter)
43 {
45 }
46
47 if(!(pDDSD->dwFlags & DDSD_CAPS))
48 {
50 }
51 if (pDDraw->lpLcl->dwProcessId != GetCurrentProcessId() )
52 {
54 }
55
58 {
59 return DDERR_INVALIDCAPS;
60 }
61
62 if((!(pDDSD->dwFlags & DDSD_HEIGHT) || !(pDDSD->dwFlags & DDSD_WIDTH))
64 {
66 }
67
68 else if(((pDDSD->dwFlags & DDSD_HEIGHT) || (pDDSD->dwFlags & DDSD_WIDTH))
70 {
72 }
73
74 /*
75 * program does not need set the DDSD_LPSURFACE,
76 * if they forget set it, the ddraw will automatic
77 * set it for system memory.
78 */
80 ((pDDSD->dwFlags & DDSD_LPSURFACE) != DDSD_LPSURFACE) )
81 {
82 pDDSD->dwFlags = pDDSD->dwFlags | DDSD_LPSURFACE;
83 }
84
85 /* FIXME count how many surfaces we need */
86
87 DxHeapMemAlloc(slist_int, num_of_surf * sizeof( LPDDRAWI_DDRAWSURFACE_INT ) );
88 if( slist_int == NULL)
89 {
91 goto cleanup;
92 }
93
94 DxHeapMemAlloc(slist_lcl, num_of_surf * sizeof( LPDDRAWI_DDRAWSURFACE_LCL ) );
95 if( slist_lcl == NULL )
96 {
98 goto cleanup;
99 }
100
101 /* keep pointers to all gbl surfs to be able to free them on error */
102 DxHeapMemAlloc(slist_gbl, num_of_surf * sizeof( LPDDRAWI_DDRAWSURFACE_GBL ) );
103 if( slist_gbl == NULL )
104 {
105 DxHeapMemFree(slist_int);
106 return DDERR_OUTOFMEMORY;
107 }
108
109 /* keep pointers to all more surfs to be able to free them on error */
110 DxHeapMemAlloc(slist_more, num_of_surf * sizeof( LPDDRAWI_DDRAWSURFACE_MORE ) );
111 if( slist_more == NULL )
112 {
113 DxHeapMemFree(slist_int);
114 return DDERR_OUTOFMEMORY;
115 }
116
117 for( count=0; count < num_of_surf; count++ )
118 {
119 /* Allocate the surface interface and needed members */
120 DxHeapMemAlloc(ThisSurfInt, sizeof( DDRAWI_DDRAWSURFACE_INT ) );
121 if( ThisSurfInt == NULL )
122 {
124 goto cleanup;
125 }
126
127 DxHeapMemAlloc(ThisSurfLcl, sizeof( DDRAWI_DDRAWSURFACE_LCL ) );
128 if( ThisSurfLcl == NULL )
129 {
131 goto cleanup;
132 }
133
134 DxHeapMemAlloc(ThisSurfGbl, sizeof( DDRAWI_DDRAWSURFACE_GBL ) );
135 if( ThisSurfGbl == NULL )
136 {
138 goto cleanup;
139 }
140
141 DxHeapMemAlloc(ThisSurfMore, sizeof( DDRAWI_DDRAWSURFACE_MORE ) );
142 if( ThisSurfMore == NULL )
143 {
145 goto cleanup;
146 }
147
148 /* setup lists, really needed are slist_lcl, slist_int
149 other slists should be released on return */
150
151 slist_int[count] = ThisSurfInt;
152 slist_lcl[count] = ThisSurfLcl;
153 slist_gbl[count] = ThisSurfGbl;
154 slist_more[count] = ThisSurfMore;
155
156 /* Start now fill in the member as they shall look like before call to createsurface */
157
158 ThisSurfInt->lpLcl = ThisSurfLcl;
159 ThisSurfLcl->lpGbl = ThisSurfGbl;
160
161 ThisSurfLcl->ddsCaps.dwCaps = pDDSD->ddsCaps.dwCaps;
162
163 ThisSurfGbl->lpDD = pDDraw->lpLcl->lpGbl;
164 ThisSurfGbl->lpDDHandle = pDDraw->lpLcl->lpGbl;
165
166 /* FIXME ? */
168
170 {
171 ThisSurfGbl->wWidth = pDDraw->lpLcl->lpGbl->vmiData.dwDisplayWidth;
172 ThisSurfGbl->wHeight = pDDraw->lpLcl->lpGbl->vmiData.dwDisplayHeight;
173 ThisSurfGbl->lPitch = pDDraw->lpLcl->lpGbl->vmiData.lDisplayPitch;
174 ThisSurfGbl->dwLinearSize = pDDraw->lpLcl->lpGbl->vmiData.lDisplayPitch;
175
176
177 ThisSurfMore->dmiDDrawReserved7.wWidth = pDDraw->lpLcl->lpGbl->vmiData.dwDisplayWidth;
179 ThisSurfMore->dmiDDrawReserved7.wBPP = pDDraw->lpLcl->lpGbl->dwMonitorFrequency;
180
181 /* FIXME ThisSurfaceMore->dmiDDrawReserved7.wMonitorsAttachedToDesktop */
183 pDDraw->lpLcl->lpPrimary = ThisSurfInt;
184 }
185 else
186 {
187 ThisSurfGbl->wWidth = (WORD)pDDSD->dwWidth;
188 ThisSurfGbl->wHeight = (WORD)pDDSD->dwHeight;
189 ThisSurfGbl->lPitch = pDDSD->lPitch;
190 ThisSurfGbl->dwLinearSize = pDDSD->lPitch;
191 }
192
193 if(pDDraw->lpVtbl == &DirectDraw7_Vtable)
194 {
195 ThisSurfInt->lpVtbl = &DirectDrawSurface7_Vtable;
196 }
197 else if(pDDraw->lpVtbl == &DirectDraw4_Vtable)
198 {
199 ThisSurfInt->lpVtbl = &DirectDrawSurface4_Vtable;
200 }
201 else if(pDDraw->lpVtbl == &DirectDraw2_Vtable)
202 {
203 ThisSurfInt->lpVtbl = &DirectDrawSurface2_Vtable;
204 }
205 else if(pDDraw->lpVtbl == &DirectDraw_Vtable)
206 {
207 ThisSurfInt->lpVtbl = &DirectDrawSurface_Vtable;
208 }
209 else
210 {
212 goto cleanup;
213 }
214
215 ThisSurfLcl->lpSurfMore = ThisSurfMore;
216 ThisSurfMore->dwSize = sizeof(DDRAWI_DDRAWSURFACE_MORE);
217 ThisSurfMore->lpDD_int = pDDraw;
218 ThisSurfMore->lpDD_lcl = pDDraw->lpLcl;
219 ThisSurfMore->slist = slist_lcl;
220
221 ThisSurfLcl->dwProcessId = GetCurrentProcessId();
222
223 /* FIXME the lpLnk */
224
225 Main_DDrawSurface_AddRef(ThisSurfInt);
226 }
227
228 pDDraw->lpLcl->lpGbl->dsList = (LPDDRAWI_DDRAWSURFACE_INT) slist_int;
229
230 /* Fixme call on DdCanCreate then on DdCreateSurface createsurface data here */
231
232 /* FIXME bIsDifferentPixelFormat being set to true or false with automatic detections */
233 mDdCanCreateSurface.bIsDifferentPixelFormat = FALSE;
234
235 mDdCanCreateSurface.lpDD = pDDraw->lpLcl->lpGbl;
236 mDdCanCreateSurface.CanCreateSurface = pDDraw->lpLcl->lpDDCB->HALDD.CanCreateSurface;
237 mDdCanCreateSurface.lpDDSurfaceDesc = (LPDDSURFACEDESC) pDDSD;
238 mDdCanCreateSurface.ddRVal = DDERR_GENERIC;
239
240 if (mDdCanCreateSurface.CanCreateSurface(&mDdCanCreateSurface) == DDHAL_DRIVER_NOTHANDLED)
241 {
242 DX_STUB_str("mDdCanCreateSurface failed with DDHAL_DRIVER_NOTHANDLED.");
244 goto cleanup;
245 }
246
247 if (mDdCanCreateSurface.ddRVal != DD_OK)
248 {
249 DX_STUB_str("mDdCanCreateSurface failed.");
250 ret = mDdCanCreateSurface.ddRVal;
251 goto cleanup;
252 }
253
254 mDdCreateSurface.lpDD = pDDraw->lpLcl->lpGbl;
255 mDdCreateSurface.CreateSurface = pDDraw->lpLcl->lpGbl->lpDDCBtmp->HALDD.CreateSurface;
256 mDdCreateSurface.ddRVal = DDERR_GENERIC;
257 mDdCreateSurface.dwSCnt = num_of_surf;
258 mDdCreateSurface.lpDDSurfaceDesc = (LPDDSURFACEDESC) pDDSD;
259 mDdCreateSurface.lplpSList = slist_lcl;
260
261 if (mDdCreateSurface.CreateSurface(&mDdCreateSurface) == DDHAL_DRIVER_NOTHANDLED)
262 {
263 DX_STUB_str("mDdCreateSurface failed with DDHAL_DRIVER_NOTHANDLED.");
265 goto cleanup;
266 }
267
268 if (mDdCreateSurface.ddRVal != DD_OK)
269 {
270 DX_STUB_str("mDdCreateSurface failed.");
271 ret = mDdCreateSurface.ddRVal;
272 goto cleanup;
273 }
274
275 /* free unneeded slists */
276 if (slist_more != NULL)
277 DxHeapMemFree(slist_more);
278 if (slist_gbl != NULL)
279 DxHeapMemFree(slist_gbl);
280
281 *ppSurf = (LPDDRAWI_DDRAWSURFACE_INT) &slist_int[0]->lpVtbl;
282
283 return DD_OK;
284
285cleanup:
286 for(count = 0; count < num_of_surf; count++)
287 {
288 if (slist_more[count] != NULL)
289 DxHeapMemFree(slist_more[count]);
290 if (slist_gbl[count] != NULL)
291 DxHeapMemFree(slist_gbl[count]);
292 if (slist_lcl[count] != NULL)
293 DxHeapMemFree(slist_lcl[count]);
294 if (slist_int[count] != NULL)
295 DxHeapMemFree(slist_int[count]);
296 }
297 if (slist_more != NULL)
298 DxHeapMemFree(slist_more);
299 if (slist_gbl != NULL)
300 DxHeapMemFree(slist_gbl);
301 if (slist_lcl != NULL)
302 DxHeapMemFree(slist_lcl);
303 if (slist_int != NULL)
304 DxHeapMemFree(slist_int);
305
306 return ret;
307}
308
309
310
312{
313 RtlZeroMemory(dst_pDesc,sizeof(DDSURFACEDESC2));
314 RtlCopyMemory(dst_pDesc,src_pDesc,sizeof(DDSURFACEDESC));
315 dst_pDesc->dwSize = sizeof(DDSURFACEDESC2);
316}
317
318
319
320
321
void CopyDDSurfDescToDDSurfDesc2(LPDDSURFACEDESC2 dst_pDesc, LPDDSURFACEDESC src_pDesc)
HRESULT Internal_CreateSurface(LPDDRAWI_DIRECTDRAW_INT pDDraw, LPDDSURFACEDESC2 pDDSD, LPDDRAWI_DDRAWSURFACE_INT *ppSurf, IUnknown *pUnkOuter)
Definition: createsurface.c:18
struct _DDRAWI_DDRAWSURFACE_LCL FAR * LPDDRAWI_DDRAWSURFACE_LCL
Definition: d3dhal.h:45
#define DDSD_LPSURFACE
Definition: ddrawex.h:22
struct _DDRAWI_DDRAWSURFACE_INT * LPDDRAWI_DDRAWSURFACE_INT
Definition: ddrawi.h:132
#define DDRAWISURFGBL_ISGDISURFACE
Definition: ddrawi.h:1363
#define DDRAWILCL_SETCOOPCALLED
Definition: ddrawi.h:1196
struct _DDRAWI_DDRAWSURFACE_MORE DDRAWI_DDRAWSURFACE_MORE
#define DDHAL_DRIVER_NOTHANDLED
Definition: ddrawi.h:320
void * LPDDSURFACEDESC
Definition: ddstream.idl:23
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
ULONG WINAPI Main_DDrawSurface_AddRef(LPDDRAWI_DDRAWSURFACE_INT)
Definition: surface_main.c:40
static void cleanup(void)
Definition: main.c:1335
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
GLuint GLuint GLsizei count
Definition: gl.h:1545
IDirectDraw7Vtbl DirectDraw7_Vtable
#define DX_STUB_str(x)
Definition: rosdraw.h:254
IDirectDraw2Vtbl DirectDraw2_Vtable
Definition: ddraw_thunk.c:862
IDirectDrawSurfaceVtbl DirectDrawSurface_Vtable
#define DxHeapMemAlloc(p, m)
Definition: rosdraw.h:113
IDirectDrawSurface4Vtbl DirectDrawSurface4_Vtable
IDirectDrawVtbl DirectDraw_Vtable
Definition: ddraw_thunk.c:835
IDirectDraw4Vtbl DirectDraw4_Vtable
Definition: ddraw_thunk.c:890
IDirectDrawSurface2Vtbl DirectDrawSurface2_Vtable
IDirectDrawSurface7Vtbl DirectDrawSurface7_Vtable
#define DxHeapMemFree(p)
Definition: rosdraw.h:120
#define DDSD_WIDTH
Definition: ddraw.h:210
struct _DDSURFACEDESC2 DDSURFACEDESC2
#define DDSD_HEIGHT
Definition: ddraw.h:209
#define DDSCAPS_PRIMARYSURFACE
Definition: ddraw.h:258
#define DDERR_INVALIDCAPS
Definition: ddraw.h:75
#define DDERR_INVALIDOBJECT
Definition: ddraw.h:78
#define DDERR_OUTOFMEMORY
Definition: ddraw.h:111
#define DDERR_NOTINITIALIZED
Definition: ddraw.h:185
#define DDERR_NOCOOPERATIVELEVELSET
Definition: ddraw.h:89
#define DD_OK
Definition: ddraw.h:186
#define DDERR_GENERIC
Definition: ddraw.h:72
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
#define DDSCAPS_VIDEOMEMORY
Definition: ddraw.h:264
#define DDSD_CAPS
Definition: ddraw.h:208
#define DDSCAPS_SYSTEMMEMORY
Definition: ddraw.h:261
DDHAL_DDCALLBACKS HALDD
Definition: ddrawi.h:735
LPDDRAWI_DIRECTDRAW_GBL lpDD
Definition: ddrawi.h:784
LPDDSURFACEDESC lpDDSurfaceDesc
Definition: ddrawi.h:785
LPDDHAL_CANCREATESURFACE CanCreateSurface
Definition: ddrawi.h:788
LPDDSURFACEDESC lpDDSurfaceDesc
Definition: ddrawi.h:776
LPDDRAWI_DIRECTDRAW_GBL lpDD
Definition: ddrawi.h:775
LPDDRAWI_DDRAWSURFACE_LCL * lplpSList
Definition: ddrawi.h:777
LPDDHAL_CREATESURFACE CreateSurface
Definition: ddrawi.h:780
LPDDHAL_CREATESURFACE CreateSurface
Definition: ddrawi.h:350
LPDDHAL_CANCREATESURFACE CanCreateSurface
Definition: ddrawi.h:354
LPDDRAWI_DIRECTDRAW_GBL lpDD
Definition: ddrawi.h:1346
LPDDRAWI_DDRAWSURFACE_LCL lpLcl
Definition: ddrawi.h:1328
LPDDRAWI_DDRAWSURFACE_GBL lpGbl
Definition: ddrawi.h:1468
DISPLAYMODEINFO dmiDDrawReserved7
Definition: ddrawi.h:1454
LPDDRAWI_DDRAWSURFACE_LCL * slist
Definition: ddrawi.h:1461
LPDDRAWI_DIRECTDRAW_LCL lpDD_lcl
Definition: ddrawi.h:1431
LPDDRAWI_DIRECTDRAW_INT lpDD_int
Definition: ddrawi.h:1434
VIDMEMINFO vmiData
Definition: ddrawi.h:1236
LPDDRAWI_DDRAWSURFACE_INT dsList
Definition: ddrawi.h:1225
LPDDHAL_CALLBACKS lpDDCBtmp
Definition: ddrawi.h:1224
LPDDRAWI_DIRECTDRAW_LCL lpLcl
Definition: ddrawi.h:1148
LPDDRAWI_DDRAWSURFACE_INT lpPrimary
Definition: ddrawi.h:1169
LPDDRAWI_DIRECTDRAW_GBL lpGbl
Definition: ddrawi.h:1155
LPDDHAL_CALLBACKS lpDDCB
Definition: ddrawi.h:1179
DWORD dwCaps
Definition: ddraw.h:732
DWORD dwWidth
Definition: ddraw.h:1155
DWORD dwHeight
Definition: ddraw.h:1154
DDSCAPS2 ddsCaps
Definition: ddraw.h:1188
DWORD dwFlags
Definition: ddraw.h:1153
DWORD dwSize
Definition: ddraw.h:1152
BYTE wMonitorsAttachedToDesktop
Definition: ddrawi.h:1422
LONG lDisplayPitch
Definition: ddrawi.h:220
DWORD dwDisplayWidth
Definition: ddrawi.h:218
DWORD dwDisplayHeight
Definition: ddrawi.h:219
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
int ret
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662