Mercurial > sdl-ios-xcode
annotate src/video/wscons/SDL_wsconsvideo.c @ 1358:c71e05b4dc2e
More header massaging... works great on Windows. ;-)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 10 Feb 2006 06:48:43 +0000 |
parents | 604d73db6802 |
children | 19418e4422cb |
rev | line source |
---|---|
1187 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
1187 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
1187 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
1187 | 9 |
10 This library 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 GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
13 Lesser General Public License for more details. |
1187 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1187 | 18 |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 | |
23 #include <sys/time.h> | |
24 #include <sys/mman.h> | |
25 #include <sys/ioctl.h> | |
26 #include <dev/wscons/wsdisplay_usl_io.h> | |
27 #include <fcntl.h> | |
28 #include <unistd.h> | |
29 #include <errno.h> | |
30 | |
31 #include "SDL_video.h" | |
32 #include "SDL_mouse.h" | |
33 #include "SDL_sysvideo.h" | |
34 #include "SDL_pixels_c.h" | |
35 #include "SDL_events_c.h" | |
36 | |
37 #include "SDL_wsconsvideo.h" | |
38 #include "SDL_wsconsevents_c.h" | |
39 #include "SDL_wsconsmouse_c.h" | |
40 | |
41 #define WSCONSVID_DRIVER_NAME "wscons" | |
42 enum { | |
43 WSCONS_ROTATE_NONE = 0, | |
44 WSCONS_ROTATE_CCW = 90, | |
45 WSCONS_ROTATE_UD = 180, | |
46 WSCONS_ROTATE_CW = 270 | |
47 }; | |
48 | |
49 #define min(a,b) ((a)<(b)?(a):(b)) | |
50 | |
51 /* Initialization/Query functions */ | |
52 static int WSCONS_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
53 static SDL_Rect **WSCONS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
54 static SDL_Surface *WSCONS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
55 static int WSCONS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | |
56 static void WSCONS_VideoQuit(_THIS); | |
57 | |
58 /* Hardware surface functions */ | |
59 static int WSCONS_AllocHWSurface(_THIS, SDL_Surface *surface); | |
60 static int WSCONS_LockHWSurface(_THIS, SDL_Surface *surface); | |
61 static void WSCONS_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
62 static void WSCONS_FreeHWSurface(_THIS, SDL_Surface *surface); | |
63 | |
64 /* etc. */ | |
65 static WSCONS_bitBlit WSCONS_blit16; | |
66 static WSCONS_bitBlit WSCONS_blit16blocked; | |
67 static void WSCONS_UpdateRects(_THIS, int numrects, SDL_Rect *rects); | |
68 | |
69 void WSCONS_ReportError(char *fmt, ...) | |
70 { | |
71 char message[200]; | |
72 | |
73 message[199] = '\0'; | |
74 | |
75 va_list vaArgs; | |
76 va_start(vaArgs, fmt); | |
77 vsnprintf(message, 199, fmt, vaArgs); | |
78 va_end(vaArgs); | |
79 | |
80 SDL_SetError(message); | |
81 fprintf(stderr, "WSCONS error: %s\n", message); | |
82 } | |
83 | |
84 /* WSCONS driver bootstrap functions */ | |
85 | |
86 static int WSCONS_Available(void) | |
87 { | |
88 return 1; | |
89 } | |
90 | |
91 static void WSCONS_DeleteDevice(SDL_VideoDevice *device) | |
92 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
93 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
94 SDL_free(device); |
1187 | 95 } |
96 | |
97 static SDL_VideoDevice *WSCONS_CreateDevice(int devindex) | |
98 { | |
99 SDL_VideoDevice *device; | |
100 | |
101 /* Initialize all variables that we clean on shutdown */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
102 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); |
1187 | 103 if (device == NULL) { |
104 SDL_OutOfMemory(); | |
105 return 0; | |
106 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
107 SDL_memset(device, 0, (sizeof *device)); |
1187 | 108 device->hidden = |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
109 (struct SDL_PrivateVideoData *)SDL_malloc((sizeof *device->hidden)); |
1187 | 110 if (device->hidden == NULL) { |
111 SDL_OutOfMemory(); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
112 SDL_free(device); |
1187 | 113 return(0); |
114 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
115 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
1187 | 116 device->hidden->fd = -1; |
117 | |
118 /* Set the function pointers */ | |
119 device->VideoInit = WSCONS_VideoInit; | |
120 device->ListModes = WSCONS_ListModes; | |
121 device->SetVideoMode = WSCONS_SetVideoMode; | |
122 device->SetColors = WSCONS_SetColors; | |
123 device->UpdateRects = WSCONS_UpdateRects; | |
124 device->VideoQuit = WSCONS_VideoQuit; | |
125 device->AllocHWSurface = WSCONS_AllocHWSurface; | |
126 device->LockHWSurface = WSCONS_LockHWSurface; | |
127 device->UnlockHWSurface = WSCONS_UnlockHWSurface; | |
128 device->FreeHWSurface = WSCONS_FreeHWSurface; | |
129 device->InitOSKeymap = WSCONS_InitOSKeymap; | |
130 device->PumpEvents = WSCONS_PumpEvents; | |
131 device->free = WSCONS_DeleteDevice; | |
132 | |
133 return device; | |
134 } | |
135 | |
136 VideoBootStrap WSCONS_bootstrap = { | |
137 WSCONSVID_DRIVER_NAME, | |
138 "SDL wscons video driver", | |
139 WSCONS_Available, | |
140 WSCONS_CreateDevice | |
141 }; | |
142 | |
143 #define WSCONSDEV_FORMAT "/dev/ttyC%01x" | |
144 | |
145 int WSCONS_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
146 { | |
147 char devnamebuf[30]; | |
148 char *devname; | |
149 char *rotation; | |
150 int wstype; | |
151 int wsmode = WSDISPLAYIO_MODE_DUMBFB; | |
152 size_t len, mapsize; | |
153 int pagemask; | |
154 int width, height; | |
155 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
156 devname = SDL_getenv("SDL_WSCONSDEV"); |
1187 | 157 if (devname == NULL) { |
158 int activeVT; | |
159 if (ioctl(STDIN_FILENO, VT_GETACTIVE, &activeVT) == -1) { | |
160 WSCONS_ReportError("Unable to determine active terminal: %s", | |
161 strerror(errno)); | |
162 return -1; | |
163 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
164 SDL_snprintf(devnamebuf, sizeof(devnamebuf), WSCONSDEV_FORMAT, activeVT - 1); |
1187 | 165 devname = devnamebuf; |
166 } | |
167 | |
168 private->fd = open(devname, O_RDWR | O_NONBLOCK, 0); | |
169 if (private->fd == -1) { | |
170 WSCONS_ReportError("open %s: %s", devname, strerror(errno)); | |
171 return -1; | |
172 } | |
173 if (ioctl(private->fd, WSDISPLAYIO_GINFO, &private->info) == -1) { | |
174 WSCONS_ReportError("ioctl WSDISPLAY_GINFO: %s", strerror(errno)); | |
175 return -1; | |
176 } | |
177 if (ioctl(private->fd, WSDISPLAYIO_GTYPE, &wstype) == -1) { | |
178 WSCONS_ReportError("ioctl WSDISPLAY_GTYPE: %s", strerror(errno)); | |
179 return -1; | |
180 } | |
181 if (ioctl(private->fd, WSDISPLAYIO_LINEBYTES, &private->physlinebytes) == -1) { | |
182 WSCONS_ReportError("ioctl WSDISPLAYIO_LINEBYTES: %s", strerror(errno)); | |
183 return -1; | |
184 } | |
185 if (private->info.depth > 8) { | |
186 if (wstype == WSDISPLAY_TYPE_SUN24 || | |
187 wstype == WSDISPLAY_TYPE_SUNCG12 || | |
188 wstype == WSDISPLAY_TYPE_SUNCG14 || | |
189 wstype == WSDISPLAY_TYPE_SUNTCX || | |
190 wstype == WSDISPLAY_TYPE_SUNFFB) { | |
191 private->redMask = 0x0000ff; | |
192 private->greenMask = 0x00ff00; | |
193 private->blueMask = 0xff0000; | |
194 } else if (wstype == WSDISPLAY_TYPE_PXALCD) { | |
195 private->redMask = 0x1f << 11; | |
196 private->greenMask = 0x3f << 5; | |
197 private->blueMask = 0x1f; | |
198 } else { | |
199 WSCONS_ReportError("Unknown video hardware"); | |
200 return -1; | |
201 } | |
202 } else { | |
203 WSCONS_ReportError("Displays with 8 bpp or less are not supported"); | |
204 return -1; | |
205 } | |
206 | |
207 private->rotate = WSCONS_ROTATE_NONE; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
208 rotation = SDL_getenv("SDL_VIDEO_WSCONS_ROTATION"); |
1187 | 209 if (rotation != NULL) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
210 if (SDL_strlen(rotation) == 0) { |
1187 | 211 private->shadowFB = 0; |
212 private->rotate = WSCONS_ROTATE_NONE; | |
213 printf("Not rotating, no shadow\n"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
214 } else if (!SDL_strcmp(rotation, "NONE")) { |
1187 | 215 private->shadowFB = 1; |
216 private->rotate = WSCONS_ROTATE_NONE; | |
217 printf("Not rotating, but still using shadow\n"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
218 } else if (!SDL_strcmp(rotation, "CW")) { |
1187 | 219 private->shadowFB = 1; |
220 private->rotate = WSCONS_ROTATE_CW; | |
221 printf("Rotating screen clockwise\n"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
222 } else if (!SDL_strcmp(rotation, "CCW")) { |
1187 | 223 private->shadowFB = 1; |
224 private->rotate = WSCONS_ROTATE_CCW; | |
225 printf("Rotating screen counter clockwise\n"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
226 } else if (!SDL_strcmp(rotation, "UD")) { |
1187 | 227 private->shadowFB = 1; |
228 private->rotate = WSCONS_ROTATE_UD; | |
229 printf("Rotating screen upside down\n"); | |
230 } else { | |
231 WSCONS_ReportError("\"%s\" is not a valid value for " | |
232 "SDL_VIDEO_WSCONS_ROTATION", rotation); | |
233 return -1; | |
234 } | |
235 } | |
236 | |
237 switch (private->info.depth) { | |
238 case 1: | |
239 case 4: | |
240 case 8: | |
241 len = private->physlinebytes * private->info.height; | |
242 break; | |
243 case 16: | |
244 if (private->physlinebytes == private->info.width) { | |
245 len = private->info.width * private->info.height * sizeof(short); | |
246 } else { | |
247 len = private->physlinebytes * private->info.height; | |
248 } | |
249 if (private->rotate == WSCONS_ROTATE_NONE || | |
250 private->rotate == WSCONS_ROTATE_UD) { | |
251 private->blitFunc = WSCONS_blit16; | |
252 } else { | |
253 private->blitFunc = WSCONS_blit16blocked; | |
254 } | |
255 break; | |
256 case 32: | |
257 if (private->physlinebytes == private->info.width) { | |
258 len = private->info.width * private->info.height * sizeof(int); | |
259 } else { | |
260 len = private->physlinebytes * private->info.height; | |
261 } | |
262 break; | |
263 default: | |
264 WSCONS_ReportError("unsupported depth %d", private->info.depth); | |
265 return -1; | |
266 } | |
267 | |
268 if (private->shadowFB && private->blitFunc == NULL) { | |
269 WSCONS_ReportError("Using software buffer, but no blitter function is " | |
270 "available for this %d bpp.", private->info.depth); | |
271 return -1; | |
272 } | |
273 | |
274 if (ioctl(private->fd, WSDISPLAYIO_SMODE, &wsmode) == -1) { | |
275 WSCONS_ReportError("ioctl SMODE"); | |
276 return -1; | |
277 } | |
278 | |
279 pagemask = getpagesize() - 1; | |
280 mapsize = ((int)len + pagemask) & ~pagemask; | |
281 private->physmem = (Uint8 *)mmap(NULL, mapsize, | |
282 PROT_READ | PROT_WRITE, MAP_SHARED, | |
283 private->fd, (off_t)0); | |
284 if (private->physmem == (Uint8 *)MAP_FAILED) { | |
285 private->physmem = NULL; | |
286 WSCONS_ReportError("mmap: %s", strerror(errno)); | |
287 return -1; | |
288 } | |
289 private->fbmem_len = len; | |
290 | |
291 if (private->rotate == WSCONS_ROTATE_CW || | |
292 private->rotate == WSCONS_ROTATE_CCW) { | |
293 width = private->info.height; | |
294 height = private->info.width; | |
295 } else { | |
296 width = private->info.width; | |
297 height = private->info.height; | |
298 } | |
299 | |
300 if (private->shadowFB) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
301 private->shadowmem = (Uint8 *)SDL_malloc(len); |
1187 | 302 if (private->shadowmem == NULL) { |
303 WSCONS_ReportError("No memory for shadow"); | |
304 return -1; | |
305 } | |
306 private->fbstart = private->shadowmem; | |
307 private->fblinebytes = width * ((private->info.depth + 7) / 8); | |
308 } else { | |
309 private->fbstart = private->physmem; | |
310 private->fblinebytes = private->physlinebytes; | |
311 } | |
312 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
313 private->SDL_modelist[0] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); |
1187 | 314 private->SDL_modelist[0]->w = width; |
315 private->SDL_modelist[0]->h = height; | |
316 | |
317 vformat->BitsPerPixel = private->info.depth; | |
318 vformat->BytesPerPixel = private->info.depth / 8; | |
319 | |
320 if (WSCONS_InitKeyboard(this) == -1) { | |
321 return -1; | |
322 } | |
323 | |
324 return 0; | |
325 } | |
326 | |
327 SDL_Rect **WSCONS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
328 { | |
329 if (format->BitsPerPixel == private->info.depth) { | |
330 return private->SDL_modelist; | |
331 } else { | |
332 return NULL; | |
333 } | |
334 } | |
335 | |
336 SDL_Surface *WSCONS_SetVideoMode(_THIS, SDL_Surface *current, | |
337 int width, int height, int bpp, Uint32 flags) | |
338 { | |
339 if (width != private->SDL_modelist[0]->w || | |
340 height != private->SDL_modelist[0]->h) { | |
341 WSCONS_ReportError("Requested video mode %dx%d not supported.", | |
342 width, height); | |
343 return NULL; | |
344 } | |
345 if (bpp != private->info.depth) { | |
346 WSCONS_ReportError("Requested video depth %d bpp not supported.", bpp); | |
347 return NULL; | |
348 } | |
349 | |
350 if (!SDL_ReallocFormat(current, | |
351 bpp, | |
352 private->redMask, | |
353 private->greenMask, | |
354 private->blueMask, | |
355 0)) { | |
356 WSCONS_ReportError("Couldn't allocate new pixel format"); | |
357 return NULL; | |
358 } | |
359 | |
360 current->flags &= SDL_FULLSCREEN; | |
361 if (private->shadowFB) { | |
362 current->flags |= SDL_SWSURFACE; | |
363 } else { | |
364 current->flags |= SDL_HWSURFACE; | |
365 } | |
366 current->w = width; | |
367 current->h = height; | |
368 current->pitch = private->fblinebytes; | |
369 current->pixels = private->fbstart; | |
370 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
371 SDL_memset(private->fbstart, 0, private->fbmem_len); |
1187 | 372 |
373 return current; | |
374 } | |
375 | |
376 static int WSCONS_AllocHWSurface(_THIS, SDL_Surface *surface) | |
377 { | |
378 return -1; | |
379 } | |
380 static void WSCONS_FreeHWSurface(_THIS, SDL_Surface *surface) | |
381 { | |
382 } | |
383 | |
384 static int WSCONS_LockHWSurface(_THIS, SDL_Surface *surface) | |
385 { | |
386 return 0; | |
387 } | |
388 | |
389 static void WSCONS_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
390 { | |
391 } | |
392 | |
393 static void WSCONS_blit16(Uint8 *byte_src_pos, | |
394 int srcRightDelta, | |
395 int srcDownDelta, | |
396 Uint8 *byte_dst_pos, | |
397 int dst_linebytes, | |
398 int width, | |
399 int height) | |
400 { | |
401 int w; | |
402 Uint16 *src_pos = (Uint16 *)byte_src_pos; | |
403 Uint16 *dst_pos = (Uint16 *)byte_dst_pos; | |
404 | |
405 while (height) { | |
406 Uint16 *src = src_pos; | |
407 Uint16 *dst = dst_pos; | |
408 for (w = width; w != 0; w--) { | |
409 *dst = *src; | |
410 src += srcRightDelta; | |
411 dst++; | |
412 } | |
413 dst_pos = (Uint16 *)((Uint8 *)dst_pos + dst_linebytes); | |
414 src_pos += srcDownDelta; | |
415 height--; | |
416 } | |
417 } | |
418 | |
419 #define BLOCKSIZE_W 32 | |
420 #define BLOCKSIZE_H 32 | |
421 | |
422 static void WSCONS_blit16blocked(Uint8 *byte_src_pos, | |
423 int srcRightDelta, | |
424 int srcDownDelta, | |
425 Uint8 *byte_dst_pos, | |
426 int dst_linebytes, | |
427 int width, | |
428 int height) | |
429 { | |
430 int w; | |
431 Uint16 *src_pos = (Uint16 *)byte_src_pos; | |
432 Uint16 *dst_pos = (Uint16 *)byte_dst_pos; | |
433 | |
434 while (height > 0) { | |
435 Uint16 *src = src_pos; | |
436 Uint16 *dst = dst_pos; | |
437 for (w = width; w > 0; w -= BLOCKSIZE_W) { | |
438 WSCONS_blit16((Uint8 *)src, | |
439 srcRightDelta, | |
440 srcDownDelta, | |
441 (Uint8 *)dst, | |
442 dst_linebytes, | |
443 min(w, BLOCKSIZE_W), | |
444 min(height, BLOCKSIZE_H)); | |
445 src += srcRightDelta * BLOCKSIZE_W; | |
446 dst += BLOCKSIZE_W; | |
447 } | |
448 dst_pos = (Uint16 *)((Uint8 *)dst_pos + dst_linebytes * BLOCKSIZE_H); | |
449 src_pos += srcDownDelta * BLOCKSIZE_H; | |
450 height -= BLOCKSIZE_H; | |
451 } | |
452 } | |
453 | |
454 static void WSCONS_UpdateRects(_THIS, int numrects, SDL_Rect *rects) | |
455 { | |
456 int width = private->SDL_modelist[0]->w; | |
457 int height = private->SDL_modelist[0]->h; | |
458 int bytesPerPixel = (private->info.depth + 7) / 8; | |
459 int i; | |
460 | |
461 if (!private->shadowFB) { | |
462 return; | |
463 } | |
464 | |
465 if (private->info.depth != 16) { | |
466 WSCONS_ReportError("Shadow copy only implemented for 16 bpp"); | |
467 return; | |
468 } | |
469 | |
470 for (i = 0; i < numrects; i++) { | |
471 int x1, y1, x2, y2; | |
472 int scr_x1, scr_y1, scr_x2, scr_y2; | |
473 int sha_x1, sha_y1; | |
474 int shadowRightDelta; /* Address change when moving right in dest */ | |
475 int shadowDownDelta; /* Address change when moving down in dest */ | |
476 Uint8 *src_start; | |
477 Uint8 *dst_start; | |
478 | |
479 x1 = rects[i].x; | |
480 y1 = rects[i].y; | |
481 x2 = x1 + rects[i].w; | |
482 y2 = y1 + rects[i].h; | |
483 | |
484 if (x1 < 0) { | |
485 x1 = 0; | |
486 } else if (x1 > width) { | |
487 x1 = width; | |
488 } | |
489 if (x2 < 0) { | |
490 x2 = 0; | |
491 } else if (x2 > width) { | |
492 x2 = width; | |
493 } | |
494 if (y1 < 0) { | |
495 y1 = 0; | |
496 } else if (y1 > height) { | |
497 y1 = height; | |
498 } | |
499 if (y2 < 0) { | |
500 y2 = 0; | |
501 } else if (y2 > height) { | |
502 y2 = height; | |
503 } | |
504 if (x2 <= x1 || y2 <= y1) { | |
505 continue; | |
506 } | |
507 | |
508 switch (private->rotate) { | |
509 case WSCONS_ROTATE_NONE: | |
510 sha_x1 = scr_x1 = x1; | |
511 sha_y1 = scr_y1 = y1; | |
512 scr_x2 = x2; | |
513 scr_y2 = y2; | |
514 shadowRightDelta = 1; | |
515 shadowDownDelta = width; | |
516 break; | |
517 case WSCONS_ROTATE_CCW: | |
518 scr_x1 = y1; | |
519 scr_y1 = width - x2; | |
520 scr_x2 = y2; | |
521 scr_y2 = width - x1; | |
522 sha_x1 = x2 - 1; | |
523 sha_y1 = y1; | |
524 shadowRightDelta = width; | |
525 shadowDownDelta = -1; | |
526 break; | |
527 case WSCONS_ROTATE_UD: | |
528 scr_x1 = width - x2; | |
529 scr_y1 = height - y2; | |
530 scr_x2 = width - x1; | |
531 scr_y2 = height - y1; | |
532 sha_x1 = x2 - 1; | |
533 sha_y1 = y2 - 1; | |
534 shadowRightDelta = -1; | |
535 shadowDownDelta = -width; | |
536 break; | |
537 case WSCONS_ROTATE_CW: | |
538 scr_x1 = height - y2; | |
539 scr_y1 = x1; | |
540 scr_x2 = height - y1; | |
541 scr_y2 = x2; | |
542 sha_x1 = x1; | |
543 sha_y1 = y2 - 1; | |
544 shadowRightDelta = -width; | |
545 shadowDownDelta = 1; | |
546 break; | |
547 default: | |
548 WSCONS_ReportError("Unknown rotation"); | |
549 return; | |
550 } | |
551 | |
552 src_start = private->shadowmem + (sha_y1 * width + sha_x1) * bytesPerPixel; | |
553 dst_start = private->physmem + scr_y1 * private->physlinebytes + | |
554 scr_x1 * bytesPerPixel; | |
555 | |
556 private->blitFunc(src_start, | |
557 shadowRightDelta, | |
558 shadowDownDelta, | |
559 dst_start, | |
560 private->physlinebytes, | |
561 scr_x2 - scr_x1, | |
562 scr_y2 - scr_y1); | |
563 } | |
564 } | |
565 | |
566 int WSCONS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
567 { | |
568 return 0; | |
569 } | |
570 | |
571 /* | |
572 * Note: If we are terminated, this could be called in the middle of | |
573 * another SDL video routine -- notably UpdateRects. | |
574 */ | |
575 void WSCONS_VideoQuit(_THIS) | |
576 { | |
577 int mode = WSDISPLAYIO_MODE_EMUL; | |
578 | |
579 if (private->shadowmem != NULL) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
580 SDL_free(private->shadowmem); |
1187 | 581 private->shadowmem = NULL; |
582 } | |
583 private->fbstart = NULL; | |
584 if (this->screen != NULL) { | |
585 this->screen->pixels = NULL; | |
586 } | |
587 | |
588 if (private->SDL_modelist[0] != NULL) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
589 SDL_free(private->SDL_modelist[0]); |
1187 | 590 private->SDL_modelist[0] = NULL; |
591 } | |
592 | |
593 if (ioctl(private->fd, WSDISPLAYIO_SMODE, &mode) == -1) { | |
594 WSCONS_ReportError("ioctl SMODE"); | |
595 } | |
596 | |
597 WSCONS_ReleaseKeyboard(this); | |
598 | |
599 if (private->fd != -1) { | |
600 close(private->fd); | |
601 private->fd = -1; | |
602 } | |
603 } |