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.

262 lines
9.3 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * ***********************
  4. * * DIRECTX SAMPLE CODE *
  5. * ***********************
  6. *
  7. * Module Name: directx.h
  8. *
  9. * Content: useful constants and definitions for DirectDraw and Direct3d
  10. *
  11. * Copyright (c) 1994-1998 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. #ifndef __directx__
  15. #define __directx__
  16. //
  17. // switch to DirectDraw context if necessary.
  18. // must be used in any DDraw blt function
  19. #define DDCONTEXT if (ppdev->permediaInfo->pCurrentCtxt != (ppdev->pDDContext)) \
  20. { P2SwitchContext(ppdev, ppdev->pDDContext); }
  21. //
  22. // fourcc codes supported in the driver for blts
  23. #define FOURCC_YUV422 0x32595559
  24. //
  25. // constants for surface privatedata structure
  26. #define P2_CANPATCH 1
  27. #define P2_PPVALID 2
  28. #define P2_CKVALID 4
  29. #define P2_SURFACE_FORMAT_VALID 8
  30. #define P2_SURFACE_PRIMARY 16
  31. #define P2_EMULATED_16BITZ 32
  32. #define P2_ISPATCHED 64
  33. #define P2_SURFACE_FORMAT_PALETTE 256
  34. #define P2_SURFACE_NEEDUPDATE 0x00000200 //indicating managed
  35. //surface content is obsolete
  36. //
  37. // this magic no. tells us if the surface has already been initialized
  38. #define SURF_MAGIC_NO 0xd3d10110
  39. #define CHECK_P2_SURFACEDATA_VALIDITY(ptr) \
  40. ( ((ptr) != NULL) && ((ptr)->MagicNo == SURF_MAGIC_NO) )
  41. // Permedia specific settings for surfaces.
  42. // A pointer to this structure is stored in
  43. // each surface (in lpGbl->dwReserved1)
  44. typedef struct _permedia_surface_type {
  45. int PixelSize; //
  46. int PixelShift;
  47. int PixelMask;
  48. int FBReadPixel;
  49. int logPixelSize;
  50. int Format; // format description according to
  51. // Permedia 2 manual
  52. int FormatExtension; // format extension...
  53. int ColorComponents;
  54. int ColorOrder; // BGR=0, RGB=1
  55. int Texture16BitMode;
  56. DWORD RedMask; // masks of surface, copied from DDPIXELFORMAT
  57. DWORD GreenMask;
  58. DWORD BlueMask;
  59. DWORD AlphaMask;
  60. BOOL bAlpha; // surface contains alpha pixels
  61. BOOL bPreMult; // surface contains premultiplied alpha !!
  62. } PERMEDIA_SURFACE;
  63. //
  64. // complete private structure of a surface
  65. typedef struct tagPermediaSurfaceData
  66. {
  67. DWORD MagicNo; // Magic number to ensure
  68. // structure is valid
  69. DWORD dwFlags; // Private flags
  70. ULONG ulPackedPP; // PP values for surface pitch
  71. PERMEDIA_SURFACE SurfaceFormat;
  72. FLATPTR fpVidMem; // store the real vidmem
  73. // for managed textures
  74. VIDEOMEMORY* pvmHeap; // heap pointer for the managed
  75. // video texture
  76. DWORD dwPaletteHandle;
  77. //for video memory surface use
  78. } PermediaSurfaceData;
  79. //
  80. // these constants are used in the PERMEDIA_SURFACE structure,
  81. // Format and FormatExtension
  82. #define PERMEDIA_4BIT_PALETTEINDEX 15
  83. #define PERMEDIA_4BIT_PALETTEINDEX_EXTENSION 0
  84. #define PERMEDIA_8BIT_PALETTEINDEX 14
  85. #define PERMEDIA_8BIT_PALETTEINDEX_EXTENSION 0
  86. #define PERMEDIA_332_RGB 5
  87. #define PERMEDIA_332_RGB_EXTENSION 0
  88. #define PERMEDIA_2321_RGB 9
  89. #define PERMEDIA_2321_RGB_EXTENSION 0
  90. #define PERMEDIA_5551_RGB 1
  91. #define PERMEDIA_5551_RGB_EXTENSION 0
  92. #define PERMEDIA_565_RGB 0
  93. #define PERMEDIA_565_RGB_EXTENSION 1
  94. #define PERMEDIA_8888_RGB 0
  95. #define PERMEDIA_8888_RGB_EXTENSION 0
  96. #define PERMEDIA_888_RGB 4
  97. #define PERMEDIA_888_RGB_EXTENSION 1
  98. #define PERMEDIA_444_RGB 2
  99. #define PERMEDIA_444_RGB_EXTENSION 0
  100. #define PERMEDIA_YUV422 3
  101. #define PERMEDIA_YUV422_EXTENSION 1
  102. #define PERMEDIA_YUV411 2
  103. #define PERMEDIA_YUV411_EXTENSION 1
  104. //
  105. // Color formating helper defines
  106. // they convert an RGB value in a certain format to a RGB 32 bit value
  107. #define FORMAT_565_32BIT(val) \
  108. ( (((val & 0xF800) >> 8) << 16) |\
  109. (((val & 0x7E0) >> 3) << 8) |\
  110. ((val & 0x1F) << 3) )
  111. #define FORMAT_565_32BIT_BGR(val) \
  112. ( ((val & 0xF800) >> 8) | \
  113. (((val & 0x7E0) >> 3) << 8) | \
  114. ((val & 0x1F) << 19) )
  115. #define FORMAT_5551_32BIT(val) \
  116. ( (((val & 0x8000) >> 8) << 24) |\
  117. (((val & 0x7C00) >> 7) << 16) |\
  118. (((val & 0x3E0) >> 2) << 8) | ((val & 0x1F) << 3) )
  119. #define FORMAT_5551_32BIT_BGR(val) \
  120. ( (((val & 0x8000) >> 8) << 24) | \
  121. ((val & 0x7C00) >> 7) | \
  122. (((val & 0x3E0) >> 2) << 8) | \
  123. ((val & 0x1F) << 19) )
  124. #define FORMAT_4444_32BIT(val) \
  125. ( ((val & 0xF000) << 16) |\
  126. (((val & 0xF00) >> 4) << 16) |\
  127. ((val & 0xF0) << 8) | ((val & 0xF) << 4) )
  128. #define FORMAT_4444_32BIT_BGR(val) \
  129. ( ((val & 0xF000) << 16) | \
  130. ((val & 0xF00) >> 4) | \
  131. ((val & 0xF0) << 8) | \
  132. ((val & 0xF) << 20) )
  133. #define FORMAT_332_32BIT(val) \
  134. ( ((val & 0xE0) << 16) |\
  135. (((val & 0x1C) << 3) << 8) |\
  136. ((val & 0x3) << 6) )
  137. #define FORMAT_332_32BIT_BGR(val) \
  138. ( (val & 0xE0) | \
  139. (((val & 0x1C) << 3) << 8) | \
  140. ((val & 0x3) << 22) )
  141. #define FORMAT_2321_32BIT(val) \
  142. ( ((val & 0x80) << 24) | ((val & 0x60) << 17) |\
  143. (((val & 0x1C) << 3) << 8) | ((val & 0x3) << 6) )
  144. #define FORMAT_2321_32BIT_BGR(val) \
  145. ( ((val & 0x80) << 24) | \
  146. ((val & 0x60) << 1) | \
  147. (((val & 0x1C) << 3) << 8) | \
  148. ((val & 0x3) << 22) )
  149. #define FORMAT_8888_32BIT_BGR(val) \
  150. ( (val & 0xFF00FF00) | ( ((val & 0xFF0000) >> 16) | ((val & 0xFF) << 16) ) )
  151. #define FORMAT_888_32BIT_BGR(val) \
  152. ( (val & 0xFF00FF00) | ( ((val & 0xFF0000) >> 16) | ((val & 0xFF) << 16) ) )
  153. #define CHROMA_UPPER_ALPHA(val) \
  154. (val | 0xFF000000)
  155. #define CHROMA_LOWER_ALPHA(val) \
  156. (val & 0x00FFFFFF)
  157. #define CHROMA_332_UPPER(val) \
  158. (val | 0x001F1F3F)
  159. #define FORMAT_PALETTE_32BIT(val) \
  160. ( (val & 0xFF) | ((val & 0xFF) << 8) | ((val & 0xFF) << 16))
  161. //
  162. // Direct Draw related functions
  163. //
  164. VOID
  165. SetupPrivateSurfaceData(PPDev ppdev,
  166. PermediaSurfaceData* pPrivateData,
  167. LPDDRAWI_DDRAWSURFACE_LCL pSurface);
  168. //-----------------------------------------------------------------------------
  169. // AGP related declarations
  170. //-----------------------------------------------------------------------------
  171. //@@BEGIN_DDKSPLIT
  172. // TODO: implement 32MB AGP heap
  173. //
  174. //@@END_DDKSPLIT
  175. #define P2_AGP_HEAPSIZE 8
  176. #define DD_AGPSURFBASEOFFSET(psurf) \
  177. (psurf->fpHeapOffset - psurf->lpVidMemHeap->fpStart)
  178. #define DD_AGPSURFACEPHYSICAL(psurf) \
  179. (ppdev->dwGARTDevBase + DD_AGPSURFBASEOFFSET(psurf))
  180. #define DD_P2AGPCAPABLE(ppdev) \
  181. (ppdev->dwChipConfig & PM_CHIPCONFIG_AGPCAPABLE)
  182. //@@BEGIN_DDKSPLIT
  183. #if MULTITHREADED
  184. //-----------------------------------------------------------------------------
  185. //
  186. // WRAPMTDXCALLBACK
  187. //
  188. // Generate multithread protected wrapper for Dx callbacks
  189. //
  190. //-----------------------------------------------------------------------------
  191. #define WRAPMTDXCALLBACK(component, name, type, ptr, ppdevaccess) \
  192. DWORD CALLBACK \
  193. Mt##name( type ptr ) \
  194. { \
  195. PPDev ppdev = (PPDev)ppdevaccess; \
  196. DWORD dwRet; \
  197. \
  198. if(ppdev->ulLockCount) \
  199. { \
  200. DBG_##component((MT_LOG_LEVEL, \
  201. "Mt" #name ": re-entry! %d", ppdev->ulLockCount)); \
  202. } \
  203. EngAcquireSemaphore(ppdev->hsemLock); \
  204. ppdev->ulLockCount++; \
  205. \
  206. dwRet = name(ptr); \
  207. \
  208. ppdev->ulLockCount--; \
  209. EngReleaseSemaphore(ppdev->hsemLock); \
  210. \
  211. return dwRet; \
  212. }
  213. #endif MULTITHREADED
  214. //@@END_DDKSPLIT
  215. #endif