Changes since SDL 1.2.0 release

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402
This commit is contained in:
Sam Lantinga 2001-04-26 16:50:19 +00:00
parent 2f110628a7
commit 9b6cc5a90d
40 changed files with 1225 additions and 105 deletions

View file

@ -47,6 +47,10 @@ static SDL_error SDL_global_error;
#define SDL_GetErrBuf() (&SDL_global_error)
#endif /* DISABLE_THREADS */
#ifdef __CYGWIN__
#define DISABLE_STDIO
#endif
#define SDL_ERRBUFIZE 1024
/* Private functions */
@ -120,6 +124,7 @@ void SDL_SetError (const char *fmt, ...)
}
va_end(ap);
#ifndef DISABLE_STDIO
/* If we are in debug mode, print out an error message */
#ifdef DEBUG_ERROR
fprintf(stderr, "SDL_SetError: %s\n", SDL_GetError());
@ -128,6 +133,7 @@ void SDL_SetError (const char *fmt, ...)
fprintf(stderr, "SDL_SetError: %s\n", SDL_GetError());
}
#endif
#endif /* !DISABLE_STDIO */
}
/* Print out an integer value to a UNICODE buffer */

View file

@ -51,46 +51,59 @@ void SDL_UninstallParachute(void)
#include "SDL.h"
#include "SDL_fatal.h"
#ifdef __CYGWIN__
#define DISABLE_STDIO
#endif
/* This installs some signal handlers for the more common fatal signals,
so that if the programmer is lazy, the app doesn't die so horribly if
the program crashes.
*/
static void print_msg(const char *text)
{
#ifndef DISABLE_STDIO
fprintf(stderr, "%s", text);
#endif
}
static void SDL_Parachute(int sig)
{
signal(sig, SIG_DFL);
fprintf(stderr, "Fatal signal: ");
print_msg("Fatal signal: ");
switch (sig) {
case SIGSEGV:
fprintf(stderr, "Segmentation Fault");
print_msg("Segmentation Fault");
break;
#ifdef SIGBUS
#if SIGBUS != SIGSEGV
case SIGBUS:
fprintf(stderr, "Bus Error");
print_msg("Bus Error");
break;
#endif
#endif /* SIGBUS */
#ifdef SIGFPE
case SIGFPE:
fprintf(stderr, "Floating Point Exception");
print_msg("Floating Point Exception");
break;
#endif /* SIGFPE */
#ifdef SIGQUIT
case SIGQUIT:
fprintf(stderr, "Keyboard Quit");
print_msg("Keyboard Quit");
break;
#endif /* SIGQUIT */
#ifdef SIGPIPE
case SIGPIPE:
fprintf(stderr, "Broken Pipe");
print_msg("Broken Pipe");
break;
#endif /* SIGPIPE */
default:
#ifndef DISABLE_STDIO
fprintf(stderr, "# %d", sig);
#endif
break;
}
fprintf(stderr, " (SDL Parachute Deployed)\n");
print_msg(" (SDL Parachute Deployed)\n");
SDL_Quit();
exit(-sig);
}

View file

