Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

287 lines
8.8 KiB

  1. #ifndef __ENUM_HPP__
  2. #define __ENUM_HPP__
  3. /*==========================================================================;
  4. *
  5. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * File: enum.hpp
  8. * Content: Class for the enumerator object.
  9. *
  10. ***************************************************************************/
  11. // HACK: this belongs elsewhere
  12. #define DXGASSERT(x) DDASSERT(x)
  13. #define HALFLAG_8BITHAL 0x00000001
  14. #define HALFLAG_16BITHAL 0x00000004
  15. #define HALFLAG_24BITHAL 0x00000010
  16. #define HALFLAG_32BITHAL 0x00000040
  17. class CBaseDevice;
  18. // Base class for objects that own their own critical section
  19. class CLockOwner
  20. {
  21. public:
  22. CLockOwner() :
  23. m_bTakeCriticalSection(FALSE),
  24. m_punkSelf(NULL)
  25. {
  26. m_dwOwnerThread = ::GetCurrentThreadId();
  27. #ifdef DEBUG
  28. // Prepare IsValid debug helper
  29. for (int i = 0; i < 8; i++)
  30. {
  31. // Set some magic numbers to check
  32. // object validity in debug
  33. m_dwDebugArray[i] = D3D8MagicNumber + i;
  34. }
  35. DXGASSERT(IsValid());
  36. #endif // DEBUG
  37. } // CLockOwner
  38. ~CLockOwner()
  39. {
  40. DXGASSERT(IsValid());
  41. DXGASSERT(m_bTakeCriticalSection == TRUE ||
  42. m_bTakeCriticalSection == FALSE);
  43. if (m_bTakeCriticalSection)
  44. {
  45. ::DeleteCriticalSection(&m_CriticalSection);
  46. }
  47. } // ~CLockOwner
  48. void EnableCriticalSection()
  49. {
  50. DXGASSERT(m_bTakeCriticalSection == FALSE);
  51. m_bTakeCriticalSection = TRUE;
  52. ::InitializeCriticalSection(&m_CriticalSection);
  53. } // EnableCriticalSection()
  54. #ifdef DEBUG
  55. BOOL IsValid() const
  56. {
  57. for (int i = 0; i < 8; i++)
  58. {
  59. if ((INT)m_dwDebugArray[i] != D3D8MagicNumber + i)
  60. return FALSE;
  61. }
  62. // If we are not locking then warn if we are
  63. // not being called on the same thread
  64. if (!m_bTakeCriticalSection)
  65. {
  66. if (!CheckThread())
  67. {
  68. D3D_WARN(0, "Device that was created without D3DCREATE_MULTITHREADED "
  69. "is being used by a thread other than the creation thread.");
  70. }
  71. }
  72. return TRUE;
  73. } // IsValid
  74. #endif // DEBUG
  75. BOOL CheckThread() const
  76. {
  77. if (::GetCurrentThreadId() == m_dwOwnerThread)
  78. {
  79. return TRUE;
  80. }
  81. else
  82. {
  83. return FALSE;
  84. }
  85. } // CheckThread
  86. // Critical Section Locking
  87. void Lock()
  88. {
  89. if (m_bTakeCriticalSection)
  90. {
  91. DXGASSERT(m_bTakeCriticalSection == TRUE);
  92. ::EnterCriticalSection(&m_CriticalSection);
  93. }
  94. else
  95. {
  96. DXGASSERT(m_bTakeCriticalSection == FALSE);
  97. }
  98. DXGASSERT(IsValid());
  99. }; // Lock
  100. void Unlock()
  101. {
  102. DXGASSERT(IsValid());
  103. if (m_bTakeCriticalSection)
  104. {
  105. DXGASSERT(m_bTakeCriticalSection == TRUE);
  106. ::LeaveCriticalSection(&m_CriticalSection);
  107. }
  108. else
  109. {
  110. DXGASSERT(m_bTakeCriticalSection == FALSE);
  111. }
  112. }; // Unlock
  113. // Methods to help the API_ENTER_SUBOBJECT_RELEASE case
  114. ULONG AddRefOwner()
  115. {
  116. DXGASSERT(m_punkSelf);
  117. return m_punkSelf->AddRef();
  118. } // AddRefOwner
  119. ULONG ReleaseOwner()
  120. {
  121. DXGASSERT(m_punkSelf);
  122. return m_punkSelf->Release();
  123. } // ReleaseOwner
  124. void SetOwner(IUnknown *punkSelf)
  125. {
  126. DXGASSERT(punkSelf);
  127. m_punkSelf = punkSelf;
  128. } // SetOwner
  129. private:
  130. CRITICAL_SECTION m_CriticalSection;
  131. BOOL m_bTakeCriticalSection;
  132. DWORD m_dwOwnerThread;
  133. IUnknown *m_punkSelf;
  134. #ifdef DEBUG
  135. // Set some magic numbers to check
  136. // object validity in debug
  137. enum
  138. {
  139. D3D8MagicNumber = 0xD3D8D3D8
  140. };
  141. DWORD m_dwDebugArray[8];
  142. #endif
  143. }; // class CLockOwner
  144. // Device Caps/Modes Enumeration Object
  145. class CEnum : public CLockOwner, public IDirect3D8
  146. {
  147. public:
  148. /*** IUnknown methods ***/
  149. STDMETHOD(QueryInterface)(REFIID riid, LPVOID * ppvObj);
  150. STDMETHOD_(ULONG,AddRef)();
  151. STDMETHOD_(ULONG,Release)();
  152. STDMETHODIMP RegisterSoftwareDevice(void * pInitFunction);
  153. STDMETHODIMP_(UINT) GetAdapterCount();
  154. STDMETHODIMP GetAdapterIdentifier(UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER8 *pIdentifier);
  155. STDMETHODIMP_(UINT) GetAdapterModeCount(UINT Adapter);
  156. STDMETHODIMP EnumAdapterModes(UINT iAdapter,UINT iMode,D3DDISPLAYMODE *pMode);
  157. STDMETHODIMP CheckDeviceType(UINT Adapter,D3DDEVTYPE CheckType, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, BOOL Windowed);
  158. STDMETHODIMP CheckDeviceFormat(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT DisplayFormat,DWORD Usage,D3DRESOURCETYPE RType, D3DFORMAT CheckFormat);
  159. STDMETHODIMP GetAdapterDisplayMode(UINT Adapter, D3DDISPLAYMODE* pMode);
  160. STDMETHODIMP CheckDeviceMultiSampleType(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT RenderTargetFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType);
  161. STDMETHODIMP CheckDepthStencilMatch(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat);
  162. STDMETHODIMP GetDeviceCaps(UINT iAdapter, D3DDEVTYPE DeviceType, D3DCAPS8 *pCaps);
  163. STDMETHODIMP_(HMONITOR) GetAdapterMonitor(UINT iAdapter);
  164. STDMETHOD(CreateDevice)(
  165. UINT iAdapter,
  166. D3DDEVTYPE DeviceType,
  167. HWND hwndFocusWindow,
  168. DWORD dwBehaviorFlags,
  169. D3DPRESENT_PARAMETERS *pPresentationParams,
  170. IDirect3DDevice8 **ppDevice);
  171. // Public constructor for Direct3DCreate8 to call
  172. CEnum(UINT AppSdkVersion);
  173. D3DDISPLAYMODE* GetModeTable(UINT iAdapter) const
  174. {
  175. return m_AdapterInfo[iAdapter].pModeTable;
  176. }
  177. const DWORD GetNumModes(UINT iAdapter) const
  178. {
  179. return m_AdapterInfo[iAdapter].NumModes;
  180. }
  181. const BOOL NoDDrawSupport(UINT iAdapter) const
  182. {
  183. return m_AdapterInfo[iAdapter].bNoDDrawSupport;
  184. }
  185. void FillInCaps(D3DCAPS8 *pCaps,
  186. const D3D8_DRIVERCAPS *pDriverCaps,
  187. D3DDEVTYPE Type,
  188. UINT AdapterOrdinal) const;
  189. D3DFORMAT MapDepthStencilFormat(UINT iAdapter,
  190. D3DDEVTYPE Type,
  191. D3DFORMAT Format) const;
  192. D3DFORMAT GetUnknown16(UINT iAdapter)
  193. {
  194. return m_AdapterInfo[iAdapter].Unknown16;
  195. }
  196. DDSURFACEDESC* GetHalOpList(UINT iAdapter)
  197. {
  198. return m_AdapterInfo[iAdapter].HALCaps.pGDD8SupportedFormatOps;
  199. }
  200. DWORD GetNumHalOps(UINT iAdapter)
  201. {
  202. return m_AdapterInfo[iAdapter].HALCaps.GDD8NumSupportedFormatOps;
  203. }
  204. #ifdef WINNT
  205. void SetFullScreenDevice(UINT iAdapter,
  206. CBaseDevice *pDevice);
  207. HWND ExclusiveOwnerWindow();
  208. BOOL CheckExclusiveMode(
  209. CBaseDevice* pDevice,
  210. LPBOOL pbThisDeviceOwnsExclusive,
  211. BOOL bKeepMutex);
  212. void DoneExclusiveMode();
  213. void StartExclusiveMode();
  214. #endif // WINNT
  215. // Gamma calibrator is owned by the enumerator
  216. void LoadAndCallGammaCalibrator(
  217. D3DGAMMARAMP *pRamp,
  218. UCHAR * pDeviceName);
  219. void GetRefCaps(UINT iAdapter);
  220. void GetSwCaps(UINT iAdapter);
  221. void * GetInitFunction() const
  222. {
  223. return m_pSwInitFunction;
  224. }
  225. UINT GetAppSdkVersion() {return m_AppSdkVersion;}
  226. private:
  227. HRESULT GetAdapterCaps(UINT iAdapter,
  228. D3DDEVTYPE Type,
  229. D3D8_DRIVERCAPS** ppCaps);
  230. DWORD m_cRef;
  231. UINT m_cAdapter;
  232. ADAPTERINFO m_AdapterInfo[MAX_DX8_ADAPTERS];
  233. CBaseDevice *m_pFullScreenDevice[MAX_DX8_ADAPTERS];
  234. D3D8_DRIVERCAPS m_REFCaps[MAX_DX8_ADAPTERS];
  235. D3D8_DRIVERCAPS m_SwCaps[MAX_DX8_ADAPTERS];
  236. VOID* m_pSwInitFunction;
  237. BOOL m_bDisableHAL;
  238. BOOL m_bHasExclusive;
  239. HINSTANCE m_hGammaCalibrator;
  240. LPDDGAMMACALIBRATORPROC m_pGammaCalibratorProc;
  241. BOOL m_bAttemptedGammaCalibrator;
  242. BOOL m_bGammaCalibratorExists;
  243. UCHAR m_szGammaCalibrator[MAX_PATH];
  244. UINT m_AppSdkVersion;
  245. }; // class CEnum
  246. #endif // __ENUM_HPP__