DisplayManager.cxx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (c) Microsoft Corporation. All rights reserved
  7. #include "DisplayManager.h"
  8. using namespace DirectX;
  9. //
  10. // Constructor NULLs out vars
  11. //
  12. DISPLAYMANAGER::DISPLAYMANAGER() : m_Device(nullptr),
  13. m_DeviceContext(nullptr),
  14. m_MoveSurf(nullptr),
  15. m_VertexShader(nullptr),
  16. m_PixelShader(nullptr),
  17. m_InputLayout(nullptr),
  18. m_RTV(nullptr),
  19. m_SamplerLinear(nullptr),
  20. m_DirtyVertexBufferAlloc(nullptr),
  21. m_DirtyVertexBufferAllocSize(0)
  22. {
  23. }
  24. //
  25. // Destructor calls CleanRefs to destroy everything
  26. //
  27. DISPLAYMANAGER::~DISPLAYMANAGER()
  28. {
  29. CleanRefs();
  30. if (m_DirtyVertexBufferAlloc) {
  31. delete [] m_DirtyVertexBufferAlloc;
  32. m_DirtyVertexBufferAlloc = nullptr;
  33. }
  34. }
  35. //
  36. // Initialize D3D variables
  37. //
  38. void DISPLAYMANAGER::InitD3D(DX_RESOURCES* Data)
  39. {
  40. m_Device = Data->Device;
  41. m_DeviceContext = Data->Context;
  42. m_VertexShader = Data->VertexShader;
  43. m_PixelShader = Data->PixelShader;
  44. m_InputLayout = Data->InputLayout;
  45. m_SamplerLinear = Data->SamplerLinear;
  46. m_Device->AddRef();
  47. m_DeviceContext->AddRef();
  48. m_VertexShader->AddRef();
  49. m_PixelShader->AddRef();
  50. m_InputLayout->AddRef();
  51. m_SamplerLinear->AddRef();
  52. }
  53. //
  54. // Process a given frame and its metadata
  55. //
  56. DUPL_RETURN DISPLAYMANAGER::ProcessFrame(_In_ FRAME_DATA* Data, _Inout_ ID3D11Texture2D* SharedSurf, INT OffsetX, INT OffsetY, _In_ DXGI_OUTPUT_DESC* DeskDesc)
  57. {
  58. DUPL_RETURN Ret = DUPL_RETURN_SUCCESS;
  59. // Process dirties and moves
  60. if (Data->FrameInfo.TotalMetadataBufferSize) {
  61. D3D11_TEXTURE2D_DESC Desc;
  62. Data->Frame->GetDesc(&Desc);
  63. if (Data->MoveCount) {
  64. Ret = CopyMove(SharedSurf, reinterpret_cast<DXGI_OUTDUPL_MOVE_RECT*>(Data->MetaData), Data->MoveCount, OffsetX, OffsetY, DeskDesc, Desc.Width, Desc.Height);
  65. if (Ret != DUPL_RETURN_SUCCESS) {
  66. return Ret;
  67. }
  68. }
  69. if (Data->DirtyCount) {
  70. Ret = CopyDirty(Data->Frame, SharedSurf, reinterpret_cast<RECT*>(Data->MetaData + (Data->MoveCount * sizeof(DXGI_OUTDUPL_MOVE_RECT))), Data->DirtyCount, OffsetX, OffsetY, DeskDesc);
  71. }
  72. }
  73. return Ret;
  74. }
  75. //
  76. // Returns D3D device being used
  77. //
  78. ID3D11Device* DISPLAYMANAGER::GetDevice()
  79. {
  80. return m_Device;
  81. }
  82. //
  83. // Set appropriate source and destination rects for move rects
  84. //
  85. void DISPLAYMANAGER::SetMoveRect(_Out_ RECT* SrcRect, _Out_ RECT* DestRect, _In_ DXGI_OUTPUT_DESC* DeskDesc, _In_ DXGI_OUTDUPL_MOVE_RECT* MoveRect, INT TexWidth, INT TexHeight)
  86. {
  87. switch (DeskDesc->Rotation) {
  88. case DXGI_MODE_ROTATION_UNSPECIFIED:
  89. case DXGI_MODE_ROTATION_IDENTITY: {
  90. SrcRect->left = MoveRect->SourcePoint.x;
  91. SrcRect->top = MoveRect->SourcePoint.y;
  92. SrcRect->right = MoveRect->SourcePoint.x + MoveRect->DestinationRect.right - MoveRect->DestinationRect.left;
  93. SrcRect->bottom = MoveRect->SourcePoint.y + MoveRect->DestinationRect.bottom - MoveRect->DestinationRect.top;
  94. *DestRect = MoveRect->DestinationRect;
  95. break;
  96. }
  97. case DXGI_MODE_ROTATION_ROTATE90: {
  98. SrcRect->left = TexHeight - (MoveRect->SourcePoint.y + MoveRect->DestinationRect.bottom - MoveRect->DestinationRect.top);
  99. SrcRect->top = MoveRect->SourcePoint.x;
  100. SrcRect->right = TexHeight - MoveRect->SourcePoint.y;
  101. SrcRect->bottom = MoveRect->SourcePoint.x + MoveRect->DestinationRect.right - MoveRect->DestinationRect.left;
  102. DestRect->left = TexHeight - MoveRect->DestinationRect.bottom;
  103. DestRect->top = MoveRect->DestinationRect.left;
  104. DestRect->right = TexHeight - MoveRect->DestinationRect.top;
  105. DestRect->bottom = MoveRect->DestinationRect.right;
  106. break;
  107. }
  108. case DXGI_MODE_ROTATION_ROTATE180: {
  109. SrcRect->left = TexWidth - (MoveRect->SourcePoint.x + MoveRect->DestinationRect.right - MoveRect->DestinationRect.left);
  110. SrcRect->top = TexHeight - (MoveRect->SourcePoint.y + MoveRect->DestinationRect.bottom - MoveRect->DestinationRect.top);
  111. SrcRect->right = TexWidth - MoveRect->SourcePoint.x;
  112. SrcRect->bottom = TexHeight - MoveRect->SourcePoint.y;
  113. DestRect->left = TexWidth - MoveRect->DestinationRect.right;
  114. DestRect->top = TexHeight - MoveRect->DestinationRect.bottom;
  115. DestRect->right = TexWidth - MoveRect->DestinationRect.left;
  116. DestRect->bottom = TexHeight - MoveRect->DestinationRect.top;
  117. break;
  118. }
  119. case DXGI_MODE_ROTATION_ROTATE270: {
  120. SrcRect->left = MoveRect->SourcePoint.x;
  121. SrcRect->top = TexWidth - (MoveRect->SourcePoint.x + MoveRect->DestinationRect.right - MoveRect->DestinationRect.left);
  122. SrcRect->right = MoveRect->SourcePoint.y + MoveRect->DestinationRect.bottom - MoveRect->DestinationRect.top;
  123. SrcRect->bottom = TexWidth - MoveRect->SourcePoint.x;
  124. DestRect->left = MoveRect->DestinationRect.top;
  125. DestRect->top = TexWidth - MoveRect->DestinationRect.right;
  126. DestRect->right = MoveRect->DestinationRect.bottom;
  127. DestRect->bottom = TexWidth - MoveRect->DestinationRect.left;
  128. break;
  129. }
  130. default: {
  131. RtlZeroMemory(DestRect, sizeof(RECT));
  132. RtlZeroMemory(SrcRect, sizeof(RECT));
  133. break;
  134. }
  135. }
  136. }
  137. //
  138. // Copy move rectangles
  139. //
  140. DUPL_RETURN DISPLAYMANAGER::CopyMove(_Inout_ ID3D11Texture2D* SharedSurf, _In_reads_(MoveCount) DXGI_OUTDUPL_MOVE_RECT* MoveBuffer, UINT MoveCount, INT OffsetX, INT OffsetY, _In_ DXGI_OUTPUT_DESC* DeskDesc, INT TexWidth, INT TexHeight)
  141. {
  142. D3D11_TEXTURE2D_DESC FullDesc;
  143. SharedSurf->GetDesc(&FullDesc);
  144. // Make new intermediate surface to copy into for moving
  145. if (!m_MoveSurf) {
  146. D3D11_TEXTURE2D_DESC MoveDesc;
  147. MoveDesc = FullDesc;
  148. MoveDesc.Width = DeskDesc->DesktopCoordinates.right - DeskDesc->DesktopCoordinates.left;
  149. MoveDesc.Height = DeskDesc->DesktopCoordinates.bottom - DeskDesc->DesktopCoordinates.top;
  150. MoveDesc.BindFlags = D3D11_BIND_RENDER_TARGET;
  151. MoveDesc.MiscFlags = 0;
  152. HRESULT hr = m_Device->CreateTexture2D(&MoveDesc, nullptr, &m_MoveSurf);
  153. if (FAILED(hr)) {
  154. return ProcessFailure(m_Device, L"Failed to create staging texture for move rects", L"Error", hr, SystemTransitionsExpectedErrors);
  155. }
  156. }
  157. for (UINT i = 0; i < MoveCount; ++i) {
  158. RECT SrcRect;
  159. RECT DestRect;
  160. SetMoveRect(&SrcRect, &DestRect, DeskDesc, &(MoveBuffer[i]), TexWidth, TexHeight);
  161. // Copy rect out of shared surface
  162. D3D11_BOX Box;
  163. Box.left = SrcRect.left + DeskDesc->DesktopCoordinates.left - OffsetX;
  164. Box.top = SrcRect.top + DeskDesc->DesktopCoordinates.top - OffsetY;
  165. Box.front = 0;
  166. Box.right = SrcRect.right + DeskDesc->DesktopCoordinates.left - OffsetX;
  167. Box.bottom = SrcRect.bottom + DeskDesc->DesktopCoordinates.top - OffsetY;
  168. Box.back = 1;
  169. m_DeviceContext->CopySubresourceRegion(m_MoveSurf, 0, SrcRect.left, SrcRect.top, 0, SharedSurf, 0, &Box);
  170. // Copy back to shared surface
  171. Box.left = SrcRect.left;
  172. Box.top = SrcRect.top;
  173. Box.front = 0;
  174. Box.right = SrcRect.right;
  175. Box.bottom = SrcRect.bottom;
  176. Box.back = 1;
  177. m_DeviceContext->CopySubresourceRegion(SharedSurf, 0, DestRect.left + DeskDesc->DesktopCoordinates.left - OffsetX, DestRect.top + DeskDesc->DesktopCoordinates.top - OffsetY, 0, m_MoveSurf, 0, &Box);
  178. }
  179. return DUPL_RETURN_SUCCESS;
  180. }
  181. //
  182. // Sets up vertices for dirty rects for rotated desktops
  183. //
  184. #pragma warning(push)
  185. #pragma warning(disable:__WARNING_USING_UNINIT_VAR) // false positives in SetDirtyVert due to tool bug
  186. void DISPLAYMANAGER::SetDirtyVert(_Out_writes_(NUMVERTICES) VERTEX* Vertices, _In_ RECT* Dirty, INT OffsetX, INT OffsetY, _In_ DXGI_OUTPUT_DESC* DeskDesc, _In_ D3D11_TEXTURE2D_DESC* FullDesc, _In_ D3D11_TEXTURE2D_DESC* ThisDesc)
  187. {
  188. INT CenterX = FullDesc->Width / 2;
  189. INT CenterY = FullDesc->Height / 2;
  190. INT Width = DeskDesc->DesktopCoordinates.right - DeskDesc->DesktopCoordinates.left;
  191. INT Height = DeskDesc->DesktopCoordinates.bottom - DeskDesc->DesktopCoordinates.top;
  192. // Rotation compensated destination rect
  193. RECT DestDirty = *Dirty;
  194. // Set appropriate coordinates compensated for rotation
  195. switch (DeskDesc->Rotation) {
  196. case DXGI_MODE_ROTATION_ROTATE90: {
  197. DestDirty.left = Width - Dirty->bottom;
  198. DestDirty.top = Dirty->left;
  199. DestDirty.right = Width - Dirty->top;
  200. DestDirty.bottom = Dirty->right;
  201. Vertices[0].TexCoord = XMFLOAT2(Dirty->right / static_cast<FLOAT>(ThisDesc->Width), Dirty->bottom / static_cast<FLOAT>(ThisDesc->Height));
  202. Vertices[1].TexCoord = XMFLOAT2(Dirty->left / static_cast<FLOAT>(ThisDesc->Width), Dirty->bottom / static_cast<FLOAT>(ThisDesc->Height));
  203. Vertices[2].TexCoord = XMFLOAT2(Dirty->right / static_cast<FLOAT>(ThisDesc->Width), Dirty->top / static_cast<FLOAT>(ThisDesc->Height));
  204. Vertices[5].TexCoord = XMFLOAT2(Dirty->left / static_cast<FLOAT>(ThisDesc->Width), Dirty->top / static_cast<FLOAT>(ThisDesc->Height));
  205. break;
  206. }
  207. case DXGI_MODE_ROTATION_ROTATE180: {
  208. DestDirty.left = Width - Dirty->right;
  209. DestDirty.top = Height - Dirty->bottom;
  210. DestDirty.right = Width - Dirty->left;
  211. DestDirty.bottom = Height - Dirty->top;
  212. Vertices[0].TexCoord = XMFLOAT2(Dirty->right / static_cast<FLOAT>(ThisDesc->Width), Dirty->top / static_cast<FLOAT>(ThisDesc->Height));
  213. Vertices[1].TexCoord = XMFLOAT2(Dirty->right / static_cast<FLOAT>(ThisDesc->Width), Dirty->bottom / static_cast<FLOAT>(ThisDesc->Height));
  214. Vertices[2].TexCoord = XMFLOAT2(Dirty->left / static_cast<FLOAT>(ThisDesc->Width), Dirty->top / static_cast<FLOAT>(ThisDesc->Height));
  215. Vertices[5].TexCoord = XMFLOAT2(Dirty->left / static_cast<FLOAT>(ThisDesc->Width), Dirty->bottom / static_cast<FLOAT>(ThisDesc->Height));
  216. break;
  217. }
  218. case DXGI_MODE_ROTATION_ROTATE270: {
  219. DestDirty.left = Dirty->top;
  220. DestDirty.top = Height - Dirty->right;
  221. DestDirty.right = Dirty->bottom;
  222. DestDirty.bottom = Height - Dirty->left;
  223. Vertices[0].TexCoord = XMFLOAT2(Dirty->left / static_cast<FLOAT>(ThisDesc->Width), Dirty->top / static_cast<FLOAT>(ThisDesc->Height));
  224. Vertices[1].TexCoord = XMFLOAT2(Dirty->right / static_cast<FLOAT>(ThisDesc->Width), Dirty->top / static_cast<FLOAT>(ThisDesc->Height));
  225. Vertices[2].TexCoord = XMFLOAT2(Dirty->left / static_cast<FLOAT>(ThisDesc->Width), Dirty->bottom / static_cast<FLOAT>(ThisDesc->Height));
  226. Vertices[5].TexCoord = XMFLOAT2(Dirty->right / static_cast<FLOAT>(ThisDesc->Width), Dirty->bottom / static_cast<FLOAT>(ThisDesc->Height));
  227. break;
  228. }
  229. default:
  230. assert(false); // drop through
  231. case DXGI_MODE_ROTATION_UNSPECIFIED:
  232. case DXGI_MODE_ROTATION_IDENTITY: {
  233. Vertices[0].TexCoord = XMFLOAT2(Dirty->left / static_cast<FLOAT>(ThisDesc->Width), Dirty->bottom / static_cast<FLOAT>(ThisDesc->Height));
  234. Vertices[1].TexCoord = XMFLOAT2(Dirty->left / static_cast<FLOAT>(ThisDesc->Width), Dirty->top / static_cast<FLOAT>(ThisDesc->Height));
  235. Vertices[2].TexCoord = XMFLOAT2(Dirty->right / static_cast<FLOAT>(ThisDesc->Width), Dirty->bottom / static_cast<FLOAT>(ThisDesc->Height));
  236. Vertices[5].TexCoord = XMFLOAT2(Dirty->right / static_cast<FLOAT>(ThisDesc->Width), Dirty->top / static_cast<FLOAT>(ThisDesc->Height));
  237. break;
  238. }
  239. }
  240. // Set positions
  241. Vertices[0].Pos = XMFLOAT3((DestDirty.left + DeskDesc->DesktopCoordinates.left - OffsetX - CenterX) / static_cast<FLOAT>(CenterX),
  242. -1 * (DestDirty.bottom + DeskDesc->DesktopCoordinates.top - OffsetY - CenterY) / static_cast<FLOAT>(CenterY),
  243. 0.0f);
  244. Vertices[1].Pos = XMFLOAT3((DestDirty.left + DeskDesc->DesktopCoordinates.left - OffsetX - CenterX) / static_cast<FLOAT>(CenterX),
  245. -1 * (DestDirty.top + DeskDesc->DesktopCoordinates.top - OffsetY - CenterY) / static_cast<FLOAT>(CenterY),
  246. 0.0f);
  247. Vertices[2].Pos = XMFLOAT3((DestDirty.right + DeskDesc->DesktopCoordinates.left - OffsetX - CenterX) / static_cast<FLOAT>(CenterX),
  248. -1 * (DestDirty.bottom + DeskDesc->DesktopCoordinates.top - OffsetY - CenterY) / static_cast<FLOAT>(CenterY),
  249. 0.0f);
  250. Vertices[3].Pos = Vertices[2].Pos;
  251. Vertices[4].Pos = Vertices[1].Pos;
  252. Vertices[5].Pos = XMFLOAT3((DestDirty.right + DeskDesc->DesktopCoordinates.left - OffsetX - CenterX) / static_cast<FLOAT>(CenterX),
  253. -1 * (DestDirty.top + DeskDesc->DesktopCoordinates.top - OffsetY - CenterY) / static_cast<FLOAT>(CenterY),
  254. 0.0f);
  255. Vertices[3].TexCoord = Vertices[2].TexCoord;
  256. Vertices[4].TexCoord = Vertices[1].TexCoord;
  257. }
  258. #pragma warning(pop) // re-enable __WARNING_USING_UNINIT_VAR
  259. //
  260. // Copies dirty rectangles
  261. //
  262. DUPL_RETURN DISPLAYMANAGER::CopyDirty(_In_ ID3D11Texture2D* SrcSurface, _Inout_ ID3D11Texture2D* SharedSurf, _In_reads_(DirtyCount) RECT* DirtyBuffer, UINT DirtyCount, INT OffsetX, INT OffsetY, _In_ DXGI_OUTPUT_DESC* DeskDesc)
  263. {
  264. HRESULT hr;
  265. D3D11_TEXTURE2D_DESC FullDesc;
  266. SharedSurf->GetDesc(&FullDesc);
  267. D3D11_TEXTURE2D_DESC ThisDesc;
  268. SrcSurface->GetDesc(&ThisDesc);
  269. if (!m_RTV) {
  270. hr = m_Device->CreateRenderTargetView(SharedSurf, nullptr, &m_RTV);
  271. if (FAILED(hr)) {
  272. return ProcessFailure(m_Device, L"Failed to create render target view for dirty rects", L"Error", hr, SystemTransitionsExpectedErrors);
  273. }
  274. }
  275. D3D11_SHADER_RESOURCE_VIEW_DESC ShaderDesc;
  276. ShaderDesc.Format = ThisDesc.Format;
  277. ShaderDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
  278. ShaderDesc.Texture2D.MostDetailedMip = ThisDesc.MipLevels - 1;
  279. ShaderDesc.Texture2D.MipLevels = ThisDesc.MipLevels;
  280. // Create new shader resource view
  281. ID3D11ShaderResourceView* ShaderResource = nullptr;
  282. hr = m_Device->CreateShaderResourceView(SrcSurface, &ShaderDesc, &ShaderResource);
  283. if (FAILED(hr)) {
  284. return ProcessFailure(m_Device, L"Failed to create shader resource view for dirty rects", L"Error", hr, SystemTransitionsExpectedErrors);
  285. }
  286. FLOAT BlendFactor[4] = {0.f, 0.f, 0.f, 0.f};
  287. m_DeviceContext->OMSetBlendState(nullptr, BlendFactor, 0xFFFFFFFF);
  288. m_DeviceContext->OMSetRenderTargets(1, &m_RTV, nullptr);
  289. m_DeviceContext->VSSetShader(m_VertexShader, nullptr, 0);
  290. m_DeviceContext->PSSetShader(m_PixelShader, nullptr, 0);
  291. m_DeviceContext->PSSetShaderResources(0, 1, &ShaderResource);
  292. m_DeviceContext->PSSetSamplers(0, 1, &m_SamplerLinear);
  293. m_DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  294. // Create space for vertices for the dirty rects if the current space isn't large enough
  295. UINT BytesNeeded = sizeof(VERTEX) * NUMVERTICES * DirtyCount;
  296. if (BytesNeeded > m_DirtyVertexBufferAllocSize) {
  297. if (m_DirtyVertexBufferAlloc) {
  298. delete [] m_DirtyVertexBufferAlloc;
  299. }
  300. m_DirtyVertexBufferAlloc = new (std::nothrow) BYTE[BytesNeeded];
  301. if (!m_DirtyVertexBufferAlloc) {
  302. m_DirtyVertexBufferAllocSize = 0;
  303. return ProcessFailure(nullptr, L"Failed to allocate memory for dirty vertex buffer.", L"Error", E_OUTOFMEMORY);
  304. }
  305. m_DirtyVertexBufferAllocSize = BytesNeeded;
  306. }
  307. // Fill them in
  308. VERTEX* DirtyVertex = reinterpret_cast<VERTEX*>(m_DirtyVertexBufferAlloc);
  309. for (UINT i = 0; i < DirtyCount; ++i, DirtyVertex += NUMVERTICES) {
  310. SetDirtyVert(DirtyVertex, &(DirtyBuffer[i]), OffsetX, OffsetY, DeskDesc, &FullDesc, &ThisDesc);
  311. }
  312. // Create vertex buffer
  313. D3D11_BUFFER_DESC BufferDesc;
  314. RtlZeroMemory(&BufferDesc, sizeof(BufferDesc));
  315. BufferDesc.Usage = D3D11_USAGE_DEFAULT;
  316. BufferDesc.ByteWidth = BytesNeeded;
  317. BufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  318. BufferDesc.CPUAccessFlags = 0;
  319. D3D11_SUBRESOURCE_DATA InitData;
  320. RtlZeroMemory(&InitData, sizeof(InitData));
  321. InitData.pSysMem = m_DirtyVertexBufferAlloc;
  322. ID3D11Buffer* VertBuf = nullptr;
  323. hr = m_Device->CreateBuffer(&BufferDesc, &InitData, &VertBuf);
  324. if (FAILED(hr)) {
  325. return ProcessFailure(m_Device, L"Failed to create vertex buffer in dirty rect processing", L"Error", hr, SystemTransitionsExpectedErrors);
  326. }
  327. UINT Stride = sizeof(VERTEX);
  328. UINT Offset = 0;
  329. m_DeviceContext->IASetVertexBuffers(0, 1, &VertBuf, &Stride, &Offset);
  330. D3D11_VIEWPORT VP;
  331. VP.Width = static_cast<FLOAT>(FullDesc.Width);
  332. VP.Height = static_cast<FLOAT>(FullDesc.Height);
  333. VP.MinDepth = 0.0f;
  334. VP.MaxDepth = 1.0f;
  335. VP.TopLeftX = 0.0f;
  336. VP.TopLeftY = 0.0f;
  337. m_DeviceContext->RSSetViewports(1, &VP);
  338. m_DeviceContext->Draw(NUMVERTICES * DirtyCount, 0);
  339. VertBuf->Release();
  340. VertBuf = nullptr;
  341. ShaderResource->Release();
  342. ShaderResource = nullptr;
  343. return DUPL_RETURN_SUCCESS;
  344. }
  345. //
  346. // Clean all references
  347. //
  348. void DISPLAYMANAGER::CleanRefs()
  349. {
  350. if (m_DeviceContext) {
  351. m_DeviceContext->Release();
  352. m_DeviceContext = nullptr;
  353. }
  354. if (m_Device) {
  355. m_Device->Release();
  356. m_Device = nullptr;
  357. }
  358. if (m_MoveSurf) {
  359. m_MoveSurf->Release();
  360. m_MoveSurf = nullptr;
  361. }
  362. if (m_VertexShader) {
  363. m_VertexShader->Release();
  364. m_VertexShader = nullptr;
  365. }
  366. if (m_PixelShader) {
  367. m_PixelShader->Release();
  368. m_PixelShader = nullptr;
  369. }
  370. if (m_InputLayout) {
  371. m_InputLayout->Release();
  372. m_InputLayout = nullptr;
  373. }
  374. if (m_SamplerLinear) {
  375. m_SamplerLinear->Release();
  376. m_SamplerLinear = nullptr;
  377. }
  378. if (m_RTV) {
  379. m_RTV->Release();
  380. m_RTV = nullptr;
  381. }
  382. }