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.

195 lines
5.7 KiB

  1. #ifndef __VOLUME_HPP__
  2. #define __VOLUME_HPP__
  3. /*==========================================================================;
  4. *
  5. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * File: volume.hpp
  8. * Content: Class header the volume class. This class acts
  9. * as a level for the MipVolume 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 "mipvol.hpp"
  18. //
  19. // Each Volume implements the IDirect3DVolume8 interface.
  20. // To reduce overhead per level, we have
  21. // put most of the "real" guts of each volume into the MipVolume container
  22. // class; i.e. most of the methods of the Volume really just end
  23. // up calling something in the MipVolume object.
  24. //
  25. // The base class implementation assumes a sys-mem allocation.
  26. //
  27. //
  28. // The CVolume class is a special class that
  29. // works solely with the CMipVolume class. Each Volume
  30. // corresponds to a single level of the mip-volume. They are
  31. // not stand-alone COM objects because they share the
  32. // same life-time as their CMipVolume parent.
  33. //
  34. // The CDriverVolume class is declared later in this file
  35. //
  36. class CVolume : public IDirect3DVolume8
  37. {
  38. public:
  39. // Constructor
  40. CVolume(CMipVolume *pParent,
  41. BYTE iLevel,
  42. HANDLE hKernelHandle
  43. ) :
  44. m_pParent(pParent),
  45. m_isLocked(FALSE),
  46. m_iLevel(iLevel),
  47. m_hKernelHandle(hKernelHandle)
  48. {
  49. DXGASSERT(pParent);
  50. DXGASSERT(hKernelHandle || (pParent->GetUserPool() == D3DPOOL_SCRATCH) );
  51. #ifdef DEBUG
  52. m_cRefDebug = 0;
  53. #endif // DEBUG
  54. if (m_pParent->Desc()->Usage &
  55. (D3DUSAGE_LOCK | D3DUSAGE_LOADONCE))
  56. {
  57. m_isLockable = TRUE;
  58. }
  59. else
  60. {
  61. m_isLockable = FALSE;
  62. }
  63. return;
  64. } // CVolume
  65. ~CVolume()
  66. {
  67. DXGASSERT(m_cRefDebug == 0);
  68. if (m_pParent->GetUserPool() != D3DPOOL_SCRATCH)
  69. {
  70. // Tell the thunk layer that we need to
  71. // be freed.
  72. DXGASSERT(m_hKernelHandle);
  73. D3D8_DESTROYSURFACEDATA DestroySurfData;
  74. DestroySurfData.hDD = m_pParent->Device()->GetHandle();
  75. DestroySurfData.hSurface = m_hKernelHandle;
  76. m_pParent->Device()->GetHalCallbacks()->DestroySurface(&DestroySurfData);
  77. }
  78. #ifdef DEBUG
  79. else
  80. {
  81. DXGASSERT(m_pParent->GetUserPool() == D3DPOOL_SCRATCH);
  82. }
  83. #endif //DEBUG
  84. }; // ~CVolume
  85. public:
  86. // IUnknown methods
  87. STDMETHOD(QueryInterface) (REFIID riid,
  88. VOID **ppvObj);
  89. STDMETHOD_(ULONG,AddRef) ();
  90. STDMETHOD_(ULONG,Release) ();
  91. // IBuffer methods
  92. STDMETHOD(SetPrivateData)(REFGUID riid,
  93. CONST VOID *pvData,
  94. DWORD cbData,
  95. DWORD dwFlags);
  96. STDMETHOD(GetPrivateData)(REFGUID riid,
  97. VOID *pvData,
  98. DWORD *pcbData);
  99. STDMETHOD(FreePrivateData)(REFGUID riid);
  100. STDMETHOD(GetContainer)(REFIID riid,
  101. void **ppContainer);
  102. STDMETHOD(GetDevice)(IDirect3DDevice8 **ppDevice);
  103. // IDirect3DVolume8 methods
  104. STDMETHOD(GetDesc)(D3DVOLUME_DESC *pDesc);
  105. STDMETHOD(LockBox)(D3DLOCKED_BOX *pLockedBox,
  106. CONST D3DBOX *pBox,
  107. DWORD dwFlags);
  108. STDMETHOD(UnlockBox)(void);
  109. virtual HRESULT InternalLockBox(D3DLOCKED_BOX *pLockedBox,
  110. CONST D3DBOX *pBox,
  111. DWORD dwFlags);
  112. virtual HRESULT InternalUnlockBox();
  113. BOOL IsLocked() const
  114. {
  115. return m_isLocked;
  116. } // IsLocked
  117. protected:
  118. CMipVolume *m_pParent;
  119. BOOL m_isLocked;
  120. BOOL m_isLockable;
  121. BYTE m_iLevel;
  122. // We'll need internal handles so that
  123. // we can communicate call Destroy
  124. // and so that CDriverVolume can call
  125. // Lock/Unlock etc.
  126. HANDLE m_hKernelHandle;
  127. CBaseDevice * Device() const
  128. {
  129. return m_pParent->Device();
  130. } // Device
  131. // Debugging trick to help spew better
  132. // information if someone over-releases a volume
  133. // (Since our ref's carry over to the parent object; it
  134. // means that over-releases can be hard to find.)
  135. #ifdef DEBUG
  136. DWORD m_cRefDebug;
  137. #endif // DEBUG
  138. }; // CVolume
  139. // The CDriverVolume is a modification of the base volume
  140. // class. It overrides lock and unlock and routes the call to the
  141. // driver
  142. class CDriverVolume : public CVolume
  143. {
  144. public:
  145. // Constructor
  146. CDriverVolume(CMipVolume *pParent,
  147. BYTE iLevel,
  148. HANDLE hKernelHandle
  149. ) :
  150. CVolume(pParent, iLevel, hKernelHandle)
  151. {
  152. } // CDriverVolume
  153. public:
  154. STDMETHOD(LockBox)(D3DLOCKED_BOX *pLockedBox,
  155. CONST D3DBOX *pBox,
  156. DWORD dwFlags);
  157. STDMETHOD(UnlockBox)();
  158. virtual HRESULT InternalLockBox(D3DLOCKED_BOX *pLockedBox,
  159. CONST D3DBOX *pBox,
  160. DWORD dwFlags);
  161. virtual HRESULT InternalUnlockBox();
  162. }; // CDriverVolume
  163. #endif // __VOLUME_HPP__