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.

401 lines
10 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: misc.c
  6. * Content: DirectDraw misc. routines
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 13-mar-95 craige initial implementation
  11. * 19-mar-95 craige use HRESULTs, added DeleteFromActiveProcessList
  12. * 23-mar-95 craige added DeleteFromFlippableList
  13. * 29-mar-95 craige DeleteFromActiveProcessList return codes
  14. * 01-apr-95 craige happy fun joy updated header file
  15. * 06-apr-95 craige split out process list stuff
  16. * 13-jun-95 kylej moved in FindAttachedFlip, added CanBeFlippable
  17. * 16-jun-95 craige new surface structure
  18. * 26-jun-95 craige reorganized surface structure
  19. * 05-dec-95 colinmc changed DDSCAPS_TEXTUREMAP => DDSCAPS_TEXTURE for
  20. * consistency with Direct3D
  21. * 07-dec-95 colinmc support for mip-maps (flippable mip-maps can get
  22. * pretty complex)
  23. * 08-jan-96 kylej added interface structures
  24. * 17-mar-96 colinmc Bug 13124: flippable mip-maps.
  25. * 24-mar-96 colinmc Bug 14321: not possible to specify back buffer and
  26. * mip-map count in a single call
  27. * 08-dec-96 colinmc Initial AGP support
  28. * 24-mar-97 jeffno Optimized Surfaces
  29. * 07-may-97 colinmc Move AGP detection stuff to ddagp.c
  30. *
  31. ***************************************************************************/
  32. #include "ddrawpr.h"
  33. #define DIRECTXVXDNAME "\\\\.\\DDRAW.VXD"
  34. #if 0
  35. /*
  36. * DeleteFromFlippableList
  37. */
  38. BOOL DeleteFromFlippableList(
  39. LPDDRAWI_DIRECTDRAW pdrv,
  40. LPDDRAWI_DDRAWSURFACE_GBL psurf )
  41. {
  42. LPDDRAWI_DDRAWSURFACE_GBL curr;
  43. LPDDRAWI_DDRAWSURFACE_GBL last;
  44. curr = pdrv->dsFlipList;
  45. if( curr == NULL )
  46. {
  47. return FALSE;
  48. }
  49. last = NULL;
  50. while( curr != psurf )
  51. {
  52. last = curr;
  53. curr = curr->lpFlipLink;
  54. if( curr == NULL )
  55. {
  56. return FALSE;
  57. }
  58. }
  59. if( last == NULL )
  60. {
  61. pdrv->dsFlipList = pdrv->dsFlipList->lpFlipLink;
  62. }
  63. else
  64. {
  65. last->lpFlipLink = curr->lpFlipLink;
  66. }
  67. return TRUE;
  68. } /* DeleteFromFlippableList */
  69. #endif
  70. #define DDSCAPS_FLIPPABLETYPES \
  71. (DDSCAPS_OVERLAY | \
  72. DDSCAPS_TEXTURE | \
  73. DDSCAPS_ALPHA | \
  74. DDSCAPS_ZBUFFER)
  75. /*
  76. * CanBeFlippable
  77. *
  78. * Check to see if these two surfaces can be part of a flippable chain
  79. */
  80. BOOL CanBeFlippable( LPDDRAWI_DDRAWSURFACE_LCL this_lcl,
  81. LPDDRAWI_DDRAWSURFACE_LCL this_attach_lcl)
  82. {
  83. if( ( this_lcl->ddsCaps.dwCaps & DDSCAPS_FLIPPABLETYPES ) ==
  84. ( this_attach_lcl->ddsCaps.dwCaps & DDSCAPS_FLIPPABLETYPES ) )
  85. {
  86. /*
  87. * Flipping chains of optimized mipmaps have DDSCAPS_MIPMAP on every
  88. * surface in the list (since each surface represents an entire mipmap
  89. * chain. So, if both surfaces are optimized mipmaps, then they can
  90. * be flipped
  91. */
  92. if (this_lcl->ddsCaps.dwCaps & DDSCAPS_OPTIMIZED)
  93. {
  94. /*
  95. * We are definitely dealing with an optimized surface, so we're safe to
  96. * make the decision any way we like without fear of regressing other
  97. * flipping behaviour
  98. */
  99. if ( (this_lcl->ddsCaps.dwCaps & (DDSCAPS_OPTIMIZED|DDSCAPS_MIPMAP)) ==
  100. (DDSCAPS_OPTIMIZED|DDSCAPS_MIPMAP) )
  101. {
  102. if ( (this_attach_lcl->ddsCaps.dwCaps & (DDSCAPS_OPTIMIZED|DDSCAPS_MIPMAP)) ==
  103. (DDSCAPS_OPTIMIZED|DDSCAPS_MIPMAP) )
  104. {
  105. return TRUE;
  106. }
  107. }
  108. DPF(1,"Optimized mip-maps not flippable");
  109. return FALSE;
  110. }
  111. /*
  112. * No longer enough to see if both surfaces are exactly the same
  113. * type of flippable surface. A mip-map can have both a mip-map and
  114. * a non-mip-map texture attached both of which are marked as
  115. * flippable. A mip-map also flips with the non-mip-map texture (not
  116. * the other mip-map. Therefore, if both surfaces are textures we need
  117. * to check to also check that they are not both mip-maps before declaring
  118. * them flippable.
  119. */
  120. if( ( ( this_lcl->ddsCaps.dwCaps & this_attach_lcl->ddsCaps.dwCaps ) &
  121. ( DDSCAPS_TEXTURE | DDSCAPS_MIPMAP ) ) == ( DDSCAPS_TEXTURE | DDSCAPS_MIPMAP ) )
  122. return FALSE;
  123. else
  124. return TRUE;
  125. }
  126. else
  127. {
  128. return FALSE;
  129. }
  130. } /* CanBeFlippable */
  131. /*
  132. * FindAttachedFlip
  133. *
  134. * find an attached flipping surface of the same type
  135. */
  136. LPDDRAWI_DDRAWSURFACE_INT FindAttachedFlip(
  137. LPDDRAWI_DDRAWSURFACE_INT this_int )
  138. {
  139. LPATTACHLIST ptr;
  140. LPDDRAWI_DDRAWSURFACE_LCL this_lcl;
  141. LPDDRAWI_DDRAWSURFACE_INT psurf_int;
  142. LPDDRAWI_DDRAWSURFACE_LCL psurf_lcl;
  143. if( this_int == NULL)
  144. {
  145. return NULL;
  146. }
  147. this_lcl = this_int->lpLcl;
  148. for( ptr = this_lcl->lpAttachList; ptr != NULL; ptr = ptr->lpLink )
  149. {
  150. psurf_int = ptr->lpIAttached;
  151. psurf_lcl = psurf_int->lpLcl;
  152. if( (psurf_lcl->ddsCaps.dwCaps & DDSCAPS_FLIP) &&
  153. CanBeFlippable( this_lcl, psurf_lcl ) )
  154. {
  155. return psurf_int;
  156. }
  157. }
  158. return NULL;
  159. } /* FindAttachedFlip */
  160. /*
  161. * FindAttachedSurfaceLeft
  162. *
  163. * find an attached left surface
  164. */
  165. LPDDRAWI_DDRAWSURFACE_INT FindAttachedSurfaceLeft(
  166. LPDDRAWI_DDRAWSURFACE_INT this_int )
  167. {
  168. LPATTACHLIST ptr;
  169. LPDDRAWI_DDRAWSURFACE_LCL this_lcl;
  170. LPDDRAWI_DDRAWSURFACE_INT psurf_int;
  171. LPDDRAWI_DDRAWSURFACE_LCL psurf_lcl;
  172. if( this_int == NULL)
  173. {
  174. return NULL;
  175. }
  176. this_lcl = this_int->lpLcl;
  177. for( ptr = this_lcl->lpAttachList; ptr != NULL; ptr = ptr->lpLink )
  178. {
  179. psurf_int = ptr->lpIAttached;
  180. psurf_lcl = psurf_int->lpLcl;
  181. if (psurf_lcl->lpSurfMore->ddsCapsEx.dwCaps2 & DDSCAPS2_STEREOSURFACELEFT)
  182. return psurf_int;
  183. }
  184. return NULL;
  185. } /* FindAttachedSurfaceLeft */
  186. /*
  187. * FindAttachedMipMap
  188. *
  189. * find an attached mip-map surface
  190. */
  191. LPDDRAWI_DDRAWSURFACE_INT FindAttachedMipMap(
  192. LPDDRAWI_DDRAWSURFACE_INT this_int )
  193. {
  194. LPATTACHLIST ptr;
  195. LPDDRAWI_DDRAWSURFACE_LCL this_lcl;
  196. LPDDRAWI_DDRAWSURFACE_INT psurf_int;
  197. LPDDRAWI_DDRAWSURFACE_LCL psurf_lcl;
  198. if( this_int == NULL)
  199. return NULL;
  200. this_lcl = this_int->lpLcl;
  201. for( ptr = this_lcl->lpAttachList; ptr != NULL; ptr = ptr->lpLink )
  202. {
  203. psurf_int = ptr->lpIAttached;
  204. psurf_lcl = psurf_int->lpLcl;
  205. if( psurf_lcl->ddsCaps.dwCaps & DDSCAPS_MIPMAP )
  206. return psurf_int;
  207. }
  208. return NULL;
  209. } /* FindAttachedMipMap */
  210. /*
  211. * FindParentMipMap
  212. *
  213. * find the parent mip-map level of the given level
  214. */
  215. LPDDRAWI_DDRAWSURFACE_INT FindParentMipMap(
  216. LPDDRAWI_DDRAWSURFACE_INT this_int )
  217. {
  218. LPATTACHLIST ptr;
  219. LPDDRAWI_DDRAWSURFACE_LCL this_lcl;
  220. LPDDRAWI_DDRAWSURFACE_INT psurf_int;
  221. LPDDRAWI_DDRAWSURFACE_LCL psurf_lcl;
  222. if( this_int == NULL)
  223. return NULL;
  224. this_lcl = this_int->lpLcl;
  225. DDASSERT( this_lcl->ddsCaps.dwCaps & DDSCAPS_MIPMAP );
  226. for( ptr = this_lcl->lpAttachListFrom; ptr != NULL; ptr = ptr->lpLink )
  227. {
  228. psurf_int = ptr->lpIAttached;
  229. psurf_lcl = psurf_int->lpLcl;
  230. if( psurf_lcl->ddsCaps.dwCaps & DDSCAPS_MIPMAP )
  231. return psurf_int;
  232. }
  233. return NULL;
  234. } /* FindParentMipMap */
  235. #ifdef WINNT
  236. /*
  237. * IsDifferentPixelFormat
  238. *
  239. * determine if two pixel formats are the same or not
  240. *
  241. * (CMcC) 12/14/95 Really useful - so no longer static
  242. *
  243. * This is the WINNT copy, since the video memory management files
  244. * it normally resides in (ddheap.c) is no longer part of the
  245. * user-mode ddraw.dll
  246. */
  247. BOOL IsDifferentPixelFormat( LPDDPIXELFORMAT pdpf1, LPDDPIXELFORMAT pdpf2 )
  248. {
  249. /*
  250. * same flags?
  251. */
  252. if( pdpf1->dwFlags != pdpf2->dwFlags )
  253. {
  254. VDPF(( 5, S, "Flags differ!" ));
  255. return TRUE;
  256. }
  257. /*
  258. * same bitcount for non-YUV surfaces?
  259. */
  260. if( !(pdpf1->dwFlags & (DDPF_YUV | DDPF_FOURCC)) )
  261. {
  262. if( pdpf1->dwRGBBitCount != pdpf2->dwRGBBitCount )
  263. {
  264. VDPF(( 5, S, "RGB Bitcount differs!" ));
  265. return TRUE;
  266. }
  267. }
  268. /*
  269. * same RGB properties?
  270. */
  271. if( pdpf1->dwFlags & DDPF_RGB )
  272. {
  273. if( pdpf1->dwRBitMask != pdpf2->dwRBitMask )
  274. {
  275. VDPF(( 5, S, "RBitMask differs!" ));
  276. return TRUE;
  277. }
  278. if( pdpf1->dwGBitMask != pdpf2->dwGBitMask )
  279. {
  280. VDPF(( 5, S, "GBitMask differs!" ));
  281. return TRUE;
  282. }
  283. if( pdpf1->dwBBitMask != pdpf2->dwBBitMask )
  284. {
  285. VDPF(( 5, S, "BBitMask differs!" ));
  286. return TRUE;
  287. }
  288. if( pdpf1->dwRGBAlphaBitMask != pdpf2->dwRGBAlphaBitMask )
  289. {
  290. VDPF(( 5, S, "RGBAlphaBitMask differs!" ));
  291. return TRUE;
  292. }
  293. }
  294. /*
  295. * same YUV properties?
  296. */
  297. if( pdpf1->dwFlags & DDPF_YUV )
  298. {
  299. VDPF(( 5, S, "YUV???" ));
  300. if( pdpf1->dwFourCC != pdpf2->dwFourCC )
  301. {
  302. return TRUE;
  303. }
  304. if( pdpf1->dwYUVBitCount != pdpf2->dwYUVBitCount )
  305. {
  306. return TRUE;
  307. }
  308. if( pdpf1->dwYBitMask != pdpf2->dwYBitMask )
  309. {
  310. return TRUE;
  311. }
  312. if( pdpf1->dwUBitMask != pdpf2->dwUBitMask )
  313. {
  314. return TRUE;
  315. }
  316. if( pdpf1->dwVBitMask != pdpf2->dwVBitMask )
  317. {
  318. return TRUE;
  319. }
  320. if( pdpf1->dwYUVAlphaBitMask != pdpf2->dwYUVAlphaBitMask )
  321. {
  322. return TRUE;
  323. }
  324. }
  325. /*
  326. * Possible to use FOURCCs w/o setting the DDPF_YUV flag
  327. * ScottM 7/11/96
  328. */
  329. else if( pdpf1->dwFlags & DDPF_FOURCC )
  330. {
  331. VDPF(( 5, S, "FOURCC???" ));
  332. if( pdpf1->dwFourCC != pdpf2->dwFourCC )
  333. {
  334. return TRUE;
  335. }
  336. }
  337. /*
  338. * If Interleaved Z then check Z bit masks are the same
  339. */
  340. if( pdpf1->dwFlags & DDPF_ZPIXELS )
  341. {
  342. VDPF(( 5, S, "ZPIXELS???" ));
  343. if( pdpf1->dwRGBZBitMask != pdpf2->dwRGBZBitMask )
  344. return TRUE;
  345. }
  346. return FALSE;
  347. } /* IsDifferentPixelFormat */
  348. #endif //WINNT
  349. /*
  350. * Get a handle for communicating with the DirectX VXD (DDRAW.VXD).
  351. */
  352. #ifdef WIN95
  353. HANDLE GetDXVxdHandle( void )
  354. {
  355. HANDLE hvxd;
  356. hvxd = CreateFile( DIRECTXVXDNAME,
  357. GENERIC_WRITE,
  358. FILE_SHARE_WRITE,
  359. NULL,
  360. OPEN_EXISTING,
  361. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_GLOBAL_HANDLE,
  362. NULL);
  363. #ifdef DEBUG
  364. if( INVALID_HANDLE_VALUE == hvxd )
  365. DPF_ERR( "Could not connect to the DirectX VXD" );
  366. #endif /* DEBUG */
  367. return hvxd;
  368. } /* GetDXVxdHandle */
  369. #endif /* WIN95 */