Sync with trunk r63743.
[reactos.git] / 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 DPRINT1("Setting pixel format from win32k!\n");
125
126 pdc = DC_LockDc(hdc);
127 if (!pdc)
128 {
129 EngSetLastError(ERROR_INVALID_HANDLE);
130 return FALSE;
131 }
132
133 if (!pdc->ipfdDevMax)
134 IntGetipfdDevMax(pdc);
135
136 if ( ipfd < 1 ||
137 ipfd > pdc->ipfdDevMax )
138 {
139 EngSetLastError(ERROR_INVALID_PARAMETER);
140 goto Exit;
141 }
142
143 UserEnterExclusive();
144 hWnd = UserGethWnd(hdc, &pWndObj);
145 UserLeave();
146
147 if (!hWnd)
148 {
149 EngSetLastError(ERROR_INVALID_WINDOW_STYLE);
150 goto Exit;
151 }
152
153 ppdev = pdc->ppdev;
154
155 /*
156 WndObj is needed so exit on NULL pointer.
157 */
158 if (pWndObj)
159 pso = pWndObj->psoOwner;
160 else
161 {
162 EngSetLastError(ERROR_INVALID_PIXEL_FORMAT);
163 goto Exit;
164 }
165
166 if (ppdev->flFlags & PDEV_META_DEVICE)
167 {
168 UNIMPLEMENTED;
169 goto Exit;
170 }
171
172 if (ppdev->DriverFunctions.SetPixelFormat)
173 {
174 Ret = ppdev->DriverFunctions.SetPixelFormat(
175 pso,
176 ipfd,
177 hWnd);
178 }
179
180 Exit:
181 DC_UnlockDc(pdc);
182 return Ret;
183 }
184
185 BOOL
186 APIENTRY
187 NtGdiSwapBuffers(
188 _In_ HDC hdc)
189 {
190 PDC pdc;
191 PPDEVOBJ ppdev;
192 HWND hWnd;
193 PWNDOBJ pWndObj;
194 SURFOBJ *pso = NULL;
195 BOOL Ret = FALSE;
196
197 pdc = DC_LockDc(hdc);
198 if (!pdc)
199 {
200 EngSetLastError(ERROR_INVALID_HANDLE);
201 return FALSE;
202 }
203
204 UserEnterExclusive();
205 hWnd = UserGethWnd(hdc, &pWndObj);
206 UserLeave();
207
208 if (!hWnd)
209 {
210 EngSetLastError(ERROR_INVALID_WINDOW_STYLE);
211 goto Exit;
212 }
213
214 ppdev = pdc->ppdev;
215
216 /*
217 WndObj is needed so exit on NULL pointer.
218 */
219 if (pWndObj)
220 pso = pWndObj->psoOwner;
221 else
222 {
223 EngSetLastError(ERROR_INVALID_PIXEL_FORMAT);
224 goto Exit;
225 }
226
227 if (ppdev->flFlags & PDEV_META_DEVICE)
228 {
229 UNIMPLEMENTED;
230 goto Exit;
231 }
232
233 if (ppdev->DriverFunctions.SwapBuffers)
234 {
235 Ret = ppdev->DriverFunctions.SwapBuffers(pso, pWndObj);
236 }
237
238 Exit:
239 DC_UnlockDc(pdc);
240 return Ret;
241 }
242
243 /* EOF */