| 1 | /* $Id: ddraw2d.h,v 1.2 2002-12-29 14:11:01 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * DX Draw base class definition | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1998 Sander va Leeuwen | 
|---|
| 7 | * Copyright 1999 Markus Montkowski | 
|---|
| 8 | * | 
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 10 | * | 
|---|
| 11 | */ | 
|---|
| 12 |  | 
|---|
| 13 | #ifndef __OS2DDRAW_HPP__ | 
|---|
| 14 | #define __OS2DDRAW_HPP__ | 
|---|
| 15 |  | 
|---|
| 16 | #include <ddraw.h> | 
|---|
| 17 | #include <d3d.h> | 
|---|
| 18 | #undef APIENTRY | 
|---|
| 19 | #define APIENTRY _System | 
|---|
| 20 | #include "divewrap.h" | 
|---|
| 21 | #define mmioFOURCC( ch0, ch1, ch2, ch3 )                         \ | 
|---|
| 22 | ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) |    \ | 
|---|
| 23 | ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) ) | 
|---|
| 24 | #include <fourcc.h> | 
|---|
| 25 | #undef THIS | 
|---|
| 26 | #define THIS VOID* | 
|---|
| 27 |  | 
|---|
| 28 | //testestest | 
|---|
| 29 | //#define SUPPORT_ALL_DIVE_FOURCCS | 
|---|
| 30 | //testestest | 
|---|
| 31 |  | 
|---|
| 32 | #define MAX_FOURCC_CODES        4 | 
|---|
| 33 |  | 
|---|
| 34 | #define ODINDDRAW_SECTION       "DirectDraw" | 
|---|
| 35 |  | 
|---|
| 36 | // This variable is global, mixing windowed and FS DDraw doesn't | 
|---|
| 37 | // make much sense | 
|---|
| 38 | extern BOOL bUseFSDD; | 
|---|
| 39 |  | 
|---|
| 40 | class OS2IDirectDraw | 
|---|
| 41 | { | 
|---|
| 42 | public: | 
|---|
| 43 | //this one has to go first! | 
|---|
| 44 | IDirectDraw4Vtbl *lpVtbl; | 
|---|
| 45 | IDirectDraw4Vtbl *lpVtbl2;         // 2nd Vtable pointer An other MS assumtion see below | 
|---|
| 46 | DWORD            *pdwUnknownData;  // MS DDCAPS (DX6 SDK bin\tools )program makes an assumtion that after the | 
|---|
| 47 | // VTable comes a pointer to some data | 
|---|
| 48 | // to avoid crashes we do it a favor and alloc a buffer | 
|---|
| 49 | // with 255 DWORDS | 
|---|
| 50 | // Known data in the buffer Height(offset 235), | 
|---|
| 51 | // Height (236),  Bits (241) | 
|---|
| 52 | // ToDO : | 
|---|
| 53 | // debug into DirectDrawCreate and se what MS is doing ! | 
|---|
| 54 | //Use for Direct3D interface (This != this) | 
|---|
| 55 | IDirect3DVtbl    *lpVtbl3D; | 
|---|
| 56 | IDirect3DVtbl    *lpVtbl3D2; | 
|---|
| 57 | DWORD            *pdwUnknownData3D; | 
|---|
| 58 |  | 
|---|
| 59 | IDirectDrawVtbl  Vtbl; | 
|---|
| 60 | IDirectDraw2Vtbl  Vtbl2; | 
|---|
| 61 | // MS did it again with direct/X 6 they changed the behavior of the directdraw component | 
|---|
| 62 | // So we now need 2 Virt. Tables one for the old and one for the new so we return the | 
|---|
| 63 | // right interface if one creates a DX6 directdraw object but wants a DX2,3,5 interface | 
|---|
| 64 | IDirectDraw4Vtbl  Vtbl4; | 
|---|
| 65 | IDirect3DVtbl     Vtbl3D; | 
|---|
| 66 |  | 
|---|
| 67 | OS2IDirectDraw(GUID *lpGUID); | 
|---|
| 68 | ~OS2IDirectDraw(); | 
|---|
| 69 | // Simple management for Surfaces should be good enougth for now | 
|---|
| 70 | inline  BOOL          HasPrimarySurface() { return PrimaryExists;} | 
|---|
| 71 | void          SetPrimarySurface(BOOL NewStatus){PrimaryExists = NewStatus;} | 
|---|
| 72 | int           Referenced; | 
|---|
| 73 | inline  HRESULT       GetLastError()    { return lastError;    } | 
|---|
| 74 | inline  HDIVE         GetDiveInstance() { return hDive;        } | 
|---|
| 75 | inline  HDIVE         GetCCDiveInstance() { return hDiveColorConv;} | 
|---|
| 76 | inline  char *        GetFrameBuffer()  { return pFrameBuffer; } | 
|---|
| 77 | inline  int           GetScreenWidth()  { return screenwidth;  } | 
|---|
| 78 | inline  int           GetScreenHeight() { return screenheight; } | 
|---|
| 79 | inline  int           GetScreenBpp()    { return screenbpp;} | 
|---|
| 80 | inline  DWORD         GetCooperativeLevel() { return dwCoopMode; }; | 
|---|
| 81 | inline  HWND          GetClientWindow() { return hwndClient; }; | 
|---|
| 82 |  | 
|---|
| 83 | FOURCC        GetScreenFourCC(); | 
|---|
| 84 | BOOL          IsFourCCSupported(FOURCC fourcc); | 
|---|
| 85 | // We should be able to use any mode with less or same bits and same or | 
|---|
| 86 | // smaller size to be able to report all supported mode in the enum | 
|---|
| 87 | // functions we need the physical screen size. Other information is later | 
|---|
| 88 | // also needed so get all the info we can get | 
|---|
| 89 | DIVE_CAPS dCaps; | 
|---|
| 90 | VOID *pPrimSurf; | 
|---|
| 91 |  | 
|---|
| 92 | private: | 
|---|
| 93 | VOID SwitchDisplay(HWND hwnd); | 
|---|
| 94 |  | 
|---|
| 95 |  | 
|---|
| 96 | protected: | 
|---|
| 97 |  | 
|---|
| 98 | HRESULT lastError; | 
|---|
| 99 | HDIVE   hDive;           // Handle to Screen DIVE instance | 
|---|
| 100 | HDIVE   hDiveColorConv;  // Handle to Offscreen DIVE instance for Color conversion | 
|---|
| 101 | char   *pFrameBuffer; | 
|---|
| 102 | HWND    hwndClient; | 
|---|
| 103 | DWORD   dwCoopMode; | 
|---|
| 104 | int     screenwidth, screenheight, screenbpp; | 
|---|
| 105 | BOOL    PrimaryExists; | 
|---|
| 106 | BOOL    bScale; | 
|---|
| 107 | int     oldwidth, oldheight, oldbpp, oldscanlines; | 
|---|
| 108 | BOOL    bInFullScreen; | 
|---|
| 109 |  | 
|---|
| 110 |  | 
|---|
| 111 | // Linked list management | 
|---|
| 112 | OS2IDirectDraw* next;                   // Next OS2IDirectDraw | 
|---|
| 113 | static    OS2IDirectDraw* ddraw;                  // List of OS2IDirectDraw | 
|---|
| 114 |  | 
|---|
| 115 | friend    HRESULT WIN32API DrawQueryInterface(THIS, REFIID riid, LPVOID  * ppvObj); | 
|---|
| 116 | friend    ULONG   WIN32API DrawAddRef(THIS); | 
|---|
| 117 | friend    ULONG   WIN32API DrawRelease(THIS); | 
|---|
| 118 | friend    HRESULT WIN32API DrawCompact(THIS); | 
|---|
| 119 | friend    HRESULT WIN32API DrawCreateClipper(THIS, DWORD, LPDIRECTDRAWCLIPPER *, IUnknown  * ); | 
|---|
| 120 | friend    HRESULT WIN32API DrawCreatePalette(THIS, DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE *, IUnknown  * ); | 
|---|
| 121 | friend    HRESULT WIN32API DrawCreateSurface(THIS, LPDDSURFACEDESC, LPDIRECTDRAWSURFACE  *, IUnknown  *); | 
|---|
| 122 | friend    HRESULT WIN32API DrawCreateSurface4(THIS, LPDDSURFACEDESC2, LPDIRECTDRAWSURFACE4  *, IUnknown  *); | 
|---|
| 123 | friend    HRESULT WIN32API DrawDuplicateSurface(THIS, LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE  * ); | 
|---|
| 124 | friend    HRESULT WIN32API DrawDuplicateSurface4(THIS, LPDIRECTDRAWSURFACE4, LPDIRECTDRAWSURFACE4  * ); | 
|---|
| 125 | friend    HRESULT WIN32API DrawEnumDisplayModes(THIS, DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK ); | 
|---|
| 126 | friend    HRESULT WIN32API DrawEnumDisplayModes4(THIS, DWORD, LPDDSURFACEDESC2, LPVOID, LPDDENUMMODESCALLBACK2 ); | 
|---|
| 127 | friend    HRESULT WIN32API DrawEnumSurfaces(THIS, DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK ); | 
|---|
| 128 | friend    HRESULT WIN32API DrawEnumSurfaces4(THIS, DWORD, LPDDSURFACEDESC2, LPVOID,LPDDENUMSURFACESCALLBACK2 ); | 
|---|
| 129 | friend    HRESULT WIN32API DrawFlipToGDISurface(THIS); | 
|---|
| 130 | friend    HRESULT WIN32API DrawGetCaps(THIS, LPDDCAPS, LPDDCAPS); | 
|---|
| 131 | friend    HRESULT WIN32API DrawGetDisplayMode(THIS, LPDDSURFACEDESC); | 
|---|
| 132 | friend    HRESULT WIN32API DrawGetFourCCCodes(THIS, LPDWORD, LPDWORD); | 
|---|
| 133 | friend    HRESULT WIN32API DrawGetGDISurface(THIS, LPDIRECTDRAWSURFACE  *); | 
|---|
| 134 | friend    HRESULT WIN32API DrawGetGDISurface4(THIS, LPDIRECTDRAWSURFACE4  *); | 
|---|
| 135 | friend    HRESULT WIN32API DrawGetMonitorFrequency(THIS, LPDWORD); | 
|---|
| 136 | friend    HRESULT WIN32API DrawGetScanLine(THIS, LPDWORD); | 
|---|
| 137 | friend    HRESULT WIN32API DrawGetVerticalBlankStatus(THIS, LPBOOL); | 
|---|
| 138 | friend    HRESULT WIN32API DrawInitialize(THIS, GUID  *); | 
|---|
| 139 | friend    HRESULT WIN32API DrawRestoreDisplayMode(THIS); | 
|---|
| 140 | friend    HRESULT WIN32API DrawSetCooperativeLevel(THIS, HWND, DWORD); | 
|---|
| 141 | friend    HRESULT WIN32API DrawSetDisplayMode(THIS, DWORD, DWORD,DWORD); | 
|---|
| 142 | friend    HRESULT WIN32API DrawSetDisplayMode2(THIS, DWORD, DWORD,DWORD, DWORD, DWORD); | 
|---|
| 143 | friend    HRESULT WIN32API DrawWaitForVerticalBlank(THIS, DWORD, HANDLE); | 
|---|
| 144 | // V2 Interface | 
|---|
| 145 | friend    HRESULT WIN32API DrawGetAvailableVidMem(THIS, LPDDSCAPS, LPDWORD, LPDWORD); | 
|---|
| 146 | friend    HRESULT WIN32API DrawGetAvailableVidMem4(THIS, LPDDSCAPS2, LPDWORD, LPDWORD); | 
|---|
| 147 | // V4 Interface | 
|---|
| 148 | friend    HRESULT WIN32API GetSurfaceFromDC(THIS, HDC, LPDIRECTDRAWSURFACE4 *); | 
|---|
| 149 | friend    HRESULT WIN32API RestoreAllSurfaces(THIS) ; | 
|---|
| 150 | friend    HRESULT WIN32API TestCooperativeLevel(THIS) ; | 
|---|
| 151 | friend    HRESULT WIN32API GetDeviceIdentifier(THIS, LPDDDEVICEIDENTIFIER, DWORD ); | 
|---|
| 152 | /*** IDirect3D methods ***/ | 
|---|
| 153 | friend    HRESULT WIN32API D3DQueryInterface(THIS, REFIID riid, LPVOID  * ppvObj); | 
|---|
| 154 | friend    ULONG   WIN32API D3DAddRef(THIS); | 
|---|
| 155 | friend    ULONG   WIN32API D3DRelease(THIS); | 
|---|
| 156 | friend    HRESULT WIN32API D3DInitialize(THIS, REFIID); | 
|---|
| 157 | friend    HRESULT WIN32API D3DEnumDevices(THIS, LPD3DENUMDEVICESCALLBACK, LPVOID); | 
|---|
| 158 | friend    HRESULT WIN32API D3DCreateLight(THIS, LPDIRECT3DLIGHT*, IUnknown*); | 
|---|
| 159 | friend    HRESULT WIN32API D3DCreateMaterial(THIS, LPDIRECT3DMATERIAL*, IUnknown*); | 
|---|
| 160 | friend    HRESULT WIN32API D3DCreateViewport(THIS, LPDIRECT3DVIEWPORT*, IUnknown*); | 
|---|
| 161 | friend    HRESULT WIN32API D3DFindDevice(THIS, LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT); | 
|---|
| 162 |  | 
|---|
| 163 | }; | 
|---|
| 164 |  | 
|---|
| 165 | #define OFFSET_D3DVTABLE        (LONG)(&((OS2IDirectDraw *)NULL)->lpVtbl3D) | 
|---|
| 166 | #define DDraw3D_GetThisPtr(a)   (OS2IDirectDraw *)((ULONG)a-OFFSET_D3DVTABLE) | 
|---|
| 167 |  | 
|---|
| 168 | //****************************************************************************** | 
|---|
| 169 | HRESULT WIN32API DrawQueryInterface(THIS, REFIID riid, LPVOID  * ppvObj); | 
|---|
| 170 | ULONG   WIN32API DrawAddRef(THIS); | 
|---|
| 171 | ULONG   WIN32API DrawRelease(THIS); | 
|---|
| 172 | HRESULT WIN32API DrawCompact(THIS); | 
|---|
| 173 | HRESULT WIN32API DrawCreateClipper(THIS, DWORD, LPDIRECTDRAWCLIPPER *, IUnknown  * ); | 
|---|
| 174 | HRESULT WIN32API DrawCreatePalette(THIS, DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE *, IUnknown  * ); | 
|---|
| 175 | HRESULT WIN32API DrawCreateSurface(THIS, LPDDSURFACEDESC, LPDIRECTDRAWSURFACE  *, IUnknown  *); | 
|---|
| 176 | HRESULT WIN32API DrawDuplicateSurface(THIS, LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE  * ); | 
|---|
| 177 | HRESULT WIN32API DrawEnumDisplayModes(THIS, DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK ); | 
|---|
| 178 | HRESULT WIN32API DrawEnumSurfaces(THIS, DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK ); | 
|---|
| 179 | HRESULT WIN32API DrawFlipToGDISurface(THIS); | 
|---|
| 180 | HRESULT WIN32API DrawGetCaps(THIS, LPDDCAPS, LPDDCAPS); | 
|---|
| 181 | HRESULT WIN32API DrawGetDisplayMode(THIS, LPDDSURFACEDESC); | 
|---|
| 182 | HRESULT WIN32API DrawGetFourCCCodes(THIS, LPDWORD, LPDWORD); | 
|---|
| 183 | HRESULT WIN32API DrawGetGDISurface(THIS, LPDIRECTDRAWSURFACE  *); | 
|---|
| 184 | HRESULT WIN32API DrawGetMonitorFrequency(THIS, LPDWORD); | 
|---|
| 185 | HRESULT WIN32API DrawGetScanLine(THIS, LPDWORD); | 
|---|
| 186 | HRESULT WIN32API DrawGetVerticalBlankStatus(THIS, LPBOOL); | 
|---|
| 187 | HRESULT WIN32API DrawInitialize(THIS, GUID  *); | 
|---|
| 188 | HRESULT WIN32API DrawRestoreDisplayMode(THIS); | 
|---|
| 189 | HRESULT WIN32API DrawSetCooperativeLevel(THIS, HWND, DWORD); | 
|---|
| 190 | HRESULT WIN32API DrawSetDisplayMode(THIS, DWORD, DWORD,DWORD); | 
|---|
| 191 | HRESULT WIN32API DrawSetDisplayMode2(THIS, DWORD, DWORD,DWORD, DWORD, DWORD); | 
|---|
| 192 | HRESULT WIN32API DrawWaitForVerticalBlank(THIS, DWORD, HANDLE); | 
|---|
| 193 | // V2 | 
|---|
| 194 | HRESULT WIN32API DrawGetAvailableVidMem(THIS, LPDDSCAPS, LPDWORD, LPDWORD); | 
|---|
| 195 | // V4 | 
|---|
| 196 | HRESULT WIN32API DrawGetSurfaceFromDC(THIS, HDC, LPDIRECTDRAWSURFACE4 *); | 
|---|
| 197 | HRESULT WIN32API DrawRestoreAllSurfaces(THIS) ; | 
|---|
| 198 | HRESULT WIN32API DrawTestCooperativeLevel(THIS) ; | 
|---|
| 199 | HRESULT WIN32API DrawGetDeviceIdentifier(THIS, LPDDDEVICEIDENTIFIER, DWORD ); | 
|---|
| 200 | // functions which ifaces are changed in DirectX6 after all MS uses COM where an programmer | 
|---|
| 201 | // isn't allowd to change a function iface after he published the iface (See MS COM docs!) | 
|---|
| 202 | HRESULT WIN32API DrawCreateSurface4(THIS, LPDDSURFACEDESC2, LPDIRECTDRAWSURFACE4  *, IUnknown  *); | 
|---|
| 203 | HRESULT WIN32API DrawDuplicateSurface4(THIS, LPDIRECTDRAWSURFACE4, LPDIRECTDRAWSURFACE4  * ); | 
|---|
| 204 | HRESULT WIN32API DrawEnumDisplayModes4(THIS, DWORD, LPDDSURFACEDESC2, LPVOID, LPDDENUMMODESCALLBACK2 ); | 
|---|
| 205 | HRESULT WIN32API DrawEnumSurfaces4(THIS, DWORD, LPDDSURFACEDESC2, LPVOID,LPDDENUMSURFACESCALLBACK2 ); | 
|---|
| 206 | HRESULT WIN32API DrawGetDisplayMode4(THIS, LPDDSURFACEDESC2); | 
|---|
| 207 | HRESULT WIN32API DrawGetGDISurface4(THIS, LPDIRECTDRAWSURFACE4  *); | 
|---|
| 208 | HRESULT WIN32API DrawGetAvailableVidMem4(THIS, LPDDSCAPS2, LPDWORD, LPDWORD); | 
|---|
| 209 |  | 
|---|
| 210 | /*** IDirect3D methods ***/ | 
|---|
| 211 | HRESULT WIN32API D3DQueryInterface(THIS, REFIID riid, LPVOID  * ppvObj); | 
|---|
| 212 | ULONG   WIN32API D3DAddRef(THIS); | 
|---|
| 213 | ULONG   WIN32API D3DRelease(THIS); | 
|---|
| 214 | HRESULT WIN32API D3DInitialize(THIS, REFIID); | 
|---|
| 215 | HRESULT WIN32API D3DEnumDevices(THIS, LPD3DENUMDEVICESCALLBACK, LPVOID); | 
|---|
| 216 | HRESULT WIN32API D3DCreateLight(THIS, LPDIRECT3DLIGHT*, IUnknown*); | 
|---|
| 217 | HRESULT WIN32API D3DCreateMaterial(THIS, LPDIRECT3DMATERIAL*, IUnknown*); | 
|---|
| 218 | HRESULT WIN32API D3DCreateViewport(THIS, LPDIRECT3DVIEWPORT*, IUnknown*); | 
|---|
| 219 | HRESULT WIN32API D3DFindDevice(THIS, LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT); | 
|---|
| 220 |  | 
|---|
| 221 | #define FOURCC_YUY2  mmioFOURCC( 'Y', 'U', 'Y', '2' ) | 
|---|
| 222 | #define FOURCC_UYVY  mmioFOURCC( 'U', 'Y', 'V', 'Y' ) | 
|---|
| 223 |  | 
|---|
| 224 | extern BOOL fHideCursorOnLock; | 
|---|
| 225 |  | 
|---|
| 226 | #endif | 
|---|