Source code of Windows XP (NT5)
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.

329 lines
10 KiB

  1. #ifndef __SURFACE_HPP__
  2. #define __SURFACE_HPP__
  3. /*==========================================================================;
  4. *
  5. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * File: surface.hpp
  8. * Content: Class header the stand-alone surface class. This class
  9. * is intended to be returned by the CreateRenderTarget
  10. * creation method. It is also used by the CreateZStencil
  11. * device method.
  12. *
  13. ***************************************************************************/
  14. // Includes
  15. #include "d3dobj.hpp"
  16. #include "d3di.hpp"
  17. //
  18. // The CSurface class is a standalone surface class; "standalone" indicates
  19. // that it doesn't rely on another class for storing state.
  20. //
  21. // The base class implementation assumes a sys-mem allocation.
  22. //
  23. class CSurface : public CBaseObject, public CBaseSurface
  24. {
  25. public:
  26. // Creation method to allow creation of render targets
  27. static HRESULT CreateRenderTarget(CBaseDevice *pDevice,
  28. DWORD cpWidth,
  29. DWORD cpHeight,
  30. D3DFORMAT Format,
  31. D3DMULTISAMPLE_TYPE MultiSampleType,
  32. BOOL bLockable,
  33. REF_TYPE refType,
  34. IDirect3DSurface8 **ppSurface)
  35. {
  36. DWORD Usage = D3DUSAGE_RENDERTARGET;
  37. if (bLockable)
  38. Usage = D3DUSAGE_LOCK | D3DUSAGE_RENDERTARGET;
  39. return Create(pDevice,
  40. cpWidth,
  41. cpHeight,
  42. Usage,
  43. Format,
  44. MultiSampleType,
  45. refType,
  46. ppSurface);
  47. }
  48. // Creation method to allow creation of Z/Stencil buffers
  49. static HRESULT CreateZStencil(CBaseDevice *pDevice,
  50. DWORD cpWidth,
  51. DWORD cpHeight,
  52. D3DFORMAT Format,
  53. D3DMULTISAMPLE_TYPE MultiSampleType,
  54. REF_TYPE refType,
  55. IDirect3DSurface8 **ppSurface)
  56. {
  57. return Create(pDevice,
  58. cpWidth,
  59. cpHeight,
  60. D3DUSAGE_DEPTHSTENCIL,
  61. Format,
  62. MultiSampleType,
  63. refType,
  64. ppSurface);
  65. }
  66. // Creation method for stand-along ImageSurface
  67. static HRESULT CreateImageSurface(CBaseDevice *pDevice,
  68. DWORD cpWidth,
  69. DWORD cpHeight,
  70. D3DFORMAT Format,
  71. REF_TYPE refType,
  72. IDirect3DSurface8 **ppSurface);
  73. // Destructor
  74. virtual ~CSurface();
  75. // IUnknown methods
  76. STDMETHOD(QueryInterface) (REFIID riid,
  77. VOID **ppvObj);
  78. STDMETHOD_(ULONG,AddRef) ();
  79. STDMETHOD_(ULONG,Release) ();
  80. // IBuffer methods
  81. STDMETHOD(SetPrivateData)(REFGUID riid,
  82. CONST VOID *pvData,
  83. DWORD cbData,
  84. DWORD dwFlags);
  85. STDMETHOD(GetPrivateData)(REFGUID riid,
  86. VOID *pvData,
  87. DWORD *pcbData);
  88. STDMETHOD(FreePrivateData)(REFGUID riid);
  89. STDMETHOD(GetContainer)(REFIID riid,
  90. void **ppContainer);
  91. STDMETHOD(GetDevice)(IDirect3DDevice8 **ppDevice);
  92. // IDirect3DSurface8 methods
  93. STDMETHOD(GetDesc)(D3DSURFACE_DESC *pDesc);
  94. STDMETHOD(LockRect)(D3DLOCKED_RECT *pLockedRectData,
  95. CONST RECT *pRect,
  96. DWORD dwFlags) PURE;
  97. STDMETHOD(UnlockRect)() PURE;
  98. BOOL IsLockable() const
  99. {
  100. if (m_desc.Usage & D3DUSAGE_LOCK)
  101. return TRUE;
  102. else
  103. return FALSE;
  104. } // IsLockable
  105. #ifdef DEBUG
  106. // DPF helper for explaining why lock failed
  107. void ReportWhyLockFailed(void) const;
  108. #else // !DEBUG
  109. void ReportWhyLockFailed(void) const
  110. {
  111. // Do Nothing In Retail
  112. } // ReportWhyLockFailed
  113. #endif // !DEBUG
  114. D3DFORMAT GetUserFormat() const
  115. {
  116. return m_formatUser;
  117. } // GetUserFormat
  118. // BaseSurface methods
  119. virtual DWORD DrawPrimHandle() const
  120. {
  121. return BaseDrawPrimHandle();
  122. } // GetDrawPrimHandle
  123. virtual HANDLE KernelHandle() const
  124. {
  125. return BaseKernelHandle();
  126. } // GetKernelHandle
  127. virtual DWORD IncrementUseCount()
  128. {
  129. return CBaseObject::IncrementUseCount();
  130. } // IncrementUseCount
  131. virtual DWORD DecrementUseCount()
  132. {
  133. return CBaseObject::DecrementUseCount();
  134. } // DecrementUseCount
  135. virtual void Batch()
  136. {
  137. ULONGLONG qwBatch = static_cast<CD3DBase*>(Device())->CurrentBatch();
  138. DXGASSERT(qwBatch >= m_qwBatchCount);
  139. m_qwBatchCount = qwBatch;
  140. } // Batch
  141. // Sync should be called before
  142. // any read or write access to the surface
  143. virtual void Sync()
  144. {
  145. static_cast<CD3DBase*>(Device())->Sync(m_qwBatchCount);
  146. } // Sync
  147. // OnDestroy function is called just
  148. // before an object is about to get deleted; we
  149. // use this to provide synching prior to deletion
  150. virtual void OnDestroy()
  151. {
  152. Sync();
  153. }; // OnDestroy
  154. virtual D3DSURFACE_DESC InternalGetDesc() const;
  155. virtual CBaseDevice * InternalGetDevice() const
  156. {
  157. return CBaseObject::Device();
  158. } // Device
  159. // Determines if a LOAD_ONCE surface has already
  160. // been loaded
  161. virtual BOOL IsLoaded() const
  162. {
  163. // These kinds of surfaces (RT/DS/Image) are never
  164. // load-once; so this should never be called.
  165. DXGASSERT(!(m_desc.Usage & D3DUSAGE_LOADONCE));
  166. DXGASSERT(FALSE);
  167. return FALSE;
  168. } // IsLoaded
  169. // End Of BaseSurface methods
  170. protected:
  171. // Creation method to allow creation of render targets/zbuffers
  172. static HRESULT Create(CBaseDevice *pDevice,
  173. DWORD cpWidth,
  174. DWORD cpHeight,
  175. DWORD dwUsage,
  176. D3DFORMAT Format,
  177. D3DMULTISAMPLE_TYPE MultiSampleType,
  178. REF_TYPE refType,
  179. IDirect3DSurface8 **ppSurface);
  180. // Surface description
  181. D3DSURFACE_DESC m_desc;
  182. // Pool that User specified
  183. D3DPOOL m_poolUser;
  184. // Format that User specified
  185. D3DFORMAT m_formatUser;
  186. // Constructor returns an error code
  187. // if the object could not be fully
  188. // constructed
  189. CSurface(CBaseDevice *pDevice,
  190. DWORD cpWidth,
  191. DWORD cpHeight,
  192. DWORD dwUsage,
  193. D3DFORMAT Format,
  194. REF_TYPE refType,
  195. HRESULT *phr
  196. );
  197. private:
  198. // Batch count to make sure that the current
  199. // command buffer has been flushed
  200. // before read or write access to the
  201. // bits
  202. ULONGLONG m_qwBatchCount;
  203. }; // class CSurface
  204. // Derived class for system-memory version
  205. class CSysMemSurface : public CSurface
  206. {
  207. // CSurface is the master class and can access
  208. // whatever it wants
  209. friend CSurface;
  210. public:
  211. // Constructor
  212. CSysMemSurface(CBaseDevice *pDevice,
  213. DWORD cpWidth,
  214. DWORD cpHeight,
  215. DWORD dwUsage,
  216. D3DFORMAT Format,
  217. REF_TYPE refType,
  218. HRESULT *phr
  219. );
  220. // destructor
  221. virtual ~CSysMemSurface();
  222. // Override Lock and Unlock
  223. STDMETHOD(LockRect)(D3DLOCKED_RECT *pLockedRectData,
  224. CONST RECT *pRect,
  225. DWORD dwFlags);
  226. STDMETHOD(UnlockRect)();
  227. // Internal lock functions bypass
  228. // parameter checking and also whether the
  229. // surface marked as Lockable or LockOnce
  230. // etc. (Methods of CBaseSurface)
  231. virtual HRESULT InternalLockRect(D3DLOCKED_RECT *pLockedRectData,
  232. CONST RECT *pRect,
  233. DWORD dwFlags);
  234. virtual HRESULT InternalUnlockRect();
  235. private:
  236. BYTE *m_rgbPixels;
  237. }; // class CSysMemSurface
  238. // Derived class for the driver allocated version
  239. class CDriverSurface : public CSurface
  240. {
  241. // CSurface is the master class and can access
  242. // whatever it wants
  243. friend CSurface;
  244. public:
  245. // Constructor
  246. CDriverSurface(CBaseDevice *pDevice,
  247. DWORD cpWidth,
  248. DWORD cpHeight,
  249. DWORD dwUsage,
  250. D3DFORMAT UserFormat,
  251. D3DFORMAT RealFormat,
  252. D3DMULTISAMPLE_TYPE MultiSampleType,
  253. HANDLE hKernelHandle,
  254. REF_TYPE refType,
  255. HRESULT *phr
  256. );
  257. // destructor
  258. virtual ~CDriverSurface();
  259. // Override Lock and Unlock
  260. STDMETHOD(LockRect)(D3DLOCKED_RECT *pLockedRectData,
  261. CONST RECT *pRect,
  262. DWORD dwFlags);
  263. STDMETHOD(UnlockRect)();
  264. // Internal lock functions bypass
  265. // parameter checking and also whether the
  266. // surface marked as Lockable or LockOnce
  267. // etc. (Methods of CBaseSurface)
  268. virtual HRESULT InternalLockRect(D3DLOCKED_RECT *pLockedRectData,
  269. CONST RECT *pRect,
  270. DWORD dwFlags);
  271. virtual HRESULT InternalUnlockRect();
  272. }; // CDriverSurface
  273. #endif // __SURFACE_HPP__