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.

202 lines
5.7 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * **************************
  4. * * DirectDraw SAMPLE CODE *
  5. * **************************
  6. *
  7. * Module Name: ddenable.c
  8. *
  9. * Content:
  10. *
  11. * Copyright (c) 1994-1998 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. #include "precomp.h"
  15. #include "directx.h"
  16. #include "dd.h"
  17. //-----------------------------------------------------------------------------
  18. //
  19. // SetDdPixelFormat
  20. //
  21. // fill a DDPIXELFORMAT structure based with the current mode info
  22. //
  23. //-----------------------------------------------------------------------------
  24. VOID
  25. SetDdPixelFormat(PPDev ppdev,
  26. LPDDPIXELFORMAT pdpf )
  27. {
  28. pdpf->dwSize = sizeof( DDPIXELFORMAT );
  29. pdpf->dwFourCC = 0;
  30. pdpf->dwFlags = DDPF_RGB;
  31. pdpf->dwRBitMask = ppdev->flRed;
  32. pdpf->dwGBitMask = ppdev->flGreen;
  33. pdpf->dwBBitMask = ppdev->flBlue;
  34. // Calculate some bitdepth dependent stuff
  35. switch (ppdev->iBitmapFormat)
  36. {
  37. case BMF_8BPP:
  38. pdpf->dwRGBAlphaBitMask = 0;
  39. pdpf->dwRGBBitCount=8;
  40. pdpf->dwFlags |= DDPF_PALETTEINDEXED8;
  41. break;
  42. case BMF_16BPP:
  43. pdpf->dwRGBBitCount=16;
  44. switch(ppdev->flRed)
  45. {
  46. case 0x7C00:
  47. pdpf->dwRGBAlphaBitMask = 0x8000L;
  48. break;
  49. default:
  50. pdpf->dwRGBAlphaBitMask = 0x0L;
  51. }
  52. break;
  53. case BMF_24BPP:
  54. pdpf->dwRGBAlphaBitMask = 0x00000000L;
  55. pdpf->dwRGBBitCount=24;
  56. break;
  57. case BMF_32BPP:
  58. pdpf->dwRGBAlphaBitMask = 0xff000000L;
  59. pdpf->dwRGBBitCount=32;
  60. break;
  61. default:
  62. ASSERTDD(FALSE,"trying to build unknown pixelformat");
  63. break;
  64. }
  65. } // buildPixelFormat
  66. //-----------------------------------------------------------------------------
  67. //
  68. // SetupDDData
  69. //
  70. // Called to fill in DirectDraw specific information in the ppdev.
  71. //
  72. //-----------------------------------------------------------------------------
  73. VOID
  74. SetupDDData(PPDev ppdev)
  75. {
  76. DBG_DD((7, "SetupDDData"));
  77. SetDdPixelFormat(ppdev, &ppdev->ddpfDisplay);
  78. //
  79. // Setup the display size information
  80. // cxMemory = Pixels across for one scanline
  81. // (not necessarily the same as the screen width)
  82. // cyMemory = Scanline height of the memory
  83. //
  84. ppdev->cxMemory = ppdev->cxScreen;
  85. ppdev->cyMemory = ppdev->FrameBufferLength /
  86. (ppdev->cxScreen << ppdev->bPixShift);
  87. // reset some DDraw specific vars
  88. ppdev->bDdStereoMode=FALSE;
  89. ppdev->dwNewDDSurfaceOffset=0xffffffff;
  90. // Reset the GART copies.
  91. ppdev->dwGARTLin = 0;
  92. ppdev->dwGARTDev = 0;
  93. }// SetupDDData()
  94. //-----------------------------------------------------------------------------
  95. //
  96. // DrvEnableDirectDraw
  97. //
  98. // This function is called by GDI at start of day or after a mode switch
  99. // to enable DirectDraw
  100. //
  101. //-----------------------------------------------------------------------------
  102. BOOL
  103. DrvEnableDirectDraw(DHPDEV dhpdev,
  104. DD_CALLBACKS* pCallBacks,
  105. DD_SURFACECALLBACKS* pSurfaceCallBacks,
  106. DD_PALETTECALLBACKS* pPaletteCallBacks)
  107. {
  108. PPDev ppdev = (PDev*)dhpdev;
  109. DBG_DD((7,"DrvEnableDirectDraw called"));
  110. ppdev->pDDContext = P2AllocateNewContext(ppdev,
  111. (PULONG)P2DisableAllUnits,
  112. 0,
  113. P2CtxtUserFunc);
  114. if ( ppdev->pDDContext == NULL )
  115. {
  116. DBG_DD((0, "DrvEnableDirectDraw: ERROR: "
  117. "failed to allocate DDRAW context"));
  118. //
  119. // Since we have already got the ppdev->pvmList, pointer to video memory
  120. // heap list, in DrvGetDirectDrawInfo(), we better NULL it out here.
  121. // The reason is that we can't enable DirectDraw. So the system won't
  122. // initialize the DDRAW heap manager for us. Then we won't be able to
  123. // use the video memory heap at all.
  124. //
  125. ppdev->pvmList = NULL;
  126. return(FALSE);
  127. }
  128. DBG_DD((7," Created DD Register context: 0x%p", ppdev->pDDContext));
  129. //
  130. // setup some DirectDraw/D3D specific data in ppdev
  131. //
  132. SetupDDData(ppdev);
  133. InitDDHAL(ppdev);
  134. //
  135. // Fill in the function pointers at start of day.
  136. // We copy these from the Initialisation done in InitDDHAL32Bit.
  137. //
  138. memcpy(pCallBacks, &ppdev->DDHALCallbacks, sizeof(DD_CALLBACKS));
  139. memcpy(pSurfaceCallBacks, &ppdev->DDSurfCallbacks,
  140. sizeof(DD_SURFACECALLBACKS));
  141. return(TRUE);
  142. } // DrvEnableDirectDraw()
  143. //-----------------------------------------------------------------------------
  144. //
  145. // DrvDisableDirectDraw
  146. //
  147. // This function is called by GDI at end of day or after a mode switch
  148. //
  149. //-----------------------------------------------------------------------------
  150. VOID
  151. DrvDisableDirectDraw( DHPDEV dhpdev)
  152. {
  153. PPDev ppdev;
  154. DBG_DD((0, "DrvDisableDirectDraw(%lx)", dhpdev));
  155. ppdev = (PDev*) dhpdev;
  156. P2FreeContext (ppdev, ppdev->pDDContext);
  157. ppdev->pDDContext = NULL;
  158. ppdev->pvmList = NULL;
  159. MEMTRACKERDEBUGCHK();
  160. DBG_DD((3," freed Register context: 0x%x", ppdev->pDDContext));
  161. } /* DrvDisableDirectDraw */