4a4117e2f0065daa5f7c20678e2f20835071e6ce
[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) IntGetipfdDevMax(pdc);
65
66 if ((ipfd < 1) || (ipfd > pdc->ipfdDevMax))
67 {
68 EngSetLastError(ERROR_INVALID_PARAMETER);
69 goto Exit;
70 }
71
72 ppdev = pdc->ppdev;
73
74 if (ppdev->flFlags & PDEV_META_DEVICE)
75 {
76 UNIMPLEMENTED;
77 goto Exit;
78 }
79
80 if (ppdev->DriverFunctions.DescribePixelFormat)
81 {
82 Ret = ppdev->DriverFunctions.DescribePixelFormat(
83 ppdev->dhpdev,
84 ipfd,
85 sizeof(pfdSafe),
86 &pfdSafe);
87 }
88
89 if (Ret && cjpfd)
90 {
91 _SEH2_TRY
92 {
93 cjpfd = min(cjpfd, sizeof(PIXELFORMATDESCRIPTOR));
94 ProbeForWrite(ppfd, cjpfd, 1);
95 RtlCopyMemory(ppfd, &pfdSafe, cjpfd);
96 }
97 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
98 {
99 SetLastNtError(_SEH2_GetExceptionCode());
100 }
101 _SEH2_END;
102 }
103
104 Exit:
105 DC_UnlockDc(pdc);
106 return Ret;
107 }
108
109
110 BOOL
111 APIENTRY
112 NtGdiSetPixelFormat(
113 IN HDC hdc,
114 IN INT ipfd)
115 {
116 PDC pdc;
117 PPDEVOBJ ppdev;
118 HWND hWnd;
119 PWNDOBJ pWndObj;
120 SURFOBJ *pso = NULL;
121 BOOL Ret = FALSE;
122
123 pdc = DC_LockDc(hdc);
124 if (!pdc)
125 {
126 EngSetLastError(ERROR_INVALID_HANDLE);
127 return FALSE;
128 }
129
130 if (!pdc->ipfdDevMax) IntGetipfdDevMax(pdc);
131
132 if ( ipfd < 1 ||
133 ipfd > pdc->ipfdDevMax )
134 {
135 EngSetLastError(ERROR_INVALID_PARAMETER);
136 goto Exit;
137 }
138
139 UserEnterExclusive();
140 hWnd = UserGethWnd(hdc, &pWndObj);
141 UserLeave();
142
143 if (!hWnd)
144 {
145 EngSetLastError(ERROR_INVALID_WINDOW_STYLE);
146 goto Exit;
147 }
148
149 ppdev = pdc->ppdev;
150
151 /*
152 WndObj is needed so exit on NULL pointer.
153 */
154 if (pWndObj) pso = pWndObj->psoOwner;
155 else
156 {
157 EngSetLastError(ERROR_INVALID_PIXEL_FORMAT);
158 goto Exit;
159 }
160
161 if (ppdev->flFlags & PDEV_META_DEVICE)
162 {
163 UNIMPLEMENTED;
164 goto Exit;
165 }
166
167 if (ppdev->DriverFunctions.SetPixelFormat)
168 {
169 Ret = ppdev->DriverFunctions.SetPixelFormat(
170 pso,
171 ipfd,
172 hWnd);
173 }
174
175 Exit:
176 DC_UnlockDc(pdc);
177 return Ret;
178 }
179
180 BOOL
181 APIENTRY
182 NtGdiSwapBuffers(HDC hDC)
183 {
184 UNIMPLEMENTED;
185 return FALSE;
186 }
187
188 /* EOF */