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.

220 lines
5.8 KiB

  1. //=============================================================================
  2. // Copyright (c) 1999 Microsoft Corporation
  3. //
  4. // swapchan.hpp
  5. //
  6. // Swap chain implementation. A swap chain contains a primary surface, back
  7. // buffers, and exclusive mode state such as fullscreen, stereoscopy, cover
  8. // window, and the what is required to flip back buffers.
  9. //
  10. // Created 11/16/1999 johnstep (John Stephens)
  11. //=============================================================================
  12. #ifndef __SWAPCHAN_HPP__
  13. #define __SWAPCHAN_HPP__
  14. #include "surface.hpp"
  15. #include "dxcursor.hpp"
  16. //-----------------------------------------------------------------------------
  17. // CSwapChain
  18. //-----------------------------------------------------------------------------
  19. class CSwapChain : public CBaseObject, public IDirect3DSwapChain8
  20. {
  21. public:
  22. CSwapChain(
  23. CBaseDevice *pDevice,
  24. REF_TYPE refType);
  25. void Init(
  26. D3DPRESENT_PARAMETERS *pPresentationParameters,
  27. HRESULT *pHr
  28. );
  29. virtual ~CSwapChain();
  30. CDriverSurface *PrimarySurface() const
  31. {
  32. return m_pPrimarySurface;
  33. }
  34. CDriverSurface *BackBuffer(UINT i) const
  35. {
  36. if (m_ppBackBuffers && i < m_PresentationData.BackBufferCount)
  37. return m_ppBackBuffers[i];
  38. else
  39. return NULL;
  40. }
  41. UINT Width() const
  42. {
  43. return m_PresentationData.BackBufferWidth;
  44. }
  45. UINT Height() const
  46. {
  47. return m_PresentationData.BackBufferHeight;
  48. }
  49. D3DFORMAT BackBufferFormat() const
  50. {
  51. return m_PresentationData.BackBufferFormat;
  52. }
  53. BOOL Windowed() const
  54. {
  55. return m_PresentationData.Windowed;
  56. }
  57. BOOL PresentUseBlt() const
  58. {
  59. return m_PresentUseBlt;
  60. }
  61. // IUnknown methods
  62. STDMETHODIMP QueryInterface(REFIID iid, void **ppInterface);
  63. STDMETHODIMP_(ULONG) AddRef();
  64. STDMETHODIMP_(ULONG) Release();
  65. // IDirect3D8SwapChain8 methods
  66. STDMETHODIMP
  67. GetBackBuffer(
  68. UINT iBackBuffer,
  69. D3DBACKBUFFER_TYPE Type,
  70. IDirect3DSurface8 **ppBackBuffer
  71. );
  72. STDMETHODIMP
  73. Present(
  74. CONST RECT *pSrcRect,
  75. CONST RECT *pDestRect,
  76. HWND hTargetWindow,
  77. CONST RGNDATA *pDstRegion
  78. );
  79. // Internal methods
  80. HRESULT
  81. Reset(
  82. D3DPRESENT_PARAMETERS *pPresentationParameters
  83. );
  84. HRESULT FlipToGDISurface(void);
  85. void SetGammaRamp(DWORD dwFlags, CONST D3DGAMMARAMP *pRamp);
  86. void GetGammaRamp(D3DGAMMARAMP *pRamp);
  87. #ifdef WINNT
  88. void MakeFullscreen();
  89. void DoneExclusiveMode(BOOL);
  90. void StartExclusiveMode(BOOL);
  91. void HIDESHOW_IME();
  92. BOOL IsWinProcDeactivated() const;
  93. DWORD PickRefreshRate(
  94. DWORD Width,
  95. DWORD Height,
  96. DWORD RefreshRate,
  97. D3DFORMAT Format);
  98. #endif //WINNT
  99. VOID Destroy();
  100. protected:
  101. UINT m_presentnext;
  102. CDriverSurface *m_pPrimarySurface;
  103. //HEL and REF allocate the render targets in system memory themselves
  104. //but the blt from system memory to the primary surface will cause tearing,
  105. //so ideally we'd put the n backbuffers in system memory and then a single
  106. //m_pMirrorSurface in video memory. When presenting the system
  107. //memory backbuffer,
  108. //we can blt to the video memory backbuffer and then flip
  109. //Naturally device has to have enough video memory and support flip
  110. //otherwise m_pMirrorSurface will be NULL, and Present will
  111. //simply Blt from m_ppBackBuffers to m_pPrimarySurface
  112. CDriverSurface *m_pMirrorSurface;
  113. CDriverSurface **m_ppBackBuffers;
  114. UINT m_cBackBuffers;
  115. HRESULT CreateWindowed(
  116. UINT width,
  117. UINT height,
  118. D3DFORMAT backBufferFormat,
  119. UINT cBackBuffers,
  120. D3DMULTISAMPLE_TYPE MultiSampleType,
  121. BOOL bDiscard,
  122. BOOL bLockable
  123. );
  124. HRESULT CreateFullscreen(
  125. UINT width,
  126. UINT height,
  127. D3DFORMAT backBufferFormat,
  128. UINT cBackBuffers,
  129. UINT presentationRate,
  130. D3DMULTISAMPLE_TYPE MultiSampleType,
  131. BOOL bDiscard,
  132. BOOL bLockable
  133. );
  134. #ifdef DEBUG
  135. void DebugDiscardBackBuffer(HANDLE SurfaceToClear) const;
  136. #else
  137. void DebugDiscardBackBuffer(HANDLE SurfaceToClear) const
  138. {
  139. // No-op in retail
  140. }; // DebugDiscardBackBuffer
  141. #endif
  142. private:
  143. friend CBaseDevice;
  144. friend CCursor;
  145. D3DPRESENT_PARAMETERS m_PresentationData;
  146. CCursor* m_pCursor;
  147. HANDLE m_hGDISurface;
  148. HRESULT SetCooperativeLevel();
  149. HRESULT SetAppHWnd();
  150. HRESULT FlipToSurface(HANDLE hTargetSurface);
  151. void UpdateFrameRate( void );
  152. BOOL m_bExclusiveMode;
  153. LPVOID m_pCursorShadow;
  154. LPVOID m_pHotTracking;
  155. LONG m_lIMEState;
  156. LONG m_lSetIME;
  157. UINT m_uiErrorMode;
  158. DWORD m_dwFlipFlags;
  159. D3D8_BLTDATA m_BltData;
  160. UINT m_ClientWidth;
  161. UINT m_ClientHeight;
  162. BOOL m_bClientChanged;
  163. RECT m_DstRect;
  164. RECT m_SrcRect;
  165. RECT* m_pDstRect;
  166. RECT* m_pSrcRect;
  167. DWORD m_dwFlags;
  168. #ifdef WINNT
  169. DWORD m_dwForceRefreshRate;
  170. #endif
  171. DWORD m_dwFlipCnt;
  172. DWORD m_dwFlipTime;
  173. BOOL m_PresentUseBlt;
  174. D3DSWAPEFFECT m_UserSwapEffect; // what the user specified
  175. // Please keep this entry at the end of the struct... it'll make assembly-
  176. // level debugging easier.
  177. BOOL m_GammaSet;
  178. D3DGAMMARAMP m_DesiredGammaRamp;
  179. // DO NOT PUT ANYTHING HERE
  180. }; // class CSwapChain
  181. #define D3D_REGFLAGS_SHOWFRAMERATE 0x01
  182. #ifdef WINNT
  183. #define D3D_REGFLAGS_FLIPNOVSYNC 0x02
  184. #endif
  185. #endif // __SWAPCHAN_HPP__