@ -29,13 +29,12 @@ static char rcsid =
(necessary because SDL audio emulates threads with fork()
*/
#include <stdlib.h>
#ifdef FORK_HACK
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stddef.h>
#else
#include <stdlib.h>
#endif
#include "SDL_audiomem.h"

View file

@ -96,7 +96,7 @@ static const Uint8 mix8[] =
#define ADJUST_VOLUME(s, v) (s = (s*v)/SDL_MIX_MAXVOLUME)
#define ADJUST_VOLUME_U8(s, v) (s = (((s-128)*v)/SDL_MIX_MAXVOLUME)+128)
void SDL_MixAudio (Uint8 *dst, Uint8 *src, Uint32 len, int volume)
void SDL_MixAudio (Uint8 *dst, const Uint8 *src, Uint32 len, int volume)
{
Uint16 format;

View file

@ -48,6 +48,9 @@ static char rcsid =
#ifdef __FreeBSD__
#include <machine/soundcard.h>
#endif
#ifdef __OpenBSD__
#include <soundcard.h>
#endif
#ifdef __USLC__
#include <sys/soundcard.h>
#endif

View file

@ -46,6 +46,9 @@ static char rcsid =
#ifdef __FreeBSD__
#include <machine/soundcard.h>
#endif
#ifdef __OpenBSD__
#include <soundcard.h>
#endif
#ifdef __USLC__
#include <sys/soundcard.h>
#endif

View file

@ -36,6 +36,7 @@ static char rcsid =
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/cdio.h>
#include "SDL_error.h"
@ -64,7 +65,8 @@ static void SDL_SYS_CDClose(SDL_CD *cdrom);
/* Some ioctl() errno values which occur when the tray is empty */
#define ERRNO_TRAYEMPTY(errno) \
((errno == EIO) || (errno == ENOENT) || (errno == EINVAL))
((errno == EIO) || (errno == ENOENT) || (errno == EINVAL) || \
(errno == ENODEV))
/* Check a drive to see if it is a CD-ROM */
static int CheckDrive(char *drive, struct stat *stbuf)
@ -96,6 +98,8 @@ static int CheckDrive(char *drive, struct stat *stbuf)
}
close(cdfd);
}
else if (ERRNO_TRAYEMPTY(errno))
is_cd = 1;
}
return(is_cd);
}
@ -137,7 +141,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
int SDL_SYS_CDInit(void)
{
static char *checklist[] = {
#ifdef __OpenBSD__
"?0 cd?a", "cdrom", NULL
#else
"?0 cd?c", "?0 acd?c", "cdrom", NULL
#endif
};
char *SDLcdrom;
int i, j, exists;

286
src/timer/SDL_timer.c Normal file
View file

@ -0,0 +1,286 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
5635-34 Springhouse Dr.
Pleasanton, CA 94588 (USA)
slouken@devolution.com
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
#include <stdlib.h>
#include <stdio.h> /* For the definition of NULL */
#include "SDL_error.h"
#include "SDL_timer.h"
#include "SDL_timer_c.h"
#include "SDL_mutex.h"
#include "SDL_systimer.h"
/* #define DEBUG_TIMERS */
int SDL_timer_started = 0;
int SDL_timer_running = 0;
/* Data to handle a single periodic alarm */
Uint32 SDL_alarm_interval = 0;
SDL_TimerCallback SDL_alarm_callback;
static SDL_bool list_changed = SDL_FALSE;
/* Data used for a thread-based timer */
static int SDL_timer_threaded = 0;
struct _SDL_TimerID {
Uint32 interval;
SDL_NewTimerCallback cb;
void *param;
Uint32 last_alarm;
struct _SDL_TimerID *next;
};
static SDL_TimerID SDL_timers = NULL;
static Uint32 num_timers = 0;
static SDL_mutex *SDL_timer_mutex;
/* Set whether or not the timer should use a thread.
This should not be called while the timer subsystem is running.
*/
int SDL_SetTimerThreaded(int value)
{
int retval;
if ( SDL_timer_started ) {
SDL_SetError("Timer already initialized");
retval = -1;
} else {
retval = 0;
SDL_timer_threaded = value;
}
return retval;
}
int SDL_TimerInit(void)
{
int retval;
SDL_timer_running = 0;
SDL_SetTimer(0, NULL);
retval = 0;
if ( ! SDL_timer_threaded ) {
retval = SDL_SYS_TimerInit();
}
if ( SDL_timer_threaded ) {
SDL_timer_mutex = SDL_CreateMutex();
}
SDL_timer_started = 1;
return(retval);
}
void SDL_TimerQuit(void)
{
SDL_SetTimer(0, NULL);
if ( SDL_timer_threaded < 2 ) {
SDL_SYS_TimerQuit();
}
if ( SDL_timer_threaded ) {
SDL_DestroyMutex(SDL_timer_mutex);
}
SDL_timer_started = 0;
SDL_timer_threaded = 0;
}
void SDL_ThreadedTimerCheck(void)
{
Uint32 now, ms;
SDL_TimerID t, prev, next;
int removed;
now = SDL_GetTicks();
SDL_mutexP(SDL_timer_mutex);
for ( prev = NULL, t = SDL_timers; t; t = next ) {
removed = 0;
ms = t->interval - SDL_TIMESLICE;
next = t->next;
if ( (t->last_alarm < now) && ((now - t->last_alarm) > ms) ) {
if ( (now - t->last_alarm) < t->interval ) {
t->last_alarm += t->interval;
} else {
t->last_alarm = now;
}
list_changed = SDL_FALSE;
#ifdef DEBUG_TIMERS
printf("Executing timer %p (thread = %d)\n",
t, SDL_ThreadID());
#endif
SDL_mutexV(SDL_timer_mutex);
ms = t->cb(t->interval, t->param);
SDL_mutexP(SDL_timer_mutex);
if ( list_changed ) {
/* Abort, list of timers has been modified */
break;
}
if ( ms != t->interval ) {
if ( ms ) {
t->interval = ROUND_RESOLUTION(ms);
} else { /* Remove the timer from the linked list */
#ifdef DEBUG_TIMERS
printf("SDL: Removing timer %p\n", t);
#endif
if ( prev ) {
prev->next = next;
} else {
SDL_timers = next;
}
free(t);
-- num_timers;
removed = 1;
}
}
}
/* Don't update prev if the timer has disappeared */
if ( ! removed ) {
prev = t;
}
}
SDL_mutexV(SDL_timer_mutex);
}
SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param)
{
SDL_TimerID t;
if ( ! SDL_timer_mutex ) {
if ( SDL_timer_started ) {
SDL_SetError("This platform doesn't support multiple timers");
} else {
SDL_SetError("You must call SDL_Init(SDL_INIT_TIMER) first");
}
return NULL;
}
if ( ! SDL_timer_threaded ) {
SDL_SetError("Multiple timers require threaded events!");
return NULL;
}
SDL_mutexP(SDL_timer_mutex);
t = (SDL_TimerID) malloc(sizeof(struct _SDL_TimerID));
if ( t ) {
t->interval = ROUND_RESOLUTION(interval);
t->cb = callback;
t->param = param;
t->last_alarm = SDL_GetTicks();
t->next = SDL_timers;
SDL_timers = t;
++ num_timers;
list_changed = SDL_TRUE;
SDL_timer_running = 1;
}
#ifdef DEBUG_TIMERS
printf("SDL_AddTimer(%d) = %08x num_timers = %d\n", interval, (Uint32)t, num_timers);
#endif
SDL_mutexV(SDL_timer_mutex);
return t;
}
SDL_bool SDL_RemoveTimer(SDL_TimerID id)
{
SDL_TimerID t, prev = NULL;
SDL_bool removed;
removed = SDL_FALSE;
SDL_mutexP(SDL_timer_mutex);
/* Look for id in the linked list of timers */
for (t = SDL_timers; t; prev=t, t = t->next ) {
if ( t == id ) {
if(prev) {
prev->next = t->next;
} else {
SDL_timers = t->next;
}
free(t);
-- num_timers;
removed = SDL_TRUE;
list_changed = SDL_TRUE;
break;
}
}
#ifdef DEBUG_TIMERS
printf("SDL_RemoveTimer(%08x) = %d num_timers = %d thread = %d\n", (Uint32)id, removed, num_timers, SDL_ThreadID());
#endif
SDL_mutexV(SDL_timer_mutex);
return removed;
}
static void SDL_RemoveAllTimers(SDL_TimerID t)
{
SDL_TimerID freeme;
/* Changed to non-recursive implementation.
The recursive implementation is elegant, but subject to
stack overflow if there are lots and lots of timers.
*/
while ( t ) {
freeme = t;
t = t->next;
free(freeme);
}
}
/* Old style callback functions are wrapped through this */
static Uint32 callback_wrapper(Uint32 ms, void *param)
{
SDL_TimerCallback func = (SDL_TimerCallback) param;
return (*func)(ms);
}
int SDL_SetTimer(Uint32 ms, SDL_TimerCallback callback)
{
int retval;
#ifdef DEBUG_TIMERS
printf("SDL_SetTimer(%d)\n", ms);
#endif
retval = 0;
if ( SDL_timer_running ) { /* Stop any currently running timer */
SDL_timer_running = 0;
if ( SDL_timer_threaded ) {
SDL_mutexP(SDL_timer_mutex);
SDL_RemoveAllTimers(SDL_timers);
SDL_timers = NULL;
SDL_mutexV(SDL_timer_mutex);
} else {
SDL_SYS_StopTimer();
}
}
if ( ms ) {
if ( SDL_timer_threaded ) {
retval = (SDL_AddTimer(ms, callback_wrapper,
(void *)callback) != NULL);
} else {
SDL_timer_running = 1;
SDL_alarm_interval = ms;
SDL_alarm_callback = callback;
retval = SDL_SYS_StartTimer();
}
}
return retval;
}

