39dabbce8c47d52d7a0ee93ff951458d1bb52a03
[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 {
66 if (!IntGetipfdDevMax(pdc))
67 {
68 /* EngSetLastError ? */
69 goto Exit;
70 }
71 }
72
73 if (!ppfd)
74 {
75 Ret = pdc->ipfdDevMax;
76 goto Exit;
77 }
78
79 if ((ipfd < 1) || (ipfd > pdc->ipfdDevMax))
80 {
81 EngSetLastError(ERROR_INVALID_PARAMETER);
82 goto Exit;
83 }
84
85 ppdev = pdc->ppdev;
86
87 if (ppdev->flFlags & PDEV_META_DEVICE)
88 {
89 UNIMPLEMENTED;
90 goto Exit;
91 }
92
93 if (ppdev->DriverFunctions.DescribePixelFormat)
94 {
95 Ret = ppdev->DriverFunctions.DescribePixelFormat(
96 ppdev->dhpdev,
97 ipfd,
98 sizeof(pfdSafe),
99 &pfdSafe);
100 }
101
102 if (Ret && cjpfd)
103 {
104 _SEH2_TRY
105 {
106 cjpfd = min(cjpfd, sizeof(PIXELFORMATDESCRIPTOR));
107 ProbeForWrite(ppfd, cjpfd, 1);
108 RtlCopyMemory(ppfd, &pfdSafe, cjpfd);
109 }
110 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
111 {
112 SetLastNtError(_SEH2_GetExceptionCode());
113 }
114 _SEH2_END;
115 }
116
117 Exit:
118 DC_UnlockDc(pdc);
119 return Ret;
120 }
121
122
123 BOOL
124 APIENTRY
125 NtGdiSetPixelFormat(
126 _In_ HDC hdc,
127 _In_ INT ipfd)
128 {
129 PDC pdc;
130 PPDEVOBJ ppdev;
131 HWND hWnd;
132 PWNDOBJ pWndObj;
133 SURFOBJ *pso = NULL;
134 BOOL Ret = FALSE;
135
136 DPRINT1("Setting pixel format from win32k!\n");
137
138 pdc = DC_LockDc(hdc);
139 if (!pdc)
140 {
141 EngSetLastError(ERROR_INVALID_HANDLE);
142 return FALSE;
143 }
144
145 if (!pdc->ipfdDevMax)
146 IntGetipfdDevMax(pdc);
147
148 if ( ipfd < 1 ||
149 ipfd > pdc->ipfdDevMax )
150 {
151 EngSetLastError(ERROR_INVALID_PARAMETER);
152 goto Exit;
153 }
154
155 UserEnterExclusive();
156 hWnd = UserGethWnd(hdc, &pWndObj);
157 UserLeave();
158
159 if (!hWnd)
160 {
161 EngSetLastError(ERROR_INVALID_WINDOW_STYLE);
162 goto Exit;
163 }
164
165 ppdev = pdc->ppdev;
166
167 /*
168 WndObj is needed so exit on NULL pointer.
169 */
170 if (pWndObj)
171 pso = pWndObj->psoOwner;
172 else
173 {
174 EngSetLastError(ERROR_INVALID_PIXEL_FORMAT);
175 goto Exit;
176 }
177
178 if (ppdev->flFlags & PDEV_META_DEVICE)
179 {
180 UNIMPLEMENTED;
181 goto Exit;
182 }
183
184 if (ppdev->DriverFunctions.SetPixelFormat)
185 {
186 Ret = ppdev->DriverFunctions.SetPixelFormat(
187 pso,
188 ipfd,
189 hWnd);
190 }
191
192 Exit:
193 DC_UnlockDc(pdc);
194 return Ret;
195 }
196
197 BOOL
198 APIENTRY
199 NtGdiSwapBuffers(
200 _In_ HDC hdc)
201 {
202 PDC pdc;
203 PPDEVOBJ ppdev;
204 HWND hWnd;
205 PWNDOBJ pWndObj;
206 SURFOBJ *pso = NULL;
207 BOOL Ret = FALSE;
208
209 pdc = DC_LockDc(hdc);
210 if (!pdc)
211 {
212 EngSetLastError(ERROR_INVALID_HANDLE);
213 return FALSE;
214 }
215
216 UserEnterExclusive();
217 hWnd = UserGethWnd(hdc, &pWndObj);
218 UserLeave();
219
220 if (!hWnd)
221 {
222 EngSetLastError(ERROR_INVALID_WINDOW_STYLE);
223 goto Exit;
224 }
225
226 ppdev = pdc->ppdev;
227
228 /*
229 WndObj is needed so exit on NULL pointer.
230 */
231 if (pWndObj)
232 pso = pWndObj->psoOwner;
233 else
234 {
235 EngSetLastError(ERROR_INVALID_PIXEL_FORMAT);
236 goto Exit;
237 }
238
239 if (ppdev->flFlags & PDEV_META_DEVICE)
240 {
241 UNIMPLEMENTED;
242 goto Exit;
243 }
244
245 if (ppdev->DriverFunctions.SwapBuffers)
246 {
247 Ret = ppdev->DriverFunctions.SwapBuffers(pso, pWndObj);
248 }
249
250 Exit:
251 DC_UnlockDc(pdc);
252 return Ret;
253 }
254
255 /* EOF */