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