View file

@ -36,6 +36,10 @@ static char rcsid =
#include "SDL_timer.h"
#include "SDL_timer_c.h"
#if _POSIX_THREAD_SYSCALL_SOFT
#include <pthread.h>
#endif
#if defined(DISABLE_THREADS) || defined(FORK_HACK)
#define USE_ITIMER
#endif
@ -96,6 +100,9 @@ void SDL_Delay (Uint32 ms)
do {
errno = 0;
#if _POSIX_THREAD_SYSCALL_SOFT
pthread_yield_np();
#endif
#ifdef USE_NANOSLEEP
tv.tv_sec = elapsed.tv_sec;
tv.tv_nsec = elapsed.tv_nsec;

View file

@ -5,7 +5,7 @@ noinst_LTLIBRARIES = libvideo.la
# Define which subdirectories need to be built
SUBDIRS = @VIDEO_SUBDIRS@
DIST_SUBDIRS = x11 dga fbcon svga ggi aalib \
DIST_SUBDIRS = dummy x11 dga fbcon svga ggi aalib \
wincommon windib windx5 \
maccommon macdsp macrom bwindow photon cybergfx

View file

@ -109,12 +109,21 @@ static char rcsid =
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#define PIXEL_COPY(to, from, len, bpp) \
do { \
if(bpp == 4) { \
SDL_memcpy4(to, from, (unsigned)(len)); \
} else { \
SDL_memcpy(to, from, (unsigned)(len) * (bpp)); \
} \
} while(0)
/*
* Various colorkey blit methods, for opaque and per-surface alpha
*/
#define OPAQUE_BLIT(to, from, length, bpp, alpha) \
SDL_memcpy(to, from, (unsigned)(length * bpp))
PIXEL_COPY(to, from, length, bpp)
/*
* For 32bpp pixels on the form 0x00rrggbb:
@ -657,9 +666,9 @@ static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst,
if(crun > right - cofs) \
crun = right - cofs; \
if(crun > 0) \
SDL_memcpy(dstbuf + cofs * sizeof(Ptype), \
PIXEL_COPY(dstbuf + cofs * sizeof(Ptype), \
srcbuf + (cofs - ofs) * sizeof(Ptype), \
(unsigned)crun * sizeof(Ptype)); \
(unsigned)crun, sizeof(Ptype)); \
srcbuf += run * sizeof(Ptype); \
ofs += run; \
} else if(!ofs) \
@ -816,8 +825,8 @@ int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect,
run = ((Ctype *)srcbuf)[1]; \
srcbuf += 2 * sizeof(Ctype); \
if(run) { \
SDL_memcpy(dstbuf + ofs * sizeof(Ptype), srcbuf, \
run * sizeof(Ptype)); \
PIXEL_COPY(dstbuf + ofs * sizeof(Ptype), srcbuf, \
run, sizeof(Ptype)); \
srcbuf += run * sizeof(Ptype); \
ofs += run; \
} else if(!ofs) \

View file

@ -195,8 +195,8 @@ static void BlitNto1SurfaceAlphaKey(SDL_BlitInfo *info)
}
}
/* fast RGB888->(A)RGB888 blending with surface alpha */
static void BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo *info)
/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
static void BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo *info)
{
int width = info->d_width;
int height = info->d_height;
@ -204,32 +204,58 @@ static void BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo *info)
int srcskip = info->s_skip >> 2;
Uint32 *dstp = (Uint32 *)info->d_pixels;
int dstskip = info->d_skip >> 2;
SDL_PixelFormat *srcfmt = info->src;
unsigned alpha = srcfmt->alpha;
while(height--) {
DUFFS_LOOP4({
Uint32 s;
Uint32 d;
Uint32 s1;
Uint32 d1;
s = *srcp;
d = *dstp;
s1 = s & 0xff00ff;
d1 = d & 0xff00ff;
d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff;
s &= 0xff00;
d &= 0xff00;
d = (d + ((s - d) * alpha >> 8)) & 0xff00;
*dstp = d1 | d | 0xff000000;
++srcp;
++dstp;
Uint32 s = *srcp++;
Uint32 d = *dstp;
*dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
+ (s & d & 0x00010101)) | 0xff000000;
}, width);
srcp += srcskip;
dstp += dstskip;
}
}
/* fast RGB888->(A)RGB888 blending with surface alpha */
static void BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo *info)
{
unsigned alpha = info->src->alpha;
if(alpha == 128) {
BlitRGBtoRGBSurfaceAlpha128(info);
} else {
int width = info->d_width;
int height = info->d_height;
Uint32 *srcp = (Uint32 *)info->s_pixels;
int srcskip = info->s_skip >> 2;
Uint32 *dstp = (Uint32 *)info->d_pixels;
int dstskip = info->d_skip >> 2;
while(height--) {
DUFFS_LOOP4({
Uint32 s;
Uint32 d;
Uint32 s1;
Uint32 d1;
s = *srcp;
d = *dstp;
s1 = s & 0xff00ff;
d1 = d & 0xff00ff;
d1 = (d1 + ((s1 - d1) * alpha >> 8))
& 0xff00ff;
s &= 0xff00;
d &= 0xff00;
d = (d + ((s - d) * alpha >> 8)) & 0xff00;
*dstp = d1 | d | 0xff000000;
++srcp;
++dstp;
}, width);
srcp += srcskip;
dstp += dstskip;
}
}
}
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
static void BlitRGBtoRGBPixelAlpha(SDL_BlitInfo *info)
{
@ -277,8 +303,18 @@ static void BlitRGBtoRGBPixelAlpha(SDL_BlitInfo *info)
}
}
/* fast RGB565->RGB565 blending with surface alpha */
static void Blit565to565SurfaceAlpha(SDL_BlitInfo *info)
/* 16bpp special case for per-surface alpha=50%: blend 2 pixels in parallel */
/* blend a single 16 bit pixel at 50% */
#define BLEND16_50(d, s, mask) \
((((s & mask) + (d & mask)) >> 1) + (s & d & (~mask & 0xffff)))
/* blend two 16 bit pixels at 50% */
#define BLEND2x16_50(d, s, mask) \
(((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) \
+ (s & d & (~(mask | mask << 16))))
static void Blit16to16SurfaceAlpha128(SDL_BlitInfo *info, Uint16 mask)
{
int width = info->d_width;
int height = info->d_height;
@ -286,56 +322,163 @@ static void Blit565to565SurfaceAlpha(SDL_BlitInfo *info)
int srcskip = info->s_skip >> 1;
Uint16 *dstp = (Uint16 *)info->d_pixels;
int dstskip = info->d_skip >> 1;
unsigned alpha = info->src->alpha >> 3; /* downscale alpha to 5 bits */
while(height--) {
DUFFS_LOOP4({
Uint32 s = *srcp++;
Uint32 d = *dstp;
/*
* shift out the middle component (green) to the high 16
* bits, and process all three RGB components at the same
* time.
*/
s = (s | s << 16) & 0x07e0f81f;
d = (d | d << 16) & 0x07e0f81f;
d += (s - d) * alpha >> 5;
d &= 0x07e0f81f;
*dstp++ = d | d >> 16;
}, width);
srcp += srcskip;
dstp += dstskip;
if(((unsigned long)srcp ^ (unsigned long)dstp) & 2) {
/*
* Source and destination not aligned, pipeline it.
* This is mostly a win for big blits but no loss for
* small ones
*/
Uint32 prev_sw;
int w = width;
/* handle odd destination */
if((unsigned long)dstp & 2) {
Uint16 d = *dstp, s = *srcp;
*dstp = BLEND16_50(d, s, mask);
dstp++;
srcp++;
w--;
}
srcp++; /* srcp is now 32-bit aligned */
/* bootstrap pipeline with first halfword */
prev_sw = ((Uint32 *)srcp)[-1];
while(w > 1) {
Uint32 sw, dw, s;
sw = *(Uint32 *)srcp;
dw = *(Uint32 *)dstp;
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
s = (prev_sw << 16) + (sw >> 16);
else
s = (prev_sw >> 16) + (sw << 16);
prev_sw = sw;
*(Uint32 *)dstp = BLEND2x16_50(dw, s, mask);
dstp += 2;
srcp += 2;
w -= 2;
}
/* final pixel if any */
if(w) {
Uint16 d = *dstp, s;
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
s = prev_sw;
else
s = prev_sw >> 16;
*dstp = BLEND16_50(d, s, mask);
srcp++;
dstp++;
}
srcp += srcskip - 1;
dstp += dstskip;
} else {
/* source and destination are aligned */
int w = width;
/* first odd pixel? */
if((unsigned long)srcp & 2) {
Uint16 d = *dstp, s = *srcp;
*dstp = BLEND16_50(d, s, mask);
srcp++;
dstp++;
w--;
}
/* srcp and dstp are now 32-bit aligned */
while(w > 1) {
Uint32 sw = *(Uint32 *)srcp;
Uint32 dw = *(Uint32 *)dstp;
*(Uint32 *)dstp = BLEND2x16_50(dw, sw, mask);
srcp += 2;
dstp += 2;
w -= 2;
}
/* last odd pixel? */
if(w) {
Uint16 d = *dstp, s = *srcp;
*dstp = BLEND16_50(d, s, mask);
srcp++;
dstp++;
}
srcp += srcskip;
dstp += dstskip;
}
}
}
/* fast RGB565->RGB565 blending with surface alpha */
static void Blit565to565SurfaceAlpha(SDL_BlitInfo *info)
{
unsigned alpha = info->src->alpha;
if(alpha == 128) {
Blit16to16SurfaceAlpha128(info, 0xf7de);
} else {
int width = info->d_width;
int height = info->d_height;
Uint16 *srcp = (Uint16 *)info->s_pixels;
int srcskip = info->s_skip >> 1;
Uint16 *dstp = (Uint16 *)info->d_pixels;
int dstskip = info->d_skip >> 1;
alpha >>= 3; /* downscale alpha to 5 bits */
while(height--) {
DUFFS_LOOP4({
Uint32 s = *srcp++;
Uint32 d = *dstp;
/*
* shift out the middle component (green) to
* the high 16 bits, and process all three RGB
* components at the same time.
*/
s = (s | s << 16) & 0x07e0f81f;
d = (d | d << 16) & 0x07e0f81f;
d += (s - d) * alpha >> 5;
d &= 0x07e0f81f;
*dstp++ = d | d >> 16;
}, width);
srcp += srcskip;
dstp += dstskip;
}
}
}
/* fast RGB555->RGB555 blending with surface alpha */
static void Blit555to555SurfaceAlpha(SDL_BlitInfo *info)
{
int width = info->d_width;
int height = info->d_height;
Uint16 *srcp = (Uint16 *)info->s_pixels;
int srcskip = info->s_skip >> 1;
Uint16 *dstp = (Uint16 *)info->d_pixels;
int dstskip = info->d_skip >> 1;
unsigned alpha = info->src->alpha >> 3; /* downscale alpha to 5 bits */
unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */
if(alpha == 128) {
Blit16to16SurfaceAlpha128(info, 0xfbde);
} else {
int width = info->d_width;
int height = info->d_height;
Uint16 *srcp = (Uint16 *)info->s_pixels;
int srcskip = info->s_skip >> 1;
Uint16 *dstp = (Uint16 *)info->d_pixels;
int dstskip = info->d_skip >> 1;
alpha >>= 3; /* downscale alpha to 5 bits */
while(height--) {
DUFFS_LOOP4({
Uint32 s = *srcp++;
Uint32 d = *dstp;
/*
* shift out the middle component (green) to the high 16
* bits, and process all three RGB components at the same
* time.
*/
s = (s | s << 16) & 0x03e07c1f;
d = (d | d << 16) & 0x03e07c1f;
d += (s - d) * alpha >> 5;
d &= 0x03e07c1f;
*dstp++ = d | d >> 16;
}, width);
srcp += srcskip;
dstp += dstskip;
while(height--) {
DUFFS_LOOP4({
Uint32 s = *srcp++;
Uint32 d = *dstp;
/*
* shift out the middle component (green) to
* the high 16 bits, and process all three RGB
* components at the same time.
*/
s = (s | s << 16) & 0x03e07c1f;
d = (d | d << 16) & 0x03e07c1f;
d += (s - d) * alpha >> 5;
d &= 0x03e07c1f;
*dstp++ = d | d >> 16;
}, width);
srcp += srcskip;
dstp += dstskip;
}
}
}

View file

@ -723,7 +723,9 @@ void SDL_EraseCursor(SDL_Surface *screen)
SDL_Rect area;
SDL_MouseRect(&area);
video->UpdateRects(this, 1, &area);
if ( video->UpdateRects ) {
video->UpdateRects(this, 1, &area);
}
}
}

