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.

353 lines
12 KiB

  1. #ifndef __IBUFFER_HPP__
  2. #define __IBUFFER_HPP__
  3. /*==========================================================================;
  4. *
  5. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * File: ibuffer.hpp
  8. * Content: Class header the Index buffer class
  9. *
  10. ***************************************************************************/
  11. // Includes
  12. #include "buffer.hpp"
  13. // The base-class implementation of the Index buffer assumes
  14. // that it is resides system-memory. It may be managed.
  15. class CIndexBuffer : public IDirect3DIndexBuffer8, public CBuffer
  16. {
  17. public:
  18. // Creation function for Index Buffers
  19. static HRESULT Create(CBaseDevice *pDevice,
  20. DWORD cbLength,
  21. DWORD dwUsage,
  22. D3DFORMAT Format,
  23. D3DPOOL Pool,
  24. REF_TYPE refType,
  25. IDirect3DIndexBuffer8 **ppIndexBuffer);
  26. static HRESULT CreateSysmemIndexBuffer(CBaseDevice *pDevice,
  27. DWORD cbLength,
  28. DWORD dwUsage,
  29. DWORD dwActualUsage,
  30. D3DFORMAT Format,
  31. D3DPOOL Pool,
  32. D3DPOOL ActualPool,
  33. REF_TYPE refType,
  34. CIndexBuffer **pIB);
  35. static HRESULT CreateDriverIndexBuffer(CBaseDevice *pDevice,
  36. DWORD cbLength,
  37. DWORD dwUsage,
  38. DWORD dwActualUsage,
  39. D3DFORMAT Format,
  40. D3DPOOL Pool,
  41. D3DPOOL ActualPool,
  42. REF_TYPE refType,
  43. CIndexBuffer **pVB);
  44. static HRESULT CreateDriverManagedIndexBuffer(CBaseDevice *pDevice,
  45. DWORD cbLength,
  46. DWORD dwUsage,
  47. DWORD dwActualUsage,
  48. D3DFORMAT Format,
  49. D3DPOOL Pool,
  50. D3DPOOL ActualPool,
  51. REF_TYPE refType,
  52. CIndexBuffer **pVB);
  53. // Methods for Resource Management
  54. // Create duplicate of current object in new pool;
  55. // LOD is ignored for our type
  56. virtual HRESULT Clone(D3DPOOL Pool,
  57. CResource **ppResource) const;
  58. virtual const D3DBUFFER_DESC* GetBufferDesc() const;
  59. HRESULT UpdateDirtyPortion(CResource *pResourceTarget);
  60. // IUnknown methods
  61. STDMETHOD(QueryInterface) (REFIID riid,
  62. LPVOID FAR * ppvObj);
  63. STDMETHOD_(ULONG,AddRef) ();
  64. STDMETHOD_(ULONG,Release) ();
  65. // Some Methods for IDirect3DBuffer
  66. STDMETHOD(SetPrivateData)(REFGUID riid,
  67. CONST VOID* pvData,
  68. DWORD cbData,
  69. DWORD dwFlags);
  70. STDMETHOD(GetPrivateData)(REFGUID riid,
  71. LPVOID pvData,
  72. LPDWORD pcbData);
  73. STDMETHOD(FreePrivateData)(REFGUID riid);
  74. STDMETHOD(GetDevice)(IDirect3DDevice8 **ppDevice);
  75. STDMETHOD_(DWORD, GetPriority)();
  76. STDMETHOD_(DWORD, SetPriority)(DWORD dwPriority);
  77. STDMETHOD_(void, PreLoad)();
  78. STDMETHOD_(D3DRESOURCETYPE, GetType)();
  79. // Methods for IDirect3DIndexBuffer8
  80. STDMETHOD(Lock)(UINT cbOffsetToLock,
  81. UINT cbSizeToLock,
  82. BYTE **ppbData,
  83. DWORD dwFlags);
  84. STDMETHOD(Unlock)();
  85. STDMETHOD(GetDesc)(D3DINDEXBUFFER_DESC *pDesc);
  86. BYTE* Data() const
  87. {
  88. DXGASSERT(m_desc.Usage & D3DUSAGE_SOFTWAREPROCESSING);
  89. DXGASSERT(m_desc.Pool == D3DPOOL_SYSTEMMEM || m_desc.Pool == D3DPOOL_MANAGED);
  90. DXGASSERT(m_LockCount == 0);
  91. return GetPrivateDataPointer();
  92. }
  93. protected:
  94. CIndexBuffer(CBaseDevice *pDevice,
  95. DWORD cbLength,
  96. DWORD dwUsage,
  97. DWORD dwActualUsage,
  98. D3DFORMAT Format,
  99. D3DPOOL Pool,
  100. D3DPOOL ActualPool,
  101. REF_TYPE refType,
  102. HRESULT *phr);
  103. #if DBG
  104. HRESULT ValidateLockParams(UINT cbOffsetToLock,
  105. UINT SizeToLock,
  106. BYTE **ppbData,
  107. DWORD dwFlags) const;
  108. #endif // DBG
  109. // Member data
  110. D3DINDEXBUFFER_DESC m_desc;
  111. DWORD m_usageUser;
  112. }; // class CIndexBuffer
  113. class CIndexBufferMT : public CIndexBuffer
  114. {
  115. public:
  116. STDMETHOD(Lock)(UINT cbOffsetToLock,
  117. UINT cbSizeToLock,
  118. BYTE **ppbData,
  119. DWORD dwFlags)
  120. {
  121. API_ENTER(Device());
  122. return CIndexBuffer::Lock(cbOffsetToLock, cbSizeToLock, ppbData, dwFlags);
  123. }
  124. STDMETHOD(Unlock)()
  125. {
  126. API_ENTER(Device());
  127. return CIndexBuffer::Unlock();
  128. }
  129. friend CIndexBuffer;
  130. protected:
  131. CIndexBufferMT(CBaseDevice *pDevice,
  132. DWORD cbLength,
  133. DWORD Usage,
  134. DWORD ActualUsage,
  135. D3DFORMAT Format,
  136. D3DPOOL Pool,
  137. D3DPOOL ActualPool,
  138. REF_TYPE refType,
  139. HRESULT *phr) :
  140. CIndexBuffer(pDevice,
  141. cbLength,
  142. Usage,
  143. ActualUsage,
  144. Format,
  145. Pool,
  146. ActualPool,
  147. refType,
  148. phr)
  149. {
  150. }
  151. }; // class CIndexBufferMT
  152. // This derived version of the Index buffer class
  153. // overrides lock/unlock to call the driver instead
  154. class CDriverIndexBuffer : public CIndexBuffer
  155. {
  156. public:
  157. STDMETHOD(Lock)(UINT cbOffsetToLock,
  158. UINT cbSizeToLock,
  159. BYTE **ppbData,
  160. DWORD dwFlags);
  161. STDMETHOD(Unlock)();
  162. HRESULT LockI(DWORD dwFlags);
  163. HRESULT UnlockI();
  164. BYTE* Data() const
  165. {
  166. DXGASSERT(FALSE); // Direct pointer access not supported
  167. return 0;
  168. }
  169. // Alloc CIndexBuffer to construct this object
  170. friend CIndexBuffer;
  171. protected:
  172. CDriverIndexBuffer(CBaseDevice *pDevice,
  173. DWORD cbLength,
  174. DWORD Usage,
  175. DWORD ActualUsage,
  176. D3DFORMAT Format,
  177. D3DPOOL Pool,
  178. D3DPOOL ActualPool,
  179. REF_TYPE refType,
  180. HRESULT *phr);
  181. ~CDriverIndexBuffer();
  182. BYTE* m_pbData; // stores cached pointer
  183. }; // class CDriverIndexBuffer
  184. class CDriverIndexBufferMT : public CDriverIndexBuffer
  185. {
  186. public:
  187. STDMETHOD(Lock)(UINT cbOffsetToLock,
  188. UINT cbSizeToLock,
  189. BYTE **ppbData,
  190. DWORD dwFlags)
  191. {
  192. API_ENTER(Device());
  193. return CDriverIndexBuffer::Lock(cbOffsetToLock, cbSizeToLock, ppbData, dwFlags);
  194. }
  195. STDMETHOD(Unlock)()
  196. {
  197. API_ENTER(Device());
  198. return CDriverIndexBuffer::Unlock();
  199. }
  200. friend CIndexBuffer;
  201. protected:
  202. CDriverIndexBufferMT(CBaseDevice *pDevice,
  203. DWORD cbLength,
  204. DWORD Usage,
  205. DWORD ActualUsage,
  206. D3DFORMAT Format,
  207. D3DPOOL Pool,
  208. D3DPOOL ActualPool,
  209. REF_TYPE refType,
  210. HRESULT *phr) :
  211. CDriverIndexBuffer(pDevice,
  212. cbLength,
  213. Usage,
  214. ActualUsage,
  215. Format,
  216. Pool,
  217. ActualPool,
  218. refType,
  219. phr)
  220. {
  221. }
  222. }; // class CIndexBufferMT
  223. // This derived version of the Index buffer class
  224. // overrides lock/unlock to call the driver instead
  225. class CDriverManagedIndexBuffer : public CIndexBuffer
  226. {
  227. public:
  228. STDMETHOD(Lock)(UINT cbOffsetToLock,
  229. UINT cbSizeToLock,
  230. BYTE **ppbData,
  231. DWORD dwFlags);
  232. STDMETHOD(Unlock)();
  233. BYTE* Data() const
  234. {
  235. DXGASSERT(m_desc.Usage & D3DUSAGE_SOFTWAREPROCESSING);
  236. DXGASSERT((m_desc.Usage & D3DUSAGE_WRITEONLY) == 0);
  237. DXGASSERT(m_LockCount == 0);
  238. DXGASSERT(m_pbData != 0);
  239. return m_pbData;
  240. }
  241. // Alloc CIndexBuffer to construct this object
  242. friend CIndexBuffer;
  243. protected:
  244. CDriverManagedIndexBuffer(CBaseDevice *pDevice,
  245. DWORD cbLength,
  246. DWORD Usage,
  247. DWORD ActualUsage,
  248. D3DFORMAT Format,
  249. D3DPOOL Pool,
  250. D3DPOOL ActualPool,
  251. REF_TYPE refType,
  252. HRESULT *phr);
  253. HRESULT UpdateCachedPointer(CBaseDevice*);
  254. friend HRESULT CResource::RestoreDriverManagementState(CBaseDevice*);
  255. BYTE* m_pbData; // stores cached pointer
  256. BOOL m_bDriverCalled;
  257. }; // class CDriverManagedIndexBuffer
  258. class CDriverManagedIndexBufferMT : public CDriverManagedIndexBuffer
  259. {
  260. public:
  261. STDMETHOD(Lock)(UINT cbOffsetToLock,
  262. UINT cbSizeToLock,
  263. BYTE **ppbData,
  264. DWORD dwFlags)
  265. {
  266. API_ENTER(Device());
  267. return CDriverManagedIndexBuffer::Lock(cbOffsetToLock, cbSizeToLock, ppbData, dwFlags);
  268. }
  269. STDMETHOD(Unlock)()
  270. {
  271. API_ENTER(Device());
  272. return CDriverManagedIndexBuffer::Unlock();
  273. }
  274. // Alloc CIndexBuffer to construct this object
  275. friend CIndexBuffer;
  276. protected:
  277. CDriverManagedIndexBufferMT(CBaseDevice *pDevice,
  278. DWORD cbLength,
  279. DWORD Usage,
  280. DWORD ActualUsage,
  281. D3DFORMAT Format,
  282. D3DPOOL Pool,
  283. D3DPOOL ActualPool,
  284. REF_TYPE refType,
  285. HRESULT *phr) :
  286. CDriverManagedIndexBuffer(pDevice,
  287. cbLength,
  288. Usage,
  289. ActualUsage,
  290. Format,
  291. Pool,
  292. ActualPool,
  293. refType,
  294. phr)
  295. {
  296. }
  297. }; // class CDriverIndexBufferMT
  298. #endif // __IBUFFER_HPP__