First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / dixmods / extmod / xf86dga.c
blob0736167f89fa8bbe5d180973ca6f432ef6338294
2 /*
4 Copyright (c) 1995 Jon Tombs
5 Copyright (c) 1995, 1996, 1999 XFree86 Inc
7 */
9 #ifdef HAVE_XORG_CONFIG_H
10 #include <xorg-config.h>
11 #endif
13 #define NEED_REPLIES
14 #define NEED_EVENTS
15 #include <X11/X.h>
16 #include <X11/Xproto.h>
17 #include "misc.h"
18 #include "dixstruct.h"
19 #include "extnsionst.h"
20 #include "colormapst.h"
21 #include "cursorstr.h"
22 #include "scrnintstr.h"
23 #include "servermd.h"
24 #define _XF86DGA_SERVER_
25 #include <X11/extensions/xf86dga.h>
26 #include <X11/extensions/xf86dgastr.h>
27 #include "swaprep.h"
28 #include "dgaproc.h"
30 #include "xf86dgaext.h"
33 static DISPATCH_PROC(ProcXF86DGADirectVideo);
34 static DISPATCH_PROC(ProcXF86DGAGetVidPage);
35 static DISPATCH_PROC(ProcXF86DGAGetVideoLL);
36 static DISPATCH_PROC(ProcXF86DGAGetViewPortSize);
37 static DISPATCH_PROC(ProcXF86DGASetVidPage);
38 static DISPATCH_PROC(ProcXF86DGASetViewPort);
39 static DISPATCH_PROC(ProcXF86DGAInstallColormap);
40 static DISPATCH_PROC(ProcXF86DGAQueryDirectVideo);
41 static DISPATCH_PROC(ProcXF86DGAViewPortChanged);
44 static int
45 ProcXF86DGAGetVideoLL(ClientPtr client)
47 REQUEST(xXF86DGAGetVideoLLReq);
48 xXF86DGAGetVideoLLReply rep;
49 XDGAModeRec mode;
50 int num, offset, flags;
51 char *name;
53 if (stuff->screen > screenInfo.numScreens)
54 return BadValue;
56 REQUEST_SIZE_MATCH(xXF86DGAGetVideoLLReq);
57 rep.type = X_Reply;
58 rep.length = 0;
59 rep.sequenceNumber = client->sequence;
61 if(!DGAAvailable(stuff->screen))
62 return (DGAErrorBase + XF86DGANoDirectVideoMode);
64 if(!(num = DGAGetOldDGAMode(stuff->screen)))
65 return (DGAErrorBase + XF86DGANoDirectVideoMode);
67 /* get the parameters for the mode that best matches */
68 DGAGetModeInfo(stuff->screen, &mode, num);
70 if(!DGAOpenFramebuffer(stuff->screen, &name,
71 (unsigned char**)(&rep.offset),
72 (int*)(&rep.bank_size), &offset, &flags))
73 return BadAlloc;
75 rep.offset += mode.offset;
76 rep.width = mode.bytesPerScanline / (mode.bitsPerPixel >> 3);
77 rep.ram_size = rep.bank_size >> 10;
79 WriteToClient(client, SIZEOF(xXF86DGAGetVideoLLReply), (char *)&rep);
80 return (client->noClientException);
83 static int
84 ProcXF86DGADirectVideo(ClientPtr client)
86 int num;
87 PixmapPtr pix;
88 XDGAModeRec mode;
89 REQUEST(xXF86DGADirectVideoReq);
91 if (stuff->screen > screenInfo.numScreens)
92 return BadValue;
94 REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
96 if (!DGAAvailable(stuff->screen))
97 return DGAErrorBase + XF86DGANoDirectVideoMode;
99 if (stuff->enable & XF86DGADirectGraphics) {
100 if(!(num = DGAGetOldDGAMode(stuff->screen)))
101 return (DGAErrorBase + XF86DGANoDirectVideoMode);
102 } else
103 num = 0;
105 if(Success != DGASetMode(stuff->screen, num, &mode, &pix))
106 return (DGAErrorBase + XF86DGAScreenNotActive);
108 DGASetInputMode (stuff->screen,
109 (stuff->enable & XF86DGADirectKeyb) != 0,
110 (stuff->enable & XF86DGADirectMouse) != 0);
112 return (client->noClientException);
115 static int
116 ProcXF86DGAGetViewPortSize(ClientPtr client)
118 int num;
119 XDGAModeRec mode;
120 REQUEST(xXF86DGAGetViewPortSizeReq);
121 xXF86DGAGetViewPortSizeReply rep;
123 if (stuff->screen > screenInfo.numScreens)
124 return BadValue;
126 REQUEST_SIZE_MATCH(xXF86DGAGetViewPortSizeReq);
127 rep.type = X_Reply;
128 rep.length = 0;
129 rep.sequenceNumber = client->sequence;
131 if (!DGAAvailable(stuff->screen))
132 return (DGAErrorBase + XF86DGANoDirectVideoMode);
134 if(!(num = DGAGetOldDGAMode(stuff->screen)))
135 return (DGAErrorBase + XF86DGANoDirectVideoMode);
137 DGAGetModeInfo(stuff->screen, &mode, num);
139 rep.width = mode.viewportWidth;
140 rep.height = mode.viewportHeight;
142 WriteToClient(client, SIZEOF(xXF86DGAGetViewPortSizeReply), (char *)&rep);
143 return (client->noClientException);
146 static int
147 ProcXF86DGASetViewPort(ClientPtr client)
149 REQUEST(xXF86DGASetViewPortReq);
151 if (stuff->screen > screenInfo.numScreens)
152 return BadValue;
154 REQUEST_SIZE_MATCH(xXF86DGASetViewPortReq);
156 if (!DGAActive(stuff->screen))
158 int num;
159 PixmapPtr pix;
160 XDGAModeRec mode;
162 if(!(num = DGAGetOldDGAMode(stuff->screen)))
163 return (DGAErrorBase + XF86DGANoDirectVideoMode);
164 if(Success != DGASetMode(stuff->screen, num, &mode, &pix))
165 return (DGAErrorBase + XF86DGAScreenNotActive);
168 if (DGASetViewport(stuff->screen, stuff->x, stuff->y, DGA_FLIP_RETRACE)
169 != Success)
170 return DGAErrorBase + XF86DGADirectNotActivated;
172 return (client->noClientException);
175 static int
176 ProcXF86DGAGetVidPage(ClientPtr client)
178 REQUEST(xXF86DGAGetVidPageReq);
179 xXF86DGAGetVidPageReply rep;
181 if (stuff->screen > screenInfo.numScreens)
182 return BadValue;
184 REQUEST_SIZE_MATCH(xXF86DGAGetVidPageReq);
185 rep.type = X_Reply;
186 rep.length = 0;
187 rep.sequenceNumber = client->sequence;
188 rep.vpage = 0; /* silently fail */
190 WriteToClient(client, SIZEOF(xXF86DGAGetVidPageReply), (char *)&rep);
191 return (client->noClientException);
195 static int
196 ProcXF86DGASetVidPage(ClientPtr client)
198 REQUEST(xXF86DGASetVidPageReq);
200 if (stuff->screen > screenInfo.numScreens)
201 return BadValue;
203 REQUEST_SIZE_MATCH(xXF86DGASetVidPageReq);
205 /* silently fail */
207 return (client->noClientException);
211 static int
212 ProcXF86DGAInstallColormap(ClientPtr client)
214 ColormapPtr pcmp;
215 REQUEST(xXF86DGAInstallColormapReq);
217 REQUEST_SIZE_MATCH(xXF86DGAInstallColormapReq);
219 if (!DGAActive(stuff->screen))
220 return (DGAErrorBase + XF86DGADirectNotActivated);
222 pcmp = (ColormapPtr )LookupIDByType(stuff->id, RT_COLORMAP);
223 if (pcmp) {
224 DGAInstallCmap(pcmp);
225 return (client->noClientException);
226 } else {
227 client->errorValue = stuff->id;
228 return (BadColor);
232 static int
233 ProcXF86DGAQueryDirectVideo(ClientPtr client)
235 REQUEST(xXF86DGAQueryDirectVideoReq);
236 xXF86DGAQueryDirectVideoReply rep;
238 if (stuff->screen > screenInfo.numScreens)
239 return BadValue;
241 REQUEST_SIZE_MATCH(xXF86DGAQueryDirectVideoReq);
242 rep.type = X_Reply;
243 rep.length = 0;
244 rep.sequenceNumber = client->sequence;
245 rep.flags = 0;
247 if (DGAAvailable(stuff->screen))
248 rep.flags = XF86DGADirectPresent;
250 WriteToClient(client, SIZEOF(xXF86DGAQueryDirectVideoReply), (char *)&rep);
251 return (client->noClientException);
254 static int
255 ProcXF86DGAViewPortChanged(ClientPtr client)
257 REQUEST(xXF86DGAViewPortChangedReq);
258 xXF86DGAViewPortChangedReply rep;
260 if (stuff->screen > screenInfo.numScreens)
261 return BadValue;
263 REQUEST_SIZE_MATCH(xXF86DGAViewPortChangedReq);
265 if (!DGAActive(stuff->screen))
266 return (DGAErrorBase + XF86DGADirectNotActivated);
268 rep.type = X_Reply;
269 rep.length = 0;
270 rep.sequenceNumber = client->sequence;
271 rep.result = 1;
273 WriteToClient(client, SIZEOF(xXF86DGAViewPortChangedReply), (char *)&rep);
274 return (client->noClientException);
278 ProcXF86DGADispatch(register ClientPtr client)
280 REQUEST(xReq);
282 switch (stuff->data)
284 case X_XF86DGAGetVideoLL:
285 return ProcXF86DGAGetVideoLL(client);
286 case X_XF86DGADirectVideo:
287 return ProcXF86DGADirectVideo(client);
288 case X_XF86DGAGetViewPortSize:
289 return ProcXF86DGAGetViewPortSize(client);
290 case X_XF86DGASetViewPort:
291 return ProcXF86DGASetViewPort(client);
292 case X_XF86DGAGetVidPage:
293 return ProcXF86DGAGetVidPage(client);
294 case X_XF86DGASetVidPage:
295 return ProcXF86DGASetVidPage(client);
296 case X_XF86DGAInstallColormap:
297 return ProcXF86DGAInstallColormap(client);
298 case X_XF86DGAQueryDirectVideo:
299 return ProcXF86DGAQueryDirectVideo(client);
300 case X_XF86DGAViewPortChanged:
301 return ProcXF86DGAViewPortChanged(client);
302 default:
303 return BadRequest;