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.

486 lines
13 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: layer.c
  3. *
  4. * OpenGL layer planes support
  5. *
  6. * History:
  7. * Fri Mar 16 13:27:47 1995 -by- Drew Bliss [drewb]
  8. * Created
  9. *
  10. * Copyright (c) 1995 Microsoft Corporation
  11. \**************************************************************************/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #include <glp.h>
  15. #include <glscreen.h>
  16. #include <glgenwin.h>
  17. #include "gencx.h"
  18. #include "context.h"
  19. // Macro to call glFlush or glFinish only if a RC is current.
  20. #define GLFLUSH() if (GLTEB_CLTCURRENTRC()) glFlush()
  21. #define GLFINISH() if (GLTEB_CLTCURRENTRC()) glFinish()
  22. /*****************************Private*Routine******************************\
  23. *
  24. * ValidateLayerIndex
  25. *
  26. * Checks to see whether the given layer index is legal for the given
  27. * pixel format
  28. *
  29. * History:
  30. * Fri Mar 17 14:35:27 1995 -by- Drew Bliss [drewb]
  31. * Created
  32. *
  33. \**************************************************************************/
  34. BOOL APIENTRY ValidateLayerIndex(int iLayerPlane, PIXELFORMATDESCRIPTOR *ppfd)
  35. {
  36. if (iLayerPlane < 0)
  37. {
  38. if (-iLayerPlane > ((ppfd->bReserved >> 4) & 15))
  39. {
  40. SetLastError(ERROR_INVALID_PARAMETER);
  41. return FALSE;
  42. }
  43. }
  44. else if (iLayerPlane > 0)
  45. {
  46. if (iLayerPlane > (ppfd->bReserved & 15))
  47. {
  48. SetLastError(ERROR_INVALID_PARAMETER);
  49. return FALSE;
  50. }
  51. }
  52. else
  53. return FALSE;
  54. return TRUE;
  55. }
  56. /*****************************Private*Routine******************************\
  57. *
  58. * ValidateLayerIndexForDc
  59. *
  60. * Checks to see whether the given layer index is valid for the
  61. * pixel format currently selected in the DC
  62. *
  63. * Returns the current pixel format
  64. *
  65. * History:
  66. * Fri Mar 17 14:35:55 1995 -by- Drew Bliss [drewb]
  67. * Created
  68. *
  69. \**************************************************************************/
  70. static BOOL ValidateLayerIndexForDc(int iLayerPlane,
  71. HDC hdc,
  72. PIXELFORMATDESCRIPTOR *ppfd)
  73. {
  74. int ipfd;
  75. if (IsDirectDrawDevice(hdc))
  76. {
  77. SetLastError(ERROR_INVALID_FUNCTION);
  78. return FALSE;
  79. }
  80. ipfd = GetPixelFormat(hdc);
  81. if (ipfd == 0)
  82. {
  83. return FALSE;
  84. }
  85. if (DescribePixelFormat(hdc, ipfd,
  86. sizeof(PIXELFORMATDESCRIPTOR), ppfd) == 0)
  87. {
  88. return FALSE;
  89. }
  90. return ValidateLayerIndex(iLayerPlane, ppfd);
  91. }
  92. /******************************Public*Routine******************************\
  93. *
  94. * wglDescribeLayerPlane
  95. *
  96. * Describes the given layer plane
  97. *
  98. * History:
  99. * Fri Mar 17 13:16:23 1995 -by- Drew Bliss [drewb]
  100. * Created
  101. \**************************************************************************/
  102. BOOL WINAPI wglDescribeLayerPlane(HDC hdc,
  103. int iPixelFormat,
  104. int iLayerPlane,
  105. UINT nBytes,
  106. LPLAYERPLANEDESCRIPTOR plpd)
  107. {
  108. PIXELFORMATDESCRIPTOR pfd;
  109. BOOL bRet;
  110. if (IsDirectDrawDevice(hdc))
  111. {
  112. SetLastError(ERROR_INVALID_FUNCTION);
  113. return FALSE;
  114. }
  115. // Retrieve the pixel format information
  116. // Validates the HDC and pixel format
  117. if (DescribePixelFormat(hdc, iPixelFormat, sizeof(pfd), &pfd) == 0)
  118. {
  119. return FALSE;
  120. }
  121. // Check for correct size of return buffer
  122. if (nBytes < sizeof(LAYERPLANEDESCRIPTOR))
  123. {
  124. SetLastError(ERROR_INVALID_PARAMETER);
  125. return FALSE;
  126. }
  127. // Make sure the given layer plane is valid
  128. if (!ValidateLayerIndex(iLayerPlane, &pfd))
  129. {
  130. return FALSE;
  131. }
  132. // Generic implementations don't currently support layers
  133. ASSERTOPENGL(!(pfd.dwFlags & PFD_GENERIC_FORMAT)
  134. || (pfd.dwFlags & PFD_GENERIC_ACCELERATED), "bad generic pfd");
  135. if (!(pfd.dwFlags & PFD_GENERIC_ACCELERATED))
  136. {
  137. PGLDRIVER pgldrv;
  138. // Pass request on to the driver if it supports it
  139. pgldrv = pgldrvLoadInstalledDriver(hdc);
  140. if (pgldrv != NULL &&
  141. pgldrv->pfnDrvDescribeLayerPlane != NULL)
  142. {
  143. bRet = pgldrv->pfnDrvDescribeLayerPlane(hdc, iPixelFormat,
  144. iLayerPlane, nBytes, plpd);
  145. }
  146. else
  147. {
  148. bRet = FALSE;
  149. }
  150. }
  151. else
  152. {
  153. bRet = GenMcdDescribeLayerPlane(hdc, iPixelFormat, iLayerPlane,
  154. nBytes, plpd);
  155. }
  156. return bRet;
  157. }
  158. /******************************Public*Routine******************************\
  159. *
  160. * wglSetLayerPaletteEntries
  161. *
  162. * Sets palette entries for the given layer plane
  163. *
  164. * History:
  165. * Fri Mar 17 13:17:11 1995 -by- Drew Bliss [drewb]
  166. * Created
  167. *
  168. \**************************************************************************/
  169. int WINAPI wglSetLayerPaletteEntries(HDC hdc,
  170. int iLayerPlane,
  171. int iStart,
  172. int cEntries,
  173. CONST COLORREF *pcr)
  174. {
  175. PIXELFORMATDESCRIPTOR pfd;
  176. int iRet;
  177. // Validate the layer and retrieve the current pixel format
  178. if (!ValidateLayerIndexForDc(iLayerPlane, hdc, &pfd))
  179. {
  180. return 0;
  181. }
  182. // Flush OpenGL calls.
  183. GLFLUSH();
  184. // Generic implementations don't currently support layers
  185. ASSERTOPENGL(!(pfd.dwFlags & PFD_GENERIC_FORMAT)
  186. || (pfd.dwFlags & PFD_GENERIC_ACCELERATED), "bad generic pfd");
  187. if (!(pfd.dwFlags & PFD_GENERIC_ACCELERATED))
  188. {
  189. PGLDRIVER pgldrv;
  190. // Pass request on to the driver if it supports it
  191. pgldrv = pgldrvLoadInstalledDriver(hdc);
  192. if (pgldrv != NULL &&
  193. pgldrv->pfnDrvSetLayerPaletteEntries != NULL)
  194. {
  195. iRet = pgldrv->pfnDrvSetLayerPaletteEntries(hdc, iLayerPlane,
  196. iStart, cEntries, pcr);
  197. }
  198. else
  199. {
  200. iRet = 0;
  201. }
  202. }
  203. else
  204. {
  205. iRet = GenMcdSetLayerPaletteEntries(hdc, iLayerPlane,
  206. iStart, cEntries, pcr);
  207. }
  208. return iRet;
  209. }
  210. /******************************Public*Routine******************************\
  211. *
  212. * wglGetLayerPaletteEntries
  213. *
  214. * Retrieves palette information for the given layer plane
  215. *
  216. * History:
  217. * Fri Mar 17 13:18:00 1995 -by- Drew Bliss [drewb]
  218. * Created
  219. *
  220. \**************************************************************************/
  221. int WINAPI wglGetLayerPaletteEntries(HDC hdc,
  222. int iLayerPlane,
  223. int iStart,
  224. int cEntries,
  225. COLORREF *pcr)
  226. {
  227. PIXELFORMATDESCRIPTOR pfd;
  228. int iRet;
  229. // Validate the layer and retrieve the current pixel format
  230. if (!ValidateLayerIndexForDc(iLayerPlane, hdc, &pfd))
  231. {
  232. return 0;
  233. }
  234. // Generic implementations don't currently support layers
  235. ASSERTOPENGL(!(pfd.dwFlags & PFD_GENERIC_FORMAT)
  236. || (pfd.dwFlags & PFD_GENERIC_ACCELERATED), "bad generic pfd");
  237. if (!(pfd.dwFlags & PFD_GENERIC_ACCELERATED))
  238. {
  239. PGLDRIVER pgldrv;
  240. // Pass request on to the driver if it supports it
  241. pgldrv = pgldrvLoadInstalledDriver(hdc);
  242. if (pgldrv != NULL &&
  243. pgldrv->pfnDrvGetLayerPaletteEntries != NULL)
  244. {
  245. iRet = pgldrv->pfnDrvGetLayerPaletteEntries(hdc, iLayerPlane,
  246. iStart, cEntries, pcr);
  247. }
  248. else
  249. {
  250. iRet = 0;
  251. }
  252. }
  253. else
  254. {
  255. iRet = GenMcdGetLayerPaletteEntries(hdc, iLayerPlane,
  256. iStart, cEntries, pcr);
  257. }
  258. return iRet;
  259. }
  260. /******************************Public*Routine******************************\
  261. *
  262. * wglRealizeLayerPalette
  263. *
  264. * Realizes the current palette for the given layer plane
  265. *
  266. * History:
  267. * Fri Mar 17 13:18:54 1995 -by- Drew Bliss [drewb]
  268. * Created
  269. *
  270. \**************************************************************************/
  271. BOOL WINAPI wglRealizeLayerPalette(HDC hdc,
  272. int iLayerPlane,
  273. BOOL bRealize)
  274. {
  275. PIXELFORMATDESCRIPTOR pfd;
  276. BOOL bRet;
  277. // Validate the layer and retrieve the current pixel format
  278. if (!ValidateLayerIndexForDc(iLayerPlane, hdc, &pfd))
  279. {
  280. return FALSE;
  281. }
  282. // Flush OpenGL calls.
  283. GLFLUSH();
  284. // Generic implementations don't currently support layers
  285. ASSERTOPENGL(!(pfd.dwFlags & PFD_GENERIC_FORMAT)
  286. || (pfd.dwFlags & PFD_GENERIC_ACCELERATED), "bad generic pfd");
  287. if (!(pfd.dwFlags & PFD_GENERIC_ACCELERATED))
  288. {
  289. PGLDRIVER pgldrv;
  290. // Pass request on to the driver if it supports it
  291. pgldrv = pgldrvLoadInstalledDriver(hdc);
  292. if (pgldrv != NULL &&
  293. pgldrv->pfnDrvRealizeLayerPalette != NULL)
  294. {
  295. bRet = pgldrv->pfnDrvRealizeLayerPalette(hdc, iLayerPlane,
  296. bRealize);
  297. }
  298. else
  299. {
  300. bRet = FALSE;
  301. }
  302. }
  303. else
  304. {
  305. bRet = GenMcdRealizeLayerPalette(hdc, iLayerPlane, bRealize);
  306. }
  307. return bRet;
  308. }
  309. /******************************Public*Routine******************************\
  310. *
  311. * wglSwapLayerBuffers
  312. *
  313. * Swaps the buffers indicated by fuFlags
  314. *
  315. * History:
  316. * Fri Mar 17 13:19:20 1995 -by- Drew Bliss [drewb]
  317. * Created
  318. *
  319. \**************************************************************************/
  320. BOOL WINAPI wglSwapLayerBuffers(HDC hdc,
  321. UINT fuFlags)
  322. {
  323. GLGENwindow *pwnd;
  324. int ipfd;
  325. BOOL bRet;
  326. GLWINDOWID gwid;
  327. #if 0
  328. // If fuFlags == -1, it is a SwapBuffers call.
  329. if (fuFlags & 0x80000000)
  330. {
  331. SetLastError(ERROR_INVALID_PARAMETER);
  332. return FALSE;
  333. }
  334. #endif
  335. if (IsDirectDrawDevice(hdc))
  336. {
  337. SetLastError(ERROR_INVALID_FUNCTION);
  338. return FALSE;
  339. }
  340. // Finish OpenGL calls.
  341. GLFINISH();
  342. ipfd = GetPixelFormat(hdc);
  343. if (ipfd == 0)
  344. {
  345. return FALSE;
  346. }
  347. WindowIdFromHdc(hdc, &gwid);
  348. pwnd = pwndGetFromID(&gwid);
  349. if (!pwnd)
  350. {
  351. return FALSE;
  352. }
  353. if (ipfd > pwnd->ipfdDevMax)
  354. {
  355. PIXELFORMATDESCRIPTOR pfd;
  356. if (DescribePixelFormat(hdc, ipfd,
  357. sizeof(PIXELFORMATDESCRIPTOR), &pfd) == 0)
  358. {
  359. return FALSE;
  360. }
  361. // Generic implementations only support the main plane unless MCD
  362. // has overlay support.
  363. if (pfd.dwFlags & PFD_GENERIC_ACCELERATED)
  364. {
  365. // MCD always support this (whether or not there are layers).
  366. bRet = GenMcdSwapLayerBuffers(hdc, fuFlags);
  367. }
  368. else if (fuFlags & WGL_SWAP_MAIN_PLANE)
  369. {
  370. // We are generic, so substituting SwapBuffers is OK as long
  371. // as the main plane is being swapped. We ignore the bits for
  372. // the layer planes (they don't exist!).
  373. bRet = SwapBuffers(hdc);
  374. }
  375. else
  376. {
  377. // We are generic and the request is to swap only layer planes
  378. // (none of which exist). Since we ignore unsupported planes
  379. // there is nothing to do, but we can return success.
  380. bRet = TRUE;
  381. }
  382. }
  383. else
  384. {
  385. PGLDRIVER pgldrv;
  386. // Pass request on to the driver if it supports it
  387. pgldrv = pgldrvLoadInstalledDriver(hdc);
  388. if (pgldrv != NULL &&
  389. pgldrv->pfnDrvSwapLayerBuffers != NULL)
  390. {
  391. bRet = pgldrv->pfnDrvSwapLayerBuffers(hdc, fuFlags);
  392. }
  393. else if (fuFlags & WGL_SWAP_MAIN_PLANE)
  394. {
  395. // If the driver doesn't have DrvSwapLayerBuffers, we
  396. // can still try and swap the main plane via
  397. // SwapBuffers. The bit flags for unsupported planes
  398. // are ignored
  399. // We're assuming that the fact that the driver doesn't
  400. // expose DrvSwapLayerBuffers means that it doesn't support
  401. // layers at all, possibly not a valid assumption but
  402. // a reasonably safe one. If the driver did support layers,
  403. // this call will cause swapping of all layer planes and
  404. // problems will result
  405. bRet = SwapBuffers(hdc);
  406. }
  407. else
  408. {
  409. // Nothing to swap.
  410. //
  411. // Again, we are assuming that if the driver doesn't support
  412. // DrvSwapLayerBuffers, there are no layer planes at all.
  413. // However, since we ignore the bits for layers that do not
  414. // exist, this is not an error case.
  415. bRet = TRUE;
  416. }
  417. }
  418. pwndRelease(pwnd);
  419. return bRet;
  420. }