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.

161 lines
3.7 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: CDirect3D.cpp
  3. *
  4. * This file contains the code to support the functionality test harness
  5. * for GDI+. This includes menu options and calling the appropriate
  6. * functions for execution.
  7. *
  8. * Created: 05-May-2000 - Jeff Vezina [t-jfvez]
  9. *
  10. * Copyright (c) 2000 Microsoft Corporation
  11. *
  12. \**************************************************************************/
  13. #include "CDirect3D.h"
  14. #include "CFuncTest.h"
  15. extern CFuncTest g_FuncTest;
  16. CDirect3D::CDirect3D(BOOL bRegression)
  17. {
  18. strcpy(m_szName,"Direct3D");
  19. m_paDD7=NULL;
  20. m_paDDSurf7=NULL;
  21. m_bRegression=bRegression;
  22. }
  23. CDirect3D::~CDirect3D()
  24. {
  25. if (m_paDD7!=NULL)
  26. {
  27. m_paDD7->Release();
  28. m_paDD7=NULL;
  29. }
  30. }
  31. BOOL CDirect3D::Init()
  32. {
  33. #if HW_ACCELERATION_SUPPORT
  34. if (DirectDrawCreateEx(NULL,(void **)&m_paDD7,IID_IDirectDraw7,NULL)!=DD_OK)
  35. return false;
  36. if (gDD->SetCooperativeLevel(m_hWnd,DDSCL_NORMAL)!=DD_OK)
  37. return false;
  38. #endif
  39. return COutput::Init();
  40. }
  41. Graphics *CDirect3D::PreDraw(int &nOffsetX,int &nOffsetY)
  42. {
  43. Graphics *g=NULL;
  44. #if HW_ACCELERATION_SUPPORT
  45. DDSURFACEDESC2 ddsd;
  46. ZeroMemory(&ddsd, sizeof(ddsd));
  47. ddsd.dwSize = sizeof(ddsd);
  48. ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
  49. ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
  50. ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
  51. switch(depth)
  52. {
  53. case 32:
  54. ddsd.dwFlags |= DDSD_PIXELFORMAT;
  55. ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
  56. ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
  57. ddsd.ddpfPixelFormat.dwRGBBitCount = 32;
  58. ddsd.ddpfPixelFormat.dwRBitMask = 0xFF0000;
  59. ddsd.ddpfPixelFormat.dwGBitMask = 0xFF00;
  60. ddsd.ddpfPixelFormat.dwBBitMask = 0xFF;
  61. break;
  62. case 16:
  63. ddsd.dwFlags |= DDSD_PIXELFORMAT;
  64. ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
  65. ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
  66. ddsd.ddpfPixelFormat.dwRGBBitCount = 16;
  67. ddsd.ddpfPixelFormat.dwRBitMask = 0xEC00;
  68. ddsd.ddpfPixelFormat.dwGBitMask = 0x3E0;
  69. ddsd.ddpfPixelFormat.dwBBitMask = 0x1F;
  70. break;
  71. default:
  72. MessageBoxA(NULL,
  73. "Unsupprted depth for D3D",
  74. "",
  75. MB_OK);
  76. return;
  77. }
  78. ddsd.dwWidth = (int)TESTAREAWIDTH;
  79. ddsd.dwHeight = (int)TESTAREAHEIGHT;
  80. HRESULT err;
  81. err = m_paDD7->CreateSurface(&ddsd, &dds, NULL);
  82. if(err != DD_OK)
  83. {
  84. MessageBoxA(NULL,
  85. "Unable to create surface",
  86. "",
  87. MB_OK);
  88. return;
  89. }
  90. HDC hdc;
  91. err = m_paDDSurf7->GetDC(&hdc);
  92. #if 0
  93. if(err != DD_OK)
  94. {
  95. MessageBoxA(NULL,
  96. "Unable to get DC from DDraw surface",
  97. "",
  98. MB_OK);
  99. m_paDDSurf7->Release();
  100. return;
  101. }
  102. g = Graphics::GetFromHdc(hdc);
  103. BitBlt(hdc, 0, 0, (int)TESTAREAWIDTH, (int)TESTAREAHEIGHT, NULL, 0, 0, WHITENESS);
  104. m_paDDSurf7->ReleaseDC(hdc);
  105. #else
  106. BitBlt(hdc, 0, 0, (int)TESTAREAWIDTH, (int)TESTAREAHEIGHT, NULL, 0, 0, WHITENESS);
  107. m_paDDSurf7->ReleaseDC(hdc);
  108. bitmap = new Bitmap(dds);
  109. g = new Graphics(bitmap);
  110. #endif
  111. // Since we are doing the test on another surface
  112. nOffsetX=0;
  113. nOffsetY=0;
  114. #endif
  115. return g;
  116. }
  117. void CDirect3D::PostDraw(RECT rTestArea)
  118. {
  119. #if HW_ACCELERATION_SUPPORT
  120. delete bitmap;
  121. HRESULT err;
  122. HDC hdc;
  123. HDC hdcOrig = GetDC(g_FuncTest.m_hWndMain);
  124. err = m_paDDSurf7->GetDC(&hdc);
  125. if(err == DD_OK)
  126. {
  127. BitBlt(hdcOrig, rTestArea.left, rTestArea.top, (int)TESTAREAWIDTH, (int)TESTAREAHEIGHT, hdc, 0, 0, SRCCOPY);
  128. }
  129. m_paDDSurf7->ReleaseDC(hdc);
  130. m_paDDSurf7->Release();
  131. ReleaseDC(g_FuncTest.m_hWndMain, hdcOrig);
  132. #endif
  133. }