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.

82 lines
2.4 KiB

  1. #include "stdafx.h"
  2. #include "DXSvr.h"
  3. //***************************************************************************************
  4. #define SAFE_RELEASE(p) if ((p)!=NULL) { (p)->Release(); (p)=NULL; };
  5. //***************************************************************************************
  6. IDirectDrawSurface7* g_pPrimarySurface = NULL;
  7. IDirectDrawSurface7* g_pBackSurface = NULL;
  8. IDirectDraw7* g_pDD = NULL;
  9. IDirectDrawClipper* g_pClipper = NULL;
  10. extern BOOL g_bWait;
  11. //***************************************************************************************
  12. BOOL InitD3D(HWND hWnd)
  13. {
  14. // Initialise X-Library
  15. if (FAILED(D3DXInitialize()))
  16. return FALSE;
  17. if (FAILED(D3DXCreateContext(D3DX_DEFAULT , g_bIsPreview||g_bIsTest ? 0 : D3DX_CONTEXT_FULLSCREEN , hWnd ,
  18. D3DX_DEFAULT , D3DX_DEFAULT , &g_pXContext)))
  19. return FALSE;
  20. g_pDevice = g_pXContext->GetD3DDevice();
  21. g_pBackSurface = g_pXContext->GetBackBuffer(0);
  22. g_pPrimarySurface = g_pXContext->GetPrimary();
  23. g_pDD = g_pXContext->GetDD();
  24. if (g_bIsPreview)
  25. {
  26. g_pDD->CreateClipper(0 , &g_pClipper , 0);
  27. g_pClipper->SetHWnd(0 , g_hRefWindow);
  28. }
  29. return TRUE;
  30. }
  31. //***************************************************************************************
  32. void KillD3D()
  33. {
  34. SAFE_RELEASE(g_pClipper);
  35. SAFE_RELEASE(g_pDD);
  36. SAFE_RELEASE(g_pPrimarySurface);
  37. SAFE_RELEASE(g_pBackSurface);
  38. SAFE_RELEASE(g_pDevice);
  39. SAFE_RELEASE(g_pXContext);
  40. D3DXUninitialize();
  41. }
  42. //***************************************************************************************
  43. void RestoreSurfaces()
  44. {
  45. g_pXContext->RestoreSurfaces();
  46. }
  47. //***************************************************************************************
  48. void Flip()
  49. {
  50. if (g_pXContext == NULL)
  51. return;
  52. if (g_bIsPreview)
  53. {
  54. RECT rect;
  55. GetClientRect(g_hRefWindow , &rect);
  56. ClientToScreen(g_hRefWindow , (POINT*)&rect);
  57. rect.right += rect.left; rect.bottom += rect.top;
  58. g_pPrimarySurface->SetClipper(g_pClipper);
  59. HRESULT rc;
  60. if (FAILED(rc = g_pPrimarySurface->Blt(&rect , g_pBackSurface , NULL , DDBLT_WAIT , NULL)))
  61. g_bWait = TRUE;
  62. g_pDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN , NULL);
  63. }
  64. else
  65. {
  66. g_pXContext->UpdateFrame(0);
  67. }
  68. }