]> git.pld-linux.org Git - packages/SDL.git/blob - SDL-caca.patch
http://sam.zoy.org/projects/libcaca/patch-libsdl1.2-libcaca0.5.diff
[packages/SDL.git] / SDL-caca.patch
1 $Id$
2 diff -puriN -x Makefile -x '*.la' libsdl1.2-1.2.6/configure.in libsdl1.2-1.2.6-caca/configure.in
3 --- libsdl1.2-1.2.6/configure.in        2003-11-16 23:51:54.000000000 +0100
4 +++ libsdl1.2-1.2.6-caca/configure.in   2003-11-21 15:50:49.000000000 +0100
5 @@ -952,6 +952,32 @@ CheckAAlib()
6      fi
7  }
8  
9 +dnl Find the libcaca includes
10 +CheckCaca()
11 +{
12 +    AC_ARG_ENABLE(video-caca,
13 +[  --enable-video-caca     use libcaca video driver [default=no]],
14 +                  , enable_video_caca=no)
15 +    if test x$enable_video = xyes -a x$enable_video_caca = xyes; then
16 +        AC_MSG_CHECKING(for libcaca support)
17 +        video_caca=no
18 +        AC_TRY_COMPILE([
19 +         #include <caca.h>
20 +        ],[
21 +        ],[
22 +        video_caca=yes
23 +        ])
24 +        AC_MSG_RESULT($video_caca)
25 +        if test x$video_caca = xyes; then
26 +            CFLAGS="$CFLAGS -DENABLE_CACA `caca-config --cflags`"
27 +            SYSTEM_LIBS="$SYSTEM_LIBS `caca-config --plugin-libs`"
28 +
29 +            VIDEO_SUBDIRS="$VIDEO_SUBDIRS caca"
30 +            VIDEO_DRIVERS="$VIDEO_DRIVERS caca/libvideo_caca.la"
31 +        fi
32 +    fi
33 +}
34 +
35  dnl Set up the Atari Xbios driver
36  CheckAtariXbiosVideo()
37  {
38 @@ -1738,6 +1764,7 @@ case "$target" in
39          CheckGGI
40          CheckSVGA
41          CheckAAlib
42 +        CheckCaca
43          CheckQtopia
44          CheckPicoGUI
45          CheckOpenGL
46 @@ -1819,6 +1846,7 @@ case "$target" in
47          CheckDGA
48          CheckSVGA
49          CheckAAlib
50 +        CheckCaca
51          CheckOpenGL
52          CheckPTHREAD
53          # Set up files for the main() stub
54 @@ -1865,6 +1893,7 @@ case "$target" in
55          CheckDGA
56          CheckSVGA
57          CheckAAlib
58 +        CheckCaca
59          CheckOpenGL
60          CheckPTHREAD
61          CheckUSBHID
62 @@ -1903,6 +1932,7 @@ case "$target" in
63          CheckNAS
64          CheckX11
65          CheckAAlib
66 +        CheckCaca
67          CheckOpenGL
68          CheckPTHREAD
69          CheckUSBHID
70 @@ -1945,6 +1975,7 @@ case "$target" in
71          CheckNAS
72          CheckX11
73          CheckAAlib
74 +        CheckCaca
75          CheckOpenGL
76          CheckPTHREAD
77          CheckUSBHID
78 @@ -1988,6 +2019,7 @@ case "$target" in
79          CheckNAS
80          CheckX11
81          CheckAAlib
82 +        CheckCaca
83          CheckOpenGL
84          CheckPTHREAD
85          # Set up files for the main() stub
86 @@ -2031,6 +2063,7 @@ case "$target" in
87          CheckNAS
88          CheckX11
89          CheckAAlib
90 +        CheckCaca
91          CheckOpenGL
92          CheckPTHREAD
93          # Set up files for the main() stub
94 @@ -2071,6 +2104,7 @@ case "$target" in
95          CheckNAS
96          CheckX11
97          CheckAAlib
98 +        CheckCaca
99          CheckOpenGL
100          CheckPTHREAD
101          # Set up files for the main() stub
102 @@ -2123,6 +2157,7 @@ case "$target" in
103          CheckX11
104          CheckGGI
105          CheckAAlib
106 +        CheckCaca
107          CheckOpenGL
108          CheckPTHREAD
109          # Set up files for the main() stub
110 @@ -2164,6 +2199,7 @@ case "$target" in
111          CheckX11
112          CheckGGI
113          CheckAAlib
114 +        CheckCaca
115          CheckOpenGL
116          CheckPTHREAD
117          # Set up files for the main() stub
118 @@ -2202,6 +2238,7 @@ case "$target" in
119          CheckX11
120          CheckGGI
121          CheckAAlib
122 +        CheckCaca
123          CheckOpenGL
124          CheckPTHREAD
125          SDL_LIBS="$SDL_LIBS -lrt"
126 @@ -2709,6 +2746,7 @@ src/video/Makefile
127  src/video/aalib/Makefile
128  src/video/ataricommon/Makefile
129  src/video/bwindow/Makefile
130 +src/video/caca/Makefile
131  src/video/cybergfx/Makefile
132  src/video/dc/Makefile
133  src/video/dga/Makefile
134 diff -puriN -x Makefile -x '*.la' libsdl1.2-1.2.6/src/video/Makefile.am libsdl1.2-1.2.6-caca/src/video/Makefile.am
135 --- libsdl1.2-1.2.6/src/video/Makefile.am       2003-08-30 21:13:06.000000000 +0200
136 +++ libsdl1.2-1.2.6-caca/src/video/Makefile.am  2003-11-17 00:36:40.000000000 +0100
137 @@ -5,7 +5,7 @@ noinst_LTLIBRARIES = libvideo.la
138  
139  # Define which subdirectories need to be built
140  SUBDIRS = @VIDEO_SUBDIRS@
141 -DIST_SUBDIRS = dummy x11 dga nanox fbcon directfb vgl svga ggi aalib \
142 +DIST_SUBDIRS = dummy x11 dga nanox fbcon directfb vgl svga ggi aalib caca \
143                 wincommon windib windx5 \
144                 maccommon macdsp macrom riscos quartz \
145                 bwindow ps2gs photon cybergfx epoc picogui \
146 diff -puriN -x Makefile -x '*.la' libsdl1.2-1.2.6/src/video/SDL_sysvideo.h libsdl1.2-1.2.6-caca/src/video/SDL_sysvideo.h
147 --- libsdl1.2-1.2.6/src/video/SDL_sysvideo.h    2003-08-30 21:13:07.000000000 +0200
148 +++ libsdl1.2-1.2.6-caca/src/video/SDL_sysvideo.h       2003-11-17 02:23:43.000000000 +0100
149 @@ -359,6 +359,9 @@ extern VideoBootStrap SVGALIB_bootstrap;
150  #ifdef ENABLE_AALIB
151  extern VideoBootStrap AALIB_bootstrap;
152  #endif
153 +#ifdef ENABLE_CACA
154 +extern VideoBootStrap Caca_bootstrap;
155 +#endif
156  #ifdef ENABLE_WINDIB
157  extern VideoBootStrap WINDIB_bootstrap;
158  #endif
159 diff -puriN -x Makefile -x '*.la' libsdl1.2-1.2.6/src/video/SDL_video.c libsdl1.2-1.2.6-caca/src/video/SDL_video.c
160 --- libsdl1.2-1.2.6/src/video/SDL_video.c       2003-08-30 21:13:07.000000000 +0200
161 +++ libsdl1.2-1.2.6-caca/src/video/SDL_video.c  2003-11-17 02:23:15.000000000 +0100
162 @@ -78,6 +78,9 @@ static VideoBootStrap *bootstrap[] = {
163  #ifdef ENABLE_AALIB
164         &AALIB_bootstrap,
165  #endif
166 +#ifdef ENABLE_CACA
167 +       &Caca_bootstrap,
168 +#endif
169  #ifdef ENABLE_DIRECTX
170         &DIRECTX_bootstrap,
171  #endif
172 diff -puriN -x Makefile -x '*.la' libsdl1.2-1.2.6/src/video/caca/Makefile.am libsdl1.2-1.2.6-caca/src/video/caca/Makefile.am
173 --- libsdl1.2-1.2.6/src/video/caca/Makefile.am  1970-01-01 01:00:00.000000000 +0100
174 +++ libsdl1.2-1.2.6-caca/src/video/caca/Makefile.am     2003-11-17 01:24:38.000000000 +0100
175 @@ -0,0 +1,13 @@
176 +
177 +## Makefile.am for SDL using the libcaca video driver
178 +
179 +noinst_LTLIBRARIES = libvideo_caca.la
180 +libvideo_caca_la_SOURCES = $(CACA_SRCS)
181 +
182 +# The SDL libcaca video driver sources
183 +CACA_SRCS =                    \
184 +       SDL_cacavideo.h         \
185 +       SDL_cacaevents.c        \
186 +       SDL_cacaevents_c.h      \
187 +       SDL_cacavideo.c
188 +
189 diff -puriN -x Makefile -x '*.la' libsdl1.2-1.2.6/src/video/caca/SDL_cacaevents.c libsdl1.2-1.2.6-caca/src/video/caca/SDL_cacaevents.c
190 --- libsdl1.2-1.2.6/src/video/caca/SDL_cacaevents.c     1970-01-01 01:00:00.000000000 +0100
191 +++ libsdl1.2-1.2.6-caca/src/video/caca/SDL_cacaevents.c        2003-11-21 16:04:12.000000000 +0100
192 @@ -0,0 +1,123 @@
193 +/*
194 +    SDL - Simple DirectMedia Layer
195 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
196 +
197 +    This library is free software; you can redistribute it and/or
198 +    modify it under the terms of the GNU Library General Public
199 +    License as published by the Free Software Foundation; either
200 +    version 2 of the License, or (at your option) any later version.
201 +
202 +    This library is distributed in the hope that it will be useful,
203 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
204 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
205 +    Library General Public License for more details.
206 +
207 +    You should have received a copy of the GNU Library General Public
208 +    License along with this library; if not, write to the Free
209 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
210 +
211 +    Sam Lantinga
212 +    slouken@libsdl.org
213 +*/
214 +
215 +#ifdef SAVE_RCSID
216 +static char rcsid =
217 + "@(#) $Id$";
218 +#endif
219 +
220 +#include <stdio.h>
221 +
222 +#include <caca.h>
223 +
224 +#include "SDL.h"
225 +#include "SDL_sysevents.h"
226 +#include "SDL_events_c.h"
227 +#include "SDL_cacavideo.h"
228 +#include "SDL_cacaevents_c.h"
229 +
230 +void Caca_PumpEvents(_THIS)
231 +{
232 +       static int prev_x = -1, prev_y = -1;
233 +       int posted = 0;
234 +       int event;
235 +       SDL_keysym keysym;
236 +
237 +       if( ! this->screen ) /* Wait till we got the screen initialized */
238 +         return;
239 +
240 +       do {
241 +               posted = 0;
242 +
243 +               /* Get keyboard event */
244 +               SDL_mutexP(Caca_mutex);
245 +               event = caca_get_event();
246 +               SDL_mutexV(Caca_mutex);
247 +               if ( Caca_lastkey ) {
248 +                       /* Release previous key if necessary */
249 +                       if ( !event ) {
250 +                               struct timeval now;
251 +                               Uint64 t1, t2;
252 +                               gettimeofday ( &now, NULL );
253 +                               t1 = (Uint64)now.tv_sec * 1000000 + now.tv_usec;
254 +                               t2 = (Uint64)Caca_lasttime.tv_sec * 1000000
255 +                                       + Caca_lasttime.tv_usec;
256 +                               if ( t1 < t2 + 100000 )
257 +                                       break;
258 +                       }
259 +                       keysym.scancode = Caca_lastkey;
260 +                       keysym.sym = Caca_lastkey;
261 +                       keysym.mod = KMOD_NONE;
262 +                       keysym.unicode = 0;
263 +                       if ( SDL_TranslateUNICODE ) {
264 +                               keysym.unicode = Caca_lastkey;
265 +                       }
266 +                       posted += SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
267 +                       Caca_lastkey = 0;
268 +               }
269 +               if ( event & CACA_EVENT_KEY_PRESS ) {
270 +                       int key;
271 +                       switch ( event & 0xffff )
272 +                       {
273 +                               case CACA_KEY_LEFT: key = SDLK_LEFT; break;
274 +                               case CACA_KEY_RIGHT: key = SDLK_RIGHT; break;
275 +                               case CACA_KEY_UP: key = SDLK_UP; break;
276 +                               case CACA_KEY_DOWN: key = SDLK_DOWN; break;
277 +                               default: key = event & 0xffff; break;
278 +                       }
279 +                       /* Key pressed */
280 +/*                     printf("Key pressed: %d (%c)\n", key, key); */
281 +                       keysym.scancode = key;
282 +                       keysym.sym = key;
283 +                       keysym.mod = KMOD_NONE;
284 +                       keysym.unicode = 0;
285 +                       if ( SDL_TranslateUNICODE ) {
286 +                               keysym.unicode = key;
287 +                       }
288 +                       posted += SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
289 +                       Caca_lastkey = key;
290 +                       gettimeofday ( &Caca_lasttime, NULL );
291 +               }
292 +               else if ( event & CACA_EVENT_MOUSE_CLICK ) {
293 +                       int new_x, new_y, button;
294 +                       button = (event & 0x0000ff00) >> 16;
295 +                       new_x = ((event & 0x0000ff00) >> 8) * Caca_w / caca_get_width();
296 +                       new_y = ((event & 0x000000ff) >> 0) * Caca_h / caca_get_height();
297 +
298 +                       if ( prev_x != new_x || prev_y != new_y ) {
299 +                               posted += SDL_PrivateMouseMotion(0, 0, new_x, new_y);
300 +                               prev_x = new_x;
301 +                               prev_y = new_y;
302 +                       }
303 +
304 +                       /* FIXME: we currently ignore the button type! */
305 +                       posted += SDL_PrivateMouseButton(SDL_PRESSED, 1, 0, 0);
306 +                       posted += SDL_PrivateMouseButton(SDL_RELEASED, 1, 0, 0);
307 +               }
308 +       } while ( posted );
309 +}
310 +
311 +void Caca_InitOSKeymap(_THIS)
312 +{
313 +    return;
314 +}
315 +
316 diff -puriN -x Makefile -x '*.la' libsdl1.2-1.2.6/src/video/caca/SDL_cacaevents_c.h libsdl1.2-1.2.6-caca/src/video/caca/SDL_cacaevents_c.h
317 --- libsdl1.2-1.2.6/src/video/caca/SDL_cacaevents_c.h   1970-01-01 01:00:00.000000000 +0100
318 +++ libsdl1.2-1.2.6-caca/src/video/caca/SDL_cacaevents_c.h      2003-11-17 03:04:31.000000000 +0100
319 @@ -0,0 +1,34 @@
320 +/*
321 +    SDL - Simple DirectMedia Layer
322 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
323 +
324 +    This library is free software; you can redistribute it and/or
325 +    modify it under the terms of the GNU Library General Public
326 +    License as published by the Free Software Foundation; either
327 +    version 2 of the License, or (at your option) any later version.
328 +
329 +    This library is distributed in the hope that it will be useful,
330 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
331 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
332 +    Library General Public License for more details.
333 +
334 +    You should have received a copy of the GNU Library General Public
335 +    License along with this library; if not, write to the Free
336 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
337 +
338 +    Sam Lantinga
339 +    slouken@libsdl.org
340 +*/
341 +
342 +#ifdef SAVE_RCSID
343 +static char rcsid =
344 + "@(#) $Id$";
345 +#endif
346 +
347 +#include "SDL_cacavideo.h"
348 +
349 +/* Variables and functions exported by SDL_sysevents.c to other parts 
350 +   of the native video subsystem (SDL_sysvideo.c)
351 +*/
352 +extern void Caca_PumpEvents(_THIS);
353 +extern void Caca_InitOSKeymap(_THIS);
354 diff -puriN -x Makefile -x '*.la' libsdl1.2-1.2.6/src/video/caca/SDL_cacavideo.c libsdl1.2-1.2.6-caca/src/video/caca/SDL_cacavideo.c
355 --- libsdl1.2-1.2.6/src/video/caca/SDL_cacavideo.c      1970-01-01 01:00:00.000000000 +0100
356 +++ libsdl1.2-1.2.6-caca/src/video/caca/SDL_cacavideo.c 2003-12-18 13:11:06.000000000 +0100
357 @@ -0,0 +1,301 @@
358 +/*
359 +    SDL - Simple DirectMedia Layer
360 +    Copyright (C) 2003  Sam Hocevar
361 +
362 +    This library is free software; you can redistribute it and/or
363 +    modify it under the terms of the GNU Library General Public
364 +    License as published by the Free Software Foundation; either
365 +    version 2 of the License, or (at your option) any later version.
366 +
367 +    This library is distributed in the hope that it will be useful,
368 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
369 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
370 +    Library General Public License for more details.
371 +
372 +    You should have received a copy of the GNU Library General Public
373 +    License along with this library; if not, write to the Free
374 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
375 +
376 +    Sam Hocevar
377 +    sam@zoy.org
378 +*/
379 +
380 +#ifdef SAVE_RCSID
381 +static char rcsid =
382 + "@(#) $Id$";
383 +#endif
384 +
385 +/* libcaca based SDL video driver implementation.
386 +*/
387 +
388 +#include <stdlib.h>
389 +#include <stdio.h>
390 +#include <string.h>
391 +#include <unistd.h>
392 +#include <sys/stat.h>
393 +
394 +
395 +#include "SDL.h"
396 +#include "SDL_error.h"
397 +#include "SDL_video.h"
398 +#include "SDL_mouse.h"
399 +#include "SDL_sysvideo.h"
400 +#include "SDL_pixels_c.h"
401 +#include "SDL_events_c.h"
402 +
403 +#include "SDL_cacavideo.h"
404 +#include "SDL_cacaevents_c.h"
405 +
406 +#include <caca.h>
407 +
408 +/* Initialization/Query functions */
409 +static int Caca_VideoInit(_THIS, SDL_PixelFormat *vformat);
410 +static SDL_Rect **Caca_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
411 +static SDL_Surface *Caca_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
412 +static void Caca_VideoQuit(_THIS);
413 +
414 +/* Hardware surface functions */
415 +static int Caca_AllocHWSurface(_THIS, SDL_Surface *surface);
416 +static int Caca_LockHWSurface(_THIS, SDL_Surface *surface);
417 +static int Caca_FlipHWSurface(_THIS, SDL_Surface *surface);
418 +static void Caca_UnlockHWSurface(_THIS, SDL_Surface *surface);
419 +static void Caca_FreeHWSurface(_THIS, SDL_Surface *surface);
420 +
421 +/* Cache the VideoDevice struct */
422 +static struct SDL_VideoDevice *local_this;
423 +
424 +/* libcaca driver bootstrap functions */
425 +
426 +static int Caca_Available(void)
427 +{
428 +       return 1; /* Always available ! */
429 +}
430 +
431 +static void Caca_DeleteDevice(SDL_VideoDevice *device)
432 +{
433 +       free(device->hidden);
434 +       free(device);
435 +}
436 +
437 +static SDL_VideoDevice *Caca_CreateDevice(int devindex)
438 +{
439 +       SDL_VideoDevice *device;
440 +
441 +       /* Initialize all variables that we clean on shutdown */
442 +       device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
443 +       if ( device ) {
444 +               memset(device, 0, (sizeof *device));
445 +               device->hidden = (struct SDL_PrivateVideoData *)
446 +                               malloc((sizeof *device->hidden));
447 +       }
448 +       if ( (device == NULL) || (device->hidden == NULL) ) {
449 +               SDL_OutOfMemory();
450 +               if ( device ) {
451 +                       free(device);
452 +               }
453 +               return(0);
454 +       }
455 +       memset(device->hidden, 0, (sizeof *device->hidden));
456 +
457 +       /* Set the function pointers */
458 +       device->VideoInit = Caca_VideoInit;
459 +       device->ListModes = Caca_ListModes;
460 +       device->SetVideoMode = Caca_SetVideoMode;
461 +       device->CreateYUVOverlay = NULL;
462 +       device->SetColors = NULL;
463 +       device->UpdateRects = NULL;
464 +       device->VideoQuit = Caca_VideoQuit;
465 +       device->AllocHWSurface = Caca_AllocHWSurface;
466 +       device->CheckHWBlit = NULL;
467 +       device->FillHWRect = NULL;
468 +       device->SetHWColorKey = NULL;
469 +       device->SetHWAlpha = NULL;
470 +       device->LockHWSurface = Caca_LockHWSurface;
471 +       device->UnlockHWSurface = Caca_UnlockHWSurface;
472 +       device->FlipHWSurface = NULL;
473 +       device->FreeHWSurface = Caca_FreeHWSurface;
474 +       device->SetCaption = NULL;
475 +       device->SetIcon = NULL;
476 +       device->IconifyWindow = NULL;
477 +       device->GrabInput = NULL;
478 +       device->GetWMInfo = NULL;
479 +       device->InitOSKeymap = Caca_InitOSKeymap;
480 +       device->PumpEvents = Caca_PumpEvents;
481 +
482 +       device->free = Caca_DeleteDevice;
483 +
484 +       return device;
485 +}
486 +
487 +VideoBootStrap Caca_bootstrap = {
488 +       "caca", "Color ASCII Art Library",
489 +       Caca_Available, Caca_CreateDevice
490 +};
491 +
492 +int Caca_VideoInit(_THIS, SDL_PixelFormat *vformat)
493 +{
494 +       int i;
495 +
496 +       /* Initialize all variables that we clean on shutdown */
497 +       for ( i=0; i<SDL_NUMMODES; ++i ) {
498 +               SDL_modelist[i] = malloc(sizeof(SDL_Rect));
499 +               SDL_modelist[i]->x = SDL_modelist[i]->y = 0;
500 +       }
501 +       /* Modes sorted largest to smallest */
502 +       SDL_modelist[0]->w = 1024; SDL_modelist[0]->h = 768;
503 +       SDL_modelist[1]->w = 800; SDL_modelist[1]->h = 600;
504 +       SDL_modelist[2]->w = 640; SDL_modelist[2]->h = 480;
505 +       SDL_modelist[3]->w = 320; SDL_modelist[3]->h = 400;
506 +       SDL_modelist[4]->w = 320; SDL_modelist[4]->h = 240;
507 +       SDL_modelist[5]->w = 320; SDL_modelist[5]->h = 200;
508 +       SDL_modelist[6] = NULL;
509 +
510 +       Caca_mutex = SDL_CreateMutex();
511 +
512 +       /* Initialize the library */
513 +       if ( caca_init() != 0 ) {
514 +               SDL_SetError("Unable to initialize libcaca");
515 +               return(-1);
516 +       }
517 +
518 +       /* Initialize private variables */
519 +       Caca_lastkey = 0;
520 +       Caca_bitmap = NULL;
521 +       Caca_buffer = NULL;
522 +
523 +       local_this = this;
524 +
525 +       /* Determine the screen depth (use default 8-bit depth) */
526 +       vformat->BitsPerPixel = 8;
527 +       vformat->BytesPerPixel = 1;
528 +
529 +       /* We're done! */
530 +       return(0);
531 +}
532 +
533 +SDL_Rect **Caca_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
534 +{
535 +     if(format->BitsPerPixel != 8)
536 +               return NULL;
537 +
538 +        if ( flags & SDL_FULLSCREEN ) {
539 +                return SDL_modelist;
540 +        } else {
541 +                return (SDL_Rect **) -1;
542 +        }
543 +}
544 +
545 +/* Various screen update functions available */
546 +static void Caca_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
547 +
548 +SDL_Surface *Caca_SetVideoMode(_THIS, SDL_Surface *current,
549 +                               int width, int height, int bpp, Uint32 flags)
550 +{
551 +       if ( Caca_buffer ) {
552 +               free( Caca_buffer );
553 +               Caca_buffer = NULL;
554 +       }
555 +
556 +       if ( Caca_bitmap ) {
557 +               caca_free_bitmap( Caca_bitmap );
558 +               Caca_bitmap = NULL;
559 +       }
560 +
561 +       Caca_buffer = malloc(2 * ((width + 15) & ~15) * height);
562 +       if ( ! Caca_buffer ) {
563 +               SDL_SetError("Couldn't allocate buffer for requested mode");
564 +               return(NULL);
565 +       }
566 +
567 +       memset(Caca_buffer, 0, 2 * ((width + 15) & ~15) * height);
568 +
569 +       /* Allocate the new pixel format for the screen */
570 +       if ( ! SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0) ) {
571 +               return(NULL);
572 +       }
573 +
574 +       /* Set up the new mode framebuffer */
575 +       current->flags = SDL_FULLSCREEN;
576 +       Caca_w = current->w = width;
577 +       Caca_h = current->h = height;
578 +       current->pitch = 2 * ((width + 15) & ~15);
579 +       current->pixels = Caca_buffer;
580 +
581 +       /* Create the libcaca bitmap */
582 +       Caca_bitmap = caca_create_bitmap( 16, width, height, current->pitch, 0xf800, 0x07e0, 0x001f, 0x0000 );
583 +       if ( ! Caca_bitmap ) {
584 +               SDL_SetError("Couldn't allocate libcaca bitmap");
585 +               return(NULL);
586 +       }
587 +
588 +       /* Set the blit function */
589 +       this->UpdateRects = Caca_DirectUpdate;
590 +
591 +       /* We're done */
592 +       return(current);
593 +}
594 +
595 +/* We don't actually allow hardware surfaces other than the main one */
596 +static int Caca_AllocHWSurface(_THIS, SDL_Surface *surface)
597 +{
598 +       return(-1);
599 +}
600 +static void Caca_FreeHWSurface(_THIS, SDL_Surface *surface)
601 +{
602 +       return;
603 +}
604 +
605 +/* We need to wait for vertical retrace on page flipped displays */
606 +static int Caca_LockHWSurface(_THIS, SDL_Surface *surface)
607 +{
608 +       /* TODO ? */
609 +       return(0);
610 +}
611 +static void Caca_UnlockHWSurface(_THIS, SDL_Surface *surface)
612 +{
613 +       return;
614 +}
615 +
616 +/* FIXME: How is this done with libcaca? */
617 +static int Caca_FlipHWSurface(_THIS, SDL_Surface *surface)
618 +{
619 +       SDL_mutexP(Caca_mutex);
620 +       caca_refresh();
621 +       SDL_mutexV(Caca_mutex);
622 +       return(0);
623 +}
624 +
625 +static void Caca_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
626 +{
627 +       SDL_mutexP(Caca_mutex);
628 +       caca_draw_bitmap( 0, 0, caca_get_width() - 1, caca_get_height() - 1,
629 +                         Caca_bitmap, Caca_buffer );
630 +       caca_refresh();
631 +       SDL_mutexV(Caca_mutex);
632 +       return;
633 +}
634 +
635 +/* Note:  If we are terminated, this could be called in the middle of
636 +   another SDL video routine -- notably UpdateRects.
637 +*/
638 +void Caca_VideoQuit(_THIS)
639 +{
640 +       int i;
641 +
642 +       /* Free video mode lists */
643 +       for ( i=0; i<SDL_NUMMODES; ++i ) {
644 +               if ( SDL_modelist[i] != NULL ) {
645 +                       free(SDL_modelist[i]);
646 +                       SDL_modelist[i] = NULL;
647 +               }
648 +       }
649 +
650 +       if ( Caca_bitmap ) {
651 +               caca_free_bitmap( Caca_bitmap );
652 +               Caca_bitmap = NULL;
653 +       }
654 +
655 +       caca_end();
656 +
657 +       SDL_DestroyMutex(Caca_mutex);
658 +}
659 diff -puriN -x Makefile -x '*.la' libsdl1.2-1.2.6/src/video/caca/SDL_cacavideo.h libsdl1.2-1.2.6-caca/src/video/caca/SDL_cacavideo.h
660 --- libsdl1.2-1.2.6/src/video/caca/SDL_cacavideo.h      1970-01-01 01:00:00.000000000 +0100
661 +++ libsdl1.2-1.2.6-caca/src/video/caca/SDL_cacavideo.h 2003-11-21 16:03:00.000000000 +0100
662 @@ -0,0 +1,72 @@
663 +/*
664 +    SDL - Simple DirectMedia Layer
665 +    Copyright (C) 2003  Sam Hocevar
666 +
667 +    This library is free software; you can redistribute it and/or
668 +    modify it under the terms of the GNU Library General Public
669 +    License as published by the Free Software Foundation; either
670 +    version 2 of the License, or (at your option) any later version.
671 +
672 +    This library is distributed in the hope that it will be useful,
673 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
674 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
675 +    Library General Public License for more details.
676 +
677 +    You should have received a copy of the GNU Library General Public
678 +    License along with this library; if not, write to the Free
679 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
680 +
681 +    Sam Hocevar
682 +    sam@zoy.org
683 +*/
684 +
685 +#ifdef SAVE_RCSID
686 +static char rcsid =
687 + "@(#) $Id$";
688 +#endif
689 +
690 +#ifndef _SDL_cacavideo_h
691 +#define _SDL_cacavideo_h
692 +
693 +#include "SDL_mouse.h"
694 +#include "SDL_sysvideo.h"
695 +#include "SDL_mutex.h"
696 +
697 +#include <sys/time.h>
698 +#include <time.h>
699 +
700 +#include <caca.h>
701 +
702 +/* Hidden "this" pointer for the video functions */
703 +#define _THIS  SDL_VideoDevice *this
704 +
705 +#define SDL_NUMMODES 6
706 +
707 +/* Private display data */
708 +struct SDL_PrivateVideoData {
709 +       SDL_Rect *SDL_modelist[SDL_NUMMODES+1];
710 +       SDL_mutex *mutex;
711 +
712 +       struct caca_bitmap *bitmap;
713 +       void *buffer;
714 +       int w, h;
715 +
716 +       int lastkey;
717 +       struct timeval lasttime;
718 +};
719 +
720 +/* Old variable names */
721 +#define SDL_modelist           (this->hidden->SDL_modelist)
722 +#define Caca_palette               (this->hidden->palette)
723 +#define Caca_bitmap                (this->hidden->bitmap)
724 +#define Caca_buffer                (this->hidden->buffer)
725 +
726 +#define Caca_w                     (this->hidden->w)
727 +#define Caca_h                     (this->hidden->h)
728 +
729 +#define Caca_lastkey               (this->hidden->lastkey)
730 +#define Caca_lasttime              (this->hidden->lasttime)
731 +
732 +#define Caca_mutex                 (this->hidden->mutex)
733 +
734 +#endif /* _SDL_cacavideo_h */
This page took 0.17069 seconds and 3 git commands to generate.