xref: /reactos/win32ss/reactx/dxg/d3d.c (revision c2c66aff)
1 /*
2  * COPYRIGHT:        See COPYING in the top level directory
3  * PROJECT:          ReactOS kernel
4  * PURPOSE:          Native driver for dxg implementation
5  * FILE:             win32ss/reactx/dxg/d3d.c
6  * PROGRAMER:        Sebastian Gasiorek (sebastian.gasiorek@reactos.org)
7  */
8 
9 #include <string.h>
10 #include <dxg_int.h>
11 
12 DWORD
13 NTAPI
DxDdCanCreateD3DBuffer(HANDLE DdHandle,PDD_CANCREATESURFACEDATA SurfaceData)14 DxDdCanCreateD3DBuffer(
15     HANDLE DdHandle,
16     PDD_CANCREATESURFACEDATA SurfaceData)
17 {
18     PEDD_DIRECTDRAW_LOCAL peDdL;
19     PEDD_DIRECTDRAW_GLOBAL peDdGl;
20     DWORD RetVal = DDHAL_DRIVER_NOTHANDLED;
21 
22     peDdL = (PEDD_DIRECTDRAW_LOCAL)DdHmgLock(DdHandle, ObjType_DDLOCAL_TYPE, FALSE);
23     if (!peDdL)
24         return RetVal;
25 
26     peDdGl = peDdL->peDirectDrawGlobal2;
27     gpEngFuncs.DxEngLockHdev(peDdGl->hDev);
28 
29     // assign out DirectDrawGlobal to SurfaceData
30     SurfaceData->lpDD = (PDD_DIRECTDRAW_GLOBAL)peDdGl;
31 
32     if (peDdGl->d3dBufCallbacks.CanCreateD3DBuffer)
33         RetVal = peDdGl->d3dBufCallbacks.CanCreateD3DBuffer(SurfaceData);
34 
35     gpEngFuncs.DxEngUnlockHdev(peDdGl->hDev);
36     InterlockedDecrement((VOID*)&peDdL->pobj.cExclusiveLock);
37 
38     return RetVal;
39 }
40 
41 DWORD
42 FASTCALL
intDdCreateSurfaceOrBuffer(HANDLE hDirectDrawLocal,PEDD_SURFACE pDdSurfList,DDSURFACEDESC2 * a3,DD_SURFACE_GLOBAL * pDdSurfGlob,DD_SURFACE_LOCAL * pDdSurfLoc,DD_SURFACE_MORE * pDdSurfMore,DD_CREATESURFACEDATA * pDdCreateSurfaceData,PVOID Address)43 intDdCreateSurfaceOrBuffer(HANDLE hDirectDrawLocal,
44                            PEDD_SURFACE pDdSurfList, DDSURFACEDESC2 *a3,
45                            DD_SURFACE_GLOBAL *pDdSurfGlob,
46                            DD_SURFACE_LOCAL *pDdSurfLoc,
47                            DD_SURFACE_MORE *pDdSurfMore,
48                            DD_CREATESURFACEDATA *pDdCreateSurfaceData,
49                            PVOID Address)
50 {
51   PEDD_DIRECTDRAW_LOCAL peDdL = NULL;
52   PEDD_DIRECTDRAW_GLOBAL peDdGl = NULL;
53   DD_SURFACE_LOCAL *pCurSurfLocal;
54   DD_SURFACE_GLOBAL *pCurSurfGlobal;
55   DD_SURFACE_MORE *pCurSurfMore;
56   PEDD_SURFACE pCurSurf;
57 
58   ULONG CurSurf;
59 
60   if (!pDdCreateSurfaceData)
61       return FALSE;
62 
63   if (!pDdCreateSurfaceData->dwSCnt)
64   {
65       pDdCreateSurfaceData->ddRVal = E_FAIL;
66       return FALSE;
67   }
68 
69   peDdL = (PEDD_DIRECTDRAW_LOCAL)DdHmgLock(hDirectDrawLocal, ObjType_DDLOCAL_TYPE, FALSE);
70   if (!peDdL)
71       return FALSE;
72 
73   peDdGl = peDdL->peDirectDrawGlobal2;
74 
75   if (!(pDdSurfLoc->ddsCaps.dwCaps & DDSCAPS_VISIBLE) && !(peDdGl->ddCallbacks.dwFlags & DDHAL_CB32_CREATESURFACE))
76   {
77       pDdCreateSurfaceData->ddRVal = E_FAIL;
78       return FALSE;
79   }
80 
81   pDdSurfList = (PEDD_SURFACE)EngAllocMem(FL_ZERO_MEMORY, pDdCreateSurfaceData->dwSCnt * sizeof(EDD_SURFACE), TAG_GDDP);
82   pDdSurfGlob = (DD_SURFACE_GLOBAL *)EngAllocMem(FL_ZERO_MEMORY, pDdCreateSurfaceData->dwSCnt * sizeof(DD_SURFACE_GLOBAL), TAG_GDDP);
83   pDdSurfLoc = (DD_SURFACE_LOCAL *)EngAllocMem(FL_ZERO_MEMORY, pDdCreateSurfaceData->dwSCnt * sizeof(DD_SURFACE_LOCAL), TAG_GDDP);
84   pDdSurfMore = (DD_SURFACE_MORE *)EngAllocMem(FL_ZERO_MEMORY, pDdCreateSurfaceData->dwSCnt * sizeof(DD_SURFACE_MORE), TAG_GDDP);
85 
86   gpEngFuncs.DxEngLockShareSem();
87   gpEngFuncs.DxEngLockHdev(peDdGl->hDev);
88 
89   // create all surface objects
90   for (CurSurf = 0; CurSurf < pDdCreateSurfaceData->dwSCnt; CurSurf++)
91   {
92       pCurSurf       = &pDdSurfList[CurSurf];
93       pCurSurfLocal  = &pDdSurfLoc[CurSurf];
94       pCurSurfGlobal = &pDdSurfGlob[CurSurf];
95       pCurSurfMore   = &pDdSurfMore[CurSurf];
96 
97       pCurSurf = intDdCreateNewSurfaceObject(
98                           peDdL,
99                           pCurSurf,
100                           pCurSurfGlobal,
101                           pCurSurfLocal,
102                           pCurSurfMore);
103       Address = pCurSurf;
104   }
105 
106   gpEngFuncs.DxEngUnlockHdev(peDdGl->hDev);
107   gpEngFuncs.DxEngUnlockShareSem();
108 
109   return DDHAL_DRIVER_HANDLED;
110 }
111 
112 DWORD
113 NTAPI
DxDdCreateD3DBuffer(HANDLE hDirectDrawLocal,PEDD_SURFACE pDdSurfList,DDSURFACEDESC2 * a3,DD_SURFACE_GLOBAL * pDdSurfGlob,DD_SURFACE_LOCAL * pDdSurfLoc,DD_SURFACE_MORE * pDdSurfMore,DD_CREATESURFACEDATA * pDdCreateSurfaceData,PVOID Address)114 DxDdCreateD3DBuffer(
115     HANDLE hDirectDrawLocal,
116     PEDD_SURFACE pDdSurfList,
117     DDSURFACEDESC2 *a3,
118     DD_SURFACE_GLOBAL *pDdSurfGlob,
119     DD_SURFACE_LOCAL *pDdSurfLoc,
120     DD_SURFACE_MORE *pDdSurfMore,
121     DD_CREATESURFACEDATA *pDdCreateSurfaceData,
122     PVOID Address)
123 {
124     return intDdCreateSurfaceOrBuffer(hDirectDrawLocal, pDdSurfList, a3, pDdSurfGlob, pDdSurfLoc, pDdSurfMore, pDdCreateSurfaceData, Address);
125 }
126