Mercurial > sdl-ios-xcode
annotate src/video/wscons/SDL_wsconsvideo.c @ 1383:1736c5e2173f
NetBSD support
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 20 Feb 2006 03:57:03 +0000 |
parents | 19418e4422cb |
children | d910939febfa |
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" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
33 #include "../SDL_sysvideo.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
34 #include "../SDL_pixels_c.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
35 #include "../../events/SDL_events_c.h" |
1187 | 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; | |
1383 | 194 #ifdef WSDISPLAY_TYPE_PXALCD |
1187 | 195 } else if (wstype == WSDISPLAY_TYPE_PXALCD) { |
196 private->redMask = 0x1f << 11; | |
197 private->greenMask = 0x3f << 5; | |
198 private->blueMask = 0x1f; | |
1383 | 199 #endif |
1187 | 200 } else { |
201 WSCONS_ReportError("Unknown video hardware"); | |
202 return -1; | |
203 } | |
204 } else { | |
205 WSCONS_ReportError("Displays with 8 bpp or less are not supported"); | |
206 return -1; | |
207 } | |
208 | |
209 private->rotate = WSCONS_ROTATE_NONE; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
210 rotation = SDL_getenv("SDL_VIDEO_WSCONS_ROTATION"); |
1187 | 211 if (rotation != NULL) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
212 if (SDL_strlen(rotation) == 0) { |
1187 | 213 private->shadowFB = 0; |
214 private->rotate = WSCONS_ROTATE_NONE; | |
215 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
|
216 } else if (!SDL_strcmp(rotation, "NONE")) { |
1187 | 217 private->shadowFB = 1; |
218 private->rotate = WSCONS_ROTATE_NONE; | |
219 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
|
220 } else if (!SDL_strcmp(rotation, "CW")) { |
1187 | 221 private->shadowFB = 1; |
222 private->rotate = WSCONS_ROTATE_CW; | |
223 printf("Rotating screen clockwise\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, "CCW")) { |
1187 | 225 private->shadowFB = 1; |
226 private->rotate = WSCONS_ROTATE_CCW; | |
227 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
|
228 } else if (!SDL_strcmp(rotation, "UD")) { |
1187 | 229 private->shadowFB = 1; |
230 private->rotate = WSCONS_ROTATE_UD; | |
231 printf("Rotating screen upside down\n"); | |
232 } else { | |
233 WSCONS_ReportError("\"%s\" is not a valid value for " | |
234 "SDL_VIDEO_WSCONS_ROTATION", rotation); | |
235 return -1; | |
236 } | |
237 } | |
238 | |
239 switch (private->info.depth) { | |
240 case 1: | |
241 case 4: | |
242 case 8: | |
243 len = private->physlinebytes * private->info.height; | |
244 break; | |
245 case 16: | |
246 if (private->physlinebytes == private->info.width) { | |
247 len = private->info.width * private->info.height * sizeof(short); | |
248 } else { | |
249 len = private->physlinebytes * private->info.height; | |
250 } | |
251 if (private->rotate == WSCONS_ROTATE_NONE || | |
252 private->rotate == WSCONS_ROTATE_UD) { | |
253 private->blitFunc = WSCONS_blit16; | |
254 } else { | |
255 private->blitFunc = WSCONS_blit16blocked; | |
256 } | |
257 break; | |
258 case 32: | |
259 if (private->physlinebytes == private->info.width) { | |
260 len = private->info.width * private->info.height * sizeof(int); | |
261 } else { | |
262 len = private->physlinebytes * private->info.height; | |
263 } | |
264 break; | |
265 default: | |
266 WSCONS_ReportError("unsupported depth %d", private->info.depth); | |
267 return -1; | |
268 } | |
269 | |
270 if (private->shadowFB && private->blitFunc == NULL) { | |
271 WSCONS_ReportError("Using software buffer, but no blitter function is " | |
272 "available for this %d bpp.", private->info.depth); | |
273 return -1; | |
274 } | |
275 | |
276 if (ioctl(private->fd, WSDISPLAYIO_SMODE, &wsmode) == -1) { | |
277 WSCONS_ReportError("ioctl SMODE"); | |
278 return -1; | |
279 } | |
280 | |
281 pagemask = getpagesize() - 1; | |
282 mapsize = ((int)len + pagemask) & ~pagemask; | |
283 private->physmem = (Uint8 *)mmap(NULL, mapsize, | |
284 PROT_READ | PROT_WRITE, MAP_SHARED, | |
285 private->fd, (off_t)0); | |
286 if (private->physmem == (Uint8 *)MAP_FAILED) { | |
287 private->physmem = NULL; | |
288 WSCONS_ReportError("mmap: %s", strerror(errno)); | |
289 return -1; | |
290 } | |
291 private->fbmem_len = len; | |
292 | |
293 if (private->rotate == WSCONS_ROTATE_CW || | |
294 private->rotate == WSCONS_ROTATE_CCW) { | |
295 width = private->info.height; | |
296 height = private->info.width; | |
297 } else { | |
298 width = private->info.width; | |
299 height = private->info.height; | |
300 } | |
301 | |
302 if (private->shadowFB) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
303 private->shadowmem = (Uint8 *)SDL_malloc(len); |
1187 | 304 if (private->shadowmem == NULL) { |
305 WSCONS_ReportError("No memory for shadow"); | |
306 return -1; | |
307 } | |
308 private->fbstart = private->shadowmem; | |
309 private->fblinebytes = width * ((private->info.depth + 7) / 8); | |
310 } else { | |
311 private->fbstart = private->physmem; | |
312 private->fblinebytes = private->physlinebytes; | |
313 } | |
314 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
315 private->SDL_modelist[0] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); |
1187 | 316 private->SDL_modelist[0]->w = width; |
317 private->SDL_modelist[0]->h = height; | |
318 | |
319 vformat->BitsPerPixel = private->info.depth; | |
320 vformat->BytesPerPixel = private->info.depth / 8; | |
321 | |
322 if (WSCONS_InitKeyboard(this) == -1) { | |
323 return -1; | |
324 } | |
325 | |
326 return 0; | |
327 } | |
328 | |
329 SDL_Rect **WSCONS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
330 { | |
331 if (format->BitsPerPixel == private->info.depth) { | |
332 return private->SDL_modelist; | |
333 } else { | |
334 return NULL; | |
335 } | |
336 } | |
337 | |
338 SDL_Surface *WSCONS_SetVideoMode(_THIS, SDL_Surface *current, | |
339 int width, int height, int bpp, Uint32 flags) | |
340 { | |
341 if (width != private->SDL_modelist[0]->w || | |
342 height != private->SDL_modelist[0]->h) { | |
343 WSCONS_ReportError("Requested video mode %dx%d not supported.", | |
344 width, height); | |
345 return NULL; | |
346 } | |
347 if (bpp != private->info.depth) { | |
348 WSCONS_ReportError("Requested video depth %d bpp not supported.", bpp); | |
349 return NULL; | |
350 } | |
351 | |
352 if (!SDL_ReallocFormat(current, | |
353 bpp, | |
354 private->redMask, | |
355 private->greenMask, | |
356 private->blueMask, | |
357 0)) { | |
358 WSCONS_ReportError("Couldn't allocate new pixel format"); | |
359 return NULL; | |
360 } | |
361 | |
362 current->flags &= SDL_FULLSCREEN; | |
363 if (private->shadowFB) { | |
364 current->flags |= SDL_SWSURFACE; | |
365 } else { | |
366 current->flags |= SDL_HWSURFACE; | |
367 } | |
368 current->w = width; | |
369 current->h = height; | |
370 current->pitch = private->fblinebytes; | |
371 current->pixels = private->fbstart; | |
372 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
373 SDL_memset(private->fbstart, 0, private->fbmem_len); |
1187 | 374 |
375 return current; | |
376 } | |
377 | |
378 static int WSCONS_AllocHWSurface(_THIS, SDL_Surface *surface) | |
379 { | |
380 return -1; | |
381 } | |
382 static void WSCONS_FreeHWSurface(_THIS, SDL_Surface *surface) | |
383 { | |
384 } | |
385 | |
386 static int WSCONS_LockHWSurface(_THIS, SDL_Surface *surface) | |
387 { | |
388 return 0; | |
389 } | |
390 | |
391 static void WSCONS_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
392 { | |
393 } | |
394 | |
395 static void WSCONS_blit16(Uint8 *byte_src_pos, | |
396 int srcRightDelta, | |
397 int srcDownDelta, | |
398 Uint8 *byte_dst_pos, | |
399 int dst_linebytes, | |
400 int width, | |
401 int height) | |
402 { | |
403 int w; | |
404 Uint16 *src_pos = (Uint16 *)byte_src_pos; | |
405 Uint16 *dst_pos = (Uint16 *)byte_dst_pos; | |
406 | |
407 while (height) { | |
408 Uint16 *src = src_pos; | |
409 Uint16 *dst = dst_pos; | |
410 for (w = width; w != 0; w--) { | |
411 *dst = *src; | |
412 src += srcRightDelta; | |
413 dst++; | |
414 } | |
415 dst_pos = (Uint16 *)((Uint8 *)dst_pos + dst_linebytes); | |
416 src_pos += srcDownDelta; | |
417 height--; | |
418 } | |
419 } | |
420 | |
421 #define BLOCKSIZE_W 32 | |
422 #define BLOCKSIZE_H 32 | |
423 | |
424 static void WSCONS_blit16blocked(Uint8 *byte_src_pos, | |
425 int srcRightDelta, | |
426 int srcDownDelta, | |
427 Uint8 *byte_dst_pos, | |
428 int dst_linebytes, | |
429 int width, | |
430 int height) | |
431 { | |
432 int w; | |
433 Uint16 *src_pos = (Uint16 *)byte_src_pos; | |
434 Uint16 *dst_pos = (Uint16 *)byte_dst_pos; | |
435 | |
436 while (height > 0) { | |
437 Uint16 *src = src_pos; | |
438 Uint16 *dst = dst_pos; | |
439 for (w = width; w > 0; w -= BLOCKSIZE_W) { | |
440 WSCONS_blit16((Uint8 *)src, | |
441 srcRightDelta, | |
442 srcDownDelta, | |
443 (Uint8 *)dst, | |
444 dst_linebytes, | |
445 min(w, BLOCKSIZE_W), | |
446 min(height, BLOCKSIZE_H)); | |
447 src += srcRightDelta * BLOCKSIZE_W; | |
448 dst += BLOCKSIZE_W; | |
449 } | |
450 dst_pos = (Uint16 *)((Uint8 *)dst_pos + dst_linebytes * BLOCKSIZE_H); | |
451 src_pos += srcDownDelta * BLOCKSIZE_H; | |
452 height -= BLOCKSIZE_H; | |
453 } | |
454 } | |
455 | |
456 static void WSCONS_UpdateRects(_THIS, int numrects, SDL_Rect *rects) | |
457 { | |
458 int width = private->SDL_modelist[0]->w; | |
459 int height = private->SDL_modelist[0]->h; | |
460 int bytesPerPixel = (private->info.depth + 7) / 8; | |
461 int i; | |
462 | |
463 if (!private->shadowFB) { | |
464 return; | |
465 } | |
466 | |
467 if (private->info.depth != 16) { | |
468 WSCONS_ReportError("Shadow copy only implemented for 16 bpp"); | |
469 return; | |
470 } | |
471 | |
472 for (i = 0; i < numrects; i++) { | |
473 int x1, y1, x2, y2; | |
474 int scr_x1, scr_y1, scr_x2, scr_y2; | |
475 int sha_x1, sha_y1; | |
476 int shadowRightDelta; /* Address change when moving right in dest */ | |
477 int shadowDownDelta; /* Address change when moving down in dest */ | |
478 Uint8 *src_start; | |
479 Uint8 *dst_start; | |
480 | |
481 x1 = rects[i].x; | |
482 y1 = rects[i].y; | |
483 x2 = x1 + rects[i].w; | |
484 y2 = y1 + rects[i].h; | |
485 | |
486 if (x1 < 0) { | |
487 x1 = 0; | |
488 } else if (x1 > width) { | |
489 x1 = width; | |
490 } | |
491 if (x2 < 0) { | |
492 x2 = 0; | |
493 } else if (x2 > width) { | |
494 x2 = width; | |
495 } | |
496 if (y1 < 0) { | |
497 y1 = 0; | |
498 } else if (y1 > height) { | |
499 y1 = height; | |
500 } | |
501 if (y2 < 0) { | |
502 y2 = 0; | |
503 } else if (y2 > height) { | |
504 y2 = height; | |
505 } | |
506 if (x2 <= x1 || y2 <= y1) { | |
507 continue; | |
508 } | |
509 | |
510 switch (private->rotate) { | |
511 case WSCONS_ROTATE_NONE: | |
512 sha_x1 = scr_x1 = x1; | |
513 sha_y1 = scr_y1 = y1; | |
514 scr_x2 = x2; | |
515 scr_y2 = y2; | |
516 shadowRightDelta = 1; | |
517 shadowDownDelta = width; | |
518 break; | |
519 case WSCONS_ROTATE_CCW: | |
520 scr_x1 = y1; | |
521 scr_y1 = width - x2; | |
522 scr_x2 = y2; | |
523 scr_y2 = width - x1; | |
524 sha_x1 = x2 - 1; | |
525 sha_y1 = y1; | |
526 shadowRightDelta = width; | |
527 shadowDownDelta = -1; | |
528 break; | |
529 case WSCONS_ROTATE_UD: | |
530 scr_x1 = width - x2; | |
531 scr_y1 = height - y2; | |
532 scr_x2 = width - x1; | |
533 scr_y2 = height - y1; | |
534 sha_x1 = x2 - 1; | |
535 sha_y1 = y2 - 1; | |
536 shadowRightDelta = -1; | |
537 shadowDownDelta = -width; | |
538 break; | |
539 case WSCONS_ROTATE_CW: | |
540 scr_x1 = height - y2; | |
541 scr_y1 = x1; | |
542 scr_x2 = height - y1; | |
543 scr_y2 = x2; | |
544 sha_x1 = x1; | |
545 sha_y1 = y2 - 1; | |
546 shadowRightDelta = -width; | |
547 shadowDownDelta = 1; | |
548 break; | |
549 default: | |
550 WSCONS_ReportError("Unknown rotation"); | |
551 return; | |
552 } | |
553 | |
554 src_start = private->shadowmem + (sha_y1 * width + sha_x1) * bytesPerPixel; | |
555 dst_start = private->physmem + scr_y1 * private->physlinebytes + | |
556 scr_x1 * bytesPerPixel; | |
557 | |
558 private->blitFunc(src_start, | |
559 shadowRightDelta, | |
560 shadowDownDelta, | |
561 dst_start, | |
562 private->physlinebytes, | |
563 scr_x2 - scr_x1, | |
564 scr_y2 - scr_y1); | |
565 } | |
566 } | |
567 | |
568 int WSCONS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
569 { | |
570 return 0; | |
571 } | |
572 | |
573 /* | |
574 * Note: If we are terminated, this could be called in the middle of | |
575 * another SDL video routine -- notably UpdateRects. | |
576 */ | |
577 void WSCONS_VideoQuit(_THIS) | |
578 { | |
579 int mode = WSDISPLAYIO_MODE_EMUL; | |
580 | |
581 if (private->shadowmem != NULL) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
582 SDL_free(private->shadowmem); |
1187 | 583 private->shadowmem = NULL; |
584 } | |
585 private->fbstart = NULL; | |
586 if (this->screen != NULL) { | |
587 this->screen->pixels = NULL; | |
588 } | |
589 | |
590 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
|
591 SDL_free(private->SDL_modelist[0]); |
1187 | 592 private->SDL_modelist[0] = NULL; |
593 } | |
594 | |
595 if (ioctl(private->fd, WSDISPLAYIO_SMODE, &mode) == -1) { | |
596 WSCONS_ReportError("ioctl SMODE"); | |
597 } | |
598 | |
599 WSCONS_ReleaseKeyboard(this); | |
600 | |
601 if (private->fd != -1) { | |
602 close(private->fd); | |
603 private->fd = -1; | |
604 } | |
605 } |