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.

199 lines
4.8 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: pixelfmt.c
  3. *
  4. * Client side stubs for pixel format functions.
  5. *
  6. * Created: 17-Sep-1993
  7. * Author: Hock San Lee [hockl]
  8. *
  9. * Copyright (c) 1993-1999 Microsoft Corporation
  10. \**************************************************************************/
  11. #include "precomp.h"
  12. static char szOpenGL[] = "OPENGL32";
  13. typedef int (WINAPI *PFN1)(HDC, CONST PIXELFORMATDESCRIPTOR *);
  14. typedef int (WINAPI *PFN2)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
  15. typedef int (WINAPI *PFN3)(HDC);
  16. typedef BOOL (WINAPI *PFN4)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
  17. typedef BOOL (WINAPI *PFN5)(HDC);
  18. BOOL gbSetPixelFormatCalled = FALSE;
  19. // In these routines the assumption is that OpenGL is already loaded
  20. // For that case, the LoadLibrary/FreeLibrary calls will simply
  21. // increment and decrement the reference count of the DLL, so they
  22. // won't be too expensive
  23. //
  24. // In the case where OpenGL is not loaded the DLL will be brought in
  25. // for the duration of the call only
  26. /***********************************************************************/
  27. __inline FARPROC GetAPI(char *szDll, char *szAPI, HMODULE *phDll)
  28. {
  29. *phDll = LoadLibraryA(szDll);
  30. if (*phDll == NULL)
  31. {
  32. return NULL;
  33. }
  34. return GetProcAddress(*phDll, szAPI);
  35. }
  36. /***********************************************************************/
  37. int WINAPI ChoosePixelFormat(HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd)
  38. {
  39. HMODULE hDll;
  40. PFN1 pfn = (PFN1)GetAPI(szOpenGL, "wglChoosePixelFormat", &hDll);
  41. int ipfd = 0;
  42. if (pfn)
  43. {
  44. ipfd = (*pfn)(hdc, ppfd);
  45. }
  46. if (hDll)
  47. {
  48. FreeLibrary(hDll);
  49. }
  50. return ipfd;
  51. }
  52. /***********************************************************************/
  53. int WINAPI DescribePixelFormat(HDC hdc, int iPixelFormat, UINT nBytes,
  54. LPPIXELFORMATDESCRIPTOR ppfd)
  55. {
  56. HMODULE hDll;
  57. PFN2 pfn = (PFN2)GetAPI(szOpenGL, "wglDescribePixelFormat", &hDll);
  58. int ipfd = 0;
  59. if (pfn)
  60. {
  61. ipfd = (*pfn)(hdc, iPixelFormat, nBytes, ppfd);
  62. }
  63. if (hDll)
  64. {
  65. FreeLibrary(hDll);
  66. }
  67. return ipfd;
  68. }
  69. /***********************************************************************/
  70. int WINAPI GetPixelFormat(HDC hdc)
  71. {
  72. int ipfd = 0;
  73. if (gbSetPixelFormatCalled)
  74. {
  75. HMODULE hDll;
  76. PFN3 pfn = (PFN3)GetAPI(szOpenGL, "wglGetPixelFormat", &hDll);
  77. if (pfn)
  78. {
  79. ipfd = (*pfn)(hdc);
  80. }
  81. if (hDll)
  82. {
  83. FreeLibrary(hDll);
  84. }
  85. }
  86. return ipfd;
  87. }
  88. /***********************************************************************/
  89. BOOL WINAPI SetPixelFormat(HDC hdc, int iPixelFormat,
  90. CONST PIXELFORMATDESCRIPTOR *ppfd)
  91. {
  92. HMODULE hDll;
  93. PFN4 pfn = (PFN4)GetAPI(szOpenGL, "wglSetPixelFormat", &hDll);
  94. BOOL bRet = FALSE;
  95. gbSetPixelFormatCalled = TRUE;
  96. if (pfn)
  97. {
  98. bRet = (*pfn)(hdc, iPixelFormat, ppfd);
  99. // Metafile if necessary
  100. if (bRet)
  101. {
  102. if (IS_ALTDC_TYPE(hdc) && !IS_METADC16_TYPE(hdc))
  103. {
  104. PLDC pldc;
  105. DC_PLDC(hdc, pldc, FALSE);
  106. if (pldc->iType == LO_METADC)
  107. {
  108. if (!MF_SetPixelFormat(hdc, iPixelFormat, ppfd))
  109. {
  110. bRet = FALSE;
  111. }
  112. }
  113. }
  114. }
  115. }
  116. if (hDll)
  117. {
  118. FreeLibrary(hDll);
  119. }
  120. return bRet;
  121. }
  122. /***********************************************************************/
  123. BOOL WINAPI SwapBuffers(HDC hdc)
  124. {
  125. HMODULE hDll;
  126. PFN5 pfn = (PFN5)GetAPI(szOpenGL, "wglSwapBuffers", &hDll);
  127. BOOL bRet = FALSE;
  128. if (pfn)
  129. {
  130. bRet = (*pfn)(hdc);
  131. }
  132. if (hDll)
  133. {
  134. FreeLibrary(hDll);
  135. }
  136. return bRet;
  137. }
  138. /***********************************************************************/
  139. // These stubs are for the cases where OpenGL cannot handle the pixel
  140. // format request itself because it involves device-specific information
  141. // In that case OpenGL asks GDI to go ask the display driver in kernel
  142. // mode
  143. int APIENTRY GdiDescribePixelFormat(HDC hdc, int iPixelFormat, UINT nBytes,
  144. LPPIXELFORMATDESCRIPTOR ppfd)
  145. {
  146. return NtGdiDescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd);
  147. }
  148. BOOL APIENTRY GdiSetPixelFormat(HDC hdc, int iPixelFormat)
  149. {
  150. return NtGdiSetPixelFormat(hdc, iPixelFormat);
  151. }
  152. BOOL APIENTRY GdiSwapBuffers(HDC hdc)
  153. {
  154. return NtGdiSwapBuffers(hdc);
  155. }