ReactOS  0.4.14-dev-376-gaedba84
createsurface.c File Reference
#include "rosdraw.h"
Include dependency graph for createsurface.c:

Go to the source code of this file.

Functions

HRESULT Internal_CreateSurface (LPDDRAWI_DIRECTDRAW_INT pDDraw, LPDDSURFACEDESC2 pDDSD, LPDDRAWI_DDRAWSURFACE_INT *ppSurf, IUnknown *pUnkOuter)
 
void CopyDDSurfDescToDDSurfDesc2 (LPDDSURFACEDESC2 dst_pDesc, LPDDSURFACEDESC src_pDesc)
 

Function Documentation

◆ CopyDDSurfDescToDDSurfDesc2()

void CopyDDSurfDescToDDSurfDesc2 ( LPDDSURFACEDESC2  dst_pDesc,
LPDDSURFACEDESC  src_pDesc 
)

Definition at line 311 of file createsurface.c.

312 {
313  RtlZeroMemory(dst_pDesc,sizeof(DDSURFACEDESC2));
314  RtlCopyMemory(dst_pDesc,src_pDesc,sizeof(DDSURFACEDESC));
315  dst_pDesc->dwSize = sizeof(DDSURFACEDESC2);
316 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
DWORD dwSize
Definition: ddraw.h:1152
struct _DDSURFACEDESC2 DDSURFACEDESC2
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by Main_DirectDraw_CreateSurface().

◆ Internal_CreateSurface()

HRESULT Internal_CreateSurface ( LPDDRAWI_DIRECTDRAW_INT  pDDraw,
LPDDSURFACEDESC2  pDDSD,
LPDDRAWI_DDRAWSURFACE_INT ppSurf,
IUnknown pUnkOuter 
)

Definition at line 18 of file createsurface.c.

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;
34  DWORD count;
35  HRESULT ret;
36 
37  if((pDDraw->lpLcl->dwLocalFlags & DDRAWILCL_SETCOOPCALLED) != DDRAWILCL_SETCOOPCALLED)
38  {
40  }
41 
42  if(pUnkOuter)
43  {
44  return CLASS_E_NOAGGREGATION;
45  }
46 
47  if(!(pDDSD->dwFlags & DDSD_CAPS))
48  {
49  return DDERR_INVALIDPARAMS;
50  }
51  if (pDDraw->lpLcl->dwProcessId != GetCurrentProcessId() )
52  {
53  return DDERR_INVALIDOBJECT;
54  }
55 
58  {
59  return DDERR_INVALIDCAPS;
60  }
61 
62  if((!(pDDSD->dwFlags & DDSD_HEIGHT) || !(pDDSD->dwFlags & DDSD_WIDTH))
63  && !(pDDSD->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
64  {
65  return DDERR_INVALIDPARAMS;
66  }
67 
68  else if(((pDDSD->dwFlags & DDSD_HEIGHT) || (pDDSD->dwFlags & DDSD_WIDTH))
70  {
71  return DDERR_INVALIDPARAMS;
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;
178  ThisSurfMore->dmiDDrawReserved7.wHeight = pDDraw->lpLcl->lpGbl->vmiData.dwDisplayHeight;
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 
285 cleanup:
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 }
LPDDSURFACEDESC lpDDSurfaceDesc
Definition: ddrawi.h:776
DWORD dwFlags
Definition: ddraw.h:1153
IDirectDrawVtbl DirectDraw_Vtable
Definition: ddraw_thunk.c:835
GLuint GLuint GLsizei count
Definition: gl.h:1545
LPDDRAWI_DIRECTDRAW_LCL lpLcl
Definition: ddrawi.h:1148
#define DDHAL_DRIVER_NOTHANDLED
Definition: ddrawi.h:320
#define DDSD_LPSURFACE
Definition: ddrawex.h:22
LPDDRAWI_DIRECTDRAW_INT lpDD_int
Definition: ddrawi.h:1434
#define DX_STUB_str(x)
Definition: rosdraw.h:254
LPDDRAWI_DDRAWSURFACE_LCL lpLcl
Definition: ddrawi.h:1328
#define DDERR_NOTINITIALIZED
Definition: ddraw.h:185
DISPLAYMODEINFO dmiDDrawReserved7
Definition: ddrawi.h:1454
LPDDRAWI_DIRECTDRAW_GBL lpDD
Definition: ddrawi.h:1346
IDirectDrawSurface2Vtbl DirectDrawSurface2_Vtable
#define DDERR_OUTOFMEMORY
Definition: ddraw.h:111
#define DxHeapMemFree(p)
Definition: rosdraw.h:120
IDirectDraw2Vtbl DirectDraw2_Vtable
Definition: ddraw_thunk.c:862
#define DDERR_NOCOOPERATIVELEVELSET
Definition: ddraw.h:89
IDirectDraw4Vtbl DirectDraw4_Vtable
Definition: ddraw_thunk.c:890
DWORD dwWidth
Definition: ddraw.h:1155
#define DD_OK
Definition: ddraw.h:186
#define DDSD_CAPS
Definition: ddraw.h:208
LPDDHAL_CANCREATESURFACE CanCreateSurface
Definition: ddrawi.h:788
#define DDERR_INVALIDOBJECT
Definition: ddraw.h:78
struct _DDRAWI_DDRAWSURFACE_MORE DDRAWI_DDRAWSURFACE_MORE
IDirectDrawSurface4Vtbl DirectDrawSurface4_Vtable
#define DDSCAPS_SYSTEMMEMORY
Definition: ddraw.h:261
#define DDRAWISURFGBL_ISGDISURFACE
Definition: ddrawi.h:1363
DDSCAPS2 ddsCaps
Definition: ddraw.h:1188
BYTE wMonitorsAttachedToDesktop
Definition: ddrawi.h:1422
DWORD dwCaps
Definition: ddraw.h:732
smooth NULL
Definition: ftsmooth.c:416
LPDDRAWI_DDRAWSURFACE_LCL * slist
Definition: ddrawi.h:1461
#define DDSCAPS_VIDEOMEMORY
Definition: ddraw.h:264
#define DDERR_GENERIC
Definition: ddraw.h:72
#define DDSD_HEIGHT
Definition: ddraw.h:209
struct _DDRAWI_DDRAWSURFACE_INT * LPDDRAWI_DDRAWSURFACE_INT
Definition: ddrawi.h:132
struct _DDRAWI_DDRAWSURFACE_LCL FAR * LPDDRAWI_DDRAWSURFACE_LCL
Definition: d3dhal.h:45
IDirectDrawSurfaceVtbl DirectDrawSurface_Vtable
LPDDRAWI_DDRAWSURFACE_LCL * lplpSList
Definition: ddrawi.h:777
LONG HRESULT
Definition: typedefs.h:77
#define DxHeapMemAlloc(p, m)
Definition: rosdraw.h:113
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
LPDDRAWI_DIRECTDRAW_LCL lpDD_lcl
Definition: ddrawi.h:1431
int ret
ULONG WINAPI Main_DDrawSurface_AddRef(LPDDRAWI_DDRAWSURFACE_INT)
Definition: surface_main.c:40
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662
DWORD dwHeight
Definition: ddraw.h:1154
LPDDRAWI_DIRECTDRAW_GBL lpDD
Definition: ddrawi.h:775
LPDDSURFACEDESC lpDDSurfaceDesc
Definition: ddrawi.h:785
#define DDSD_WIDTH
Definition: ddraw.h:210
IDirectDrawSurface7Vtbl DirectDrawSurface7_Vtable
#define DDSCAPS_PRIMARYSURFACE
Definition: ddraw.h:258
#define DDERR_INVALIDCAPS
Definition: ddraw.h:75
char * cleanup(char *str)
Definition: wpickclick.c:99
IDirectDraw7Vtbl DirectDraw7_Vtable
LPDDRAWI_DIRECTDRAW_GBL lpDD
Definition: ddrawi.h:784
void * LPDDSURFACEDESC
Definition: ddstream.idl:19
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1158
#define DDRAWILCL_SETCOOPCALLED
Definition: ddrawi.h:1196
LPDDHAL_CREATESURFACE CreateSurface
Definition: ddrawi.h:780

Referenced by Main_DirectDraw_CreateSurface(), and Main_DirectDraw_CreateSurface4().