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.

265 lines
7.7 KiB

  1. #ifndef __CUBESURF_HPP__
  2. #define __CUBESURF_HPP__
  3. /*==========================================================================;
  4. *
  5. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * File: cubesurf.hpp
  8. * Content: Class header the cubesurface class. This class acts
  9. * as a level for the CubeMap 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 "cubemap.hpp"
  18. //
  19. // The CCubeSurface class is a special class that
  20. // works solely with the CCubeMap class. Each CubeSurface
  21. // corresponds to a single level and face of the cube-map. They are
  22. // not stand-alone COM objects because they share the
  23. // same life-time as their CCubeMap parent.
  24. //
  25. // The CDriverCubeSurface class handles
  26. // the driver-managed and vid-mem versions of this
  27. // class.
  28. //
  29. class CCubeSurface : public CBaseSurface
  30. {
  31. public:
  32. // Constructor
  33. CCubeSurface(CCubeMap *pParent,
  34. BYTE iFace,
  35. BYTE iLevel,
  36. HANDLE hKernelHandle)
  37. :
  38. m_pParent(pParent),
  39. m_iFace(iFace),
  40. m_iLevel(iLevel),
  41. m_hKernelHandle(hKernelHandle)
  42. {
  43. DXGASSERT(hKernelHandle || (pParent->GetUserPool() == D3DPOOL_SCRATCH) );
  44. DXGASSERT(m_pParent);
  45. #ifdef DEBUG
  46. m_cRefDebug = 0;
  47. #endif // DEBUG
  48. if (m_pParent->Desc()->Usage &
  49. (D3DUSAGE_LOCK | D3DUSAGE_LOADONCE))
  50. {
  51. m_isLockable = TRUE;
  52. }
  53. else
  54. {
  55. m_isLockable = FALSE;
  56. }
  57. } // CCubeSurface
  58. ~CCubeSurface()
  59. {
  60. DXGASSERT(m_pParent);
  61. DXGASSERT(m_cRefDebug == 0);
  62. if (m_hKernelHandle)
  63. {
  64. // Tell the thunk layer that we need to
  65. // be freed.
  66. D3D8_DESTROYSURFACEDATA DestroySurfData;
  67. DestroySurfData.hDD = m_pParent->Device()->GetHandle();
  68. DestroySurfData.hSurface = m_hKernelHandle;
  69. m_pParent->Device()->GetHalCallbacks()->DestroySurface(&DestroySurfData);
  70. }
  71. #ifdef DEBUG
  72. else
  73. {
  74. DXGASSERT(m_pParent->GetUserPool() == D3DPOOL_SCRATCH);
  75. }
  76. #endif //DEBUG
  77. }; // ~CCubeSurface
  78. public:
  79. // IUnknown methods
  80. STDMETHOD(QueryInterface) (REFIID riid,
  81. LPVOID FAR * ppvObj);
  82. STDMETHOD_(ULONG,AddRef) ();
  83. STDMETHOD_(ULONG,Release) ();
  84. // IBuffer methods
  85. STDMETHOD(SetPrivateData)(REFGUID riid,
  86. CONST VOID* pvData,
  87. DWORD cbData,
  88. DWORD dwFlags);
  89. STDMETHOD(GetPrivateData)(REFGUID riid,
  90. LPVOID pvData,
  91. LPDWORD pcbData);
  92. STDMETHOD(FreePrivateData)(REFGUID riid);
  93. STDMETHOD(GetContainer)(REFIID riid,
  94. void **ppContainer);
  95. STDMETHOD(GetDevice)(IDirect3DDevice8 ** ppvObj);
  96. // IDirect3DSurface8 methods
  97. STDMETHOD(GetDesc)(D3DSURFACE_DESC *pDesc);
  98. STDMETHOD(LockRect)(D3DLOCKED_RECT *pLockedRectData,
  99. CONST RECT *pRect,
  100. DWORD dwFlags);
  101. STDMETHOD(UnlockRect)();
  102. // BaseSurface methods
  103. virtual DWORD DrawPrimHandle() const
  104. {
  105. return D3D8GetDrawPrimHandle(m_hKernelHandle);
  106. } // GetDrawPrimHandle
  107. virtual HANDLE KernelHandle() const
  108. {
  109. return m_hKernelHandle;
  110. } // GetKernelHandle
  111. virtual DWORD IncrementUseCount()
  112. {
  113. return m_pParent->IncrementUseCount();
  114. } // IncrementUseCount
  115. virtual DWORD DecrementUseCount()
  116. {
  117. return m_pParent->DecrementUseCount();
  118. } // DecrementUseCount
  119. virtual void Batch()
  120. {
  121. m_pParent->Batch();
  122. return;
  123. } // Batch
  124. virtual void Sync()
  125. {
  126. m_pParent->Sync();
  127. return;
  128. } // Sync
  129. // Internal lock functions bypass
  130. // parameter checking and also whether the
  131. // surface marked as Lockable or LockOnce
  132. // etc. (Methods of CBaseSurface.)
  133. virtual HRESULT InternalLockRect(D3DLOCKED_RECT *pLockedRectData,
  134. CONST RECT *pRect,
  135. DWORD dwFlags);
  136. virtual HRESULT InternalUnlockRect();
  137. virtual D3DSURFACE_DESC InternalGetDesc() const;
  138. // Access the device of the surface
  139. virtual CBaseDevice *InternalGetDevice() const
  140. {
  141. return m_pParent->Device();
  142. } // InternalGetDevice
  143. // Determines if a LOAD_ONCE surface has already
  144. // been loaded
  145. virtual BOOL IsLoaded() const
  146. {
  147. DXGASSERT(m_pParent->Desc()->Usage & D3DUSAGE_LOADONCE);
  148. if (m_isLockable)
  149. {
  150. return FALSE;
  151. }
  152. else
  153. {
  154. return TRUE;
  155. }
  156. } // IsLoaded
  157. // End Of BaseSurface methods
  158. // Quick accessor for the device
  159. // Access the device of the surface
  160. CBaseDevice *Device() const
  161. {
  162. return m_pParent->Device();
  163. } // Device
  164. protected:
  165. CCubeMap *m_pParent;
  166. BOOL m_isLockable;
  167. BYTE m_iLevel;
  168. BYTE m_iFace;
  169. // Helper function so that we can put all
  170. // the private data into the same list. This
  171. // returns a value that can be used to tag
  172. // each of the private datas that are held
  173. // by the master cubemap. Also, the value
  174. // of (m_cLevel) is used as the tag for
  175. // the CubeMap's private data itself
  176. BYTE CombinedFaceLevel()
  177. {
  178. DXGASSERT(m_iLevel < (1<<5));
  179. DXGASSERT(m_iFace < (1<<3));
  180. return (m_iFace << 5) + m_iLevel;
  181. } // CombinedFaceLevel
  182. // We'll need a kernel handle so that
  183. // we can communicate to the kernel for
  184. // the Destroy call
  185. HANDLE m_hKernelHandle;
  186. // Debugging trick to help spew better
  187. // information if someone over-releases a cubesurface
  188. // (Since our ref's carry over to the parent object; it
  189. // means that over-releases can be hard to find.)
  190. #ifdef DEBUG
  191. DWORD m_cRefDebug;
  192. #endif // DEBUG
  193. }; // CCubeSurface
  194. // The CDriverCubeSurface is a modification of the base Cube-map
  195. // class. It keeps track some additional information and overrides
  196. // some of the methods. It implements Lock/Unlock by calling the
  197. // driver; hence it is used for both driver-managed and vid-mem
  198. // surface
  199. class CDriverCubeSurface : public CCubeSurface
  200. {
  201. public:
  202. // Constructor
  203. CDriverCubeSurface(CCubeMap *pParent,
  204. BYTE iFace,
  205. BYTE iLevel,
  206. HANDLE hKernelHandle)
  207. :
  208. CCubeSurface(pParent, iFace, iLevel, hKernelHandle)
  209. {
  210. } // Init
  211. STDMETHOD(LockRect)(D3DLOCKED_RECT *pLockedRectData,
  212. CONST RECT *pRect,
  213. DWORD dwFlags);
  214. STDMETHOD(UnlockRect)(THIS);
  215. // Internal lock functions bypass
  216. // parameter checking and also whether the
  217. // surface marked as Lockable or LockOnce
  218. // etc. (Methods of CBaseSurface.)
  219. virtual HRESULT InternalLockRect(D3DLOCKED_RECT *pLockedRectData,
  220. CONST RECT *pRect,
  221. DWORD dwFlags);
  222. virtual HRESULT InternalUnlockRect();
  223. }; // CDriverCubeSurface
  224. #endif // __CUBESURF_HPP__