View file

@ -53,6 +53,17 @@ do { \
: "memory" ); \
} while(0)
#define SDL_memcpy4(dst, src, len) \
do { \
int ecx, edi, esi; \
__asm__ __volatile__ ( \
"cld\n\t" \
"rep ; movsl" \
: "=&c" (ecx), "=&D" (edi), "=&S" (esi) \
: "0" ((unsigned)(len)), "1" (dst), "2" (src) \
: "memory" ); \
} while(0)
#define SDL_revcpy(dst, src, len) \
do { \
int u0, u1, u2; \
@ -104,9 +115,15 @@ do { \
#ifndef SDL_memcpy
#define SDL_memcpy(dst, src, len) memcpy(dst, src, len)
#endif
#ifndef SDL_memcpy4
#define SDL_memcpy4(dst, src, len) memcpy(dst, src, (len) << 2)
#endif
#ifndef SDL_revcpy
#define SDL_revcpy(dst, src, len) memmove(dst, src, len)
#endif
#ifndef SDL_memset4
#define SDL_memset4(dst, val, len) \
do { \

View file

@ -355,6 +355,9 @@ extern VideoBootStrap DIRECTX_bootstrap;
#ifdef ENABLE_BWINDOW
extern VideoBootStrap BWINDOW_bootstrap;
#endif
#ifdef ENABLE_DUMMYVIDEO
extern VideoBootStrap DUMMY_bootstrap;
#endif
/* MacOS X gets the proper defines from configure */
#if defined(macintosh) && !defined(MACOSX)
#define ENABLE_TOOLBOX

View file

@ -83,6 +83,9 @@ static VideoBootStrap *bootstrap[] = {
#endif
#ifdef ENABLE_CYBERGRAPHICS
&CGX_bootstrap,
#endif
#ifdef ENABLE_DUMMYVIDEO
&DUMMY_bootstrap,
#endif
NULL
};

View file

@ -50,6 +50,10 @@ public:
xoff = x;
yoff = y;
}
virtual void GetXYOffset(int &x, int &y) {
x = xoff;
y = yoff;
}
/* The view changed size. If it means we're in fullscreen, we
* draw a nice black box in the entire view to get black borders.
*/

View file

@ -156,6 +156,16 @@ public:
#endif
SDL_View->SetXYOffset(x, y);
}
virtual void GetXYOffset(int &x, int &y) {
#ifdef HAVE_OPENGL
if ( the_view == SDL_GLView ) {
x = 0;
y = 0;
return;
}
#endif
SDL_View->GetXYOffset(x, y);
}
virtual bool BeginDraw(void) {
return(Lock());
}

View file

@ -262,7 +262,12 @@ void BE_PumpEvents(_THIS)
/* Check for mouse motion */
if ( point != last_point ) {
SDL_PrivateMouseMotion(0, 0, (int)point.x, (int)point.y);
int x, y;
SDL_Win->GetXYOffset(x, y);
x = (int)point.x - x;
y = (int)point.y - y;
SDL_PrivateMouseMotion(0, 0, x, y);
}
last_point = point;

View file

@ -0,0 +1,15 @@
## Makefile.am for SDL using the null video driver
noinst_LTLIBRARIES = libvideo_null.la
libvideo_null_la_SOURCES = $(NULL_SRCS)
# The SDL null video driver sources
NULL_SRCS = \
SDL_nullvideo.h \
SDL_nullevents.c \
SDL_nullevents_c.h \
SDL_nullmouse.c \
SDL_nullmouse_c.h \
SDL_nullvideo.c

View file

@ -0,0 +1,48 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@devolution.com
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
/* Being a null driver, there's no event stream. We just define stubs for
most of the API. */
#include "SDL.h"
#include "SDL_sysevents.h"
#include "SDL_events_c.h"
#include "SDL_nullvideo.h"
#include "SDL_nullevents_c.h"
void DUMMY_PumpEvents(_THIS)
{
/* do nothing. */
}
void DUMMY_InitOSKeymap(_THIS)
{
/* do nothing. */
}
/* end of SDL_nullevents.c ... */

View file

@ -0,0 +1,37 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@devolution.com
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
#include "SDL_nullvideo.h"
/* Variables and functions exported by SDL_sysevents.c to other parts
of the native video subsystem (SDL_sysvideo.c)
*/
extern void DUMMY_InitOSKeymap(_THIS);
extern void DUMMY_PumpEvents(_THIS);
/* end of SDL_nullevents_c.h ... */

View file

@ -0,0 +1,40 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@devolution.com
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
#include <stdio.h>
#include "SDL_error.h"
#include "SDL_mouse.h"
#include "SDL_events_c.h"
#include "SDL_nullmouse_c.h"
/* The implementation dependent data for the window manager cursor */
struct WMcursor {
int unused;
};

View file

@ -0,0 +1,30 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@devolution.com
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
#include "SDL_nullvideo.h"
/* Functions to be exported */

View file

@ -0,0 +1,245 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@devolution.com
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
/* Dummy SDL video driver implementation; this is just enough to make an
* SDL-based application THINK it's got a working video driver, for
* applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
* and also for use as a collection of stubs when porting SDL to a new
* platform for which you haven't yet written a valid video driver.
*
* This is also a great way to determine bottlenecks: if you think that SDL
* is a performance problem for a given platform, enable this driver, and
* then see if your application runs faster without video overhead.
*
* Initial work by Ryan C. Gordon (icculus@linuxgames.com). A good portion
* of this was cut-and-pasted from Stephane Peter's work in the AAlib
* SDL video driver. Renamed to "DUMMY" by Sam Lantinga.
*/
#include <stdio.h>
#include <stdlib.h>
#include "SDL.h"
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_sysvideo.h"
#include "SDL_pixels_c.h"
#include "SDL_events_c.h"
#include "SDL_nullvideo.h"
#include "SDL_nullevents_c.h"
#include "SDL_nullmouse_c.h"
/* Initialization/Query functions */
static int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Rect **DUMMY_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
static SDL_Surface *DUMMY_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
static int DUMMY_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
static void DUMMY_VideoQuit(_THIS);
/* Hardware surface functions */
static int DUMMY_AllocHWSurface(_THIS, SDL_Surface *surface);
static int DUMMY_LockHWSurface(_THIS, SDL_Surface *surface);
static int DUMMY_FlipHWSurface(_THIS, SDL_Surface *surface);
static void DUMMY_UnlockHWSurface(_THIS, SDL_Surface *surface);
static void DUMMY_FreeHWSurface(_THIS, SDL_Surface *surface);
/* etc. */
static void DUMMY_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
/* DUMMY driver bootstrap functions */
static int DUMMY_Available(void)
{
return 1; /* Always available ! */
}
static void DUMMY_DeleteDevice(SDL_VideoDevice *device)
{
free(device->hidden);
free(device);
}
static SDL_VideoDevice *DUMMY_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
if ( device ) {
memset(device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateVideoData *)
malloc((sizeof *device->hidden));
}
if ( (device == NULL) || (device->hidden == NULL) ) {
SDL_OutOfMemory();
if ( device ) {
free(device);
}
return(0);
}
memset(device->hidden, 0, (sizeof *device->hidden));
/* Set the function pointers */
device->VideoInit = DUMMY_VideoInit;
device->ListModes = DUMMY_ListModes;
device->SetVideoMode = DUMMY_SetVideoMode;
device->CreateYUVOverlay = NULL;
device->SetColors = DUMMY_SetColors;
device->UpdateRects = DUMMY_UpdateRects;
device->VideoQuit = DUMMY_VideoQuit;
device->AllocHWSurface = DUMMY_AllocHWSurface;
device->CheckHWBlit = NULL;
device->FillHWRect = NULL;
device->SetHWColorKey = NULL;
device->SetHWAlpha = NULL;
device->LockHWSurface = DUMMY_LockHWSurface;
device->UnlockHWSurface = DUMMY_UnlockHWSurface;
device->FlipHWSurface = NULL;
device->FreeHWSurface = DUMMY_FreeHWSurface;
device->SetCaption = NULL;
device->SetIcon = NULL;
device->IconifyWindow = NULL;
device->GrabInput = NULL;
device->GetWMInfo = NULL;
device->InitOSKeymap = DUMMY_InitOSKeymap;
device->PumpEvents = DUMMY_PumpEvents;
device->free = DUMMY_DeleteDevice;
return device;
}
VideoBootStrap DUMMY_bootstrap = {
"dummy", "SDL dummy video driver",
DUMMY_Available, DUMMY_CreateDevice
};
int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
fprintf(stderr, "WARNING: You are using the SDL dummy video driver!\n");
/* Determine the screen depth (use default 8-bit depth) */
/* we change this during the SDL_SetVideoMode implementation... */
vformat->BitsPerPixel = 8;
vformat->BytesPerPixel = 1;
/* We're done! */
return(0);
}
SDL_Rect **DUMMY_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
return (SDL_Rect **) -1;
}
SDL_Surface *DUMMY_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags)
{
if ( this->hidden->buffer ) {
free( this->hidden->buffer );
}
this->hidden->buffer = malloc(width * height * (bpp / 8));
if ( ! this->hidden->buffer ) {
SDL_SetError("Couldn't allocate buffer for requested mode");
return(NULL);
}
/* printf("Setting mode %dx%d\n", width, height); */
memset(this->hidden->buffer, 0, width * height * (bpp / 8));
/* Allocate the new pixel format for the screen */
if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
free(this->hidden->buffer);
this->hidden->buffer = NULL;
SDL_SetError("Couldn't allocate new pixel format for requested mode");
return(NULL);
}
/* Set up the new mode framebuffer */
current->flags = flags & SDL_FULLSCREEN;
this->hidden->w = current->w = width;
this->hidden->h = current->h = height;
current->pitch = current->w * (bpp / 8);
current->pixels = this->hidden->buffer;
/* We're done */
return(current);
}
/* We don't actually allow hardware surfaces other than the main one */
static int DUMMY_AllocHWSurface(_THIS, SDL_Surface *surface)
{
return(-1);
}
static void DUMMY_FreeHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
/* We need to wait for vertical retrace on page flipped displays */
static int DUMMY_LockHWSurface(_THIS, SDL_Surface *surface)
{
return(0);
}
static void DUMMY_UnlockHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
static int DUMMY_FlipHWSurface(_THIS, SDL_Surface *surface)
{
return(0);
}
static void DUMMY_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
{
/* do nothing. */
}
int DUMMY_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
/* do nothing of note. */
return(1);
}
/* Note: If we are terminated, this could be called in the middle of
another SDL video routine -- notably UpdateRects.
*/
void DUMMY_VideoQuit(_THIS)
{
if (this->screen->pixels != NULL)
{
free(this->screen->pixels);
this->screen->pixels = NULL;
}
}

