Mercurial > sdl-ios-xcode
comparison src/video/Xext/Xxf86dga/XF86DGA2.c @ 292:eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Incorporated XFree86 extension libraries into the source
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 05 Mar 2002 19:55:32 +0000 |
parents | |
children | f1b029d3b301 |
comparison
equal
deleted
inserted
replaced
291:68a8a8237c09 | 292:eadc0746dfaf |
---|---|
1 /* $XFree86: xc/lib/Xxf86dga/XF86DGA2.c,v 1.18 2001/08/17 13:27:51 dawes Exp $ */ | |
2 /* | |
3 | |
4 Copyright (c) 1995 Jon Tombs | |
5 Copyright (c) 1995,1996 The XFree86 Project, Inc | |
6 | |
7 */ | |
8 | |
9 /* THIS IS NOT AN X CONSORTIUM STANDARD */ | |
10 | |
11 #ifdef __EMX__ /* needed here to override certain constants in X headers */ | |
12 #define INCL_DOS | |
13 #define INCL_DOSIOCTL | |
14 #include <os2.h> | |
15 #endif | |
16 | |
17 #define NEED_EVENTS | |
18 #define NEED_REPLIES | |
19 #include <X11/Xlibint.h> | |
20 #include "xf86dga.h" | |
21 #include "xf86dgastr.h" | |
22 #include <X11/extensions/Xext.h> | |
23 #include "extutil.h" | |
24 #include <stdio.h> | |
25 | |
26 #if defined(linux) /* Needed for framebuffer console support */ | |
27 #include <sys/ioctl.h> | |
28 #include <linux/fb.h> | |
29 #endif | |
30 | |
31 /* If you change this, change the Bases[] array below as well */ | |
32 #define MAX_HEADS 16 | |
33 | |
34 char *SDL_NAME(xdga_extension_name) = XF86DGANAME; | |
35 | |
36 static XExtensionInfo _xdga_info_data; | |
37 static XExtensionInfo *xdga_info = &_xdga_info_data; | |
38 | |
39 | |
40 Bool SDL_NAME(XDGAMapFramebuffer)(int, char *, unsigned char*, CARD32, CARD32, CARD32); | |
41 void SDL_NAME(XDGAUnmapFramebuffer)(int); | |
42 unsigned char* SDL_NAME(XDGAGetMappedMemory)(int); | |
43 | |
44 #define XDGACheckExtension(dpy,i,val) \ | |
45 XextCheckExtension (dpy, i, SDL_NAME(xdga_extension_name), val) | |
46 | |
47 /***************************************************************************** | |
48 * * | |
49 * private utility routines * | |
50 * * | |
51 *****************************************************************************/ | |
52 | |
53 static int xdga_close_display(Display *dpy, XExtCodes *codes); | |
54 static Bool xdga_wire_to_event(Display *dpy, XEvent *event, xEvent *wire_ev); | |
55 static Status xdga_event_to_wire(Display *dpy, XEvent *event, xEvent *wire_ev); | |
56 | |
57 static XExtensionHooks xdga_extension_hooks = { | |
58 NULL, /* create_gc */ | |
59 NULL, /* copy_gc */ | |
60 NULL, /* flush_gc */ | |
61 NULL, /* free_gc */ | |
62 NULL, /* create_font */ | |
63 NULL, /* free_font */ | |
64 xdga_close_display, /* close_display */ | |
65 xdga_wire_to_event, /* wire_to_event */ | |
66 xdga_event_to_wire, /* event_to_wire */ | |
67 NULL, /* error */ | |
68 NULL, /* error_string */ | |
69 }; | |
70 | |
71 static XEXT_GENERATE_CLOSE_DISPLAY (xdga_close_display, xdga_info) | |
72 | |
73 | |
74 XEXT_GENERATE_FIND_DISPLAY (SDL_NAME(xdga_find_display), xdga_info, | |
75 "XFree86-DGA", | |
76 &xdga_extension_hooks, | |
77 0, NULL) | |
78 | |
79 | |
80 static Status | |
81 xdga_event_to_wire( | |
82 Display *dpy, | |
83 XEvent *event, | |
84 xEvent *wire_ev | |
85 ){ | |
86 return True; | |
87 } | |
88 | |
89 static Bool | |
90 xdga_wire_to_event( | |
91 Display *dpy, | |
92 XEvent *event, | |
93 xEvent *wire_ev | |
94 ){ | |
95 dgaEvent *wire = (dgaEvent *) wire_ev; | |
96 SDL_NAME(XDGAButtonEvent) *bevent; | |
97 SDL_NAME(XDGAKeyEvent) *kevent; | |
98 SDL_NAME(XDGAMotionEvent) *mevent; | |
99 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
100 | |
101 XDGACheckExtension (dpy, info, False); | |
102 | |
103 switch((wire->u.u.type & 0x7f) - info->codes->first_event) { | |
104 case MotionNotify: | |
105 mevent = (SDL_NAME(XDGAMotionEvent)*)event; | |
106 mevent->type = wire->u.u.type & 0x7F; | |
107 mevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire); | |
108 mevent->display = dpy; | |
109 mevent->screen = wire->u.event.screen; | |
110 mevent->time = wire->u.event.time; | |
111 mevent->state = wire->u.event.state; | |
112 mevent->dx = wire->u.event.dx; | |
113 mevent->dy = wire->u.event.dy; | |
114 return True; | |
115 case ButtonPress: | |
116 case ButtonRelease: | |
117 bevent = (SDL_NAME(XDGAButtonEvent)*)event; | |
118 bevent->type = wire->u.u.type & 0x7F; | |
119 bevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire); | |
120 bevent->display = dpy; | |
121 bevent->screen = wire->u.event.screen; | |
122 bevent->time = wire->u.event.time; | |
123 bevent->state = wire->u.event.state; | |
124 bevent->button = wire->u.u.detail; | |
125 return True; | |
126 case KeyPress: | |
127 case KeyRelease: | |
128 kevent = (SDL_NAME(XDGAKeyEvent)*)event; | |
129 kevent->type = wire->u.u.type & 0x7F; | |
130 kevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire); | |
131 kevent->display = dpy; | |
132 kevent->screen = wire->u.event.screen; | |
133 kevent->time = wire->u.event.time; | |
134 kevent->state = wire->u.event.state; | |
135 kevent->keycode = wire->u.u.detail; | |
136 return True; | |
137 } | |
138 | |
139 return False; | |
140 } | |
141 | |
142 | |
143 Bool SDL_NAME(XDGAQueryExtension) ( | |
144 Display *dpy, | |
145 int *event_basep, | |
146 int *error_basep | |
147 ){ | |
148 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
149 | |
150 if (XextHasExtension(info)) { | |
151 *event_basep = info->codes->first_event; | |
152 *error_basep = info->codes->first_error; | |
153 return True; | |
154 } else { | |
155 return False; | |
156 } | |
157 } | |
158 | |
159 | |
160 Bool SDL_NAME(XDGAQueryVersion)( | |
161 Display *dpy, | |
162 int *majorVersion, | |
163 int *minorVersion | |
164 ){ | |
165 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
166 xXDGAQueryVersionReply rep; | |
167 xXDGAQueryVersionReq *req; | |
168 | |
169 XDGACheckExtension (dpy, info, False); | |
170 | |
171 LockDisplay(dpy); | |
172 GetReq(XDGAQueryVersion, req); | |
173 req->reqType = info->codes->major_opcode; | |
174 req->dgaReqType = X_XDGAQueryVersion; | |
175 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { | |
176 UnlockDisplay(dpy); | |
177 SyncHandle(); | |
178 return False; | |
179 } | |
180 *majorVersion = rep.majorVersion; | |
181 *minorVersion = rep.minorVersion; | |
182 UnlockDisplay(dpy); | |
183 SyncHandle(); | |
184 if (*majorVersion >= 2) | |
185 { | |
186 int i, j; | |
187 | |
188 for (i = 0, j = info->codes->first_event; | |
189 i < XF86DGANumberEvents; | |
190 i++, j++) | |
191 { | |
192 XESetWireToEvent (dpy, j, xdga_wire_to_event); | |
193 XESetEventToWire (dpy, j, xdga_event_to_wire); | |
194 } | |
195 SDL_NAME(XDGASetClientVersion)(dpy); | |
196 } | |
197 return True; | |
198 } | |
199 | |
200 Bool SDL_NAME(XDGASetClientVersion)( | |
201 Display *dpy | |
202 ){ | |
203 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
204 xXDGASetClientVersionReq *req; | |
205 | |
206 XDGACheckExtension (dpy, info, False); | |
207 | |
208 LockDisplay(dpy); | |
209 GetReq(XDGASetClientVersion, req); | |
210 req->reqType = info->codes->major_opcode; | |
211 req->dgaReqType = X_XDGASetClientVersion; | |
212 req->major = XDGA_MAJOR_VERSION; | |
213 req->minor = XDGA_MINOR_VERSION; | |
214 UnlockDisplay(dpy); | |
215 SyncHandle(); | |
216 return True; | |
217 } | |
218 | |
219 Bool SDL_NAME(XDGAOpenFramebuffer)( | |
220 Display *dpy, | |
221 int screen | |
222 ){ | |
223 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
224 xXDGAOpenFramebufferReply rep; | |
225 xXDGAOpenFramebufferReq *req; | |
226 char *deviceName = NULL; | |
227 Bool ret; | |
228 | |
229 XDGACheckExtension (dpy, info, False); | |
230 | |
231 LockDisplay(dpy); | |
232 GetReq(XDGAOpenFramebuffer, req); | |
233 req->reqType = info->codes->major_opcode; | |
234 req->dgaReqType = X_XDGAOpenFramebuffer; | |
235 req->screen = screen; | |
236 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { | |
237 UnlockDisplay(dpy); | |
238 SyncHandle(); | |
239 return False; | |
240 } | |
241 | |
242 if(rep.length) { | |
243 deviceName = Xmalloc(rep.length << 2); | |
244 _XRead(dpy, deviceName, rep.length << 2); | |
245 } | |
246 | |
247 ret = SDL_NAME(XDGAMapFramebuffer)(screen, deviceName, | |
248 (unsigned char*)(long)rep.mem1, | |
249 rep.size, rep.offset, rep.extra); | |
250 | |
251 if(deviceName) | |
252 Xfree(deviceName); | |
253 | |
254 UnlockDisplay(dpy); | |
255 SyncHandle(); | |
256 return ret; | |
257 } | |
258 | |
259 void SDL_NAME(XDGACloseFramebuffer)( | |
260 Display *dpy, | |
261 int screen | |
262 ){ | |
263 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
264 xXDGACloseFramebufferReq *req; | |
265 | |
266 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); | |
267 | |
268 SDL_NAME(XDGAUnmapFramebuffer)(screen); | |
269 | |
270 LockDisplay(dpy); | |
271 GetReq(XDGACloseFramebuffer, req); | |
272 req->reqType = info->codes->major_opcode; | |
273 req->dgaReqType = X_XDGACloseFramebuffer; | |
274 req->screen = screen; | |
275 UnlockDisplay(dpy); | |
276 SyncHandle(); | |
277 } | |
278 | |
279 | |
280 | |
281 SDL_NAME(XDGAMode)* SDL_NAME(XDGAQueryModes)( | |
282 Display *dpy, | |
283 int screen, | |
284 int *num | |
285 ){ | |
286 XExtDisplayInfo *dinfo = SDL_NAME(xdga_find_display) (dpy); | |
287 xXDGAQueryModesReply rep; | |
288 xXDGAQueryModesReq *req; | |
289 SDL_NAME(XDGAMode) *modes = NULL; | |
290 | |
291 *num = 0; | |
292 | |
293 XDGACheckExtension (dpy, dinfo, NULL); | |
294 | |
295 LockDisplay(dpy); | |
296 GetReq(XDGAQueryModes, req); | |
297 req->reqType = dinfo->codes->major_opcode; | |
298 req->dgaReqType = X_XDGAQueryModes; | |
299 req->screen = screen; | |
300 | |
301 if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { | |
302 if(rep.length) { | |
303 xXDGAModeInfo info; | |
304 int i, size; | |
305 char *offset; | |
306 | |
307 size = rep.length << 2; | |
308 size -= rep.number * sz_xXDGAModeInfo; /* find text size */ | |
309 modes = (SDL_NAME(XDGAMode)*)Xmalloc((rep.number * sizeof(SDL_NAME(XDGAMode))) + size); | |
310 offset = (char*)(&modes[rep.number]); /* start of text */ | |
311 | |
312 | |
313 if(modes) { | |
314 for(i = 0; i < rep.number; i++) { | |
315 _XRead(dpy, (char*)(&info), sz_xXDGAModeInfo); | |
316 | |
317 modes[i].num = info.num; | |
318 modes[i].verticalRefresh = | |
319 (float)info.vsync_num / (float)info.vsync_den; | |
320 modes[i].flags = info.flags; | |
321 modes[i].imageWidth = info.image_width; | |
322 modes[i].imageHeight = info.image_height; | |
323 modes[i].pixmapWidth = info.pixmap_width; | |
324 modes[i].pixmapHeight = info.pixmap_height; | |
325 modes[i].bytesPerScanline = info.bytes_per_scanline; | |
326 modes[i].byteOrder = info.byte_order; | |
327 modes[i].depth = info.depth; | |
328 modes[i].bitsPerPixel = info.bpp; | |
329 modes[i].redMask = info.red_mask; | |
330 modes[i].greenMask = info.green_mask; | |
331 modes[i].blueMask = info.blue_mask; | |
332 modes[i].visualClass = info.visual_class; | |
333 modes[i].viewportWidth = info.viewport_width; | |
334 modes[i].viewportHeight = info.viewport_height; | |
335 modes[i].xViewportStep = info.viewport_xstep; | |
336 modes[i].yViewportStep = info.viewport_ystep; | |
337 modes[i].maxViewportX = info.viewport_xmax; | |
338 modes[i].maxViewportY = info.viewport_ymax; | |
339 modes[i].viewportFlags = info.viewport_flags; | |
340 modes[i].reserved1 = info.reserved1; | |
341 modes[i].reserved2 = info.reserved2; | |
342 | |
343 _XRead(dpy, offset, info.name_size); | |
344 modes[i].name = offset; | |
345 offset += info.name_size; | |
346 } | |
347 *num = rep.number; | |
348 } else | |
349 _XEatData(dpy, rep.length << 2); | |
350 } | |
351 } | |
352 | |
353 UnlockDisplay(dpy); | |
354 SyncHandle(); | |
355 | |
356 return modes; | |
357 } | |
358 | |
359 | |
360 SDL_NAME(XDGADevice) * | |
361 SDL_NAME(XDGASetMode)( | |
362 Display *dpy, | |
363 int screen, | |
364 int mode | |
365 ){ | |
366 XExtDisplayInfo *dinfo = SDL_NAME(xdga_find_display) (dpy); | |
367 xXDGASetModeReply rep; | |
368 xXDGASetModeReq *req; | |
369 SDL_NAME(XDGADevice) *dev = NULL; | |
370 Pixmap pid; | |
371 | |
372 XDGACheckExtension (dpy, dinfo, NULL); | |
373 | |
374 LockDisplay(dpy); | |
375 GetReq(XDGASetMode, req); | |
376 req->reqType = dinfo->codes->major_opcode; | |
377 req->dgaReqType = X_XDGASetMode; | |
378 req->screen = screen; | |
379 req->mode = mode; | |
380 req->pid = pid = XAllocID(dpy); | |
381 | |
382 if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { | |
383 if(rep.length) { | |
384 xXDGAModeInfo info; | |
385 int size; | |
386 | |
387 size = rep.length << 2; | |
388 size -= sz_xXDGAModeInfo; /* get text size */ | |
389 | |
390 dev = (SDL_NAME(XDGADevice)*)Xmalloc(sizeof(SDL_NAME(XDGADevice)) + size); | |
391 | |
392 if(dev) { | |
393 _XRead(dpy, (char*)(&info), sz_xXDGAModeInfo); | |
394 | |
395 dev->mode.num = info.num; | |
396 dev->mode.verticalRefresh = | |
397 (float)info.vsync_num / (float)info.vsync_den; | |
398 dev->mode.flags = info.flags; | |
399 dev->mode.imageWidth = info.image_width; | |
400 dev->mode.imageHeight = info.image_height; | |
401 dev->mode.pixmapWidth = info.pixmap_width; | |
402 dev->mode.pixmapHeight = info.pixmap_height; | |
403 dev->mode.bytesPerScanline = info.bytes_per_scanline; | |
404 dev->mode.byteOrder = info.byte_order; | |
405 dev->mode.depth = info.depth; | |
406 dev->mode.bitsPerPixel = info.bpp; | |
407 dev->mode.redMask = info.red_mask; | |
408 dev->mode.greenMask = info.green_mask; | |
409 dev->mode.blueMask = info.blue_mask; | |
410 dev->mode.visualClass = info.visual_class; | |
411 dev->mode.viewportWidth = info.viewport_width; | |
412 dev->mode.viewportHeight = info.viewport_height; | |
413 dev->mode.xViewportStep = info.viewport_xstep; | |
414 dev->mode.yViewportStep = info.viewport_ystep; | |
415 dev->mode.maxViewportX = info.viewport_xmax; | |
416 dev->mode.maxViewportY = info.viewport_ymax; | |
417 dev->mode.viewportFlags = info.viewport_flags; | |
418 dev->mode.reserved1 = info.reserved1; | |
419 dev->mode.reserved2 = info.reserved2; | |
420 | |
421 dev->mode.name = (char*)(&dev[1]); | |
422 _XRead(dpy, dev->mode.name, info.name_size); | |
423 | |
424 dev->pixmap = (rep.flags & XDGAPixmap) ? pid : 0; | |
425 dev->data = SDL_NAME(XDGAGetMappedMemory)(screen); | |
426 | |
427 if(dev->data) | |
428 dev->data += rep.offset; | |
429 } | |
430 /* not sure what to do if the allocation fails */ | |
431 } | |
432 } | |
433 | |
434 UnlockDisplay(dpy); | |
435 SyncHandle(); | |
436 | |
437 return dev; | |
438 } | |
439 | |
440 | |
441 void SDL_NAME(XDGASetViewport)( | |
442 Display *dpy, | |
443 int screen, | |
444 int x, | |
445 int y, | |
446 int flags | |
447 ){ | |
448 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
449 xXDGASetViewportReq *req; | |
450 | |
451 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); | |
452 | |
453 LockDisplay(dpy); | |
454 GetReq(XDGASetViewport, req); | |
455 req->reqType = info->codes->major_opcode; | |
456 req->dgaReqType = X_XDGASetViewport; | |
457 req->screen = screen; | |
458 req->x = x; | |
459 req->y = y; | |
460 req->flags = flags; | |
461 UnlockDisplay(dpy); | |
462 SyncHandle(); | |
463 } | |
464 | |
465 | |
466 void SDL_NAME(XDGAInstallColormap)( | |
467 Display *dpy, | |
468 int screen, | |
469 Colormap cmap | |
470 ){ | |
471 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
472 xXDGAInstallColormapReq *req; | |
473 | |
474 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); | |
475 | |
476 LockDisplay(dpy); | |
477 GetReq(XDGAInstallColormap, req); | |
478 req->reqType = info->codes->major_opcode; | |
479 req->dgaReqType = X_XDGAInstallColormap; | |
480 req->screen = screen; | |
481 req->cmap = cmap; | |
482 UnlockDisplay(dpy); | |
483 SyncHandle(); | |
484 } | |
485 | |
486 void SDL_NAME(XDGASelectInput)( | |
487 Display *dpy, | |
488 int screen, | |
489 long mask | |
490 ){ | |
491 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
492 xXDGASelectInputReq *req; | |
493 | |
494 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); | |
495 | |
496 LockDisplay(dpy); | |
497 GetReq(XDGASelectInput, req); | |
498 req->reqType = info->codes->major_opcode; | |
499 req->dgaReqType = X_XDGASelectInput; | |
500 req->screen = screen; | |
501 req->mask = mask; | |
502 UnlockDisplay(dpy); | |
503 SyncHandle(); | |
504 } | |
505 | |
506 void SDL_NAME(XDGAFillRectangle)( | |
507 Display *dpy, | |
508 int screen, | |
509 int x, | |
510 int y, | |
511 unsigned int width, | |
512 unsigned int height, | |
513 unsigned long color | |
514 ){ | |
515 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
516 xXDGAFillRectangleReq *req; | |
517 | |
518 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); | |
519 | |
520 LockDisplay(dpy); | |
521 GetReq(XDGAFillRectangle, req); | |
522 req->reqType = info->codes->major_opcode; | |
523 req->dgaReqType = X_XDGAFillRectangle; | |
524 req->screen = screen; | |
525 req->x = x; | |
526 req->y = y; | |
527 req->width = width; | |
528 req->height = height; | |
529 req->color = color; | |
530 UnlockDisplay(dpy); | |
531 SyncHandle(); | |
532 } | |
533 | |
534 void SDL_NAME(XDGACopyArea)( | |
535 Display *dpy, | |
536 int screen, | |
537 int srcx, | |
538 int srcy, | |
539 unsigned int width, | |
540 unsigned int height, | |
541 int dstx, | |
542 int dsty | |
543 ){ | |
544 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
545 xXDGACopyAreaReq *req; | |
546 | |
547 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); | |
548 | |
549 LockDisplay(dpy); | |
550 GetReq(XDGACopyArea, req); | |
551 req->reqType = info->codes->major_opcode; | |
552 req->dgaReqType = X_XDGACopyArea; | |
553 req->screen = screen; | |
554 req->srcx = srcx; | |
555 req->srcy = srcy; | |
556 req->width = width; | |
557 req->height = height; | |
558 req->dstx = dstx; | |
559 req->dsty = dsty; | |
560 UnlockDisplay(dpy); | |
561 SyncHandle(); | |
562 } | |
563 | |
564 void SDL_NAME(XDGACopyTransparentArea)( | |
565 Display *dpy, | |
566 int screen, | |
567 int srcx, | |
568 int srcy, | |
569 unsigned int width, | |
570 unsigned int height, | |
571 int dstx, | |
572 int dsty, | |
573 unsigned long key | |
574 ){ | |
575 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
576 xXDGACopyTransparentAreaReq *req; | |
577 | |
578 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); | |
579 | |
580 LockDisplay(dpy); | |
581 GetReq(XDGACopyTransparentArea, req); | |
582 req->reqType = info->codes->major_opcode; | |
583 req->dgaReqType = X_XDGACopyTransparentArea; | |
584 req->screen = screen; | |
585 req->srcx = srcx; | |
586 req->srcy = srcy; | |
587 req->width = width; | |
588 req->height = height; | |
589 req->dstx = dstx; | |
590 req->dsty = dsty; | |
591 req->key = key; | |
592 UnlockDisplay(dpy); | |
593 SyncHandle(); | |
594 } | |
595 | |
596 | |
597 int SDL_NAME(XDGAGetViewportStatus)( | |
598 Display *dpy, | |
599 int screen | |
600 ){ | |
601 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
602 xXDGAGetViewportStatusReply rep; | |
603 xXDGAGetViewportStatusReq *req; | |
604 int status = 0; | |
605 | |
606 XDGACheckExtension (dpy, info, 0); | |
607 | |
608 LockDisplay(dpy); | |
609 GetReq(XDGAGetViewportStatus, req); | |
610 req->reqType = info->codes->major_opcode; | |
611 req->dgaReqType = X_XDGAGetViewportStatus; | |
612 req->screen = screen; | |
613 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) | |
614 status = rep.status; | |
615 UnlockDisplay(dpy); | |
616 SyncHandle(); | |
617 return status; | |
618 } | |
619 | |
620 void SDL_NAME(XDGASync)( | |
621 Display *dpy, | |
622 int screen | |
623 ){ | |
624 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
625 xXDGASyncReply rep; | |
626 xXDGASyncReq *req; | |
627 | |
628 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); | |
629 | |
630 LockDisplay(dpy); | |
631 GetReq(XDGASync, req); | |
632 req->reqType = info->codes->major_opcode; | |
633 req->dgaReqType = X_XDGASync; | |
634 req->screen = screen; | |
635 _XReply(dpy, (xReply *)&rep, 0, xFalse); | |
636 UnlockDisplay(dpy); | |
637 SyncHandle(); | |
638 } | |
639 | |
640 | |
641 void SDL_NAME(XDGAChangePixmapMode)( | |
642 Display *dpy, | |
643 int screen, | |
644 int *x, | |
645 int *y, | |
646 int mode | |
647 ){ | |
648 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
649 xXDGAChangePixmapModeReq *req; | |
650 xXDGAChangePixmapModeReply rep; | |
651 | |
652 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); | |
653 | |
654 LockDisplay(dpy); | |
655 GetReq(XDGAChangePixmapMode, req); | |
656 req->reqType = info->codes->major_opcode; | |
657 req->dgaReqType = X_XDGAChangePixmapMode; | |
658 req->screen = screen; | |
659 req->x = *x; | |
660 req->y = *y; | |
661 req->flags = mode; | |
662 _XReply(dpy, (xReply *)&rep, 0, xFalse); | |
663 *x = rep.x; | |
664 *y = rep.y; | |
665 UnlockDisplay(dpy); | |
666 SyncHandle(); | |
667 } | |
668 | |
669 Colormap SDL_NAME(XDGACreateColormap)( | |
670 Display *dpy, | |
671 int screen, | |
672 SDL_NAME(XDGADevice) *dev, | |
673 int alloc | |
674 ){ | |
675 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); | |
676 xXDGACreateColormapReq *req; | |
677 Colormap cid; | |
678 | |
679 XDGACheckExtension (dpy, info, -1); | |
680 | |
681 LockDisplay(dpy); | |
682 GetReq(XDGACreateColormap, req); | |
683 req->reqType = info->codes->major_opcode; | |
684 req->dgaReqType = X_XDGACreateColormap; | |
685 req->screen = screen; | |
686 req->mode = dev->mode.num; | |
687 req->alloc = alloc; | |
688 cid = req->id = XAllocID(dpy); | |
689 UnlockDisplay(dpy); | |
690 SyncHandle(); | |
691 | |
692 return cid; | |
693 } | |
694 | |
695 | |
696 void SDL_NAME(XDGAKeyEventToXKeyEvent)( | |
697 SDL_NAME(XDGAKeyEvent)* dk, | |
698 XKeyEvent* xk | |
699 ){ | |
700 xk->type = dk->type; | |
701 xk->serial = dk->serial; | |
702 xk->send_event = False; | |
703 xk->display = dk->display; | |
704 xk->window = RootWindow(dk->display, dk->screen); | |
705 xk->root = xk->window; | |
706 xk->subwindow = None; | |
707 xk->time = dk->time; | |
708 xk->x = xk->y = xk->x_root = xk->y_root = 0; | |
709 xk->state = dk->state; | |
710 xk->keycode = dk->keycode; | |
711 xk->same_screen = True; | |
712 } | |
713 | |
714 #include <X11/Xmd.h> | |
715 #include <stdlib.h> | |
716 #include <stdio.h> | |
717 #include <fcntl.h> | |
718 #if defined(ISC) | |
719 # define HAS_SVR3_MMAP | |
720 # include <sys/types.h> | |
721 # include <errno.h> | |
722 | |
723 # include <sys/at_ansi.h> | |
724 # include <sys/kd.h> | |
725 | |
726 # include <sys/sysmacros.h> | |
727 # include <sys/immu.h> | |
728 # include <sys/region.h> | |
729 | |
730 # include <sys/mmap.h> | |
731 #else | |
732 # if !defined(Lynx) | |
733 # if !defined(__EMX__) | |
734 # include <sys/mman.h> | |
735 # endif | |
736 # else | |
737 # include <sys/types.h> | |
738 # include <errno.h> | |
739 # include <smem.h> | |
740 # endif | |
741 #endif | |
742 #include <sys/wait.h> | |
743 #include <signal.h> | |
744 #include <unistd.h> | |
745 | |
746 #if defined(SVR4) && !defined(sun) && !defined(SCO325) | |
747 #define DEV_MEM "/dev/pmem" | |
748 #elif defined(SVR4) && defined(sun) | |
749 #define DEV_MEM "/dev/xsvc" | |
750 #else | |
751 #define DEV_MEM "/dev/mem" | |
752 #endif | |
753 | |
754 | |
755 | |
756 typedef struct _DGAMapRec{ | |
757 unsigned char *physical; | |
758 unsigned char *virtual; | |
759 CARD32 size; | |
760 int fd; | |
761 int screen; | |
762 struct _DGAMapRec *next; | |
763 } DGAMapRec, *DGAMapPtr; | |
764 | |
765 static Bool | |
766 DGAMapPhysical(int, char*, unsigned char*, CARD32, CARD32, CARD32, DGAMapPtr); | |
767 static void DGAUnmapPhysical(DGAMapPtr); | |
768 | |
769 static DGAMapPtr _Maps = NULL; | |
770 | |
771 | |
772 unsigned char* | |
773 SDL_NAME(XDGAGetMappedMemory)(int screen) | |
774 { | |
775 DGAMapPtr pMap = _Maps; | |
776 unsigned char *pntr = NULL; | |
777 | |
778 while(pMap != NULL) { | |
779 if(pMap->screen == screen) { | |
780 pntr = pMap->virtual; | |
781 break; | |
782 } | |
783 pMap = pMap->next; | |
784 } | |
785 | |
786 return pntr; | |
787 } | |
788 | |
789 Bool | |
790 SDL_NAME(XDGAMapFramebuffer)( | |
791 int screen, | |
792 char *name, /* optional device name */ | |
793 unsigned char* base, /* physical memory */ | |
794 CARD32 size, /* size */ | |
795 CARD32 offset, /* optional offset */ | |
796 CARD32 extra /* optional extra data */ | |
797 ){ | |
798 DGAMapPtr pMap = _Maps; | |
799 Bool result; | |
800 | |
801 /* is it already mapped ? */ | |
802 while(pMap != NULL) { | |
803 if(pMap->screen == screen) | |
804 return True; | |
805 pMap = pMap->next; | |
806 } | |
807 | |
808 if(extra & XDGANeedRoot) { | |
809 /* we should probably check if we have root permissions and | |
810 return False here */ | |
811 | |
812 } | |
813 | |
814 pMap = (DGAMapPtr)Xmalloc(sizeof(DGAMapRec)); | |
815 | |
816 result = DGAMapPhysical(screen, name, base, size, offset, extra, pMap); | |
817 | |
818 if(result) { | |
819 pMap->next = _Maps; | |
820 _Maps = pMap; | |
821 } else | |
822 Xfree(pMap); | |
823 | |
824 return result; | |
825 } | |
826 | |
827 void | |
828 SDL_NAME(XDGAUnmapFramebuffer)(int screen) | |
829 { | |
830 DGAMapPtr pMap = _Maps; | |
831 DGAMapPtr pPrev = NULL; | |
832 | |
833 /* is it already mapped */ | |
834 while(pMap != NULL) { | |
835 if(pMap->screen == screen) | |
836 break; | |
837 pPrev = pMap; | |
838 pMap = pMap->next; | |
839 } | |
840 | |
841 if(!pMap) | |
842 return; | |
843 | |
844 DGAUnmapPhysical(pMap); | |
845 | |
846 if(!pPrev) | |
847 _Maps = pMap->next; | |
848 else | |
849 pPrev->next = pMap->next; | |
850 | |
851 Xfree(pMap); | |
852 } | |
853 | |
854 | |
855 static Bool | |
856 DGAMapPhysical( | |
857 int screen, | |
858 char *name, /* optional device name */ | |
859 unsigned char* base, /* physical memory */ | |
860 CARD32 size, /* size */ | |
861 CARD32 offset, /* optional offset */ | |
862 CARD32 extra, /* optional extra data */ | |
863 DGAMapPtr pMap | |
864 ) { | |
865 #if defined(ISC) && defined(HAS_SVR3_MMAP) | |
866 struct kd_memloc mloc; | |
867 #elif defined(__EMX__) | |
868 APIRET rc; | |
869 ULONG action; | |
870 HFILE hfd; | |
871 #endif | |
872 | |
873 base += offset; | |
874 | |
875 pMap->screen = screen; | |
876 pMap->physical = base; | |
877 pMap->size = size; | |
878 | |
879 #if defined(ISC) && defined(HAS_SVR3_MMAP) | |
880 if ((pMap->fd = open("/dev/mmap", O_RDWR)) < 0) | |
881 return False; | |
882 mloc.vaddr = (char *)0; | |
883 mloc.physaddr = (char *)base; | |
884 mloc.length = size; | |
885 mloc.ioflg=1; | |
886 | |
887 if ((pMap->virtual = (void *)ioctl(pMap->fd, MAP, &mloc)) == (void *)-1) | |
888 return False; | |
889 #elif defined (__EMX__) | |
890 /* | |
891 * Dragon warning here! /dev/pmap$ is never closed, except on progam exit. | |
892 * Consecutive calling of this routine will make PMAP$ driver run out | |
893 * of memory handles. Some umap/close mechanism should be provided | |
894 */ | |
895 | |
896 rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN, | |
897 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2)NULL); | |
898 if (rc != 0) | |
899 return False; | |
900 { | |
901 struct map_ioctl { | |
902 union { | |
903 ULONG phys; | |
904 void* user; | |
905 } a; | |
906 ULONG size; | |
907 } pmap,dmap; | |
908 ULONG plen,dlen; | |
909 #define XFREE86_PMAP 0x76 | |
910 #define PMAP_MAP 0x44 | |
911 | |
912 pmap.a.phys = base; | |
913 pmap.size = size; | |
914 rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP, | |
915 (PULONG)&pmap, sizeof(pmap), &plen, | |
916 (PULONG)&dmap, sizeof(dmap), &dlen); | |
917 if (rc == 0) { | |
918 pMap->virtual = dmap.a.user; | |
919 } | |
920 } | |
921 if (rc != 0) | |
922 return False; | |
923 #elif defined (Lynx) | |
924 pMap->virtual = smem_create("XF86DGA", (char*)base, size, SM_READ|SM_WRITE); | |
925 #else | |
926 #ifndef MAP_FILE | |
927 #define MAP_FILE 0 | |
928 #endif | |
929 if (!name) | |
930 name = DEV_MEM; | |
931 if ((pMap->fd = open(name, O_RDWR)) < 0) | |
932 #if defined(linux) | |
933 { /* /dev/fb0 fallback added by Sam Lantinga <hercules@lokigames.com> */ | |
934 /* Try to fall back to /dev/fb on Linux - FIXME: verify the device */ | |
935 struct fb_fix_screeninfo finfo; | |
936 | |
937 if ((pMap->fd = open("/dev/fb0", O_RDWR)) < 0) { | |
938 return False; | |
939 } | |
940 /* The useable framebuffer console memory may not be the whole | |
941 framebuffer that X has access to. :-( | |
942 */ | |
943 if ( ioctl(pMap->fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) { | |
944 close(pMap->fd); | |
945 return False; | |
946 } | |
947 /* Warning: On PPC, the size and virtual need to be offset by: | |
948 (((long)finfo.smem_start) - | |
949 (((long)finfo.smem_start)&~(PAGE_SIZE-1))) | |
950 */ | |
951 base = 0; | |
952 size = finfo.smem_len; | |
953 } | |
954 #else | |
955 return False; | |
956 #endif | |
957 pMap->virtual = mmap(NULL, size, PROT_READ | PROT_WRITE, | |
958 MAP_FILE | MAP_SHARED, pMap->fd, (off_t)base); | |
959 if (pMap->virtual == (void *)-1) | |
960 return False; | |
961 #endif | |
962 | |
963 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ | |
964 && !defined(__EMX__) | |
965 mprotect(pMap->virtual, size, PROT_READ | PROT_WRITE); | |
966 #endif | |
967 | |
968 return True; | |
969 } | |
970 | |
971 | |
972 | |
973 static void | |
974 DGAUnmapPhysical(DGAMapPtr pMap) | |
975 { | |
976 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ | |
977 && !defined(__EMX__) | |
978 mprotect(pMap->virtual,pMap->size, PROT_READ); | |
979 #elif defined(Lynx) | |
980 /* XXX this doesn't allow enable after disable */ | |
981 smem_create(NULL, pMap->virtual, pMap->size, SM_DETACH); | |
982 smem_remove("XF86DGA"); | |
983 #endif | |
984 | |
985 | |
986 /* We need to unmap and close too !!!!!!!!!!*/ | |
987 } |