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.

261 lines
7.0 KiB

  1. #ifndef __MIPSURF_HPP__
  2. #define __MIPSURF_HPP__
  3. /*==========================================================================;
  4. *
  5. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * File: mipsurf.hpp
  8. * Content: Class header the mipsurface class. This class acts
  9. * as a level for the MipMap class. The base class
  10. * assumes a system-memory allocation; while the
  11. * Driver sub-class will call the driver for every
  12. * lock and unlock operation.
  13. *
  14. *
  15. ***************************************************************************/
  16. // Includes
  17. #include "mipmap.hpp"
  18. //
  19. // Each MipSurface implements the IDirect3DSurface8 interface.
  20. // To reduce overhead per level, we have
  21. // put most of the "real" guts of each surface into the MipMap container
  22. // class; i.e. most of the methods of the MipSurface really just end
  23. // up calling something in the MipMap object.
  24. //
  25. // The base class implementation assumes a sys-mem allocation.
  26. //
  27. //
  28. // The CMipSurface class is a special class that
  29. // works solely with the CMipMap class. Each MipSurface
  30. // corresponds to a single level of the mip-map. They are
  31. // not stand-alone COM objects because they share the
  32. // same life-time as their CMipMap parent.
  33. //
  34. // The CDriverMipSurface class is declared later in this file
  35. //
  36. class CMipSurface : public CBaseSurface
  37. {
  38. public:
  39. // Constructor
  40. CMipSurface(CMipMap *pParent,
  41. BYTE iLevel,
  42. HANDLE hKernelHandle
  43. ) :
  44. m_pParent(pParent),
  45. m_iLevel(iLevel),
  46. m_hKernelHandle(hKernelHandle)
  47. {
  48. DXGASSERT(pParent);
  49. DXGASSERT(hKernelHandle || (pParent->GetUserPool() == D3DPOOL_SCRATCH) );
  50. #ifdef DEBUG
  51. m_cRefDebug = 0;
  52. #endif // DEBUG
  53. if (m_pParent->Desc()->Usage &
  54. (D3DUSAGE_LOCK | D3DUSAGE_LOADONCE))
  55. {
  56. m_isLockable = TRUE;
  57. }
  58. else
  59. {
  60. m_isLockable = FALSE;
  61. }
  62. return;
  63. } // CMipSurface
  64. ~CMipSurface()
  65. {
  66. DXGASSERT(m_cRefDebug == 0);
  67. //m_hKernelHandle will be 0 if this is a scratch pool.
  68. if (m_hKernelHandle)
  69. {
  70. // Tell the thunk layer that we need to
  71. // be freed.
  72. D3D8_DESTROYSURFACEDATA DestroySurfData;
  73. DestroySurfData.hDD = m_pParent->Device()->GetHandle();
  74. DestroySurfData.hSurface = m_hKernelHandle;
  75. m_pParent->Device()->GetHalCallbacks()->DestroySurface(&DestroySurfData);
  76. }
  77. #ifdef DEBUG
  78. else
  79. {
  80. DXGASSERT(m_pParent->GetUserPool() == D3DPOOL_SCRATCH);
  81. }
  82. #endif //DEBUG
  83. }; // ~CMipSurface
  84. public:
  85. // IUnknown methods
  86. STDMETHOD(QueryInterface) (REFIID riid,
  87. LPVOID FAR * ppvObj);
  88. STDMETHOD_(ULONG,AddRef) ();
  89. STDMETHOD_(ULONG,Release) ();
  90. // IBuffer methods
  91. STDMETHOD(SetPrivateData)(REFGUID riid,
  92. CONST VOID* pvData,
  93. DWORD cbData,
  94. DWORD dwFlags);
  95. STDMETHOD(GetPrivateData)(REFGUID riid,
  96. LPVOID pvData,
  97. LPDWORD pcbData);
  98. STDMETHOD(FreePrivateData)(REFGUID riid);
  99. STDMETHOD(GetContainer)(REFIID riid,
  100. void **ppContainer);
  101. STDMETHOD(GetDevice)(IDirect3DDevice8 **ppDevice);
  102. // IDirect3DSurface8 methods
  103. STDMETHOD(GetDesc)(D3DSURFACE_DESC *pDesc);
  104. STDMETHOD(LockRect)(D3DLOCKED_RECT *pLockedRectData,
  105. CONST RECT *pRect,
  106. DWORD dwFlags);
  107. STDMETHOD(UnlockRect)();
  108. // BaseSurface methods
  109. virtual DWORD DrawPrimHandle() const
  110. {
  111. return D3D8GetDrawPrimHandle(m_hKernelHandle);
  112. } // DrawPrimHandle
  113. virtual HANDLE KernelHandle() const
  114. {
  115. return m_hKernelHandle;
  116. } // KernelHandle
  117. virtual DWORD IncrementUseCount()
  118. {
  119. return m_pParent->IncrementUseCount();
  120. } // IncrementUseCount
  121. virtual DWORD DecrementUseCount()
  122. {
  123. return m_pParent->DecrementUseCount();
  124. } // DecrementUseCount
  125. virtual void Batch()
  126. {
  127. m_pParent->Batch();
  128. return;
  129. } // Batch
  130. virtual void Sync()
  131. {
  132. m_pParent->Sync();
  133. return;
  134. } // Sync
  135. // Internal lock functions bypass
  136. // parameter checking and also whether the
  137. // surface marked as Lockable or LockOnce
  138. // etc. (Methods of CBaseSurface.)
  139. virtual HRESULT InternalLockRect(D3DLOCKED_RECT *pLockedRectData,
  140. CONST RECT *pRect,
  141. DWORD dwFlags);
  142. virtual HRESULT InternalUnlockRect();
  143. virtual D3DSURFACE_DESC InternalGetDesc() const;
  144. virtual CBaseDevice * InternalGetDevice() const
  145. {
  146. return m_pParent->Device();
  147. } // InternalGetDevice
  148. // Determines if a LOAD_ONCE surface has already
  149. // been loaded
  150. virtual BOOL IsLoaded() const
  151. {
  152. DXGASSERT(m_pParent->Desc()->Usage & D3DUSAGE_LOADONCE);
  153. if (m_isLockable)
  154. {
  155. return FALSE;
  156. }
  157. else
  158. {
  159. return TRUE;
  160. }
  161. } // IsLoaded
  162. // End Of BaseSurface methods
  163. // Quick method to avoid the virtual function call
  164. CBaseDevice * Device() const
  165. {
  166. return m_pParent->Device();
  167. } // Device
  168. protected:
  169. CMipMap *m_pParent;
  170. BOOL m_isLockable;
  171. BYTE m_iLevel;
  172. // We'll need internal handles so that
  173. // we can communicate call Destroy
  174. // and so that CDriverMipMap can call
  175. // Lock/Unlock etc.
  176. HANDLE m_hKernelHandle;
  177. // Debugging trick to help spew better
  178. // information if someone over-releases a mipsurface
  179. // (Since our ref's carry over to the parent object; it
  180. // means that over-releases can be hard to find.)
  181. #ifdef DEBUG
  182. DWORD m_cRefDebug;
  183. #endif // DEBUG
  184. }; // CMipSurface
  185. // The CDriverMipSurface is a modification of the base mipsurf
  186. // class. It overrides lock and unlock and routes the call to the
  187. // driver
  188. class CDriverMipSurface : public CMipSurface
  189. {
  190. public:
  191. // Constructor
  192. CDriverMipSurface(CMipMap *pParent,
  193. BYTE iLevel,
  194. HANDLE hKernelHandle
  195. ) :
  196. CMipSurface(pParent, iLevel, hKernelHandle)
  197. {
  198. } // CDriverMipSurface
  199. public:
  200. STDMETHOD(LockRect)(D3DLOCKED_RECT *pLockedRectData,
  201. CONST RECT *pRect,
  202. DWORD dwFlags);
  203. STDMETHOD(UnlockRect)();
  204. // Internal lock functions bypass
  205. // parameter checking and also whether the
  206. // surface marked as Lockable or LockOnce
  207. // etc. (Methods of CBaseSurface.)
  208. virtual HRESULT InternalLockRect(D3DLOCKED_RECT *pLockedRectData,
  209. CONST RECT *pRect,
  210. DWORD dwFlags);
  211. virtual HRESULT InternalUnlockRect();
  212. }; // CDriverMipSurface
  213. #endif // __MIPSURF_HPP__