View file

@ -0,0 +1,46 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@devolution.com
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
#ifndef _SDL_nullvideo_h
#define _SDL_nullvideo_h
#include "SDL_mouse.h"
#include "SDL_sysvideo.h"
#include "SDL_mutex.h"
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_VideoDevice *this
/* Private display data */
struct SDL_PrivateVideoData {
int w, h;
void *buffer;
};
#endif /* _SDL_nullvideo_h */

View file

@ -370,6 +370,10 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current,
/* Set up the new mode framebuffer */
current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE);
if ( bpp == 8 ) {
/* FIXME: What about DirectColor? */
current->flags |= SDL_HWPALETTE;
}
current->w = width;
current->h = height;
current->pitch = modeinfo->linewidth;

View file

@ -134,10 +134,10 @@ static void WIN_GetKeyboardState(void)
if ( keyboard[VK_RMENU] & 0x80) {
state |= KMOD_RALT;
}
if ( keyboard[VK_NUMLOCK] & 0x80) {
if ( keyboard[VK_NUMLOCK] & 0x01) {
state |= KMOD_NUM;
}
if ( keyboard[VK_CAPITAL] & 0x80) {
if ( keyboard[VK_CAPITAL] & 0x01) {
state |= KMOD_CAPS;
}
}

View file

@ -1684,6 +1684,7 @@ static int DX5_AllocHWSurface(_THIS, SDL_Surface *surface)
return(DX5_AllocDDSurface(this, surface, NULL, SDL_HWSURFACE));
}
#ifdef DDRAW_DEBUG
void PrintSurface(char *title, LPDIRECTDRAWSURFACE3 surface, Uint32 flags)
{
DDSURFACEDESC ddsd;
@ -1717,6 +1718,7 @@ void PrintSurface(char *title, LPDIRECTDRAWSURFACE3 surface, Uint32 flags)
ddsd.ddpfPixelFormat.dwBBitMask);
#endif
}
#endif /* DDRAW_DEBUG */
static int DX5_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect)