Update PDEVOBJ and GRAPHICS_DEVICE fields
[reactos.git] / reactos / subsystems / win32 / win32k / objects / wingl.c
1 /*
2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$ */
20
21 #include <w32k.h>
22
23 #define NDEBUG
24 #include <debug.h>
25
26 static
27 INT
28 FASTCALL
29 IntGetipfdDevMax(PDC pdc)
30 {
31 INT Ret = 0;
32 PPDEVOBJ ppdev = pdc->ppdev;
33
34 if (ppdev->flFlags & PDEV_META_DEVICE)
35 {
36 return 0;
37 }
38
39 if (ppdev->DriverFunctions.DescribePixelFormat)
40 {
41 Ret = ppdev->DriverFunctions.DescribePixelFormat(
42 ppdev->dhpdev,
43 1,
44 0,
45 NULL);
46 }
47
48 if (Ret) pdc->ipfdDevMax = Ret;
49
50 return Ret;
51 }
52
53
54 INT
55 APIENTRY
56 NtGdiDescribePixelFormat(HDC hDC,
57 INT PixelFormat,
58 UINT BufSize,
59 LPPIXELFORMATDESCRIPTOR pfd)
60 {
61 PDC pdc;
62 PPDEVOBJ ppdev;
63 INT Ret = 0;
64 PIXELFORMATDESCRIPTOR pfdSafe;
65 NTSTATUS Status = STATUS_SUCCESS;
66
67 if (!BufSize) return 0;
68
69 pdc = DC_LockDc(hDC);
70 if (!pdc)
71 {
72 SetLastWin32Error(ERROR_INVALID_HANDLE);
73 return 0;
74 }
75
76 if (!pdc->ipfdDevMax) IntGetipfdDevMax(pdc);
77
78 if ( BufSize < sizeof(PIXELFORMATDESCRIPTOR) ||
79 PixelFormat < 1 ||
80 PixelFormat > pdc->ipfdDevMax )
81 {
82 SetLastWin32Error(ERROR_INVALID_PARAMETER);
83 goto Exit;
84 }
85
86 ppdev = pdc->ppdev;
87
88 if (ppdev->flFlags & PDEV_META_DEVICE)
89 {
90 UNIMPLEMENTED;
91 goto Exit;
92 }
93
94 if (ppdev->DriverFunctions.DescribePixelFormat)
95 {
96 Ret = ppdev->DriverFunctions.DescribePixelFormat(
97 ppdev->dhpdev,
98 PixelFormat,
99 sizeof(PIXELFORMATDESCRIPTOR),
100 &pfdSafe);
101 }
102
103 _SEH2_TRY
104 {
105 ProbeForWrite( pfd,
106 sizeof(PIXELFORMATDESCRIPTOR),
107 1);
108 RtlCopyMemory(&pfdSafe, pfd, sizeof(PIXELFORMATDESCRIPTOR));
109 }
110 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
111 {
112 Status = _SEH2_GetExceptionCode();
113 }
114 _SEH2_END;
115
116 if (!NT_SUCCESS(Status)) SetLastNtError(Status);
117
118 Exit:
119 DC_UnlockDc(pdc);
120 return Ret;
121 }
122
123
124 BOOL
125 APIENTRY
126 NtGdiSetPixelFormat(
127 IN HDC hdc,
128 IN INT ipfd)
129 {
130 PDC pdc;
131 PPDEVOBJ ppdev;
132 HWND hWnd;
133 PWNDOBJ pWndObj;
134 SURFOBJ *pso = NULL;
135 BOOL Ret = FALSE;
136
137 pdc = DC_LockDc(hdc);
138 if (!pdc)
139 {
140 SetLastWin32Error(ERROR_INVALID_HANDLE);
141 return FALSE;
142 }
143
144 if (!pdc->ipfdDevMax) IntGetipfdDevMax(pdc);
145
146 if ( ipfd < 1 ||
147 ipfd > pdc->ipfdDevMax )
148 {
149 SetLastWin32Error(ERROR_INVALID_PARAMETER);
150 goto Exit;
151 }
152
153 UserEnterExclusive();
154 hWnd = UserGethWnd(hdc, &pWndObj);
155 UserLeave();
156
157 if (!hWnd)
158 {
159 SetLastWin32Error(ERROR_INVALID_WINDOW_STYLE);
160 goto Exit;
161 }
162
163 ppdev = pdc->ppdev;
164
165 /*
166 WndObj is needed so exit on NULL pointer.
167 */
168 if (pWndObj) pso = pWndObj->psoOwner;
169 else
170 {
171 SetLastWin32Error(ERROR_INVALID_PIXEL_FORMAT);
172 goto Exit;
173 }
174
175 if (ppdev->flFlags & PDEV_META_DEVICE)
176 {
177 UNIMPLEMENTED;
178 goto Exit;
179 }
180
181 if (ppdev->DriverFunctions.SetPixelFormat)
182 {
183 Ret = ppdev->DriverFunctions.SetPixelFormat(
184 pso,
185 ipfd,
186 hWnd);
187 }
188
189 Exit:
190 DC_UnlockDc(pdc);
191 return Ret;
192 }
193
194 BOOL
195 APIENTRY
196 NtGdiSwapBuffers(HDC hDC)
197 {
198 UNIMPLEMENTED;
199 return FALSE;
200 }
201
202 /* EOF */