[WIN32K]
[reactos.git] / reactos / win32ss / gdi / ntgdi / wingl.c
1 /*
2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: subsystems/win32/win32k/objects/wingl.c
5 * PURPOSE: WinGL API
6 * PROGRAMMER:
7 */
8
9 #include <win32k.h>
10
11 #define NDEBUG
12 #include <debug.h>
13
14 static
15 INT
16 FASTCALL
17 IntGetipfdDevMax(PDC pdc)
18 {
19 INT Ret = 0;
20 PPDEVOBJ ppdev = pdc->ppdev;
21
22 if (ppdev->flFlags & PDEV_META_DEVICE)
23 {
24 return 0;
25 }
26
27 if (ppdev->DriverFunctions.DescribePixelFormat)
28 {
29 Ret = ppdev->DriverFunctions.DescribePixelFormat(
30 ppdev->dhpdev,
31 1,
32 0,
33 NULL);
34 }
35
36 if (Ret) pdc->ipfdDevMax = Ret;
37
38 return Ret;
39 }
40
41 _Success_(return != 0)
42 INT
43 APIENTRY
44 NtGdiDescribePixelFormat(
45 _In_ HDC hdc,
46 _In_ INT ipfd,
47 _In_ UINT cjpfd,
48 _When_(cjpfd != 0, _Out_) PPIXELFORMATDESCRIPTOR ppfd)
49 {
50 PDC pdc;
51 PPDEVOBJ ppdev;
52 INT Ret = 0;
53 PIXELFORMATDESCRIPTOR pfdSafe;
54
55 if ((ppfd == NULL) && (cjpfd != 0)) return 0;
56
57 pdc = DC_LockDc(hdc);
58 if (!pdc)
59 {
60 EngSetLastError(ERROR_INVALID_HANDLE);
61 return 0;
62 }
63
64 if (!pdc->ipfdDevMax)
65 IntGetipfdDevMax(pdc);
66
67 if ((ipfd < 1) || (ipfd > pdc->ipfdDevMax))
68 {
69 EngSetLastError(ERROR_INVALID_PARAMETER);
70 goto Exit;
71 }
72
73 ppdev = pdc->ppdev;
74
75 if (ppdev->flFlags & PDEV_META_DEVICE)
76 {
77 UNIMPLEMENTED;
78 goto Exit;
79 }
80
81 if (ppdev->DriverFunctions.DescribePixelFormat)
82 {
83 Ret = ppdev->DriverFunctions.DescribePixelFormat(
84 ppdev->dhpdev,
85 ipfd,
86 sizeof(pfdSafe),
87 &pfdSafe);
88 }
89
90 if (Ret && cjpfd)
91 {
92 _SEH2_TRY
93 {
94 cjpfd = min(cjpfd, sizeof(PIXELFORMATDESCRIPTOR));
95 ProbeForWrite(ppfd, cjpfd, 1);
96 RtlCopyMemory(ppfd, &pfdSafe, cjpfd);
97 }
98 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
99 {
100 SetLastNtError(_SEH2_GetExceptionCode());
101 }
102 _SEH2_END;
103 }
104
105 Exit:
106 DC_UnlockDc(pdc);
107 return Ret;
108 }
109
110
111 BOOL
112 APIENTRY
113 NtGdiSetPixelFormat(
114 _In_ HDC hdc,
115 _In_ INT ipfd)
116 {
117 PDC pdc;
118 PPDEVOBJ ppdev;
119 HWND hWnd;
120 PWNDOBJ pWndObj;
121 SURFOBJ *pso = NULL;
122 BOOL Ret = FALSE;
123
124 pdc = DC_LockDc(hdc);
125 if (!pdc)
126 {
127 EngSetLastError(ERROR_INVALID_HANDLE);
128 return FALSE;
129 }
130
131 if (!pdc->ipfdDevMax)
132 IntGetipfdDevMax(pdc);
133
134 if ( ipfd < 1 ||
135 ipfd > pdc->ipfdDevMax )
136 {
137 EngSetLastError(ERROR_INVALID_PARAMETER);
138 goto Exit;
139 }
140
141 UserEnterExclusive();
142 hWnd = UserGethWnd(hdc, &pWndObj);
143 UserLeave();
144
145 if (!hWnd)
146 {
147 EngSetLastError(ERROR_INVALID_WINDOW_STYLE);
148 goto Exit;
149 }
150
151 ppdev = pdc->ppdev;
152
153 /*
154 WndObj is needed so exit on NULL pointer.
155 */
156 if (pWndObj)
157 pso = pWndObj->psoOwner;
158 else
159 {
160 EngSetLastError(ERROR_INVALID_PIXEL_FORMAT);
161 goto Exit;
162 }
163
164 if (ppdev->flFlags & PDEV_META_DEVICE)
165 {
166 UNIMPLEMENTED;
167 goto Exit;
168 }
169
170 if (ppdev->DriverFunctions.SetPixelFormat)
171 {
172 Ret = ppdev->DriverFunctions.SetPixelFormat(
173 pso,
174 ipfd,
175 hWnd);
176 }
177
178 Exit:
179 DC_UnlockDc(pdc);
180 return Ret;
181 }
182
183 BOOL
184 APIENTRY
185 NtGdiSwapBuffers(
186 _In_ HDC hdc)
187 {
188 PDC pdc;
189 PPDEVOBJ ppdev;
190 HWND hWnd;
191 PWNDOBJ pWndObj;
192 SURFOBJ *pso = NULL;
193 BOOL Ret = FALSE;
194
195 pdc = DC_LockDc(hdc);
196 if (!pdc)
197 {
198 EngSetLastError(ERROR_INVALID_HANDLE);
199 return FALSE;
200 }
201
202 UserEnterExclusive();
203 hWnd = UserGethWnd(hdc, &pWndObj);
204 UserLeave();
205
206 if (!hWnd)
207 {
208 EngSetLastError(ERROR_INVALID_WINDOW_STYLE);
209 goto Exit;
210 }
211
212 ppdev = pdc->ppdev;
213
214 /*
215 WndObj is needed so exit on NULL pointer.
216 */
217 if (pWndObj)
218 pso = pWndObj->psoOwner;
219 else
220 {
221 EngSetLastError(ERROR_INVALID_PIXEL_FORMAT);
222 goto Exit;
223 }
224
225 if (ppdev->flFlags & PDEV_META_DEVICE)
226 {
227 UNIMPLEMENTED;
228 goto Exit;
229 }
230
231 if (ppdev->DriverFunctions.SwapBuffers)
232 {
233 Ret = ppdev->DriverFunctions.SwapBuffers(pso, pWndObj);
234 }
235
236 Exit:
237 DC_UnlockDc(pdc);
238 return Ret;
239 }
240
241 /* EOF */