Date: Thu, 16 Jan 2003 13:48:31 +0200
authorSam Lantinga <slouken@libsdl.org>
Mon, 20 Jan 2003 01:38:37 +0000
changeset 5718e3ce997621c
parent 570 04d6411da49d
child 572 4c740ee76027
Date: Thu, 16 Jan 2003 13:48:31 +0200
From: "Mike Gorchak"
Subject: All QNX patches

whole patches concerning QNX. Almost all code has been rewritten by Julian
and me. Added initial support for hw overlays in QNX and many many others
fixes.

P.S. This patches has been reviewed by Dave Rempel from QSSL and included in
SDL 1.2.5 distribution, which coming on 3rd party CD for newest 6.2.1
version of QNX, which will be available soon.
BUGS
src/cdrom/qnx/SDL_syscdrom.c
src/video/photon/SDL_ph_events.c
src/video/photon/SDL_ph_events_c.h
src/video/photon/SDL_ph_image.c
src/video/photon/SDL_ph_image_c.h
src/video/photon/SDL_ph_modes.c
src/video/photon/SDL_ph_modes_c.h
src/video/photon/SDL_ph_mouse.c
src/video/photon/SDL_ph_video.c
src/video/photon/SDL_ph_video.h
src/video/photon/SDL_ph_wm.c
src/video/photon/SDL_phyuv.c
src/video/photon/SDL_phyuv_c.h
     1.1 --- a/BUGS	Mon Jan 20 01:37:07 2003 +0000
     1.2 +++ b/BUGS	Mon Jan 20 01:38:37 2003 +0000
     1.3 @@ -188,14 +188,8 @@
     1.4   
     1.5  	The only hardware surface is the primary view surface.
     1.6   
     1.7 -	Mouse events don't seem to be working right.
     1.8 - 
     1.9  	Fullscreen doesn't display correctly.
    1.10   
    1.11 -	The software surfaces could use some speed up.
    1.12 - 
    1.13 -	The mouse cursor doesn't look right.
    1.14 -
    1.15  AmigaOS:  -= NOT YET SUPPORTED =-
    1.16  	The OpenGL support isn't implemented yet.
    1.17  
     2.1 --- a/src/cdrom/qnx/SDL_syscdrom.c	Mon Jan 20 01:37:07 2003 +0000
     2.2 +++ b/src/cdrom/qnx/SDL_syscdrom.c	Mon Jan 20 01:38:37 2003 +0000
     2.3 @@ -33,24 +33,26 @@
     2.4  #include <sys/ioctl.h>
     2.5  #include <fcntl.h>
     2.6  #include <stdio.h>
     2.7 +#include <errno.h>
     2.8  #include <string.h>
     2.9 -#include <errno.h>
    2.10  #include <unistd.h>
    2.11  #include <sys/cdrom.h>
    2.12  #include <sys/dcmd_cam.h>
    2.13  
    2.14 -
    2.15  #include "SDL_error.h"
    2.16  #include "SDL_cdrom.h"
    2.17 +#include "SDL_timer.h"
    2.18  #include "SDL_syscdrom.h"
    2.19  
    2.20 +/* The maximum number of CD-ROM drives we'll detect */
    2.21 +#define MAX_DRIVES 16
    2.22  
    2.23 -/* The maximum number of CD-ROM drives we'll detect */
    2.24 -#define MAX_DRIVES	16	
    2.25 +#define QNX_CD_OPENMODE O_RDONLY | O_EXCL
    2.26  
    2.27  /* A list of available CD-ROM drives */
    2.28  static char *SDL_cdlist[MAX_DRIVES];
    2.29  static dev_t SDL_cdmode[MAX_DRIVES];
    2.30 +static int   SDL_cdopen[MAX_DRIVES];
    2.31  
    2.32  /* The system-dependent CD control functions */
    2.33  static const char *SDL_SYS_CDName(int drive);
    2.34 @@ -64,341 +66,491 @@
    2.35  static int SDL_SYS_CDEject(SDL_CD *cdrom);
    2.36  static void SDL_SYS_CDClose(SDL_CD *cdrom);
    2.37  
    2.38 -/* Some ioctl() errno values which occur when the tray is empty */
    2.39 -#define ERRNO_TRAYEMPTY(errno)	\
    2.40 -	((errno == EIO) || (errno == ENOENT) || (errno == EINVAL))
    2.41 +/* Check a drive to see if it is a CD-ROM */
    2.42 +static int CheckDrive(char *drive, struct stat *stbuf)
    2.43 +{
    2.44 +    int is_cd, cdfd;
    2.45 +    cam_devinfo_t dinfo;
    2.46 +    int devctlret=0;
    2.47  
    2.48 -/* Check a drive to see if it is a CD-ROM */
    2.49 -static int CheckDrive(char *drive, char *mnttype, struct stat *stbuf)
    2.50 -{
    2.51 -	int is_cd, cdfd;
    2.52 -	cdrom_subch_data_t info;
    2.53 +    int atapi;
    2.54 +    int removable;
    2.55 +    int cdb10;
    2.56  
    2.57 -	/* If it doesn't exist, return -1 */
    2.58 -	if ( stat(drive, stbuf) < 0 ) {
    2.59 -		return(-1);
    2.60 -	}
    2.61 +    /* If it doesn't exist, return -1 */
    2.62 +    if (stat(drive, stbuf) < 0)
    2.63 +    {
    2.64 +        return(-1);
    2.65 +    }
    2.66  
    2.67 -	/* If it does exist, verify that it's an available CD-ROM */
    2.68 -	is_cd = 0;
    2.69 -	if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) {
    2.70 -		cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0);
    2.71 -		if ( cdfd >= 0 ) {
    2.72 -			info.subch_command.data_format = CDROM_MSF;
    2.73 -			/* Under Linux, EIO occurs when a disk is not present.
    2.74 -			 */
    2.75 -			if ((devctl(cdfd,DCMD_CAM_CDROMSUBCHNL,&info,sizeof(info),0) == 0) ||
    2.76 -						ERRNO_TRAYEMPTY(errno) )
    2.77 -			{
    2.78 -				is_cd = 1;
    2.79 -			}
    2.80 -			close(cdfd);
    2.81 -		}
    2.82 -	}
    2.83 -	return(is_cd);
    2.84 +    /* If it does exist, verify that it's an available CD-ROM */
    2.85 +    is_cd = 0;
    2.86 +
    2.87 +    if (S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode))
    2.88 +    {
    2.89 +        cdfd = open(drive, QNX_CD_OPENMODE);
    2.90 +        if ( cdfd >= 0 )
    2.91 +        {
    2.92 +            devctlret=devctl(cdfd, DCMD_CAM_DEVINFO, &dinfo, sizeof(cam_devinfo_t), NULL);
    2.93 +
    2.94 +            if (devctlret==EOK)
    2.95 +            {
    2.96 +               atapi=dinfo.flags & DEV_ATAPI;
    2.97 +               removable=dinfo.flags & DEV_REMOVABLE;
    2.98 +               cdb10=dinfo.flags & DEV_CDB_10; /* I'm not sure about that flag */
    2.99 +
   2.100 +               /* in the near future need to add more checks for splitting cdroms from other devices */
   2.101 +               if ((atapi)&&(removable))
   2.102 +               {
   2.103 +                   is_cd = 1;
   2.104 +               }
   2.105 +            }
   2.106 +
   2.107 +            close(cdfd);
   2.108 +        }
   2.109 +    }
   2.110 +    return(is_cd);
   2.111  }
   2.112  
   2.113  /* Add a CD-ROM drive to our list of valid drives */
   2.114  static void AddDrive(char *drive, struct stat *stbuf)
   2.115  {
   2.116 -	int i;
   2.117 +    int i;
   2.118  
   2.119 -	if ( SDL_numcds < MAX_DRIVES ) {
   2.120 -		/* Check to make sure it's not already in our list.
   2.121 -	 	   This can happen when we see a drive via symbolic link.
   2.122 -		 */
   2.123 -		for ( i=0; i<SDL_numcds; ++i ) {
   2.124 -			if ( stbuf->st_rdev == SDL_cdmode[i] ) {
   2.125 -#ifdef DEBUG_CDROM
   2.126 -  fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]);
   2.127 -#endif
   2.128 -				return;
   2.129 -			}
   2.130 -		}
   2.131 +    if (SDL_numcds < MAX_DRIVES)
   2.132 +    {
   2.133 +        /* Check to make sure it's not already in our list.
   2.134 +        This can happen when we see a drive via symbolic link. */
   2.135  
   2.136 -		/* Add this drive to our list */
   2.137 -		i = SDL_numcds;
   2.138 -		SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
   2.139 -		if ( SDL_cdlist[i] == NULL ) {
   2.140 -			SDL_OutOfMemory();
   2.141 -			return;
   2.142 -		}
   2.143 -		strcpy(SDL_cdlist[i], drive);
   2.144 -		SDL_cdmode[i] = stbuf->st_rdev;
   2.145 -		++SDL_numcds;
   2.146 -#ifdef DEBUG_CDROM
   2.147 -  fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
   2.148 -#endif
   2.149 -	}
   2.150 +        for (i=0; i<SDL_numcds; ++i)
   2.151 +        {
   2.152 +            if (stbuf->st_rdev == SDL_cdmode[i])
   2.153 +            {
   2.154 +                return;
   2.155 +            }
   2.156 +        }
   2.157 +
   2.158 +        /* Add this drive to our list */
   2.159 +
   2.160 +        i = SDL_numcds;
   2.161 +        SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
   2.162 +        if (SDL_cdlist[i] == NULL)
   2.163 +        {
   2.164 +            SDL_OutOfMemory();
   2.165 +            return;
   2.166 +        }
   2.167 +        strcpy(SDL_cdlist[i], drive);
   2.168 +        SDL_cdmode[i] = stbuf->st_rdev;
   2.169 +        ++SDL_numcds;
   2.170 +    }
   2.171  }
   2.172  
   2.173 -int  SDL_SYS_CDInit(void)
   2.174 +int SDL_SYS_CDInit(void)
   2.175  {
   2.176 -	/* checklist: /dev/cdrom, /dev/hd?, /dev/scd? /dev/sr? */
   2.177 -	static char *checklist[] = {
   2.178 -		"cdrom", "?0 cd?", "?1 cd?", "?a hd?", "?0 scd?", "?0 sr?", NULL
   2.179 -	};
   2.180 -	char *SDLcdrom;
   2.181 -	int i, j, exists;
   2.182 -	char drive[32];
   2.183 -	struct stat stbuf;
   2.184 +    /* checklist: /dev/cdrom, /dev/cd?, /dev/scd? */
   2.185 +    static char *checklist[]={"cdrom", "?0 cd?", "?1 cd?", "?0 scd?", NULL};
   2.186  
   2.187 -	/* Fill in our driver capabilities */
   2.188 -	SDL_CDcaps.Name = SDL_SYS_CDName;
   2.189 -	SDL_CDcaps.Open = SDL_SYS_CDOpen;
   2.190 -	SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
   2.191 -	SDL_CDcaps.Status = SDL_SYS_CDStatus;
   2.192 -	SDL_CDcaps.Play = SDL_SYS_CDPlay;
   2.193 -	SDL_CDcaps.Pause = SDL_SYS_CDPause;
   2.194 -	SDL_CDcaps.Resume = SDL_SYS_CDResume;
   2.195 -	SDL_CDcaps.Stop = SDL_SYS_CDStop;
   2.196 -	SDL_CDcaps.Eject = SDL_SYS_CDEject;
   2.197 -	SDL_CDcaps.Close = SDL_SYS_CDClose;
   2.198 +    char *SDLcdrom;
   2.199 +    int i, j, exists;
   2.200 +    char drive[32];
   2.201 +    struct stat stbuf;
   2.202  
   2.203 -	/* Look in the environment for our CD-ROM drive list */
   2.204 -	SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
   2.205 -	if ( SDLcdrom != NULL ) {
   2.206 -		char *cdpath, *delim;
   2.207 -		cdpath = malloc(strlen(SDLcdrom)+1);
   2.208 -		if ( cdpath != NULL ) {
   2.209 -			strcpy(cdpath, SDLcdrom);
   2.210 -			SDLcdrom = cdpath;
   2.211 -			do {
   2.212 -				delim = strchr(SDLcdrom, ':');
   2.213 -				if ( delim ) {
   2.214 -					*delim++ = '\0';
   2.215 -				}
   2.216 -#ifdef DEBUG_CDROM
   2.217 -  fprintf(stderr, "Checking CD-ROM drive from SDL_CDROM: %s\n", SDLcdrom);
   2.218 -#endif
   2.219 -				if ( CheckDrive(SDLcdrom, NULL, &stbuf) > 0 ) {
   2.220 -					AddDrive(SDLcdrom, &stbuf);
   2.221 -				}
   2.222 -				if ( delim ) {
   2.223 -					SDLcdrom = delim;
   2.224 -				} else {
   2.225 -					SDLcdrom = NULL;
   2.226 -				}
   2.227 -			} while ( SDLcdrom );
   2.228 -			free(cdpath);
   2.229 -		}
   2.230 +    /* Fill in our driver capabilities */
   2.231 +    SDL_CDcaps.Name = SDL_SYS_CDName;
   2.232 +    SDL_CDcaps.Open = SDL_SYS_CDOpen;
   2.233 +    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
   2.234 +    SDL_CDcaps.Status = SDL_SYS_CDStatus;
   2.235 +    SDL_CDcaps.Play = SDL_SYS_CDPlay;
   2.236 +    SDL_CDcaps.Pause = SDL_SYS_CDPause;
   2.237 +    SDL_CDcaps.Resume = SDL_SYS_CDResume;
   2.238 +    SDL_CDcaps.Stop = SDL_SYS_CDStop;
   2.239 +    SDL_CDcaps.Eject = SDL_SYS_CDEject;
   2.240 +    SDL_CDcaps.Close = SDL_SYS_CDClose;
   2.241  
   2.242 -		/* If we found our drives, there's nothing left to do */
   2.243 -		if ( SDL_numcds > 0 ) {
   2.244 -			return(0);
   2.245 -		}
   2.246 -	}
   2.247 +    /* clearing device open status */
   2.248 +    for (i=0; i<MAX_DRIVES; i++)
   2.249 +    {
   2.250 +       SDL_cdopen[i]=0;
   2.251 +    }
   2.252  
   2.253 -	/* Scan the system for CD-ROM drives */
   2.254 -	for ( i=0; checklist[i]; ++i ) {
   2.255 -		if ( checklist[i][0] == '?' ) {
   2.256 -			char *insert;
   2.257 -			exists = 1;
   2.258 -			for ( j=checklist[i][1]; exists; ++j ) {
   2.259 -				sprintf(drive, "/dev/%s", &checklist[i][3]);
   2.260 -				insert = strchr(drive, '?');
   2.261 -				if ( insert != NULL ) {
   2.262 -					*insert = j;
   2.263 -				}
   2.264 -#ifdef DEBUG_CDROM
   2.265 -  fprintf(stderr, "Checking possible CD-ROM drive: %s\n", drive);
   2.266 -#endif
   2.267 -				switch (CheckDrive(drive, NULL, &stbuf)) {
   2.268 -					/* Drive exists and is a CD-ROM */
   2.269 -					case 1:
   2.270 -						AddDrive(drive, &stbuf);
   2.271 -						break;
   2.272 -					/* Drive exists, but isn't a CD-ROM */
   2.273 -					case 0:
   2.274 -						break;
   2.275 -					/* Drive doesn't exist */
   2.276 -					case -1:
   2.277 -						exists = 0;
   2.278 -						break;
   2.279 -				}
   2.280 -			}
   2.281 -		} else {
   2.282 -			sprintf(drive, "/dev/%s", checklist[i]);
   2.283 -#ifdef DEBUG_CDROM
   2.284 -  fprintf(stderr, "Checking possible CD-ROM drive: %s\n", drive);
   2.285 -#endif
   2.286 -			if ( CheckDrive(drive, NULL, &stbuf) > 0 ) {
   2.287 -				AddDrive(drive, &stbuf);
   2.288 -			}
   2.289 -		}
   2.290 -	}
   2.291 -	return(0);
   2.292 +    /* Look in the environment for our CD-ROM drive list */
   2.293 +    SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
   2.294 +    if ( SDLcdrom != NULL )
   2.295 +    {
   2.296 +        char *cdpath, *delim;
   2.297 +
   2.298 +        cdpath = malloc(strlen(SDLcdrom)+1);
   2.299 +        if (cdpath != NULL)
   2.300 +        {
   2.301 +            strcpy(cdpath, SDLcdrom);
   2.302 +            SDLcdrom = cdpath;
   2.303 +            do {
   2.304 +                delim = strchr(SDLcdrom, ':');
   2.305 +                if (delim)
   2.306 +                {
   2.307 +                    *delim++ = '\0';
   2.308 +                }
   2.309 +                if (CheckDrive(SDLcdrom, &stbuf) > 0)
   2.310 +                {
   2.311 +                    AddDrive(SDLcdrom, &stbuf);
   2.312 +                }
   2.313 +                if (delim)
   2.314 +                {
   2.315 +                    SDLcdrom = delim;
   2.316 +                }
   2.317 +                else
   2.318 +                {
   2.319 +                    SDLcdrom = NULL;
   2.320 +                }
   2.321 +            } while (SDLcdrom);
   2.322 +            free(cdpath);
   2.323 +        }
   2.324 +
   2.325 +        /* If we found our drives, there's nothing left to do */
   2.326 +        if (SDL_numcds > 0)
   2.327 +        {
   2.328 +            return(0);
   2.329 +        }
   2.330 +    }
   2.331 +
   2.332 +    /* Scan the system for CD-ROM drives */
   2.333 +    for ( i=0; checklist[i]; ++i )
   2.334 +    {
   2.335 +        if (checklist[i][0] == '?')
   2.336 +        {
   2.337 +            char* insert;
   2.338 +            exists = 1;
   2.339 +
   2.340 +            for ( j=checklist[i][1]; exists; ++j )
   2.341 +            {
   2.342 +                sprintf(drive, "/dev/%s", &checklist[i][3]);
   2.343 +                insert = strchr(drive, '?');
   2.344 +                if (insert != NULL)
   2.345 +                {
   2.346 +                    *insert = j;
   2.347 +                }
   2.348 +                switch (CheckDrive(drive, &stbuf))
   2.349 +                {
   2.350 +                    /* Drive exists and is a CD-ROM */
   2.351 +                    case 1:
   2.352 +                             AddDrive(drive, &stbuf);
   2.353 +                             break;
   2.354 +                    /* Drive exists, but isn't a CD-ROM */
   2.355 +                    case 0:
   2.356 +                             break;
   2.357 +                    /* Drive doesn't exist */
   2.358 +                    case -1:
   2.359 +                             exists = 0;
   2.360 +                             break;
   2.361 +                }
   2.362 +            }
   2.363 +        }
   2.364 +        else
   2.365 +        {
   2.366 +            sprintf(drive, "/dev/%s", checklist[i]);
   2.367 +            if (CheckDrive(drive, &stbuf) > 0)
   2.368 +            {
   2.369 +                AddDrive(drive, &stbuf);
   2.370 +            }
   2.371 +        }
   2.372 +    }
   2.373 +    return(0);
   2.374  }
   2.375  
   2.376  static const char *SDL_SYS_CDName(int drive)
   2.377  {
   2.378 -	return(SDL_cdlist[drive]);
   2.379 +    return(SDL_cdlist[drive]);
   2.380  }
   2.381  
   2.382  static int SDL_SYS_CDOpen(int drive)
   2.383  {
   2.384 -	return(open(SDL_cdlist[drive], (O_RDONLY|O_EXCL|O_NONBLOCK), 0));
   2.385 +    int handle;
   2.386 +
   2.387 +    handle=open(SDL_cdlist[drive], QNX_CD_OPENMODE);
   2.388 +
   2.389 +    if (handle>0)
   2.390 +    {
   2.391 +        SDL_cdopen[drive]=handle;
   2.392 +    }
   2.393 +
   2.394 +    return (handle);
   2.395  }
   2.396  
   2.397  static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
   2.398  {
   2.399 -	cdrom_read_toc_t toc;
   2.400 -	int i, okay;
   2.401 +    cdrom_read_toc_t toc;
   2.402 +    int i, okay;
   2.403  
   2.404 -	okay = 0;
   2.405 -	if (devctl(cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof(toc), 0) == 0) {
   2.406 -		cdrom->numtracks = toc.last_track - toc.first_track + 1;
   2.407 -		if ( cdrom->numtracks > SDL_MAX_TRACKS ) {
   2.408 -			cdrom->numtracks = SDL_MAX_TRACKS;
   2.409 -		}
   2.410 -		/* Read all the track TOC entries */
   2.411 -		for ( i=0; i<=cdrom->numtracks; ++i ) {
   2.412 -			if ( i == cdrom->numtracks ) {
   2.413 -				cdrom->track[i].id = CDROM_LEADOUT;
   2.414 -			} else {
   2.415 -#if 0 /* Sam 11/6/00 - an obsolete field? */
   2.416 -				cdrom->track[i].id = toc.cdth_trk0+i;
   2.417 -#else
   2.418 -				cdrom->track[i].id = toc.first_track+i;
   2.419 -#endif
   2.420 -			}
   2.421 -			cdrom->track[i].type = toc.toc_entry[i].control_adr;
   2.422 -			cdrom->track[i].offset = MSF_TO_FRAMES(
   2.423 -						toc.toc_entry[i].addr.msf.minute,
   2.424 -						toc.toc_entry[i].addr.msf.second,
   2.425 -						toc.toc_entry[i].addr.msf.frame);			
   2.426 -			cdrom->track[i].length = 0;
   2.427 -			if ( i > 0 ) {
   2.428 -				cdrom->track[i-1].length =
   2.429 -					cdrom->track[i].offset-
   2.430 -					cdrom->track[i-1].offset;
   2.431 -			}
   2.432 -		}
   2.433 -		if ( i == (cdrom->numtracks+1) ) {
   2.434 -			okay = 1;
   2.435 -		}
   2.436 -	}
   2.437 -	return(okay ? 0 : -1);
   2.438 +    okay = 0;
   2.439 +    if (devctl(cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof(toc), NULL) == 0)
   2.440 +    {
   2.441 +        cdrom->numtracks = toc.last_track - toc.first_track + 1;
   2.442 +        if (cdrom->numtracks > SDL_MAX_TRACKS)
   2.443 +        {
   2.444 +            cdrom->numtracks = SDL_MAX_TRACKS;
   2.445 +        }
   2.446 +        /* Read all the track TOC entries */
   2.447 +        for (i=0; i<=cdrom->numtracks; ++i)
   2.448 +        {
   2.449 +            if (i == cdrom->numtracks)
   2.450 +            {
   2.451 +                cdrom->track[i].id = CDROM_LEADOUT;
   2.452 +            }
   2.453 +            else
   2.454 +            {
   2.455 +                cdrom->track[i].id = toc.first_track+i;
   2.456 +            }
   2.457 +
   2.458 +            cdrom->track[i].type = toc.toc_entry[i].control_adr & 0x0F;
   2.459 +            cdrom->track[i].offset = toc.toc_entry[i].addr.lba;
   2.460 +            cdrom->track[i].length = 0;
   2.461 +
   2.462 +            if (i > 0)
   2.463 +            {
   2.464 +                 cdrom->track[i-1].length = cdrom->track[i].offset-cdrom->track[i-1].offset;
   2.465 +            }
   2.466 +        }
   2.467 +        if (i == (cdrom->numtracks+1))
   2.468 +        {
   2.469 +            okay = 1;
   2.470 +        }
   2.471 +    }
   2.472 +    return (okay ? 0 : -1);
   2.473  }
   2.474  
   2.475  /* Get CD-ROM status */
   2.476  static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
   2.477  {
   2.478 -	CDstatus status;
   2.479 -	cdrom_read_toc_t toc;
   2.480 -	subch_current_position_t info;
   2.481 +    CDstatus status;
   2.482  
   2.483 -#if 0 /* Sam 11/6/00 - an obsolete field? */
   2.484 -	info.subch_command.data_format = CDROM_SUBCH_CURRENT_POSITION;
   2.485 -	info.subch_command.track_number = 0;
   2.486 -#else
   2.487 -	info.data_format = CDROM_SUBCH_CURRENT_POSITION;
   2.488 -	info.track_number = 0;
   2.489 -#endif
   2.490 -	if (devctl(cdrom->id, DCMD_CAM_CDROMSUBCHNL, &info, sizeof(info), 0) != 0) {
   2.491 -		if ( ERRNO_TRAYEMPTY(errno) ) {
   2.492 -			status = CD_TRAYEMPTY;
   2.493 -		} else {
   2.494 -			status = CD_ERROR;
   2.495 -		}
   2.496 -	} else {
   2.497 -		switch (info.header.audio_status) {
   2.498 -			case CDROM_AUDIO_INVALID:
   2.499 -			case CDROM_AUDIO_NO_STATUS:
   2.500 -				/* Try to determine if there's a CD available */
   2.501 -				if (devctl(cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof(toc), 0)==0)
   2.502 -					status = CD_STOPPED;
   2.503 -				else
   2.504 -					status = CD_TRAYEMPTY;
   2.505 -				break;
   2.506 -			case CDROM_AUDIO_COMPLETED:
   2.507 -				status = CD_STOPPED;
   2.508 -				break;
   2.509 -			case CDROM_AUDIO_PLAY:
   2.510 -				status = CD_PLAYING;
   2.511 -				break;
   2.512 -			case CDROM_AUDIO_PAUSED:
   2.513 -				/* Workaround buggy CD-ROM drive */
   2.514 -				if ( info.data_format == CDROM_LEADOUT ) {
   2.515 -					status = CD_STOPPED;
   2.516 -				} else {
   2.517 -					status = CD_PAUSED;
   2.518 -				}
   2.519 -				break;
   2.520 -			default:
   2.521 -				status = CD_ERROR;
   2.522 -				break;
   2.523 -		}
   2.524 -	}
   2.525 -	if ( position ) {
   2.526 -		if ( status == CD_PLAYING || (status == CD_PAUSED) ) {
   2.527 -			*position = MSF_TO_FRAMES(
   2.528 -					info.addr.msf.minute,
   2.529 -					info.addr.msf.second,
   2.530 -					info.addr.msf.frame);
   2.531 -		} else {
   2.532 -			*position = 0;
   2.533 -		}
   2.534 -	}
   2.535 -	return(status);
   2.536 +    cdrom_read_toc_t toc;
   2.537 +    cdrom_subch_data_t info;
   2.538 +    cam_devinfo_t dinfo;
   2.539 +
   2.540 +    int devctlret=0;
   2.541 +    int drive=-1;
   2.542 +    int i;
   2.543 +    int eagaincnt=0;
   2.544 +
   2.545 +    /* check media presence before read subchannel call, some cdroms can lockups */
   2.546 +    /* if no media, while calling read subchannel functions.                     */
   2.547 +    devctlret=devctl(cdrom->id, DCMD_CAM_DEVINFO, &dinfo, sizeof(cam_devinfo_t), NULL);
   2.548 +
   2.549 +    if (devctlret==EOK)
   2.550 +    {
   2.551 +        if ((dinfo.flags & DEV_NO_MEDIA)!=0)
   2.552 +        {
   2.553 +            status = CD_TRAYEMPTY;
   2.554 +            if (position)
   2.555 +            {
   2.556 +                *position = 0;
   2.557 +            }
   2.558 +            return (status);
   2.559 +        }
   2.560 +    }
   2.561 +
   2.562 +    /* if media exists, then do other stuff */
   2.563 +
   2.564 +    memset(&info, 0x00, sizeof(info));
   2.565 +    info.subch_command.data_format = CDROM_SUBCH_CURRENT_POSITION;
   2.566 +
   2.567 +    do {
   2.568 +        devctlret=devctl(cdrom->id, DCMD_CAM_CDROMSUBCHNL, &info, sizeof(info), NULL);
   2.569 +        if (devctlret==EIO)
   2.570 +        {
   2.571 +            /* big workaround for media change, handle is unusable after that,
   2.572 +               that bug was found in QNX 6.2, 6.2.1 is not released yet.    */
   2.573 +
   2.574 +            for (i=0; i<MAX_DRIVES; i++)
   2.575 +            {
   2.576 +                if (SDL_cdopen[i]==cdrom->id)
   2.577 +                {
   2.578 +                    drive=i;
   2.579 +                    break;
   2.580 +                }
   2.581 +            }
   2.582 +            if (drive==-1)
   2.583 +            {
   2.584 +               /* that cannot happen, but ... */
   2.585 +               break;
   2.586 +            }
   2.587 +            close(cdrom->id);
   2.588 +            cdrom->id=open(SDL_cdlist[drive], QNX_CD_OPENMODE);
   2.589 +            devctlret=EAGAIN;
   2.590 +        }
   2.591 +        if (devctlret==EAGAIN)
   2.592 +        {
   2.593 +            eagaincnt++;
   2.594 +        }
   2.595 +        if (eagaincnt==2)
   2.596 +        {
   2.597 +            /* workaround for broken cdroms, which can return always EAGAIN when its not ready, */
   2.598 +            /* that mean errornous media or just no media avail                                 */
   2.599 +            devctlret=ENXIO;
   2.600 +            break;
   2.601 +        }
   2.602 +    } while ((devctlret==EAGAIN)||(devctlret==ESTALE));
   2.603 +
   2.604 +    if (devctlret != 0)
   2.605 +    {
   2.606 +        if (devctlret==ENXIO)
   2.607 +        {
   2.608 +            status = CD_TRAYEMPTY;
   2.609 +        }
   2.610 +        else
   2.611 +        {
   2.612 +            status = CD_ERROR;
   2.613 +        }
   2.614 +    }
   2.615 +    else
   2.616 +    {
   2.617 +        switch (info.current_position.header.audio_status)
   2.618 +        {
   2.619 +            case CDROM_AUDIO_INVALID:
   2.620 +            case CDROM_AUDIO_NO_STATUS:
   2.621 +                 /* Try to determine if there's a CD available */
   2.622 +                 if (devctl(cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof(toc), NULL)==0)
   2.623 +                     status = CD_STOPPED;
   2.624 +                 else
   2.625 +                     status = CD_TRAYEMPTY;
   2.626 +                 break;
   2.627 +            case CDROM_AUDIO_COMPLETED:
   2.628 +                 status = CD_STOPPED;
   2.629 +                 break;
   2.630 +            case CDROM_AUDIO_PLAY:
   2.631 +                 status = CD_PLAYING;
   2.632 +                 break;
   2.633 +            case CDROM_AUDIO_PAUSED:
   2.634 +                 /* Workaround buggy CD-ROM drive */
   2.635 +                 if (info.current_position.data_format == CDROM_LEADOUT)
   2.636 +                 {
   2.637 +                     status = CD_STOPPED;
   2.638 +                 }
   2.639 +                 else
   2.640 +                 {
   2.641 +                     status = CD_PAUSED;
   2.642 +                 }
   2.643 +                 break;
   2.644 +            default:
   2.645 +                 status = CD_ERROR;
   2.646 +                 break;
   2.647 +        }
   2.648 +    }
   2.649 +
   2.650 +    if (position)
   2.651 +    {
   2.652 +       if (status==CD_PLAYING || (status==CD_PAUSED))
   2.653 +       {
   2.654 +           *position = MSF_TO_FRAMES(info.current_position.addr.msf.minute,
   2.655 +                                     info.current_position.addr.msf.second,
   2.656 +                                     info.current_position.addr.msf.frame);
   2.657 +       }
   2.658 +       else
   2.659 +       {
   2.660 +           *position = 0;
   2.661 +       }
   2.662 +    }
   2.663 +
   2.664 +    return (status);
   2.665  }
   2.666  
   2.667  /* Start play */
   2.668  static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
   2.669  {
   2.670 -	cdrom_playmsf_t playtime;
   2.671 +    cdrom_playmsf_t playtime;
   2.672  
   2.673 -	FRAMES_TO_MSF(start,
   2.674 -	   &playtime.start_minute, &playtime.start_second, &playtime.start_frame);
   2.675 -	FRAMES_TO_MSF(start+length,
   2.676 -	   &playtime.end_minute, &playtime.end_second, &playtime.end_frame);
   2.677 -#ifdef DEBUG_CDROM
   2.678 -  fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
   2.679 -	playtime.start_minute, playtime.start_second, playtime.start_frame,
   2.680 -	playtime.end_minute, playtime.end_second, playtime.end_frame);
   2.681 -#endif
   2.682 -	return(devctl(cdrom->id, DCMD_CAM_CDROMPLAYMSF, &playtime, sizeof(playtime), 0));
   2.683 +    FRAMES_TO_MSF(start, &playtime.start_minute, &playtime.start_second, &playtime.start_frame);
   2.684 +    FRAMES_TO_MSF(start+length, &playtime.end_minute, &playtime.end_second, &playtime.end_frame);
   2.685 +
   2.686 +    if (devctl(cdrom->id, DCMD_CAM_CDROMPLAYMSF, &playtime, sizeof(playtime), NULL) != 0)
   2.687 +    {
   2.688 +       return -1;
   2.689 +    }
   2.690 +    else
   2.691 +    {
   2.692 +       return 0;
   2.693 +    }
   2.694  }
   2.695  
   2.696  /* Pause play */
   2.697  static int SDL_SYS_CDPause(SDL_CD *cdrom)
   2.698  {
   2.699 -	return(devctl(cdrom->id, DCMD_CAM_CDROMPAUSE, NULL, 0, 0));
   2.700 +    if (devctl(cdrom->id, DCMD_CAM_CDROMPAUSE, NULL, 0, NULL)!=0)
   2.701 +    {
   2.702 +       return -1;
   2.703 +    }
   2.704 +    else
   2.705 +    {
   2.706 +       return 0;
   2.707 +    }
   2.708  }
   2.709  
   2.710  /* Resume play */
   2.711  static int SDL_SYS_CDResume(SDL_CD *cdrom)
   2.712  {
   2.713 -	return(devctl(cdrom->id, DCMD_CAM_CDROMRESUME, NULL, 0, 0));
   2.714 +    if (devctl(cdrom->id, DCMD_CAM_CDROMRESUME, NULL, 0, NULL)!=0)
   2.715 +    {
   2.716 +       return -1;
   2.717 +    }
   2.718 +    else
   2.719 +    {
   2.720 +       return 0;
   2.721 +    }
   2.722  }
   2.723  
   2.724  /* Stop play */
   2.725  static int SDL_SYS_CDStop(SDL_CD *cdrom)
   2.726  {
   2.727 -	return(devctl(cdrom->id, DCMD_CAM_CDROMSTOP, NULL, 0, 0));
   2.728 +    if (devctl(cdrom->id, DCMD_CAM_CDROMSTOP, NULL, 0, NULL)!=0)
   2.729 +    {
   2.730 +       return -1;
   2.731 +    }
   2.732 +    else
   2.733 +    {
   2.734 +       return 0;
   2.735 +    }
   2.736  }
   2.737  
   2.738  /* Eject the CD-ROM */
   2.739  static int SDL_SYS_CDEject(SDL_CD *cdrom)
   2.740  {
   2.741 -	return(devctl(cdrom->id, DCMD_CAM_EJECT_MEDIA, NULL, 0, 0));
   2.742 +    if (devctl(cdrom->id, DCMD_CAM_EJECT_MEDIA, NULL, 0, NULL)!=0)
   2.743 +    {
   2.744 +       return -1;
   2.745 +    }
   2.746 +    else
   2.747 +    {
   2.748 +       return 0;
   2.749 +    }
   2.750  }
   2.751  
   2.752  /* Close the CD-ROM handle */
   2.753  static void SDL_SYS_CDClose(SDL_CD *cdrom)
   2.754  {
   2.755 -	close(cdrom->id);
   2.756 +    int i;
   2.757 +
   2.758 +    for (i=0; i<MAX_DRIVES; i++)
   2.759 +    {
   2.760 +       if (SDL_cdopen[i]==cdrom->id)
   2.761 +       {
   2.762 +           SDL_cdopen[i]=0;
   2.763 +           break;
   2.764 +       }
   2.765 +    }
   2.766 +
   2.767 +    close(cdrom->id);
   2.768  }
   2.769  
   2.770  void SDL_SYS_CDQuit(void)
   2.771  {
   2.772 -	int i;
   2.773 +    int i;
   2.774  
   2.775 -	if ( SDL_numcds > 0 ) {
   2.776 -		for ( i=0; i<SDL_numcds; ++i ) {
   2.777 -			free(SDL_cdlist[i]);
   2.778 -		}
   2.779 -		SDL_numcds = 0;
   2.780 -	}
   2.781 +    if (SDL_numcds > 0)
   2.782 +    {
   2.783 +        for (i=0; i<SDL_numcds; ++i)
   2.784 +        {
   2.785 +            free(SDL_cdlist[i]);
   2.786 +        }
   2.787 +        SDL_numcds = 0;
   2.788 +    }
   2.789  }
   2.790 -
     3.1 --- a/src/video/photon/SDL_ph_events.c	Mon Jan 20 01:37:07 2003 +0000
     3.2 +++ b/src/video/photon/SDL_ph_events.c	Mon Jan 20 01:38:37 2003 +0000
     3.3 @@ -55,67 +55,28 @@
     3.4     (idea shamelessly lifted from GII -- thanks guys! :)
     3.5   */
     3.6  
     3.7 -#if 0
     3.8 -static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent)
     3.9 -{
    3.10 -//	PhEvent_t* peekevent;
    3.11 -	PhKeyEvent_t* keyEvent;
    3.12 -	int repeated;
    3.13 -
    3.14 -	repeated = 0;
    3.15 -	switch (PhEventPeek( peekevent, EVENT_SIZE ))
    3.16 -	{
    3.17 -		case Ph_EVENT_MSG: {
    3.18 -			if(peekevent->type == Ph_EV_KEY)
    3.19 -			{
    3.20 -				keyEvent = PhGetData( peekevent );
    3.21 -				if ( !(Pk_KF_Key_Down & keyEvent->key_flags) &&
    3.22 -					(keyEvent->key_cap == keyevent->key_cap) &&
    3.23 -					(peekevent->timestamp == event->timestamp)	
    3.24 -				) {
    3.25 -					repeated = 1;
    3.26 -					 /* PhEventNext( peekevent, EVENT_SIZE ); */
    3.27 -				}				
    3.28 -			}
    3.29 -		}
    3.30 -		break;
    3.31 -
    3.32 -		case -1: {
    3.33 -			perror( "PhEventPeek failed" );
    3.34 -		}
    3.35 -		break;
    3.36 -
    3.37 -		default: /* no events pending */
    3.38 -	}
    3.39 -	return(repeated);
    3.40 -}
    3.41 -#endif
    3.42 -
    3.43  static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
    3.44  {
    3.45 -/*	PhPointerEvent_t *pointer = PhGetData( winEvent ); */
    3.46 -	PhRect_t *rect = PhGetRects( winEvent );
    3.47 +    PhRect_t *rect = PhGetRects( winEvent );
    3.48  
    3.49 -	int centre_x, centre_y;
    3.50 -	int dx, dy;
    3.51 -        short abs_x, abs_y;
    3.52 -	int posted;
    3.53 +    int centre_x, centre_y;
    3.54 +    int dx, dy;
    3.55 +    short abs_x, abs_y;
    3.56 +    int posted;
    3.57  
    3.58 -	centre_x = SDL_VideoSurface->w / 2;
    3.59 -	centre_y = SDL_VideoSurface->h / 2;
    3.60 +    centre_x = SDL_VideoSurface->w / 2;
    3.61 +    centre_y = SDL_VideoSurface->h / 2;
    3.62  
    3.63 -	dx = rect->ul.x - centre_x;
    3.64 -	dy = rect->ul.y - centre_y;
    3.65 +    dx = rect->ul.x - centre_x;
    3.66 +    dy = rect->ul.y - centre_y;
    3.67  
    3.68 -	posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
    3.69 +    posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
    3.70  
    3.71 -	/* Move mouse cursor to middle of the window */
    3.72 -	PtGetAbsPosition( window, &abs_x, &abs_y );
    3.73 -	PhMoveCursorAbs( PhInputGroup(NULL),
    3.74 -			abs_x + centre_x,
    3.75 -			abs_y + centre_y );
    3.76 +    /* Move mouse cursor to middle of the window */
    3.77 +    PtGetAbsPosition( window, &abs_x, &abs_y );
    3.78 +    PhMoveCursorAbs(PhInputGroup(NULL), abs_x + centre_x, abs_y + centre_y);
    3.79  
    3.80 -	return(posted);
    3.81 +    return (posted);
    3.82  }
    3.83  
    3.84  /* Control which motion flags the window has set, a flags value of -1 sets
    3.85 @@ -123,35 +84,34 @@
    3.86  
    3.87  static void set_motion_sensitivity(_THIS, unsigned int flags)
    3.88  {
    3.89 -	int rid, fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
    3.90 -	PhRegion_t region;
    3.91 +    int rid;
    3.92 +    int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
    3.93 +    PhRegion_t region;
    3.94  
    3.95 -	if( window )
    3.96 -	{
    3.97 -		rid = PtWidgetRid( window );
    3.98 -		if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
    3.99 -		{
   3.100 -			region.events_sense = ( region.events_sense & ~fields ) |
   3.101 -				( flags & fields );
   3.102 -			PhRegionChange( Ph_REGION_EV_SENSE, 0, &region,
   3.103 -					NULL, NULL );
   3.104 -		}
   3.105 -	}
   3.106 +    if( window )
   3.107 +    {
   3.108 +        rid = PtWidgetRid( window );
   3.109 +        if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
   3.110 +        {
   3.111 +            region.events_sense=(region.events_sense & ~fields)|(flags & fields);
   3.112 +            PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
   3.113 +        }
   3.114 +    }
   3.115  }
   3.116  
   3.117  /* Convert the photon button state value to an SDL value */
   3.118 -static Uint8 ph2sdl_mousebutton( unsigned short button_state )
   3.119 +static Uint8 ph2sdl_mousebutton(unsigned short button_state)
   3.120  {
   3.121 -	Uint8 mouse_button = 0;
   3.122 +    Uint8 mouse_button = 0;
   3.123  
   3.124 -	if( button_state & Ph_BUTTON_SELECT )
   3.125 -			mouse_button |= SDL_BUTTON_LEFT;
   3.126 -	if( button_state & Ph_BUTTON_MENU )
   3.127 -			mouse_button |= SDL_BUTTON_RIGHT;
   3.128 -	if( button_state & Ph_BUTTON_ADJUST )
   3.129 -			mouse_button |= SDL_BUTTON_MIDDLE;
   3.130 +    if (button_state & Ph_BUTTON_SELECT)
   3.131 +        mouse_button |= SDL_BUTTON_LEFT;
   3.132 +    if (button_state & Ph_BUTTON_MENU)
   3.133 +        mouse_button |= SDL_BUTTON_RIGHT;
   3.134 +    if (button_state & Ph_BUTTON_ADJUST)
   3.135 +        mouse_button |= SDL_BUTTON_MIDDLE;
   3.136  
   3.137 -	return( mouse_button );
   3.138 +    return (mouse_button);
   3.139  }
   3.140  
   3.141  static int ph_DispatchEvent(_THIS)
   3.142 @@ -245,10 +205,6 @@
   3.143              {
   3.144                  set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
   3.145                  posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	
   3.146 -
   3.147 -                /* Queue leaving fullscreen mode */
   3.148 -                switch_waiting = 0x01;
   3.149 -                switch_time = SDL_GetTicks() + 200;
   3.150              }
   3.151              /* gaining focus */
   3.152              else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
   3.153 @@ -323,271 +279,187 @@
   3.154  /* perform a blocking read if no events available */
   3.155  int ph_Pending(_THIS)
   3.156  {
   3.157 -	/* Flush the display connection and look to see if events are queued */
   3.158 -	PgFlush();
   3.159 +    /* Flush the display connection and look to see if events are queued */
   3.160 +    PgFlush();
   3.161  
   3.162 -     while( 1 )
   3.163 -      {   //note this is a non-blocking call
   3.164 -          switch( PhEventPeek( event, EVENT_SIZE ) )
   3.165 -           {
   3.166 -              case Ph_EVENT_MSG:
   3.167 -                 
   3.168 +    while( 1 )
   3.169 +    {   /* note this is a non-blocking call */
   3.170 +        switch( PhEventPeek( event, EVENT_SIZE ) )
   3.171 +        {
   3.172 +            case Ph_EVENT_MSG:
   3.173                   return 1;
   3.174                   break;
   3.175 -              case -1:
   3.176 -                 perror( "PhEventNext failed" );
   3.177 +            case -1:
   3.178 +                 perror("ph_Pending(): PhEventNext failed");
   3.179                   break;
   3.180 -              default:
   3.181 -             	  
   3.182 -                return 0;
   3.183 -       }
   3.184 -   }
   3.185 -
   3.186 -	/* Oh well, nothing is ready .. */
   3.187 -	return(0);
   3.188 -}
   3.189 -
   3.190 -/*
   3.191 -SAMPLE EVENT PUMP
   3.192 -=================
   3.193 -static void update( int block ){
   3.194 -
   3.195 -    int ch,fl;
   3.196 -    PhKeyEvent_t *key;
   3.197 -
   3.198 -    for( ;; ){
   3.199 -
   3.200 -        if( block ){
   3.201 -            do{
   3.202 -                fl=PhEventNext( event,EVENT_SIZE );
   3.203 -            }while( fl!=Ph_EVENT_MSG );
   3.204 -            block=0;
   3.205 -        }else{
   3.206 -            do{
   3.207 -                fl=PhEventPeek( event,EVENT_SIZE );
   3.208 -                if( !fl ) return;
   3.209 -            }while( fl!=Ph_EVENT_MSG );
   3.210 -        }
   3.211 -
   3.212 -        switch( event->type ){
   3.213 -        case Ph_EV_KEY:
   3.214 -            key=PhGetData( event );
   3.215 -            ch=key->key_cap;    // & 127;
   3.216 -            fl=key->key_flags;
   3.217 -            if( ch<32 || ch>127 ) break;
   3.218 -            if( fl & Pk_KF_Key_Down ){
   3.219 -                if( !(fl & Pk_KF_Key_Repeat) ){
   3.220 -                    if( queput-queget<QUE_SIZE ) keyque[ queput++ & QUE_MASK ]=ch;
   3.221 -                    keyMatrix[ch]=1;
   3.222 -                }
   3.223 -            }else{
   3.224 -                keyMatrix[ch]=0;
   3.225 -            }
   3.226 -            break;
   3.227 -        default:
   3.228 -            PtEventHandler( event );
   3.229 +            default:
   3.230 +                 return 0;
   3.231          }
   3.232      }
   3.233 +
   3.234 +    /* Oh well, nothing is ready .. */
   3.235 +    return(0);
   3.236  }
   3.237 -*/
   3.238  
   3.239  void ph_PumpEvents(_THIS)
   3.240  {
   3.241 -	int pending;
   3.242 +    /* Flush the display connection and look to see if events are queued */
   3.243 +    PgFlush();
   3.244  
   3.245 -	/* Keep processing pending events */
   3.246 -	pending = 0;
   3.247 -	while ( ph_Pending(this) ) {
   3.248 -		ph_DispatchEvent(this);
   3.249 -		++pending;
   3.250 -	}
   3.251 -	if ( switch_waiting ) {
   3.252 -		Uint32 now;
   3.253 -
   3.254 -		now  = SDL_GetTicks();
   3.255 -#if 0
   3.256 -		if ( pending || !SDL_VideoSurface ) {
   3.257 -			/* Try again later... */
   3.258 -			if ( switch_waiting & SDL_FULLSCREEN ) {
   3.259 -				switch_time = now + 1500;
   3.260 -			} else {
   3.261 -				switch_time = now + 200;
   3.262 -			}
   3.263 -		} else if ( now >= switch_time ) {
   3.264 -			Uint32 go_fullscreen;
   3.265 -
   3.266 -			go_fullscreen = switch_waiting & SDL_FULLSCREEN;
   3.267 -			switch_waiting = 0;
   3.268 -			if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
   3.269 -				if ( go_fullscreen ) {
   3.270 -					ph_EnterFullScreen(this);
   3.271 -				} else {
   3.272 -					ph_LeaveFullScreen(this);
   3.273 -				}
   3.274 -			}
   3.275 -			/* Handle focus in/out when grabbed */
   3.276 -/*
   3.277 -			if ( go_fullscreen ) {
   3.278 -				ph_GrabInputNoLock(this, this->input_grab);
   3.279 -			} else {
   3.280 -				ph_GrabInputNoLock(this, SDL_GRAB_OFF);
   3.281 -			}
   3.282 -*/
   3.283 -		}
   3.284 -#endif
   3.285 -	}
   3.286 +    while (ph_Pending(this))
   3.287 +    {
   3.288 +        ph_DispatchEvent(this);
   3.289 +    }
   3.290  }
   3.291  
   3.292  void ph_InitKeymap(void)
   3.293  {
   3.294 -	int i;
   3.295 +    int i;
   3.296  
   3.297 -	/* Odd keys used in international keyboards */
   3.298 -	for ( i=0; i<SDL_TABLESIZE(ODD_keymap); ++i )
   3.299 -		ODD_keymap[i] = SDLK_UNKNOWN;
   3.300 +    /* Odd keys used in international keyboards */
   3.301 +    for (i=0; i<SDL_TABLESIZE(ODD_keymap); ++i)
   3.302 +        ODD_keymap[i] = SDLK_UNKNOWN;
   3.303  
   3.304 -	/* Map the miscellaneous keys */
   3.305 -	for ( i=0; i<SDL_TABLESIZE(MISC_keymap); ++i )
   3.306 -		MISC_keymap[i] = SDLK_UNKNOWN;
   3.307 +    /* Map the miscellaneous keys */
   3.308 +    for (i=0; i<SDL_TABLESIZE(MISC_keymap); ++i)
   3.309 +        MISC_keymap[i] = SDLK_UNKNOWN;
   3.310  
   3.311 -	MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
   3.312 -	MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
   3.313 -	MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
   3.314 -	MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
   3.315 -	MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
   3.316 -	MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
   3.317 -	MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
   3.318 +    MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
   3.319 +    MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
   3.320 +    MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
   3.321 +    MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
   3.322 +    MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
   3.323 +    MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
   3.324 +    MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
   3.325  
   3.326 -	MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
   3.327 -	MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
   3.328 -	MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
   3.329 -	MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
   3.330 -	MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
   3.331 -	MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
   3.332 -	MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
   3.333 -	MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
   3.334 -	MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
   3.335 -	MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
   3.336 +    MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
   3.337 +    MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
   3.338 +    MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
   3.339 +    MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
   3.340 +    MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
   3.341 +    MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
   3.342 +    MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
   3.343 +    MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
   3.344 +    MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
   3.345 +    MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
   3.346  
   3.347 -	MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
   3.348 -	MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
   3.349 -	MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
   3.350 -	MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
   3.351 -	MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
   3.352 -	MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
   3.353 -	MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
   3.354 +    MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
   3.355 +    MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
   3.356 +    MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
   3.357 +    MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
   3.358 +    MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
   3.359 +    MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
   3.360 +    MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
   3.361  
   3.362 -	MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
   3.363 -	MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
   3.364 -	MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
   3.365 -	MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
   3.366 -	MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
   3.367 -	MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
   3.368 -	MISC_keymap[Pk_End&0xFF] = SDLK_END;
   3.369 -	MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
   3.370 -	MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
   3.371 +    MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
   3.372 +    MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
   3.373 +    MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
   3.374 +    MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
   3.375 +    MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
   3.376 +    MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
   3.377 +    MISC_keymap[Pk_End&0xFF] = SDLK_END;
   3.378 +    MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
   3.379 +    MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
   3.380  
   3.381 -	MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
   3.382 -	MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
   3.383 -	MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
   3.384 -	MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
   3.385 -	MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
   3.386 -	MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
   3.387 -	MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
   3.388 -	MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
   3.389 -	MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
   3.390 -	MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
   3.391 -	MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
   3.392 -	MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
   3.393 -	MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
   3.394 -	MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
   3.395 -	MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
   3.396 +    MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
   3.397 +    MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
   3.398 +    MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
   3.399 +    MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
   3.400 +    MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
   3.401 +    MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
   3.402 +    MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
   3.403 +    MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
   3.404 +    MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
   3.405 +    MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
   3.406 +    MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
   3.407 +    MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
   3.408 +    MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
   3.409 +    MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
   3.410 +    MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
   3.411  
   3.412 -	MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
   3.413 -	MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
   3.414 -	MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
   3.415 -	MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
   3.416 -	MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
   3.417 -	MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
   3.418 -	MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
   3.419 -	MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
   3.420 -	MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
   3.421 -	MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
   3.422 -	MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
   3.423 -	MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */
   3.424 -	MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows */
   3.425 -	MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
   3.426 +    MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
   3.427 +    MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
   3.428 +    MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
   3.429 +    MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
   3.430 +    MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
   3.431 +    MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
   3.432 +    MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
   3.433 +    MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
   3.434 +    MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
   3.435 +    MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
   3.436 +    MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
   3.437 +    MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;   /* Left "Windows"  */
   3.438 +    MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;   /* Right "Windows" */
   3.439 +    MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key    */
   3.440  
   3.441 -	MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
   3.442 -	MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
   3.443 -//	MISC_keymap[Pk_Sys_Req] = SDLK_SYSREQ;
   3.444 -	MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
   3.445 -	MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
   3.446 -	MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
   3.447 +    MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
   3.448 +    MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
   3.449 +    MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
   3.450 +    MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
   3.451 +    MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
   3.452  }
   3.453  
   3.454  static unsigned long cap;
   3.455  
   3.456  SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
   3.457  {
   3.458 -/*	
   3.459 -	'sym' is set to the value of the key with modifiers applied to it. 
   3.460 -	This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
   3.461 -	We will assume it is valid.
   3.462 -*/
   3.463 -	/* FIXME: This needs to check whether the cap & scancode is valid */
   3.464 -	cap = key->key_cap;
   3.465 -	switch (cap>>8) {
   3.466 -            case 0x00:  /* Latin 1 */
   3.467 -            case 0x01:  /* Latin 2 */
   3.468 -            case 0x02:  /* Latin 3 */
   3.469 -            case 0x03:  /* Latin 4 */
   3.470 -            case 0x04:  /* Katakana */
   3.471 -            case 0x05:  /* Arabic */
   3.472 -            case 0x06:  /* Cyrillic */
   3.473 -            case 0x07:  /* Greek */
   3.474 -            case 0x08:  /* Technical */
   3.475 -            case 0x0A:  /* Publishing */
   3.476 -            case 0x0C:  /* Hebrew */
   3.477 -            case 0x0D:  /* Thai */
   3.478 -                keysym->sym = (SDLKey)(cap&0xFF);
   3.479 -                /* Map capital letter syms to lowercase */
   3.480 -                if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
   3.481 -                    keysym->sym += ('a'-'A');
   3.482 -                break;
   3.483 -//            case 0xFE:
   3.484 -//                keysym->sym = ODD_keymap[sym&0xFF];
   3.485 -//                break;
   3.486 -            case 0xF0:
   3.487 -                keysym->sym = MISC_keymap[cap&0xFF];
   3.488 -                break;
   3.489 -            default:
   3.490 -/*                fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap); */
   3.491 -		keysym->sym = SDLK_UNKNOWN;                
   3.492 -                break;
   3.493 -	}
   3.494 -	keysym->scancode = key->key_scan;
   3.495 -	keysym->unicode = 0;
   3.496 -	if( SDL_TranslateUNICODE )
   3.497 -	{
   3.498 -		char utf8[MB_CUR_MAX];
   3.499 -		int utf8len;
   3.500 -		wchar_t unicode;
   3.501 +    /* 'sym' is set to the value of the key with modifiers applied to it.
   3.502 +       This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
   3.503 +       We will assume it is valid. */
   3.504  
   3.505 -		utf8len = PhKeyToMb( utf8, key );
   3.506 -		if( utf8len > 0 )
   3.507 -		{
   3.508 -			utf8len = mbtowc( &unicode, utf8, utf8len );
   3.509 -			if( utf8len > 0)
   3.510 -				keysym->unicode = unicode;
   3.511 -		}
   3.512 -	}
   3.513 +    /* FIXME: This needs to check whether the cap & scancode is valid */
   3.514  
   3.515 -	return (keysym);
   3.516 +    cap = key->key_cap;
   3.517 +
   3.518 +    switch (cap>>8)
   3.519 +    {
   3.520 +        case 0x00:  /* Latin 1 */
   3.521 +        case 0x01:  /* Latin 2 */
   3.522 +        case 0x02:  /* Latin 3 */
   3.523 +        case 0x03:  /* Latin 4 */
   3.524 +        case 0x04:  /* Katakana */
   3.525 +        case 0x05:  /* Arabic */
   3.526 +        case 0x06:  /* Cyrillic */
   3.527 +        case 0x07:  /* Greek */
   3.528 +        case 0x08:  /* Technical */
   3.529 +        case 0x0A:  /* Publishing */
   3.530 +        case 0x0C:  /* Hebrew */
   3.531 +        case 0x0D:  /* Thai */
   3.532 +                   keysym->sym = (SDLKey)(cap&0xFF);
   3.533 +                   /* Map capital letter syms to lowercase */
   3.534 +                   if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
   3.535 +                       keysym->sym += ('a'-'A');
   3.536 +                   break;
   3.537 +        case 0xF0:
   3.538 +                   keysym->sym = MISC_keymap[cap&0xFF];
   3.539 +                   break;
   3.540 +        default:
   3.541 +                   keysym->sym = SDLK_UNKNOWN;                
   3.542 +                   break;
   3.543 +    }
   3.544 +
   3.545 +    keysym->scancode = key->key_scan;
   3.546 +    keysym->unicode = 0;
   3.547 +
   3.548 +    if (SDL_TranslateUNICODE)
   3.549 +    {
   3.550 +        char utf8[MB_CUR_MAX];
   3.551 +        int utf8len;
   3.552 +        wchar_t unicode;
   3.553 +
   3.554 +        utf8len = PhKeyToMb(utf8, key);
   3.555 +        if (utf8len > 0)
   3.556 +        {
   3.557 +            utf8len = mbtowc(&unicode, utf8, utf8len);
   3.558 +            if (utf8len > 0)
   3.559 +                keysym->unicode = unicode;
   3.560 +        }
   3.561 +    }
   3.562 +
   3.563 +    return (keysym);
   3.564  }
   3.565  
   3.566  void ph_InitOSKeymap(_THIS)
   3.567  {
   3.568 -	ph_InitKeymap();
   3.569 +    ph_InitKeymap();
   3.570  }
   3.571 -
     4.1 --- a/src/video/photon/SDL_ph_events_c.h	Mon Jan 20 01:37:07 2003 +0000
     4.2 +++ b/src/video/photon/SDL_ph_events_c.h	Mon Jan 20 01:38:37 2003 +0000
     4.3 @@ -27,7 +27,7 @@
     4.4  
     4.5  #include "SDL_ph_video.h"
     4.6  
     4.7 -#define EVENT_SIZE sizeof( PhEvent_t ) + 1000
     4.8 +#define EVENT_SIZE sizeof(PhEvent_t) + 1000
     4.9  
    4.10  /* Functions to be exported */
    4.11  extern void ph_InitOSKeymap(_THIS);
     5.1 --- a/src/video/photon/SDL_ph_image.c	Mon Jan 20 01:37:07 2003 +0000
     5.2 +++ b/src/video/photon/SDL_ph_image.c	Mon Jan 20 01:38:37 2003 +0000
     5.3 @@ -29,16 +29,60 @@
     5.4  #include <Ph.h>
     5.5  #include <photon/Pg.h>
     5.6  
     5.7 +#include "SDL.h"
     5.8  #include "SDL_error.h"
     5.9  #include "SDL_endian.h"
    5.10 +#include "SDL_video.h"
    5.11 +#include "SDL_pixels_c.h"
    5.12  #include "SDL_ph_image_c.h"
    5.13  
    5.14 -/* remove this line, if photon headers updates */
    5.15 -int PgWaitHWIdle(void);
    5.16 +/* Mask values for SDL_ReallocFormat() */
    5.17 +struct ColourMasks
    5.18 +{
    5.19 +    Uint32 red;
    5.20 +    Uint32 green;
    5.21 +    Uint32 blue;
    5.22 +    Uint32 alpha;
    5.23 +    Uint32 bpp;
    5.24 +};
    5.25 +
    5.26 +static const struct ColourMasks *ph_GetColourMasks( int format )
    5.27 +{
    5.28 +    /* The alpha mask doesn't appear to be needed */
    5.29 +    static const struct ColourMasks phColorMasks[5] = {
    5.30 +        /*  8 bit      */  {0, 0, 0, 0, 8},
    5.31 +        /* 15 bit ARGB */  {0x7C00, 0x03E0, 0x001F, 0x8000, 16},
    5.32 +        /* 16 bit  RGB */  {0xF800, 0x07E0, 0x001F, 0x0000, 16},
    5.33 +        /* 24 bit  RGB */  {0xFF0000, 0x00FF00, 0x0000FF, 0x000000, 24},
    5.34 +        /* 32 bit ARGB */  {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 32},
    5.35 +    };
    5.36 +
    5.37 +    switch( format )
    5.38 +    {
    5.39 +        case Pg_IMAGE_PALETTE_BYTE:
    5.40 +             return &phColorMasks[0];
    5.41 +             break;
    5.42 +        case Pg_IMAGE_DIRECT_1555:
    5.43 +        case Pg_IMAGE_DIRECT_555:
    5.44 +             return &phColorMasks[1];
    5.45 +             break;
    5.46 +        case Pg_IMAGE_DIRECT_565:
    5.47 +             return &phColorMasks[2];
    5.48 +             break;
    5.49 +        case Pg_IMAGE_DIRECT_888:
    5.50 +             return &phColorMasks[3];
    5.51 +             break;
    5.52 +        case Pg_IMAGE_DIRECT_8888:
    5.53 +             return &phColorMasks[4];
    5.54 +             break;
    5.55 +    }
    5.56 +    return NULL;
    5.57 +}
    5.58  
    5.59  int ph_SetupImage(_THIS, SDL_Surface *screen)
    5.60  {
    5.61      PgColor_t* palette=NULL;
    5.62 +    const struct ColourMasks* mask;
    5.63      int type=0;
    5.64      int bpp;
    5.65      
    5.66 @@ -68,7 +112,7 @@
    5.67          }
    5.68          break;
    5.69          default:{
    5.70 -            fprintf(stderr,"ph_SetupImage(): unsupported bbp = %d\n", bpp);
    5.71 +            fprintf(stderr,"ph_SetupImage(): unsupported bpp=%d !\n", bpp);
    5.72              return -1;
    5.73          }
    5.74          break;
    5.75 @@ -84,7 +128,7 @@
    5.76          /* using shared memory for speed (set last param to 1) */
    5.77          if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL)
    5.78          {
    5.79 -            fprintf(stderr,"ph_SetupImage(): PhCreateImage failed for bpp=8.\n");
    5.80 +            fprintf(stderr,"ph_SetupImage(): PhCreateImage failed for bpp=8 !\n");
    5.81              return -1;
    5.82          }
    5.83      }
    5.84 @@ -93,14 +137,20 @@
    5.85          /* using shared memory for speed (set last param to 1) */
    5.86          if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL)
    5.87          {
    5.88 -            fprintf(stderr,"ph_SetupImage: PhCreateImage failed.\n");
    5.89 +            fprintf(stderr,"ph_SetupImage: PhCreateImage failed !\n");
    5.90              return -1;
    5.91          }
    5.92      }
    5.93 -    
    5.94 +
    5.95      screen->pixels = SDL_Image->image;
    5.96      screen->pitch = SDL_Image->bpl; /* Recalculated pitch, created by PhCreateImage */
    5.97  
    5.98 +    mask = ph_GetColourMasks(type);
    5.99 +    if (mask != NULL)
   5.100 +    {
   5.101 +        SDL_ReallocFormat(screen, mask->bpp, mask->red, mask->green, mask->blue, 0);
   5.102 +    }
   5.103 +
   5.104      this->UpdateRects = ph_NormalUpdate;
   5.105  
   5.106      return 0;
   5.107 @@ -108,8 +158,12 @@
   5.108  
   5.109  int ph_SetupOCImage(_THIS, SDL_Surface *screen)
   5.110  {
   5.111 +    const struct ColourMasks *mask;
   5.112      int type = 0;
   5.113      int bpp;
   5.114 +
   5.115 +    screen->flags &= ~SDL_DOUBLEBUF;
   5.116 +    OCImage.flags = screen->flags;
   5.117      
   5.118      bpp=screen->format->BitsPerPixel;
   5.119  
   5.120 @@ -137,22 +191,14 @@
   5.121                  }
   5.122                  break;
   5.123          default:{
   5.124 -                    fprintf(stderr,"ph_SetupOCImage(): unsupported bpp = %d\n", bpp);
   5.125 +                    fprintf(stderr,"ph_SetupOCImage(): unsupported bpp=%d !\n", bpp);
   5.126                      return -1;
   5.127                  }
   5.128                  break;
   5.129      }
   5.130  
   5.131 -    OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
   5.132 -    OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
   5.133 -    memset(OCImage.FrameData0, 0x00, (size_t)(sizeof(FRAMEDATA)));
   5.134 -    memset(OCImage.FrameData1, 0x00, (size_t)(sizeof(FRAMEDATA)));
   5.135 -
   5.136 -    if(OCImage.direct_context == NULL)
   5.137 -    {
   5.138 -        OCImage.direct_context = PdCreateDirectContext();
   5.139 -    }
   5.140 -
   5.141 +    /* Currently only offscreen contexts with the same bit depth as the
   5.142 +     * display can be created. */
   5.143      OCImage.offscreen_context = PdCreateOffscreenContext(0, screen->w, screen->h, Pg_OSC_MEM_PAGE_ALIGN);
   5.144  
   5.145      if (OCImage.offscreen_context == NULL)
   5.146 @@ -161,13 +207,22 @@
   5.147          return -1;
   5.148      }
   5.149  
   5.150 +    /* If the bit depth of the context is different than was requested,
   5.151 +     * these values need to be updated accordingly.  SDL will
   5.152 +     * allocate a shadow surface if it needs to. */
   5.153 +    mask = ph_GetColourMasks(OCImage.offscreen_context->format);
   5.154 +    if (mask != NULL)
   5.155 +    {
   5.156 +        SDL_ReallocFormat(screen, mask->bpp, mask->red, mask->green, mask->blue, 0);
   5.157 +
   5.158 +        if (mask->bpp > 8)
   5.159 +        {
   5.160 +            screen->flags &= ~SDL_HWPALETTE;
   5.161 +        }
   5.162 +    }
   5.163 +
   5.164      screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */
   5.165  
   5.166 -    if (OCImage.flags & SDL_DOUBLEBUF)
   5.167 -    {
   5.168 -        fprintf(stderr, "ph_SetupOCImage(): Hardware flag for doublebuf offscreen context\n");
   5.169 -    }
   5.170 -
   5.171      OCImage.dc_ptr.ptr8 = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context);
   5.172  
   5.173      if (OCImage.dc_ptr.ptr8 == NULL)
   5.174 @@ -176,15 +231,13 @@
   5.175          return -1;
   5.176      }
   5.177  
   5.178 +    OCImage.FrameData0 = OCImage.dc_ptr.ptr8;
   5.179      OCImage.CurrentFrameData = OCImage.FrameData0;
   5.180 -    OCImage.CurrentFrameData->Y = OCImage.dc_ptr.ptr8;
   5.181 -    OCImage.CurrentFrameData->U = NULL;
   5.182 -    OCImage.CurrentFrameData->V = NULL;
   5.183      OCImage.current = 0;
   5.184  
   5.185      PhDCSetCurrent(OCImage.offscreen_context);
   5.186  
   5.187 -    screen->pixels = OCImage.CurrentFrameData->Y;
   5.188 +    screen->pixels = OCImage.CurrentFrameData;
   5.189  
   5.190      this->UpdateRects = ph_OCUpdate;
   5.191  
   5.192 @@ -198,15 +251,67 @@
   5.193     return 0;
   5.194  }
   5.195  
   5.196 +int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen)
   5.197 +{
   5.198 +    const struct ColourMasks *mask;
   5.199 +    screen->flags &= ~SDL_DOUBLEBUF;
   5.200 +    OCImage.flags = screen->flags;
   5.201 +
   5.202 +    OCImage.offscreen_context = PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY);
   5.203 +
   5.204 +    if (OCImage.offscreen_context == NULL)
   5.205 +    {
   5.206 +        fprintf(stderr, "ph_SetupFullScreenImage(): PdCreateOffscreenContext failed !\n");
   5.207 +        return -1;
   5.208 +    }
   5.209 +
   5.210 +    /* If the bit depth of the context is different than was requested,
   5.211 +     * these values need to be updated accordingly.  SDL will
   5.212 +     * allocate a shadow surface if it needs to. */
   5.213 +    mask = ph_GetColourMasks(OCImage.offscreen_context->format);
   5.214 +    if (mask != NULL)
   5.215 +    {
   5.216 +        SDL_ReallocFormat(screen, mask->bpp, mask->red, mask->green, mask->blue, 0);
   5.217 +
   5.218 +        if (mask->bpp > 8)
   5.219 +        {
   5.220 +            screen->flags &= ~SDL_HWPALETTE;
   5.221 +        }
   5.222 +    }
   5.223 +
   5.224 +    screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */
   5.225 +
   5.226 +    OCImage.dc_ptr.ptr8 = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_context);
   5.227 +
   5.228 +    if (OCImage.dc_ptr.ptr8 == NULL)
   5.229 +    {
   5.230 +        fprintf(stderr, "ph_SetupOCImage(): PdGetOffscreenContextPtr failed !\n");
   5.231 +        return -1;
   5.232 +    }
   5.233 +
   5.234 +    /* wait for hw */
   5.235 +    PgWaitHWIdle();
   5.236 +
   5.237 +    OCImage.FrameData0 = OCImage.dc_ptr.ptr8;
   5.238 +    OCImage.CurrentFrameData = OCImage.FrameData0;
   5.239 +    OCImage.current = 0;
   5.240 +
   5.241 +    PhDCSetCurrent(OCImage.offscreen_context);
   5.242 +
   5.243 +    screen->pixels = OCImage.CurrentFrameData;
   5.244 +
   5.245 +    this->UpdateRects = ph_OCUpdate;
   5.246 +
   5.247 +    return 0;
   5.248 +}
   5.249 +
   5.250  void ph_DestroyImage(_THIS, SDL_Surface *screen)
   5.251  {
   5.252      if (OCImage.offscreen_context != NULL)
   5.253      {
   5.254          PhDCRelease(OCImage.offscreen_context);
   5.255          OCImage.offscreen_context = NULL;
   5.256 -        free(OCImage.FrameData0);
   5.257          OCImage.FrameData0 = NULL;
   5.258 -        free(OCImage.FrameData1);
   5.259          OCImage.FrameData1 = NULL;
   5.260      }
   5.261  
   5.262 @@ -230,23 +335,24 @@
   5.263      }
   5.264  }
   5.265  
   5.266 -int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags)
   5.267 +int ph_SetupUpdateFunction(_THIS, SDL_Surface *screen, Uint32 flags)
   5.268  {
   5.269      ph_DestroyImage(this, screen);
   5.270      
   5.271 -    if (flags & SDL_HWSURFACE)
   5.272 +    if ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)
   5.273      {
   5.274 -        OCImage.flags = flags;  /* needed for SDL_DOUBLEBUF check */
   5.275 +        return ph_SetupFullScreenImage(this, screen);
   5.276 +    }
   5.277 +    if ((flags & SDL_HWSURFACE)==SDL_HWSURFACE)
   5.278 +    {
   5.279          return ph_SetupOCImage(this, screen);
   5.280      }
   5.281 -    else if (flags & SDL_OPENGL)
   5.282 +    if ((flags & SDL_OPENGL)==SDL_OPENGL)
   5.283      {
   5.284          return ph_SetupOpenGLImage(this, screen);
   5.285      } 
   5.286 -    else
   5.287 -    {
   5.288 -        return ph_SetupImage(this, screen);
   5.289 -    }      
   5.290 +
   5.291 +    return ph_SetupImage(this, screen);
   5.292  }
   5.293  int ph_AllocHWSurface(_THIS, SDL_Surface *surface)
   5.294  {
   5.295 @@ -265,11 +371,6 @@
   5.296  
   5.297  int ph_LockHWSurface(_THIS, SDL_Surface *surface)
   5.298  {
   5.299 -    if ((surface == SDL_VideoSurface) && blit_queued) {
   5.300 -	PgFlush();
   5.301 -        blit_queued = 0;
   5.302 -    }
   5.303 -
   5.304      return(0);
   5.305  }
   5.306  
   5.307 @@ -307,7 +408,7 @@
   5.308  
   5.309          if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
   5.310          {
   5.311 -            fprintf(stderr,"ph_NormalUpdate(): PgDrawPhImageRectmx failed.\n");
   5.312 +            fprintf(stderr,"ph_NormalUpdate(): PgDrawPhImageRectmx failed !\n");
   5.313          }
   5.314      }
   5.315  
   5.316 @@ -325,11 +426,6 @@
   5.317      PhArea_t src_rect;
   5.318      PhArea_t dest_rect;
   5.319  
   5.320 -    if(OCImage.direct_context == NULL)
   5.321 -    {
   5.322 -        return;
   5.323 -    }
   5.324 -
   5.325      PgSetRegion(PtWidgetRid(window));
   5.326      PgSetClipping(0, NULL);
   5.327      PgWaitHWIdle();
     6.1 --- a/src/video/photon/SDL_ph_image_c.h	Mon Jan 20 01:37:07 2003 +0000
     6.2 +++ b/src/video/photon/SDL_ph_image_c.h	Mon Jan 20 01:38:37 2003 +0000
     6.3 @@ -29,7 +29,7 @@
     6.4  
     6.5  extern int ph_SetupImage(_THIS, SDL_Surface *screen);
     6.6  extern void ph_DestroyImage(_THIS, SDL_Surface *screen);
     6.7 -extern int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags);
     6.8 +extern int ph_SetupUpdateFunction(_THIS, SDL_Surface *screen, Uint32 flags);
     6.9  
    6.10  extern int ph_AllocHWSurface(_THIS, SDL_Surface *surface);
    6.11  extern void ph_FreeHWSurface(_THIS, SDL_Surface *surface);
     7.1 --- a/src/video/photon/SDL_ph_modes.c	Mon Jan 20 01:37:07 2003 +0000
     7.2 +++ b/src/video/photon/SDL_ph_modes.c	Mon Jan 20 01:38:37 2003 +0000
     7.3 @@ -31,35 +31,36 @@
     7.4  static PgVideoModeInfo_t mode_info;
     7.5  static PgVideoModes_t mode_list;
     7.6  
     7.7 -  /* The current list of available video modes */
     7.8 +/* The current list of available video modes */
     7.9  SDL_Rect  SDL_modelist[PH_MAX_VIDEOMODES];
    7.10  SDL_Rect* SDL_modearray[PH_MAX_VIDEOMODES];
    7.11  
    7.12  static int compare_modes_by_res(const void* mode1, const void* mode2)
    7.13  {
    7.14 +    if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode_info) < 0)
    7.15 +    {
    7.16 +        fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
    7.17 +            *(unsigned short*)mode1);
    7.18 +        return 0;
    7.19 +    }
    7.20  
    7.21 -	if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode_info) < 0)
    7.22 -	{
    7.23 -	    fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
    7.24 -        	    *(unsigned short*)mode1);
    7.25 -    	    return 0;
    7.26 -	}
    7.27 -	key1 = mode_info.width * mode_info.height;
    7.28 +    key1 = mode_info.width * mode_info.height;
    7.29  
    7.30 -	if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0)
    7.31 -	{
    7.32 -    	    fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
    7.33 -	            *(unsigned short*)mode2);
    7.34 -	    return 0;
    7.35 -	}
    7.36 -        key2 = mode_info.width * mode_info.height;
    7.37 +    if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0)
    7.38 +    {
    7.39 +        fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
    7.40 +            *(unsigned short*)mode2);
    7.41 +        return 0;
    7.42 +    }
    7.43  
    7.44 -	if (key1 > key2)
    7.45 -		return 1;
    7.46 -	else if (key1 == key2)
    7.47 -		return 0;
    7.48 -	else
    7.49 -		return -1;
    7.50 +    key2 = mode_info.width * mode_info.height;
    7.51 +
    7.52 +    if (key1 > key2)
    7.53 +        return 1;
    7.54 +    else if (key1 == key2)
    7.55 +        return 0;
    7.56 +    else
    7.57 +        return -1;
    7.58  }
    7.59  
    7.60  SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
    7.61 @@ -117,89 +118,6 @@
    7.62     return;
    7.63  }
    7.64  
    7.65 -#if 0
    7.66 -static void set_best_resolution(_THIS, int width, int height)
    7.67 -{
    7.68 -    /* warning ! dead variable use_vidmode ! */
    7.69 -    if ( use_vidmode ) {
    7.70 -		PgDisplaySettings_t 	settings;
    7.71 -		PgVideoModeInfo_t		current_mode_info;
    7.72 -		PgHWCaps_t my_hwcaps;
    7.73 -		unsigned short			current_bpp;
    7.74 -        int i;
    7.75 -	/*
    7.76 -		if (PgGetVideoMode( &settings ) < 0)
    7.77 -		{
    7.78 -			fprintf(stderr,"error: PgGetVideoMode failed\n");
    7.79 -			return;
    7.80 -		}
    7.81 -		if (PgGetVideoModeInfo( settings.mode, &current_mode_info ) < 0)
    7.82 -		{
    7.83 -			fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
    7.84 -			return;
    7.85 -		}
    7.86 -		*/
    7.87 -		//lu_zero 
    7.88 -         if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
    7.89 -         	{
    7.90 -                fprintf(stderr,"set_best_resolution:  GetGraphicsHWCaps failed!! \n");
    7.91 -      			//that HAVE to work
    7.92 -            }
    7.93 -         if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &current_mode_info) < 0)
    7.94 -            {
    7.95 -                fprintf(stderr,"set_best_resolution:  PgGetVideoModeInfo failed\n");
    7.96 -            }
    7.97 -		current_bpp = current_mode_info.bits_per_pixel;
    7.98 -
    7.99 -        if (PgGetVideoModeList(&mode_list) >= 0)
   7.100 -		{
   7.101 -			qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res);
   7.102 -#ifdef PH_DEBUG
   7.103 -  			printf("Available modes:\n");
   7.104 -  			for ( i = 0; i < mode_list.num_modes; ++i ) 
   7.105 -			{
   7.106 -				PgGetVideoModeInfo(mode_list.modes[i], &mode_info);
   7.107 -    			printf("Mode %d: %dx%d\n", i, mode_info.width, mode_info.height);
   7.108 -  			}
   7.109 -#endif
   7.110 -            for ( i = mode_list.num_modes-1; i >= 0 ; --i ) 
   7.111 -			{
   7.112 -				if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
   7.113 -				{
   7.114 -					fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
   7.115 -				}
   7.116 -                if ( (mode_info.width >= width) &&
   7.117 -                     (mode_info.height >= height) &&
   7.118 -					 (mode_info.bits_per_pixel == current_bpp) )
   7.119 -                    break;
   7.120 -            }
   7.121 -			if (i >= 0)
   7.122 -			{
   7.123 -                if ( (mode_info.width != current_mode_info.width) ||
   7.124 -                     (mode_info.height != current_mode_info.height) ) 
   7.125 -				{
   7.126 -					settings.mode = mode_list.modes[i];
   7.127 -					if(PgSetVideoMode( &settings ) < 0)	
   7.128 -					{
   7.129 -						fprintf(stderr,"error: PgSetVideoMode failed\n");
   7.130 -					}
   7.131 -                }
   7.132 -            }
   7.133 -        }
   7.134 -    }
   7.135 -}
   7.136 -
   7.137 -int ph_ResizeFullScreen(_THIS)
   7.138 -{
   7.139 -    if (currently_fullscreen)
   7.140 -    {
   7.141 -        set_best_resolution(this, current_w, current_h);
   7.142 -    }
   7.143 -
   7.144 -    return (1);
   7.145 -}
   7.146 -#endif /* 0 */
   7.147 -
   7.148  /* return the mode associated with width, height and bpp */
   7.149  /* if there is no mode then zero is returned             */
   7.150  int get_mode(int width, int height, int bpp)
   7.151 @@ -270,7 +188,7 @@
   7.152  		/* get closest bpp */
   7.153  		closest = i++;
   7.154  		if (mode_info.bits_per_pixel == bpp)
   7.155 -			return mode_list.modes[ closest ];
   7.156 +			return mode_list.modes[closest];
   7.157  
   7.158  		min_delta = abs(mode_info.bits_per_pixel - bpp);
   7.159  		while(1)
   7.160 @@ -300,16 +218,12 @@
   7.161  				i++;
   7.162  			}
   7.163  		}
   7.164 -		return mode_list.modes[ closest ];
   7.165 +		return mode_list.modes[closest];
   7.166  	}
   7.167  	else
   7.168      return 0;
   7.169  }
   7.170  
   7.171 -void ph_WaitMapped(_THIS);
   7.172 -void ph_WaitUnmapped(_THIS);
   7.173 -void ph_QueueEnterFullScreen(_THIS);
   7.174 -
   7.175  int ph_ToggleFullScreen(_THIS, int on)
   7.176  {
   7.177      if (currently_fullscreen)
   7.178 @@ -338,17 +252,18 @@
   7.179              }
   7.180          }
   7.181  
   7.182 -        if (OCImage.direct_context == NULL)
   7.183 +        if (OCImage.direct_context==NULL)
   7.184          {
   7.185              OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
   7.186          }
   7.187  
   7.188          if (!OCImage.direct_context)
   7.189          {
   7.190 -            fprintf(stderr, "ph_EnterFullScreen: Can't create direct context\n" );
   7.191 +            fprintf(stderr, "ph_EnterFullScreen(): Can't create direct context !\n");
   7.192 +            return 0;
   7.193          }
   7.194  
   7.195 -        PdDirectStart(OCImage.direct_context);
   7.196 +        OCImage.oldDC=PdDirectStart(OCImage.direct_context);
   7.197  
   7.198          currently_fullscreen = 1;
   7.199      }
   7.200 @@ -372,7 +287,8 @@
   7.201          {
   7.202              PdDirectStop(OCImage.direct_context);
   7.203              PdReleaseDirectContext(OCImage.direct_context);
   7.204 -            
   7.205 +            PhDCSetCurrent(OCImage.oldDC);
   7.206 +
   7.207              currently_fullscreen=0;
   7.208  
   7.209              /* Restore old video mode */
   7.210 @@ -384,7 +300,8 @@
   7.211                  
   7.212                  if (PgSetVideoMode(&mymode_settings) < 0)
   7.213                  {
   7.214 -                    fprintf(stderr,"error: PgSetVideoMode failed\n");
   7.215 +                    fprintf(stderr, "Ph_LeaveFullScreen(): PgSetVideoMode failed !\n");
   7.216 +                    return 0;
   7.217                  }
   7.218              }
   7.219  
     8.1 --- a/src/video/photon/SDL_ph_modes_c.h	Mon Jan 20 01:37:07 2003 +0000
     8.2 +++ b/src/video/photon/SDL_ph_modes_c.h	Mon Jan 20 01:38:37 2003 +0000
     8.3 @@ -36,9 +36,6 @@
     8.4  extern SDL_Rect **ph_ListModes(_THIS,SDL_PixelFormat *format, Uint32 flags);
     8.5  extern void ph_FreeVideoModes(_THIS);
     8.6  extern int ph_ResizeFullScreen(_THIS);
     8.7 -extern void ph_WaitMapped(_THIS);
     8.8 -extern void ph_WaitUnmapped(_THIS);
     8.9 -extern void ph_QueueEnterFullScreen(_THIS);
    8.10  extern int ph_EnterFullScreen(_THIS);
    8.11  extern int ph_LeaveFullScreen(_THIS);
    8.12  extern int get_mode(int width, int height, int bpp);
     9.1 --- a/src/video/photon/SDL_ph_mouse.c	Mon Jan 20 01:37:07 2003 +0000
     9.2 +++ b/src/video/photon/SDL_ph_mouse.c	Mon Jan 20 01:38:37 2003 +0000
     9.3 @@ -35,18 +35,18 @@
     9.4  #include "SDL_cursor_c.h"
     9.5  #include "SDL_ph_mouse_c.h"
     9.6  
     9.7 -struct  WMcursor {
     9.8 +struct WMcursor
     9.9 +{
    9.10      PhCursorDef_t *ph_cursor ;
    9.11  };
    9.12  
    9.13 -
    9.14  void ph_FreeWMCursor(_THIS, WMcursor *cursor)
    9.15  {
    9.16      if (window != NULL)
    9.17      {
    9.18          SDL_Lock_EventThread();
    9.19  
    9.20 -        if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0 ) < 0)
    9.21 +        if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0) < 0)
    9.22          {
    9.23              /* TODO: output error msg */
    9.24          }
    9.25 @@ -60,64 +60,61 @@
    9.26  WMcursor *ph_CreateWMCursor(_THIS,
    9.27  		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
    9.28  {
    9.29 -	WMcursor* cursor;
    9.30 -	int clen, i;
    9.31 -	unsigned char bit, databit, maskbit;
    9.32 +    WMcursor* cursor;
    9.33 +    int clen, i;
    9.34 +    unsigned char bit, databit, maskbit;
    9.35  
    9.36 -	/* Allocate and initialize the cursor memory */
    9.37 -	if ((cursor = (WMcursor*)malloc(sizeof(WMcursor))) == NULL)
    9.38 -	{
    9.39 -            SDL_OutOfMemory();
    9.40 -            return(NULL);
    9.41 -	}
    9.42 -	memset(cursor,0,sizeof(WMcursor));
    9.43 +    /* Allocate and initialize the cursor memory */
    9.44 +    if ((cursor = (WMcursor*)malloc(sizeof(WMcursor))) == NULL)
    9.45 +    {
    9.46 +        SDL_OutOfMemory();
    9.47 +        return(NULL);
    9.48 +    }
    9.49 +    memset(cursor,0,sizeof(WMcursor));
    9.50  
    9.51 -	cursor->ph_cursor = (PhCursorDef_t *) malloc(sizeof(PhCursorDef_t) + 32*4*2);
    9.52 -	if(cursor->ph_cursor == NULL)
    9.53 -	   printf("cursor malloc failed\n");
    9.54 +    cursor->ph_cursor = (PhCursorDef_t *) malloc(sizeof(PhCursorDef_t) + 32*4*2);
    9.55 +    if (cursor->ph_cursor == NULL)
    9.56 +        printf("cursor malloc failed\n");
    9.57  
    9.58 -	memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2));
    9.59 +    memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2));
    9.60  
    9.61 -	cursor->ph_cursor->hdr.type =Ph_RDATA_CURSOR;   
    9.62 -	cursor->ph_cursor->size1.x = (short)w;
    9.63 -	cursor->ph_cursor->size1.y = (short)h;
    9.64 -	cursor->ph_cursor->offset1.x = (short)hot_x;
    9.65 -	cursor->ph_cursor->offset1.y = (short)hot_y;
    9.66 -	cursor->ph_cursor->bytesperline1 = (char)w/8;
    9.67 -	cursor->ph_cursor->color1 = Pg_WHITE;
    9.68 -	cursor->ph_cursor->size2.x = (short)w;
    9.69 -        cursor->ph_cursor->size2.y = (short)h;
    9.70 -        cursor->ph_cursor->offset2.x = (short)hot_x;
    9.71 -        cursor->ph_cursor->offset2.y = (short)hot_y;
    9.72 -        cursor->ph_cursor->bytesperline2 = (char)w/8;
    9.73 -        cursor->ph_cursor->color2 = Pg_BLACK;
    9.74 +    cursor->ph_cursor->hdr.type =Ph_RDATA_CURSOR;   
    9.75 +    cursor->ph_cursor->size1.x = (short)w;
    9.76 +    cursor->ph_cursor->size1.y = (short)h;
    9.77 +    cursor->ph_cursor->offset1.x = (short)hot_x;
    9.78 +    cursor->ph_cursor->offset1.y = (short)hot_y;
    9.79 +    cursor->ph_cursor->bytesperline1 = (char)w/8;
    9.80 +    cursor->ph_cursor->color1 = Pg_WHITE;
    9.81 +    cursor->ph_cursor->size2.x = (short)w;
    9.82 +    cursor->ph_cursor->size2.y = (short)h;
    9.83 +    cursor->ph_cursor->offset2.x = (short)hot_x;
    9.84 +    cursor->ph_cursor->offset2.y = (short)hot_y;
    9.85 +    cursor->ph_cursor->bytesperline2 = (char)w/8;
    9.86 +    cursor->ph_cursor->color2 = Pg_BLACK;
    9.87  
    9.88 -	clen = (w/8)*h;
    9.89 +    clen = (w/8)*h;
    9.90  
    9.91 -	/* Copy the mask and the data to different 
    9.92 -	   bitmap planes */
    9.93 -	for ( i=0; i<clen; ++i )
    9.94 -	{
    9.95 -		for ( bit = 0; bit < 8; bit++ )
    9.96 -		{
    9.97 -			databit = data[i] & (1 << bit);
    9.98 -			maskbit = mask[i] & (1 << bit);
    9.99 +    /* Copy the mask and the data to different bitmap planes */
   9.100 +    for (i=0; i<clen; ++i)
   9.101 +    {
   9.102 +        for (bit = 0; bit < 8; bit++)
   9.103 +        {
   9.104 +            databit = data[i] & (1 << bit);
   9.105 +            maskbit = mask[i] & (1 << bit);
   9.106  
   9.107 -			cursor->ph_cursor->images[i] |= 
   9.108 -				(databit == 0) ? maskbit : 0;
   9.109 -			/* If the databit != 0, treat it as a black pixel and
   9.110 -			 * ignore the maskbit (can't do an inverted color) */
   9.111 -			cursor->ph_cursor->images[i+clen] |= databit;
   9.112 -		}
   9.113 -	}
   9.114 +            cursor->ph_cursor->images[i] |= (databit == 0) ? maskbit : 0;
   9.115 +            /* If the databit != 0, treat it as a black pixel and
   9.116 +             * ignore the maskbit (can't do an inverted color) */
   9.117 +            cursor->ph_cursor->images[i+clen] |= databit;
   9.118 +        }
   9.119 +    }
   9.120  
   9.121 -        /* #bytes following the hdr struct */
   9.122 -	cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t); 
   9.123 +    /* #bytes following the hdr struct */
   9.124 +    cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t); 
   9.125  
   9.126 -	return (cursor);
   9.127 +    return (cursor);
   9.128  }
   9.129  
   9.130 -
   9.131  PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor)
   9.132  {
   9.133      return(*cursor->ph_cursor);
   9.134 @@ -125,47 +122,46 @@
   9.135  
   9.136  int ph_ShowWMCursor(_THIS, WMcursor *cursor)
   9.137  {
   9.138 -	PtArg_t args[3];
   9.139 -	int nargs = 0;
   9.140 -	short cursor_is_defined = 0;
   9.141 +    PtArg_t args[3];
   9.142 +    int nargs = 0;
   9.143  
   9.144 -	/* Don't do anything if the display is gone */
   9.145 - 	if ( window == NULL ) {
   9.146 -    	 return(0);
   9.147 - 	}
   9.148 +    /* Don't do anything if the display is gone */
   9.149 +    if (window == NULL)
   9.150 +    {
   9.151 +        return (0);
   9.152 +    }
   9.153  
   9.154 -	/* Set the photon cursor cursor, or blank if cursor is NULL */
   9.155 -	if ( window ) {
   9.156 -		
   9.157 -		if ( cursor != NULL ) {
   9.158 -			PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0 );
   9.159 -			/* Could set next to any PgColor_t value */
   9.160 -			PtSetArg( &args[1], Pt_ARG_CURSOR_COLOR,Ph_CURSOR_DEFAULT_COLOR , 0 );
   9.161 -			PtSetArg( &args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t)) );
   9.162 -			nargs = 3;
   9.163 -			cursor_is_defined = 1;
   9.164 -		}
   9.165 -		else /* Ph_CURSOR_NONE */
   9.166 -		{
   9.167 -			PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE,Ph_CURSOR_NONE, 0);
   9.168 -			nargs = 1;
   9.169 -			cursor_is_defined = 1;
   9.170 -		}
   9.171 -		if (cursor_is_defined)
   9.172 -		{
   9.173 -    	                SDL_Lock_EventThread();
   9.174 -			
   9.175 -			if (PtSetResources( window, nargs, args ) < 0 )
   9.176 -			{
   9.177 -			    return(0);
   9.178 -			}	
   9.179 -						
   9.180 -			SDL_Unlock_EventThread();
   9.181 -		}
   9.182 -		else
   9.183 -			return(0);
   9.184 -	}
   9.185 -	return(1);
   9.186 +    /* looks like photon can't draw mouse cursor in direct mode */
   9.187 +    if ((this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
   9.188 +    {
   9.189 +        return (0);
   9.190 +    }
   9.191 +
   9.192 +    /* Set the photon cursor cursor, or blank if cursor is NULL */
   9.193 +    if (cursor!=NULL)
   9.194 +    {
   9.195 +        PtSetArg(&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
   9.196 +        /* Could set next to any PgColor_t value */
   9.197 +        PtSetArg(&args[1], Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR , 0);
   9.198 +        PtSetArg(&args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t)));
   9.199 +        nargs = 3;
   9.200 +    }
   9.201 +    else /* Ph_CURSOR_NONE */
   9.202 +    {
   9.203 +        PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
   9.204 +        nargs = 1;
   9.205 +    }
   9.206 +
   9.207 +    SDL_Lock_EventThread();
   9.208 +
   9.209 +    if (PtSetResources(window, nargs, args) < 0 )
   9.210 +    {
   9.211 +        return (0);
   9.212 +    }	
   9.213 +
   9.214 +    SDL_Unlock_EventThread();
   9.215 +
   9.216 +    return (1);
   9.217  }
   9.218  
   9.219  void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
    10.1 --- a/src/video/photon/SDL_ph_video.c	Mon Jan 20 01:37:07 2003 +0000
    10.2 +++ b/src/video/photon/SDL_ph_video.c	Mon Jan 20 01:38:37 2003 +0000
    10.3 @@ -56,6 +56,7 @@
    10.4  static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
    10.5  static void ph_VideoQuit(_THIS);
    10.6  static void ph_DeleteDevice(SDL_VideoDevice *device);
    10.7 +static void ph_UpdateMouse(_THIS);
    10.8  
    10.9  #ifdef HAVE_OPENGL
   10.10  int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags);
   10.11 @@ -90,7 +91,7 @@
   10.12                  malloc((sizeof *device->hidden));
   10.13          device->gl_data = NULL;
   10.14      }
   10.15 -    if ( (device == NULL) || (device->hidden == NULL) ) {
   10.16 +    if ((device == NULL) || (device->hidden == NULL)) {
   10.17          SDL_OutOfMemory();
   10.18          ph_DeleteDevice(device);
   10.19          return(0);
   10.20 @@ -106,9 +107,9 @@
   10.21      device->ListModes = ph_ListModes;
   10.22      device->SetVideoMode = ph_SetVideoMode;
   10.23      device->ToggleFullScreen = ph_ToggleFullScreen;
   10.24 -    device->UpdateMouse = NULL;	
   10.25 +    device->UpdateMouse = ph_UpdateMouse;
   10.26      device->SetColors = ph_SetColors;
   10.27 -    device->UpdateRects = NULL;         /* ph_ResizeImage */
   10.28 +    device->UpdateRects = NULL;         /* ph_SetupUpdateFunction */
   10.29      device->VideoQuit = ph_VideoQuit;
   10.30      device->AllocHWSurface = ph_AllocHWSurface;
   10.31      device->CheckHWBlit = NULL;
   10.32 @@ -173,6 +174,72 @@
   10.33      }
   10.34  }
   10.35  
   10.36 +static PtWidget_t *ph_CreateWindow(_THIS)
   10.37 +{
   10.38 +    PtWidget_t *widget;
   10.39 +    
   10.40 +    widget = PtCreateWidget(PtWindow, NULL, 0, 0);
   10.41 +    if (widget == NULL)
   10.42 +    {
   10.43 +        SDL_SetError("Couldn't create video window");
   10.44 +    }
   10.45 +
   10.46 +    return widget;
   10.47 +}
   10.48 +
   10.49 +static int ph_SetupWindow(_THIS, int w, int h, int flags)
   10.50 +{
   10.51 +    PtArg_t     args[32];
   10.52 +    PhPoint_t   pos = {0, 0};
   10.53 +    PhDim_t     dim = {w, h};
   10.54 +    int         nargs = 0;
   10.55 +
   10.56 +    PtSetArg(&args[nargs++], Pt_ARG_DIM, &dim, 0);
   10.57 +    PtSetArg(&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0);
   10.58 +
   10.59 +    if ((flags & SDL_RESIZABLE) == SDL_RESIZABLE)
   10.60 +    {
   10.61 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX);
   10.62 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MAX);
   10.63 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX);
   10.64 +    }
   10.65 +    else
   10.66 +    {
   10.67 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX);
   10.68 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX);
   10.69 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE);
   10.70 +    }
   10.71 +
   10.72 +    if (((flags & SDL_NOFRAME)==SDL_NOFRAME) || ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN))
   10.73 +    {
   10.74 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE);
   10.75 +    }
   10.76 +    else
   10.77 +    {
   10.78 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE |
   10.79 +                                  Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN);
   10.80 +    }
   10.81 +
   10.82 +    if (flags & SDL_FULLSCREEN)
   10.83 +    {
   10.84 +        PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0);
   10.85 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_MAX);
   10.86 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISMAX |
   10.87 +                                                               Ph_WM_STATE_ISFOCUS | Ph_WM_STATE_ISALTKEY);
   10.88 +    }
   10.89 +    else
   10.90 +    {
   10.91 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISMAX | Ph_WM_STATE_ISALTKEY);
   10.92 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE);
   10.93 +        PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED);
   10.94 +    }
   10.95 +
   10.96 +    PtSetResources(window, nargs, args);
   10.97 +    PtRealizeWidget(window);
   10.98 +
   10.99 +    return 0;
  10.100 +}
  10.101 +
  10.102  static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
  10.103  {
  10.104      PgVideoModeInfo_t my_mode_info;
  10.105 @@ -184,16 +251,22 @@
  10.106      oglctx=NULL;
  10.107  #endif /* HAVE_OPENGL */
  10.108      
  10.109 -    captionflag=0;
  10.110      old_video_mode=-1;
  10.111      old_refresh_rate=-1;
  10.112  	
  10.113      if (NULL == (event = malloc(EVENT_SIZE)))
  10.114      {
  10.115 -        exit(EXIT_FAILURE);
  10.116 +        SDL_OutOfMemory();
  10.117 +        return -1;
  10.118      }
  10.119      memset(event, 0x00, EVENT_SIZE);
  10.120  
  10.121 +    window = ph_CreateWindow(this);
  10.122 +    if (window == NULL)
  10.123 +    {
  10.124 +        return -1;
  10.125 +    }
  10.126 +
  10.127      /* Create the blank cursor */
  10.128      SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
  10.129                                            (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT,
  10.130 @@ -201,7 +274,7 @@
  10.131  
  10.132      if (SDL_BlankCursor == NULL)
  10.133      {
  10.134 -        printf("ph_VideoInit(): could not create blank cursor !\n");
  10.135 +        fprintf(stderr, "ph_VideoInit(): could not create blank cursor !\n");
  10.136      }
  10.137  
  10.138      if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
  10.139 @@ -222,7 +295,8 @@
  10.140      /* save current palette */
  10.141      if (desktopbpp==8)
  10.142      {
  10.143 -        PgGetPalette(ph_palette);
  10.144 +        PgGetPalette(savedpal);
  10.145 +        PgGetPalette(syspalph);
  10.146      }
  10.147           
  10.148      currently_fullscreen = 0;
  10.149 @@ -236,110 +310,46 @@
  10.150                  int width, int height, int bpp, Uint32 flags)
  10.151  {
  10.152      PgDisplaySettings_t settings;
  10.153 +    SDL_Color* colors;
  10.154      int mode;
  10.155 -    PtArg_t arg[32];
  10.156 -    PhDim_t dim;
  10.157      int rtnval;
  10.158      int i;
  10.159 -    unsigned long *tempptr;
  10.160 -    int pargc;
  10.161 -
  10.162 -    dim.w=width;
  10.163 -    dim.h=height;
  10.164  
  10.165      /* Lock the event thread, in multi-threading environments */
  10.166      SDL_Lock_EventThread();
  10.167  
  10.168      current->flags = flags;
  10.169  
  10.170 -    /* create window if no OpenGL support selected */
  10.171 -    if ((flags & SDL_OPENGL)!=SDL_OPENGL)
  10.172 -    {
  10.173 -        pargc=0;
  10.174 -        
  10.175 -        // prevent using HWSURFACE in window mode if desktop bpp != chosen bpp
  10.176 -        if ((flags & SDL_HWSURFACE) && (!(flags & SDL_FULLSCREEN)))
  10.177 -        {
  10.178 -           if (desktopbpp!=bpp)
  10.179 -           {
  10.180 -              fprintf(stderr, "ph_SetVideoMode(): SDL_HWSURFACE available only with chosen bpp equal desktop bpp !\n");
  10.181 -              return NULL;
  10.182 -           }
  10.183 -        }
  10.184 -
  10.185 -        PtSetArg(&arg[pargc++], Pt_ARG_DIM, &dim, 0);
  10.186 -        PtSetArg(&arg[pargc++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED);
  10.187 -
  10.188 -        /* enable window minimizing */
  10.189 -        PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE);
  10.190 -
  10.191 -        /* remove border and caption if no frame flag selected */
  10.192 -        if ((flags & SDL_NOFRAME) == SDL_NOFRAME)
  10.193 -        {
  10.194 -            PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER);
  10.195 -        }
  10.196 -        else
  10.197 -        {
  10.198 -            PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER);
  10.199 -        }
  10.200 -
  10.201 -        /* if window is not resizable then remove resize handles and maximize button */
  10.202 -        if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE)
  10.203 -        {
  10.204 -            PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX);
  10.205 -            PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX);
  10.206 -            PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX);
  10.207 -        }
  10.208 -        else
  10.209 -        {
  10.210 -            PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX);
  10.211 -            /* it is need to be Pt_FALSE to allow the application to process the resize callback */
  10.212 -            PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX);
  10.213 -            PtSetArg(&arg[pargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MAX);
  10.214 -        }
  10.215 -
  10.216 -        if (window!=NULL)
  10.217 -        {
  10.218 -            PtUnrealizeWidget(window);
  10.219 -            PtDestroyWidget(window);
  10.220 -            window=NULL;
  10.221 -        }
  10.222 -
  10.223 -        window=PtCreateWidget(PtWindow, NULL, pargc, arg);
  10.224 -        PtRealizeWidget(window);
  10.225 -        
  10.226 -        PtFlush();
  10.227 -    }
  10.228 +    ph_SetupWindow(this, width, height, flags);
  10.229  
  10.230  #ifdef HAVE_OPENGL
  10.231 -    if (flags & SDL_OPENGL)
  10.232 +    if (current->flags & SDL_OPENGL)
  10.233      {
  10.234          /* ph_SetupOpenGLContext creates also window as need */
  10.235          if (ph_SetupOpenGLContext(this, width, height, bpp, flags)==0)
  10.236          {
  10.237 -            /* setup OGL update function ... ugly method */
  10.238 -            ph_ResizeImage(this, current, flags); 
  10.239 +            ph_SetupUpdateFunction(this, current, flags); 
  10.240          }
  10.241          else
  10.242          {
  10.243              /* if context creation fail, report no OpenGL to high level */
  10.244 -            current->flags=(flags & (~SDL_OPENGL));
  10.245 +            current->flags &= ~SDL_OPENGL;
  10.246          }
  10.247  #else
  10.248 -    if (flags & SDL_OPENGL) /* if no built-in OpenGL support */
  10.249 +    if (current->flags & SDL_OPENGL) /* if no built-in OpenGL support */
  10.250      {
  10.251          fprintf(stderr, "ph_SetVideoMode(): no OpenGL support, try to recompile library.\n");
  10.252 -        current->flags=(flags & (~SDL_OPENGL));
  10.253 +        current->flags &= ~SDL_OPENGL;
  10.254          return NULL;
  10.255  #endif /* HAVE_OPENGL */
  10.256      }
  10.257      else
  10.258      {
  10.259          /* Initialize the window */
  10.260 -        if (flags & SDL_FULLSCREEN) /* Direct Context , assume SDL_HWSURFACE also set */
  10.261 +        if (current->flags & SDL_FULLSCREEN) /* Direct Context , assume SDL_HWSURFACE also set */
  10.262          {
  10.263              /* Get the video mode and set it */
  10.264 -            if (flags & SDL_ANYFORMAT)
  10.265 +            if (current->flags & SDL_ANYFORMAT)
  10.266              {
  10.267                  if ((mode = get_mode_any_format(width, height, bpp)) == 0)
  10.268                  {
  10.269 @@ -376,7 +386,8 @@
  10.270                  fprintf(stderr,"ph_SetVideoMode(): PgSetVideoMode failed !\n");
  10.271              }
  10.272  
  10.273 -            current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
  10.274 +            current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */
  10.275 +            current->flags |= SDL_HWSURFACE;
  10.276  
  10.277              /* Begin direct mode */
  10.278              ph_EnterFullScreen(this);
  10.279 @@ -385,10 +396,10 @@
  10.280          else
  10.281          {
  10.282              /* Use offscreen memory iff SDL_HWSURFACE flag is set */
  10.283 -            if (flags & SDL_HWSURFACE)
  10.284 +            if (current->flags & SDL_HWSURFACE)
  10.285              {
  10.286                  /* no stretch blit in offscreen context */
  10.287 -                current->flags = (flags & (~SDL_RESIZABLE));
  10.288 +                current->flags &= ~SDL_RESIZABLE;
  10.289              }
  10.290  
  10.291              /* using palette emulation code in window mode */
  10.292 @@ -402,55 +413,48 @@
  10.293                  {
  10.294                      desktoppal=SDLPH_PAL_SYSTEM;
  10.295                  }
  10.296 +
  10.297 +                /* fill the palette */
  10.298 +                PgGetPalette(savedpal);
  10.299 +                PgGetPalette(syspalph);
  10.300 +
  10.301 +                current->format->palette = calloc(1, sizeof(SDL_Palette));
  10.302 +                current->format->palette->ncolors = _Pg_MAX_PALETTE;
  10.303 +                current->format->palette->colors = (SDL_Color *)calloc(_Pg_MAX_PALETTE, sizeof(SDL_Color));
  10.304 +
  10.305 +                colors = current->format->palette->colors;
  10.306 +
  10.307 +                for(i=0; i<256; i++)
  10.308 +                {
  10.309 +                    colors[i].r = PgRedValue(syspalph[i]);
  10.310 +                    colors[i].g = PgGreenValue(syspalph[i]);
  10.311 +                    colors[i].b = PgBlueValue(syspalph[i]);
  10.312 +                }
  10.313              }
  10.314              else
  10.315              {
  10.316                 desktoppal=SDLPH_PAL_NONE;
  10.317              }
  10.318          }
  10.319 -
  10.320 -	/* If we are setting video to use the palette make sure we have allocated memory for it */
  10.321 -	if (bpp==8)
  10.322 -	{
  10.323 -            current->format->palette = malloc(sizeof(SDL_Palette));
  10.324 -            memset(current->format->palette, 0, sizeof(SDL_Palette));
  10.325 -            current->format->palette->ncolors = 256;
  10.326 -            current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color));
  10.327 -            /* fill the palette */
  10.328 -            rtnval = PgGetPalette(ph_palette);
  10.329 -
  10.330 -            tempptr = (unsigned long *)current->format->palette->colors;
  10.331 -
  10.332 -            for(i=0; i<256; i++)
  10.333 -            {
  10.334 -                *tempptr = (((unsigned long)ph_palette[i]) << 8);
  10.335 -                tempptr++;
  10.336 -            }
  10.337 -        }
  10.338 -
  10.339      }
  10.340  
  10.341      current->w = width;
  10.342      current->h = height;
  10.343 +
  10.344 +    /* These values can be overridden in ph_SetupUpdateFunction() */
  10.345      current->format->BitsPerPixel = bpp;
  10.346      current->format->BytesPerPixel = (bpp+7)/8;
  10.347      current->pitch = SDL_CalculatePitch(current);
  10.348  
  10.349      /* Must call at least once it setup image planes */
  10.350 -    rtnval = ph_ResizeImage(this, current, flags);
  10.351 +    rtnval = ph_SetupUpdateFunction(this, current, current->flags);
  10.352      
  10.353      if (rtnval==-1)
  10.354      {
  10.355 -        fprintf(stderr,"ph_SetVideoMode(): ph_ResizeImage failed !\n");
  10.356 +        fprintf(stderr,"ph_SetVideoMode(): ph_SetupUpdateFunction failed !\n");
  10.357          return NULL;
  10.358      }
  10.359  
  10.360 -    /* delayed set caption call */
  10.361 -    if (captionflag)
  10.362 -    {
  10.363 -        ph_SetCaption(this, this->wm_title, NULL);
  10.364 -    }
  10.365 -
  10.366      /* finish window drawing */
  10.367      PtFlush();
  10.368  
  10.369 @@ -495,12 +499,6 @@
  10.370          PtDestroyWidget(window);
  10.371          window=NULL;
  10.372      }
  10.373 -    
  10.374 -    /* restore palette */
  10.375 -    if (desktoppal!=SDLPH_PAL_NONE)
  10.376 -    {
  10.377 -        PgSetPalette(ph_palette, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
  10.378 -    }
  10.379  
  10.380  #ifdef HAVE_OPENGL
  10.381      if (oglctx)
  10.382 @@ -510,13 +508,30 @@
  10.383          oglctx=NULL;
  10.384      }
  10.385  #endif /* HAVE_OPENGL */
  10.386 +
  10.387 +    /* restore palette */
  10.388 +    if (desktoppal!=SDLPH_PAL_NONE)
  10.389 +    {
  10.390 +        PgSetPalette(savedpal, 1, 0, _Pg_MAX_PALETTE, Pg_PALSET_HARD | Pg_PALSET_FORCE_EXPOSE, 0);
  10.391 +        /* pass -1, to force release palette */
  10.392 +        PgSetPalette(savedpal, 1, 0, -1, Pg_PALSET_HARD | Pg_PALSET_FORCE_EXPOSE, 0);
  10.393 +    }
  10.394 +
  10.395 +    if (event!=NULL)
  10.396 +    {
  10.397 +        free(event);
  10.398 +        event=NULL;
  10.399 +    }
  10.400  }
  10.401  
  10.402  static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
  10.403  {
  10.404      int i;
  10.405 -    PhPoint_t point={0, 0};
  10.406 -    PgColor_t syspalph[_Pg_MAX_PALETTE];
  10.407 +    SDL_Rect updaterect;
  10.408 +
  10.409 +    updaterect.x = updaterect.y = 0;
  10.410 +    updaterect.w = this->screen->w;
  10.411 +    updaterect.h = this->screen->h;
  10.412  
  10.413      /* palette emulation code, using palette of the PhImage_t struct */
  10.414      if (desktoppal==SDLPH_PAL_EMULATE)
  10.415 @@ -525,14 +540,11 @@
  10.416          {
  10.417              for (i=firstcolor; i<firstcolor+ncolors; i++)
  10.418              {
  10.419 -                SDL_Image->palette[i]  = 0x00000000UL;
  10.420 -                SDL_Image->palette[i] |= colors[i-firstcolor].r<<16;
  10.421 -                SDL_Image->palette[i] |= colors[i-firstcolor].g<<8;
  10.422 -                SDL_Image->palette[i] |= colors[i-firstcolor].b;
  10.423 +                syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b);
  10.424 +                SDL_Image->palette[i] = syspalph[i];
  10.425              }
  10.426 -
  10.427 -           /* image needs to be redrawed, very slow method */
  10.428 -           PgDrawPhImage(&point, SDL_Image, 0);
  10.429 +            /* image needs to be redrawn */
  10.430 +            this->UpdateRects(this, 1, &updaterect);
  10.431          }
  10.432      }
  10.433      else
  10.434 @@ -541,26 +553,20 @@
  10.435          {
  10.436              for (i=firstcolor; i<firstcolor+ncolors; i++)
  10.437              {
  10.438 -                syspalph[i]  = 0x00000000UL;
  10.439 -                syspalph[i] |= colors[i-firstcolor].r<<16;
  10.440 -                syspalph[i] |= colors[i-firstcolor].g<<8;
  10.441 -                syspalph[i] |= colors[i-firstcolor].b;
  10.442 +                syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b);
  10.443              }
  10.444  
  10.445              if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
  10.446              {
  10.447 -                /* window mode must use soft palette */
  10.448 -                PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0);
  10.449 -                /* image needs to be redrawed, very slow method */
  10.450 -                if (SDL_Image)
  10.451 -                {
  10.452 -                   PgDrawPhImage(&point, SDL_Image, 0);
  10.453 -                }
  10.454 +                 /* window mode must use soft palette */
  10.455 +                PgSetPalette(&syspalph[firstcolor], 1, firstcolor, ncolors, Pg_PALSET_SOFT, 0);
  10.456 +                /* image needs to be redrawn */
  10.457 +                this->UpdateRects(this, 1, &updaterect);
  10.458              }
  10.459              else
  10.460              {
  10.461                  /* fullscreen mode must use hardware palette */
  10.462 -                PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
  10.463 +                PgSetPalette(&syspalph[firstcolor], 1, firstcolor, ncolors, Pg_PALSET_HARDLOCKED, 0);
  10.464              }
  10.465          }
  10.466          else
  10.467 @@ -576,11 +582,9 @@
  10.468  
  10.469  int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
  10.470  {
  10.471 -    PtArg_t args[8];
  10.472      PhDim_t dim;
  10.473      uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
  10.474      int OGLargc;
  10.475 -    int pargc;
  10.476  
  10.477      dim.w=width;
  10.478      dim.h=height;
  10.479 @@ -630,51 +634,6 @@
  10.480  
  10.481      PhDCSetCurrent(oglctx);
  10.482  
  10.483 -    pargc=0;
  10.484 -
  10.485 -    PtSetArg(&args[pargc++], Pt_ARG_DIM, &dim, 0);
  10.486 -    PtSetArg(&args[pargc++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED);
  10.487 -    PtSetArg(&args[pargc++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0);
  10.488 -
  10.489 -    if (flags & SDL_FULLSCREEN)
  10.490 -    {
  10.491 -        PhPoint_t pos;
  10.492 -
  10.493 -        pos.x=0;
  10.494 -        pos.y=0;
  10.495 -
  10.496 -        PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, ~0);
  10.497 -        PtSetArg(&args[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_CLOSE | Ph_WM_TOFRONT | Ph_WM_CONSWITCH);
  10.498 -        PtSetArg(&args[pargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS);
  10.499 -        PtSetArg(&args[pargc++], Pt_ARG_POS, &pos, 0);
  10.500 -    }
  10.501 -    else
  10.502 -    {
  10.503 -        /* remove border and caption if no frame flag selected */
  10.504 -        if ((flags & SDL_NOFRAME) == SDL_NOFRAME)
  10.505 -        {
  10.506 -            PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER);
  10.507 -        }
  10.508 -        else
  10.509 -        {
  10.510 -           /* if window is not resizable then remove resize handles */
  10.511 -           if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE)
  10.512 -           {
  10.513 -               PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, Ph_WM_RENDER_RESIZE);
  10.514 -           }
  10.515 -        }
  10.516 -    }
  10.517 -
  10.518 -    if (window!=NULL)
  10.519 -    {
  10.520 -        PtUnrealizeWidget(window);
  10.521 -        PtDestroyWidget(window);
  10.522 -        window=NULL;
  10.523 -    }
  10.524 -
  10.525 -    window=PtCreateWidget(PtWindow, NULL, pargc, args);
  10.526 -    PtRealizeWidget(window);
  10.527 -
  10.528      /* disable mouse for fullscreen */
  10.529      if (flags & SDL_FULLSCREEN)
  10.530      {
  10.531 @@ -717,3 +676,30 @@
  10.532  }
  10.533  
  10.534  #endif /* HAVE_OPENGL */
  10.535 +
  10.536 +static void ph_UpdateMouse(_THIS)
  10.537 +{
  10.538 +    PhCursorInfo_t phcursor;
  10.539 +    short abs_x;
  10.540 +    short abs_y;
  10.541 +
  10.542 +    /* Lock the event thread, in multi-threading environments */
  10.543 +    SDL_Lock_EventThread();
  10.544 +
  10.545 +    /* synchronizing photon mouse cursor position and SDL mouse position, if cursor appears over window. */
  10.546 +    PtGetAbsPosition(window, &abs_x, &abs_y);
  10.547 +    PhQueryCursor(PhInputGroup(NULL), &phcursor);
  10.548 +    if (((phcursor.pos.x >= abs_x) && (phcursor.pos.x <= abs_x + this->screen->w)) &&
  10.549 +        ((phcursor.pos.y >= abs_y) && (phcursor.pos.y <= abs_y + this->screen->h)))
  10.550 +    {
  10.551 +        SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
  10.552 +        SDL_PrivateMouseMotion(0, 0, phcursor.pos.x-abs_x, phcursor.pos.y-abs_y);
  10.553 +    }
  10.554 +    else
  10.555 +    {
  10.556 +        SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
  10.557 +    }
  10.558 +
  10.559 +    /* Unlock the event thread, in multi-threading environments */
  10.560 +    SDL_Unlock_EventThread();
  10.561 +}
    11.1 --- a/src/video/photon/SDL_ph_video.h	Mon Jan 20 01:37:07 2003 +0000
    11.2 +++ b/src/video/photon/SDL_ph_video.h	Mon Jan 20 01:38:37 2003 +0000
    11.3 @@ -44,18 +44,16 @@
    11.4  #define SDLPH_PAL_SYSTEM  0x00000002L
    11.5  
    11.6  typedef union vidptr{
    11.7 -  uint8_t  *volatile ptr8;
    11.8 -  uint16_t *volatile ptr16;
    11.9 -  uint32_t *volatile ptr32;
   11.10 +  uint8_t*  volatile ptr8;
   11.11 +  uint16_t* volatile ptr16;
   11.12 +  uint32_t* volatile ptr32;
   11.13   } VidPtr_t;
   11.14  
   11.15  typedef struct {
   11.16 -	unsigned char *Y;
   11.17 -	unsigned char *V;
   11.18 -	unsigned char *U;
   11.19 -}FRAMEDATA;
   11.20 -
   11.21 -#define EVENT_SIZE    sizeof( PhEvent_t ) + 1000
   11.22 +	unsigned char* Y;
   11.23 +	unsigned char* V;
   11.24 +	unsigned char* U;
   11.25 +} FRAMEDATA;
   11.26  
   11.27  /* Private display data */
   11.28  struct SDL_PrivateVideoData {
   11.29 @@ -65,15 +63,17 @@
   11.30  #ifdef HAVE_OPENGL
   11.31      PdOpenGLContext_t* OGLContext;       /* OpenGL context              */
   11.32  #endif /* HAVE_OPENGL */
   11.33 -    PgColor_t ph_palette[_Pg_MAX_PALETTE];
   11.34 +    PgColor_t savedpal[_Pg_MAX_PALETTE];
   11.35 +    PgColor_t syspalph[_Pg_MAX_PALETTE];
   11.36  
   11.37      struct {
   11.38 -        PdDirectContext_t *direct_context;
   11.39 -        PdOffscreenContext_t *offscreen_context;
   11.40 +        PdDirectContext_t*    direct_context;
   11.41 +        PdOffscreenContext_t* offscreen_context;
   11.42 +        PhDrawContext_t*      oldDC;
   11.43          VidPtr_t dc_ptr;
   11.44 -        FRAMEDATA *CurrentFrameData;
   11.45 -        FRAMEDATA *FrameData0;
   11.46 -        FRAMEDATA *FrameData1;
   11.47 +        unsigned char* CurrentFrameData;
   11.48 +        unsigned char* FrameData0;
   11.49 +        unsigned char* FrameData1;
   11.50          int current;
   11.51          long flags;
   11.52      } ocimage;
   11.53 @@ -82,40 +82,15 @@
   11.54      int old_video_mode;             /* Stored mode before fullscreen switch        */
   11.55      int old_refresh_rate;           /* Stored refresh rate befor fullscreen switch */
   11.56  
   11.57 -    /* The current width and height of the fullscreen mode */
   11.58 -    int current_w;
   11.59 -    int current_h;
   11.60 -
   11.61 -    /* Support for internal mouse warping */
   11.62 -    struct {
   11.63 -        int x;
   11.64 -        int y;
   11.65 -    } mouse_last;
   11.66 -
   11.67 -    struct {
   11.68 -        int numerator;
   11.69 -        int denominator;
   11.70 -        int threshold;
   11.71 -    } mouse_accel;
   11.72 -
   11.73      int mouse_relative;
   11.74      WMcursor* BlankCursor;
   11.75  
   11.76      int depth;			/* current visual depth (not bpp)        */
   11.77      int desktopbpp;             /* bpp of desktop at the moment of start */
   11.78      int desktoppal;             /* palette mode emulation or system      */
   11.79 -    int captionflag;            /* caption setting flag                  */
   11.80  
   11.81 -    int use_vidmode;
   11.82      int currently_fullscreen;
   11.83  
   11.84 -    /* Automatic mode switching support (entering/leaving fullscreen) */
   11.85 -    Uint32 switch_waiting;
   11.86 -    Uint32 switch_time;
   11.87 -
   11.88 -    /* Prevent too many XSync() calls */
   11.89 -    int blit_queued;
   11.90 -
   11.91      PhEvent_t* event;
   11.92  };
   11.93  
   11.94 @@ -129,23 +104,13 @@
   11.95  #define graphics_card_caps   (this->hidden->graphics_card_caps)
   11.96  #define desktopbpp           (this->hidden->desktopbpp)
   11.97  #define desktoppal           (this->hidden->desktoppal)
   11.98 -#define ph_palette           (this->hidden->ph_palette)
   11.99 +#define savedpal             (this->hidden->savedpal)
  11.100 +#define syspalph             (this->hidden->syspalph)
  11.101  
  11.102  /* Old variable names */
  11.103 -#define current_w            (this->hidden->current_w)
  11.104 -#define current_h            (this->hidden->current_h)
  11.105 -#define mouse_last           (this->hidden->mouse_last)
  11.106 -#define mouse_accel          (this->hidden->mouse_accel)
  11.107  #define mouse_relative       (this->hidden->mouse_relative)
  11.108 -#define saved_mode           (this->hidden->saved_mode)
  11.109 -#define saved_view           (this->hidden->saved_view)
  11.110 -#define use_vidmode          (this->hidden->use_vidmode)
  11.111  #define currently_fullscreen (this->hidden->currently_fullscreen)
  11.112 -#define switch_waiting       (this->hidden->switch_waiting)
  11.113 -#define switch_time          (this->hidden->switch_time)
  11.114 -#define blit_queued          (this->hidden->blit_queued)
  11.115  #define event                (this->hidden->event)
  11.116  #define SDL_BlankCursor      (this->hidden->BlankCursor)
  11.117 -#define captionflag          (this->hidden->captionflag)
  11.118  
  11.119  #endif /* _SDL_x11video_h */
    12.1 --- a/src/video/photon/SDL_ph_wm.c	Mon Jan 20 01:37:07 2003 +0000
    12.2 +++ b/src/video/photon/SDL_ph_wm.c	Mon Jan 20 01:38:37 2003 +0000
    12.3 @@ -56,15 +56,11 @@
    12.4  {
    12.5      SDL_Lock_EventThread();
    12.6  
    12.7 -    /* check for set caption call before window init */
    12.8 +    /* sanity check for set caption call before window init */
    12.9      if (window!=NULL)
   12.10      {
   12.11          PtSetResource(window, Pt_ARG_WINDOW_TITLE, title, 0);
   12.12      }
   12.13 -    else
   12.14 -    {
   12.15 -        captionflag=1;
   12.16 -    }
   12.17  
   12.18      SDL_Unlock_EventThread();
   12.19  }
   12.20 @@ -88,35 +84,34 @@
   12.21  
   12.22  SDL_GrabMode ph_GrabInputNoLock(_THIS, SDL_GrabMode mode)
   12.23  {
   12.24 +    short abs_x, abs_y;
   12.25 +
   12.26 +    if( mode == SDL_GRAB_OFF )
   12.27 +    {
   12.28 +        PtSetResource(window, Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISALTKEY);
   12.29 +    }
   12.30 +    else
   12.31 +    {
   12.32 +        PtSetResource(window, Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISALTKEY);
   12.33 +
   12.34 +        PtGetAbsPosition(window, &abs_x, &abs_y);
   12.35 +        PhMoveCursorAbs(PhInputGroup(NULL), abs_x + SDL_VideoSurface->w/2, abs_y + SDL_VideoSurface->h/2);
   12.36 +    }
   12.37 +
   12.38 +    SDL_Unlock_EventThread();
   12.39 +
   12.40      return(mode);
   12.41  }
   12.42  
   12.43  SDL_GrabMode ph_GrabInput(_THIS, SDL_GrabMode mode)
   12.44  {
   12.45 -	short abs_x, abs_y;
   12.46 +    SDL_Lock_EventThread();
   12.47 +    mode = ph_GrabInputNoLock(this, mode);
   12.48 +    SDL_Unlock_EventThread();
   12.49  
   12.50 -	SDL_Lock_EventThread();
   12.51 -/*	mode = ph_GrabInputNoLock(this, mode);*/
   12.52 +    return(mode);
   12.53 +}
   12.54  
   12.55 -	if( mode == SDL_GRAB_OFF )
   12.56 -	{
   12.57 -		PtSetResource(window, Pt_ARG_WINDOW_STATE, Pt_FALSE,
   12.58 -				Ph_WM_STATE_ISALTKEY );
   12.59 -	}
   12.60 -	else
   12.61 -	{
   12.62 -		PtSetResource(window, Pt_ARG_WINDOW_STATE, Pt_TRUE,
   12.63 -				Ph_WM_STATE_ISALTKEY );
   12.64 -
   12.65 -		PtGetAbsPosition( window, &abs_x, &abs_y );
   12.66 -		PhMoveCursorAbs( PhInputGroup( NULL ),
   12.67 -				abs_x + SDL_VideoSurface->w/2,
   12.68 -				abs_y + SDL_VideoSurface->h/2 );
   12.69 -	}
   12.70 -
   12.71 -	SDL_Unlock_EventThread();
   12.72 -	return(mode);
   12.73 -}
   12.74  
   12.75  int ph_GetWMInfo(_THIS, SDL_SysWMinfo *info)
   12.76  {
    13.1 --- a/src/video/photon/SDL_phyuv.c	Mon Jan 20 01:37:07 2003 +0000
    13.2 +++ b/src/video/photon/SDL_phyuv.c	Mon Jan 20 01:38:37 2003 +0000
    13.3 @@ -29,11 +29,6 @@
    13.4  
    13.5  #include <stdlib.h>
    13.6  #include <string.h>
    13.7 -#ifndef bool
    13.8 -#define bool char
    13.9 -#define TRUE 1
   13.10 -#define FALSE 0
   13.11 -#endif
   13.12  #include <errno.h>
   13.13  
   13.14  #include <Ph.h>
   13.15 @@ -44,606 +39,426 @@
   13.16  #include "SDL_phyuv_c.h"
   13.17  #include "SDL_yuvfuncs.h"
   13.18  
   13.19 -#if 0  //just for reference
   13.20 -/* YUV data formats			FourCC		   Layout		H sample (YUV)	V sample (YUV)	BPP */
   13.21 -#define Pg_VIDEO_FORMAT_IYU1		0x31555949	/* U2Y2Y2V2Y2Y2		144		111		12  */
   13.22 -#define Pg_VIDEO_FORMAT_IYU2		0x32555949	/* U4Y4V4U4Y4V4		111		111		24  */
   13.23 -#define Pg_VIDEO_FORMAT_UYVY		0x59565955	/* U8Y8V8Y8		122		111		16  */
   13.24 -#define Pg_VIDEO_FORMAT_YUY2		0x32595559	/* Y8U8Y8V8		122		111		16  */
   13.25 -#define Pg_VIDEO_FORMAT_YVYU		0x55595659	/* Y8V8Y8U8		122		111		16  */
   13.26 -#define Pg_VIDEO_FORMAT_V422		0x56343232	/* V8Y8U8Y8		122		111		16  */
   13.27 -#define Pg_VIDEO_FORMAT_CLJR		0x524a4c43	/* V6U6Y5Y5Y5Y5		133		111		8   */
   13.28 -#define Pg_VIDEO_FORMAT_YVU9		0x39555659	/* Planar YVU		144		144		9   */
   13.29 -#define Pg_VIDEO_FORMAT_YV12		0x32315659	/* Planar YUV		122		122		12  */
   13.30 -
   13.31 -/* There seems to be no FourCC that matches this */
   13.32 -#define Pg_VIDEO_FORMAT_YUV420		0x00000100	/* Planar YUV		122		111		16  */
   13.33 -
   13.34 -/* These formats are the same as YV12, except the U and V planes do not have to contiguously follow the Y plane */
   13.35 -/* but they're all the same to us, since we always have 3 plane pointers */
   13.36 -#define Pg_VIDEO_FORMAT_CLPL	Pg_VIDEO_FORMAT_YV12	/* Cirrus Logic Planar format */
   13.37 -#define Pg_VIDEO_FORMAT_VBPL	Pg_VIDEO_FORMAT_YV12	/* VooDoo Banshee planar format */
   13.38 -
   13.39 -#define SDL_YV12_OVERLAY	0x32315659	/* Planar mode: Y + V + U */
   13.40 -#define SDL_IYUV_OVERLAY	0x56555949	/* Planar mode: Y + U + V */
   13.41 -#define SDL_YUY2_OVERLAY	0x32595559	/* Packed mode: Y0+U0+Y1+V0 */
   13.42 -#define SDL_UYVY_OVERLAY	0x59565955	/* Packed mode: U0+Y0+V0+Y1 */
   13.43 -#define SDL_YVYU_OVERLAY	0x55595659	/* Packed mode: Y0+V0+Y1+U0 */
   13.44 -
   13.45 -#endif 
   13.46 -
   13.47 -
   13.48 -#define OVERLAY_STATE_UNINIT  0
   13.49 +#define OVERLAY_STATE_UNINIT 0
   13.50  #define OVERLAY_STATE_ACTIVE 1
   13.51  
   13.52  /* The functions used to manipulate software video overlays */
   13.53  static struct private_yuvhwfuncs ph_yuvfuncs = {
   13.54 -	ph_LockYUVOverlay,
   13.55 -	ph_UnlockYUVOverlay,
   13.56 -	ph_DisplayYUVOverlay,
   13.57 -	ph_FreeYUVOverlay
   13.58 +    ph_LockYUVOverlay,
   13.59 +    ph_UnlockYUVOverlay,
   13.60 +    ph_DisplayYUVOverlay,
   13.61 +    ph_FreeYUVOverlay
   13.62  };
   13.63  
   13.64 -
   13.65 -typedef struct {
   13.66 -  int id;
   13.67 -  int width, height;
   13.68 -  int data_size;              /* bytes */
   13.69 -  int num_planes;
   13.70 -  int *pitches;               /* bytes */
   13.71 -  int *offsets;               /* bytes */
   13.72 -  char *data;
   13.73 -  void *obdata;     
   13.74 -} XvImage;
   13.75 -
   13.76 -
   13.77  struct private_yuvhwdata {
   13.78 -	XvImage *image;	
   13.79 -	FRAMEDATA *CurrentFrameData;
   13.80 -	FRAMEDATA *FrameData0;
   13.81 -	FRAMEDATA *FrameData1;
   13.82 -	PgScalerProps_t	props;
   13.83 -	PgScalerCaps_t	caps;
   13.84 -	PgVideoChannel_t *channel;
   13.85 -	SDL_Rect CurrentWindow;
   13.86 -	long format;
   13.87 -	int screen_width;
   13.88 -	int screen_height ;
   13.89 -	int screen_bpp ;    //2
   13.90 -	bool planar;
   13.91 -	bool scaler_on ;
   13.92 -	int current;
   13.93 -	long YStride;
   13.94 -	long VStride;
   13.95 -	long UStride;
   13.96 -	long chromakey;
   13.97 -	unsigned long State;
   13.98 -	long flags;
   13.99 +    FRAMEDATA* CurrentFrameData;
  13.100 +    FRAMEDATA* FrameData0;
  13.101 +    FRAMEDATA* FrameData1;
  13.102 +    PgScalerProps_t   props;
  13.103 +    PgScalerCaps_t    caps;
  13.104 +    PgVideoChannel_t* channel;
  13.105 +    PhArea_t CurrentWindow;
  13.106 +    long format;
  13.107 +    int planar;
  13.108 +    int scaler_on;
  13.109 +    int current;
  13.110 +    long YStride;
  13.111 +    long VStride;
  13.112 +    long UStride;
  13.113 +    int ischromakey;
  13.114 +    long chromakey;
  13.115 +    unsigned long State;
  13.116 +    long flags;
  13.117 +    int locked;
  13.118  };
  13.119  
  13.120 -extern PgVideoChannel_t * PgCreateVideoChannel(unsigned type, unsigned flags);
  13.121 -extern int PgGetScalerCapabilities( PgVideoChannel_t *channel, int format_index, PgScalerCaps_t *vcaps );
  13.122 -extern int PgConfigScalerChannel(PgVideoChannel_t *channel, PgScalerProps_t *props);
  13.123 -extern void PgDestroyVideoChannel(PgVideoChannel_t *channel);
  13.124 -extern PgColor_t PgGetOverlayChromaColor(void);
  13.125 +int grab_ptrs2(PgVideoChannel_t* channel, FRAMEDATA* Frame0, FRAMEDATA* Frame1 )
  13.126 +{
  13.127 +    int planes = 0;
  13.128  
  13.129 -void
  13.130 -grab_ptrs2(PgVideoChannel_t *channel, FRAMEDATA *Frame0, FRAMEDATA *Frame1 )
  13.131 -{
  13.132 +    /* Buffers have moved; re-obtain the pointers */
  13.133 +    Frame0->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane1);
  13.134 +    Frame1->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane2);
  13.135 +    Frame0->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane1);
  13.136 +    Frame1->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane2);
  13.137 +    Frame0->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane1);
  13.138 +    Frame1->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane2);
  13.139  
  13.140 -	/* Buffers have moved; re-obtain the pointers */
  13.141 -	Frame0->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane1);
  13.142 -	Frame1->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane2);
  13.143 -	Frame0->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane1);
  13.144 -	Frame1->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane2);
  13.145 -	Frame0->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane1);
  13.146 -	Frame1->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane2);
  13.147 +    if (Frame0->Y)
  13.148 +        planes++;
  13.149  
  13.150 +    if (Frame0->U)
  13.151 +        planes++;
  13.152 +
  13.153 +    if (Frame0->V)
  13.154 +        planes++;
  13.155 +
  13.156 +    return planes;
  13.157  }
  13.158  
  13.159  SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
  13.160  {
  13.161 -	SDL_Overlay *overlay;
  13.162 -	struct private_yuvhwdata *hwdata;
  13.163 -	int xv_port;
  13.164 -	int rtncode;
  13.165 -//	PhRect_t rect;
  13.166 -//	PhSysInfo_t info;
  13.167 -//	PhRegion_t region;
  13.168 -//	short x, y;
  13.169 -	PtArg_t argt;
  13.170 -	int i =0;
  13.171 -//	bool bCont = TRUE;
  13.172 -	int Priority[20];
  13.173 -	int Type[20];
  13.174 -	int entries, select, highest;
  13.175 +    SDL_Overlay *overlay;
  13.176 +    struct private_yuvhwdata *hwdata;
  13.177 +    int xv_port;
  13.178 +    int rtncode;
  13.179 +    int planes;
  13.180 +    int i=0;
  13.181 +    PhPoint_t pos;
  13.182  
  13.183 -	PhDCSetCurrent(0);  //Need to set draw context to window esp. if we we in Offscreeen mode
  13.184 +    /* Create the overlay structure */
  13.185 +    overlay = calloc(1, sizeof(SDL_Overlay));
  13.186  
  13.187 -	/* Create the overlay structure */
  13.188 -	overlay = (SDL_Overlay *)malloc(sizeof(SDL_Overlay));
  13.189 -        memset(overlay, 0x00, sizeof(SDL_Overlay));
  13.190 -	if ( overlay == NULL ) {
  13.191 -		SDL_OutOfMemory();
  13.192 -		return(NULL);
  13.193 -	}
  13.194 -	memset(overlay, 0, (sizeof *overlay));
  13.195 +    if (overlay == NULL) {
  13.196 +        SDL_OutOfMemory();
  13.197 +        return (NULL);
  13.198 +    }
  13.199  
  13.200 -	/* Fill in the basic members */
  13.201 -	overlay->format = format;
  13.202 -	overlay->w = width;
  13.203 -	overlay->h = height;
  13.204 +    /* Fill in the basic members */
  13.205 +    overlay->format = format;
  13.206 +    overlay->w = width;
  13.207 +    overlay->h = height;
  13.208  	
  13.209 -	/* Set up the YUV surface function structure */
  13.210 -	overlay->hwfuncs = &ph_yuvfuncs;
  13.211 +    /* Set up the YUV surface function structure */
  13.212 +    overlay->hwfuncs = &ph_yuvfuncs;
  13.213  
  13.214 -	/* Create the pixel data and lookup tables */
  13.215 -	hwdata = (struct private_yuvhwdata *)malloc(sizeof(struct private_yuvhwdata));
  13.216 -        memset(hwdata, 0x00, sizeof(struct private_yuvhwdata));
  13.217 -	overlay->hwdata = hwdata;
  13.218 -	if ( hwdata == NULL ) {
  13.219 -		SDL_OutOfMemory();
  13.220 -		SDL_FreeYUVOverlay(overlay);
  13.221 -		return(NULL);
  13.222 -	}
  13.223 -	
  13.224 +    /* Create the pixel data and lookup tables */
  13.225 +    hwdata = calloc(1, sizeof(struct private_yuvhwdata));
  13.226 +
  13.227 +    overlay->hwdata = hwdata;
  13.228 +    if (hwdata == NULL) {
  13.229 +        SDL_OutOfMemory();
  13.230 +        SDL_FreeYUVOverlay(overlay);
  13.231 +        return(NULL);
  13.232 +    }
  13.233 +
  13.234 +    PhDCSetCurrent(0);
  13.235      if (overlay->hwdata->channel == NULL)
  13.236      {
  13.237          if ((overlay->hwdata->channel = PgCreateVideoChannel(Pg_VIDEO_CHANNEL_SCALER,0)) == NULL) 
  13.238          {
  13.239 -            SDL_SetError("ph_CreateYUVOverlay(): Create channel failed: %s\n", strerror( errno ));
  13.240 -            free(overlay->hwdata);
  13.241 -            free(overlay);
  13.242 -            return (NULL);
  13.243 +            SDL_SetError("ph_CreateYUVOverlay(): Create channel failed: %s\n", strerror(errno));
  13.244 +            SDL_FreeYUVOverlay(overlay);
  13.245 +
  13.246 +            return(NULL);
  13.247 +
  13.248          }
  13.249      }
  13.250  
  13.251 -    overlay->hwdata->CurrentWindow.x = 0;
  13.252 -    overlay->hwdata->CurrentWindow.y = 0;
  13.253 -    overlay->hwdata->CurrentWindow.w = 320;
  13.254 -    overlay->hwdata->CurrentWindow.h = 240;
  13.255 -
  13.256 +    PtGetAbsPosition(window, &pos.x, &pos.y);
  13.257 +    overlay->hwdata->CurrentWindow.pos.x = pos.x;
  13.258 +    overlay->hwdata->CurrentWindow.pos.y = pos.y;
  13.259 +    overlay->hwdata->CurrentWindow.size.w = width;
  13.260 +    overlay->hwdata->CurrentWindow.size.h = height;
  13.261      overlay->hwdata->State = OVERLAY_STATE_UNINIT;
  13.262 -
  13.263 -    overlay->hwdata->screen_bpp = 2;
  13.264 -    overlay->hwdata->scaler_on = FALSE;
  13.265 -    overlay->hwdata->screen_width = 1024;
  13.266 -    overlay->hwdata->screen_height  = 768;
  13.267 -
  13.268 -    overlay->hwdata->FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
  13.269 -    overlay->hwdata->FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
  13.270 -    memset(overlay->hwdata->FrameData0, 0x00, (size_t)(sizeof(FRAMEDATA)));
  13.271 -    memset(overlay->hwdata->FrameData1, 0x00, (size_t)(sizeof(FRAMEDATA)));
  13.272 -
  13.273 -    overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps);
  13.274 -
  13.275 -//Note you really don't need to do this for SDL as you are given a format, but this is a good example
  13.276 +    overlay->hwdata->FrameData0 = (FRAMEDATA *) calloc(1, sizeof(FRAMEDATA));
  13.277 +    overlay->hwdata->FrameData1 = (FRAMEDATA *) calloc(1, sizeof(FRAMEDATA));
  13.278  
  13.279      xv_port = -1;
  13.280      i=0;
  13.281 +    
  13.282 +    overlay->hwdata->ischromakey=0;
  13.283  
  13.284 -while(PgGetScalerCapabilities(overlay->hwdata->channel, i++, &(overlay->hwdata->caps)) == 0) 
  13.285 -{
  13.286 -		if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YV12) //in SDL
  13.287 -		{
  13.288 -			
  13.289 -			Priority[i-1] = 0;
  13.290 -			Type[i-1] = Pg_VIDEO_FORMAT_YV12;
  13.291 -			if(format == Pg_VIDEO_FORMAT_YV12)
  13.292 -			{
  13.293 -				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YV12;
  13.294 -				xv_port = 1; //supported
  13.295 -				Priority[i-1] = 100; //force selected
  13.296 -			}
  13.297 -			
  13.298 -		}
  13.299 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YVU9) //in SDL
  13.300 -		{
  13.301 -			
  13.302 -			Priority[i-1] = 0;
  13.303 -			Type[i-1] = Pg_VIDEO_FORMAT_YVU9;			
  13.304 -			if(format == Pg_VIDEO_FORMAT_YVU9)
  13.305 -			{
  13.306 -				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YVU9;
  13.307 -				xv_port = 1; //supported
  13.308 -				Priority[i-1] = 100; //force selected
  13.309 -			}
  13.310 -			
  13.311 -		}
  13.312 -#if 0 //this part of SDL is YUV specific
  13.313 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_RGB555)
  13.314 -		{
  13.315 -			
  13.316 -			Priority[i-1] = 3;
  13.317 -			Type[i-1] = Pg_VIDEO_FORMAT_RGB555;			
  13.318 -		}
  13.319 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_RGB565)
  13.320 -		{
  13.321 -			
  13.322 -			Priority[i-1] =  2;
  13.323 -			Type[i-1] = Pg_VIDEO_FORMAT_RGB565;			
  13.324 -		}
  13.325 -		else if(overlay->hwdata->caps.format == Pg_VIDEO_FORMAT_RGB8888)
  13.326 -		{
  13.327 -			
  13.328 -			Priority[i-1] = 1;
  13.329 -			Type[i-1] = Pg_VIDEO_FORMAT_RGB8888;			
  13.330 -		}
  13.331 -#endif
  13.332 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_IYU1)
  13.333 -		{
  13.334 -			
  13.335 -			Priority[i-1] = 0;
  13.336 -			Type[i-1] = Pg_VIDEO_FORMAT_IYU1;
  13.337 -			
  13.338 -		}
  13.339 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_IYU2)
  13.340 -		{
  13.341 -			
  13.342 -			Priority[i-1] = 0;
  13.343 -			Type[i-1] = Pg_VIDEO_FORMAT_IYU2;			
  13.344 -		}
  13.345 +    do {
  13.346 +        memset(&overlay->hwdata->caps, 0x00, sizeof(PgScalerCaps_t));
  13.347 +        overlay->hwdata->caps.size = sizeof(PgScalerCaps_t);
  13.348 +        rtncode = PgGetScalerCapabilities(overlay->hwdata->channel, i, &overlay->hwdata->caps);
  13.349 +        if (rtncode==0)
  13.350 +        { 
  13.351 +            if (overlay->hwdata->caps.format==format)
  13.352 +            {
  13.353 +               if ((overlay->hwdata->caps.flags & Pg_SCALER_CAP_DST_CHROMA_KEY) == Pg_SCALER_CAP_DST_CHROMA_KEY)
  13.354 +               {
  13.355 +                   overlay->hwdata->ischromakey=1;
  13.356 +               }
  13.357 +               xv_port=1;
  13.358 +               break;
  13.359 +            }
  13.360 +        }
  13.361 +        else
  13.362 +        {
  13.363 +           break;
  13.364 +        }
  13.365 +        i++;
  13.366 +    } while(1);
  13.367  
  13.368 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_UYVY) //in SDL
  13.369 -		{
  13.370 -			
  13.371 -			Priority[i-1] = 7;
  13.372 -			Type[i-1] = Pg_VIDEO_FORMAT_UYVY;
  13.373 -			if(format == Pg_VIDEO_FORMAT_UYVY)
  13.374 -			{
  13.375 -				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_UYVY;
  13.376 -				xv_port = 1; //supported
  13.377 -				Priority[i-1] = 100; //force selected
  13.378 -			}
  13.379 -			
  13.380 -		}
  13.381 -		else if(overlay->hwdata->caps.format == Pg_VIDEO_FORMAT_YUY2) //in SDL
  13.382 -		{
  13.383 -			
  13.384 -			Priority[i-1] = 8;
  13.385 -			Type[i-1] = Pg_VIDEO_FORMAT_YUY2;			
  13.386 -			if(format == Pg_VIDEO_FORMAT_YUY2)
  13.387 -			{
  13.388 -				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YUY2;
  13.389 -				xv_port = 1; //supported
  13.390 -				Priority[i-1] = 100; //force selected
  13.391 -			}
  13.392 -			
  13.393 -		}
  13.394 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YVYU) //in SDL
  13.395 -		{
  13.396 -			
  13.397 -			Priority[i-1] = 4;
  13.398 -			Type[i-1] = Pg_VIDEO_FORMAT_YVYU;	
  13.399 -			
  13.400 -			if(format == Pg_VIDEO_FORMAT_YVYU)
  13.401 -			{
  13.402 -				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YVYU;
  13.403 -				xv_port = 1; //supported
  13.404 -				Priority[i-1] = 100; //force selected
  13.405 -				
  13.406 -			}
  13.407 -		
  13.408 -		}
  13.409 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_V422)
  13.410 -		{
  13.411 -			
  13.412 -			Priority[i-1] = 5;
  13.413 -			Type[i-1] = Pg_VIDEO_FORMAT_V422;			
  13.414 -		}		
  13.415 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_CLJR)
  13.416 -		{
  13.417 -			
  13.418 -			Priority[i-1] = 6;
  13.419 -			Type[i-1] = Pg_VIDEO_FORMAT_CLJR;		
  13.420 -		}	
  13.421 -		else
  13.422 -		{
  13.423 -		
  13.424 -		Priority[i-1] = 0;
  13.425 -		}
  13.426 -			
  13.427 -overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps);
  13.428 -}
  13.429  
  13.430 -	if ( xv_port == -1 )
  13.431 -	{
  13.432 -		SDL_SetError("No available video ports for requested format");
  13.433 -		return(NULL);
  13.434 -	}
  13.435 +    if (xv_port == -1)
  13.436 +    {
  13.437 +        SDL_SetError("No available video ports for requested format\n");
  13.438 +        SDL_FreeYUVOverlay(overlay);
  13.439 +        return(NULL);
  13.440 +    }
  13.441   
  13.442 -//Pick the highest priority format
  13.443 -entries = i -2;
  13.444 -highest = Priority[0]; //make first entry top at begining
  13.445 -select = 0;
  13.446 -
  13.447 -for (i = 1; i < entries; i++)
  13.448 -{
  13.449 -
  13.450 -
  13.451 -   if(Priority[i] > highest)
  13.452 -   {
  13.453 -      highest = Priority[i];
  13.454 -      select  = i;
  13.455 -   }
  13.456 -} 
  13.457 -
  13.458 - 
  13.459 - 
  13.460 - overlay->hwdata->caps.size = sizeof (overlay->hwdata->caps	);
  13.461 -PgGetScalerCapabilities(overlay->hwdata->channel, select, &(overlay->hwdata->caps));
  13.462 -overlay->hwdata->props.format = overlay->hwdata->caps.format ;
  13.463 -
  13.464 -    overlay->hwdata->format = overlay->hwdata->props.format;  //to make easier for apps to use
  13.465 -
  13.466 -
  13.467 -	overlay->hwdata->props.size = sizeof (overlay->hwdata->props);
  13.468 +    overlay->hwdata->format = format;
  13.469 +    overlay->hwdata->props.format = format;
  13.470 +    overlay->hwdata->props.size = sizeof(PgScalerProps_t);
  13.471      overlay->hwdata->props.src_dim.w = width;   
  13.472      overlay->hwdata->props.src_dim.h = height;   
  13.473  	
  13.474 -	overlay->hwdata->chromakey = PgGetOverlayChromaColor();
  13.475 +    /* Don't use chromakey for now, blitting a surface will cover the window,
  13.476 +     * and therefore the chroma. */
  13.477 +    overlay->hwdata->chromakey = 0;
  13.478 +    PtSetResource(window, Pt_ARG_FILL_COLOR, overlay->hwdata->chromakey, 0);
  13.479  
  13.480 -	// Set chromakey in video widget so we can see overlay data
  13.481 -	/* I don't know where the container widget is!!!, I guess it is in hidden->window*/
  13.482 -	
  13.483 -	PtEnter(0);
  13.484 -	PtSetArg( &argt, Pt_ARG_FILL_COLOR, overlay->hwdata->chromakey, 0 );
  13.485 -	PtSetResources( window, 1, &argt ); 
  13.486 -	PtLeave(0);
  13.487 +    PhAreaToRect(&overlay->hwdata->CurrentWindow, &overlay->hwdata->props.viewport);
  13.488  
  13.489 +    overlay->hwdata->props.flags = Pg_SCALER_PROP_DOUBLE_BUFFER;
  13.490  
  13.491 -	fflush( stderr );
  13.492 +    if ((overlay->hwdata->ischromakey)&&(overlay->hwdata->chromakey))
  13.493 +    {
  13.494 +        overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
  13.495 +        overlay->hwdata->props.color_key = overlay->hwdata->chromakey;
  13.496 +        overlay->hwdata->props.color_key_mask = 0x00FFFFFFUL;
  13.497 +    } 
  13.498 +    else
  13.499 +    {
  13.500 +        overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_CHROMA_ENABLE;
  13.501 +    }
  13.502  
  13.503 -	overlay->hwdata->props.viewport.ul.x = overlay->hwdata->CurrentWindow.x;
  13.504 -	overlay->hwdata->props.viewport.ul.y = overlay->hwdata->CurrentWindow.y;
  13.505 -	//Next line MIGHT have x and y reversed!!!!!!!!!!!!
  13.506 -	overlay->hwdata->props.viewport.lr.x = overlay->hwdata->CurrentWindow.x +overlay->hwdata->CurrentWindow.w;
  13.507 -	overlay->hwdata->props.viewport.lr.y = overlay->hwdata->CurrentWindow.y + overlay->hwdata->CurrentWindow.h;
  13.508 -		
  13.509 +    rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &overlay->hwdata->props);
  13.510  
  13.511 +    switch(rtncode)
  13.512 +    {
  13.513 +        case -1: SDL_SetError("PgConfigScalerChannel failed\n");
  13.514 +		 SDL_FreeYUVOverlay(overlay);
  13.515 +		 return(NULL);
  13.516 +   		 break;
  13.517 +        case 1:
  13.518 +        case 0:
  13.519 +        default:
  13.520 +                 break;
  13.521 +    }
  13.522  
  13.523 -	overlay->hwdata->props.flags =
  13.524 -	    ~Pg_SCALER_PROP_SCALER_ENABLE | Pg_SCALER_PROP_DOUBLE_BUFFER ;
  13.525 +    planes = grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
  13.526  
  13.527 -	if (overlay->hwdata->chromakey) {
  13.528 -		overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
  13.529 -		overlay->hwdata->props.color_key = overlay->hwdata->chromakey;
  13.530 -		overlay->hwdata->props.color_key_mask = 0xffffff;
  13.531 -	} 
  13.532 -	else
  13.533 -	{
  13.534 -		overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_CHROMA_ENABLE;
  13.535 -	}
  13.536 +    if(overlay->hwdata->channel->yplane1 != NULL)			
  13.537 +        overlay->hwdata->YStride = overlay->hwdata->channel->yplane1->pitch;
  13.538 +    if(overlay->hwdata->channel->uplane1 != NULL)			
  13.539 +        overlay->hwdata->UStride = overlay->hwdata->channel->uplane1->pitch;
  13.540 +    if(overlay->hwdata->channel->vplane1 != NULL)			
  13.541 +        overlay->hwdata->VStride = overlay->hwdata->channel->vplane1->pitch;
  13.542  
  13.543 +    overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
  13.544  
  13.545 -	overlay->hwdata->scaler_on = FALSE;
  13.546 +    if(overlay->hwdata->current==0)
  13.547 +        overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
  13.548 +    else
  13.549 +        overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
  13.550  
  13.551 +    overlay->hwdata->locked = 1;
  13.552  
  13.553 +    /* Find the pitch and offset values for the overlay */
  13.554 +    overlay->planes = planes;
  13.555 +    overlay->pitches = calloc(overlay->planes, sizeof(Uint16));
  13.556 +    overlay->pixels  = calloc(overlay->planes, sizeof(Uint8*));
  13.557 +    if (!overlay->pitches || !overlay->pixels)
  13.558 +    {
  13.559 +        SDL_OutOfMemory();
  13.560 +        SDL_FreeYUVOverlay(overlay);
  13.561 +        return(NULL);
  13.562 +    }
  13.563  
  13.564 - rtncode =    PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));	
  13.565 -	switch(rtncode)
  13.566 -	{
  13.567 -	case -1:
  13.568 -		SDL_SetError("PgConfigScalerChannel failed\n");
  13.569 -		SDL_FreeYUVOverlay(overlay);
  13.570 -		return(NULL);
  13.571 -   		break;
  13.572 -	case 1:
  13.573 -		grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
  13.574 -		break;
  13.575 -	case 0:
  13.576 -	default:
  13.577 -   		break;
  13.578 -	}
  13.579 +    if (overlay->planes > 0)
  13.580 +    {
  13.581 +        overlay->pitches[0] = overlay->hwdata->channel->yplane1->pitch;
  13.582 +        overlay->pixels[0]  = overlay->hwdata->CurrentFrameData->Y;
  13.583 +    }
  13.584 +    if (overlay->planes > 1)
  13.585 +    {
  13.586 +        overlay->pitches[1] = overlay->hwdata->channel->uplane1->pitch;
  13.587 +        overlay->pixels[1]  = overlay->hwdata->CurrentFrameData->U;
  13.588 +    }
  13.589 +    if (overlay->planes > 2)
  13.590 +    {
  13.591 +        overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
  13.592 +        overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
  13.593 +    }
  13.594  
  13.595 +    overlay->hwdata->State = OVERLAY_STATE_ACTIVE;
  13.596 +    overlay->hwdata->scaler_on = 0;
  13.597 +    overlay->hw_overlay = 1;
  13.598  
  13.599 -	grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
  13.600 -
  13.601 -if(overlay->hwdata->channel->yplane1 != NULL)			
  13.602 -	overlay->hwdata->YStride = overlay->hwdata->channel->yplane1->pitch;
  13.603 -if(overlay->hwdata->channel->uplane1 != NULL)			
  13.604 -	overlay->hwdata->UStride = overlay->hwdata->channel->uplane1->pitch;
  13.605 -if(overlay->hwdata->channel->vplane1 != NULL)			
  13.606 -	overlay->hwdata->VStride = overlay->hwdata->channel->vplane1->pitch;
  13.607 -
  13.608 -
  13.609 -	overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
  13.610 -
  13.611 -
  13.612 -
  13.613 -	if (overlay->hwdata->current == -1)
  13.614 -	{
  13.615 -		SDL_SetError("PgNextFrame failed, bailing out\n");
  13.616 -		SDL_FreeYUVOverlay(overlay);
  13.617 -		return(NULL);
  13.618 -	}
  13.619 -        
  13.620 -        //set current frame for double buffering
  13.621 -	if(overlay->hwdata->current == 0)
  13.622 -	{
  13.623 -		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
  13.624 -	}
  13.625 -	else
  13.626 -	{
  13.627 -		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
  13.628 -	}
  13.629 -    
  13.630 -	overlay->hwdata->State = OVERLAY_STATE_ACTIVE;
  13.631 -
  13.632 -
  13.633 -	/* We're all done.. */
  13.634 -	return(overlay);
  13.635 +    return (overlay);
  13.636  }
  13.637  
  13.638  int ph_LockYUVOverlay(_THIS, SDL_Overlay *overlay)
  13.639  {
  13.640 -//int rtncode;
  13.641 +    if (overlay == NULL)
  13.642 +        return 0;
  13.643  
  13.644 -if(overlay == NULL)
  13.645 -   return 0;
  13.646 +    overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
  13.647 +    if (overlay->hwdata->current == -1)
  13.648 +    {
  13.649 +        SDL_SetError("PgNextFrame failed, bailing out\n");
  13.650 +        SDL_FreeYUVOverlay(overlay);
  13.651 +        return(NULL);
  13.652 +    }
  13.653  
  13.654 -//set current frame for double buffering
  13.655 -	if(overlay->hwdata->current == 0)
  13.656 -	{
  13.657 -		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
  13.658 -	}
  13.659 -	else
  13.660 -	{
  13.661 -		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
  13.662 -	}
  13.663 +    overlay->hwdata->locked = 1;
  13.664  
  13.665 -	//Lock gets the pointer and passes it to the app. The app writes all yuv data into overlay->pixels
  13.666 -//Note this is defined as Uint8 **pixels;				/* Read-write */	
  13.667 -	overlay->pixels = &overlay->hwdata->CurrentFrameData->Y; 
  13.668 -	overlay->pitches = (Uint16*) &(overlay->hwdata->YStride);
  13.669 -		
  13.670 -	return(0);
  13.671 +    /* set current frame for double buffering */
  13.672 +    if (overlay->hwdata->current == 0)
  13.673 +        overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
  13.674 +    else
  13.675 +        overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
  13.676 +
  13.677 +    if (overlay->planes > 0)
  13.678 +    {
  13.679 +        overlay->pitches[0] = overlay->hwdata->channel->yplane1->pitch;
  13.680 +        overlay->pixels[0]  = overlay->hwdata->CurrentFrameData->Y;
  13.681 +    }
  13.682 +    if (overlay->planes > 1)
  13.683 +    {
  13.684 +        overlay->pitches[1] = overlay->hwdata->channel->uplane1->pitch;
  13.685 +        overlay->pixels[1]  = overlay->hwdata->CurrentFrameData->U;
  13.686 +    }
  13.687 +    if (overlay->planes > 2)
  13.688 +    {
  13.689 +        overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
  13.690 +        overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
  13.691 +    }
  13.692 +
  13.693 +    return(0);
  13.694  }
  13.695  
  13.696  void ph_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay)
  13.697  {
  13.698 -int rtncode;
  13.699 +    int rtncode;
  13.700  
  13.701 -if(overlay == NULL)
  13.702 -   return ;
  13.703 +    if(overlay == NULL)
  13.704 +         return;
  13.705  
  13.706 -		if(overlay->hwdata->scaler_on == FALSE) 
  13.707 -		{
  13.708 -			
  13.709 -		
  13.710 -		overlay->hwdata->props.flags |= Pg_SCALER_PROP_SCALER_ENABLE;
  13.711 +    if(overlay->hwdata->scaler_on == 1) 
  13.712 +    {
  13.713          rtncode =PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
  13.714 -        	switch(rtncode)
  13.715 -			{
  13.716 -				case -1:
  13.717 -					SDL_SetError("PgConfigScalerChannel failed\n");
  13.718 -					SDL_FreeYUVOverlay(overlay);
  13.719 -   					break;
  13.720 -				case 1:
  13.721 -					grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
  13.722 -					overlay->hwdata->scaler_on = TRUE;
  13.723 -					break;
  13.724 -				case 0:
  13.725 -					default:
  13.726 -					overlay->hwdata->scaler_on = TRUE;
  13.727 -   					break;
  13.728 -			}
  13.729 -//This would be the best place to draw chromakey but we do not have a SDL_Surface in the args
  13.730 -//This means we might see a chromakey flicker at startup
  13.731 -		}
  13.732 -		overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
  13.733 +        switch(rtncode)
  13.734 +        {
  13.735 +            case -1:
  13.736 +                     SDL_SetError("PgConfigScalerChannel failed\n");
  13.737 +                     SDL_FreeYUVOverlay(overlay);
  13.738 +                     break;
  13.739 +            case 1:
  13.740 +                     grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
  13.741 +                     break;
  13.742 +            case 0:
  13.743 +            default:
  13.744 +                     break;
  13.745 +        }
  13.746 +    }
  13.747  
  13.748 -
  13.749 -	if (overlay->hwdata->current == -1) {
  13.750 -		SDL_SetError("PgNextVideoFrame failed\n");
  13.751 -		SDL_FreeYUVOverlay(overlay);	
  13.752 -		return;	
  13.753 -	}
  13.754 -
  13.755 -	overlay->pixels = NULL;
  13.756 +    /* This would be the best place to draw chromakey but we do not have a SDL_Surface in the args
  13.757 +     * This means we might see a chromakey flicker at startup. */
  13.758  }
  13.759  
  13.760  int ph_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
  13.761  {
  13.762 -int rtncode;
  13.763 +    int rtncode;
  13.764 +    PhPoint_t pos;
  13.765  
  13.766 -if(overlay == NULL)
  13.767 -   return 0;
  13.768 +    if(overlay == NULL)
  13.769 +        return -1;
  13.770  
  13.771 +    /* If CurrentWindow has change, move the viewport */
  13.772 +    if((overlay->hwdata->CurrentWindow.pos.x != dstrect->x) ||
  13.773 +       (overlay->hwdata->CurrentWindow.pos.y != dstrect->y) ||
  13.774 +       (overlay->hwdata->CurrentWindow.size.w != dstrect->w) ||
  13.775 +       (overlay->hwdata->CurrentWindow.size.h != dstrect->h) ||
  13.776 +       (overlay->hwdata->scaler_on==0))
  13.777 +    {
  13.778 +        if(overlay->hwdata->State == OVERLAY_STATE_UNINIT)
  13.779 +            return -1;
  13.780  
  13.781 -	/*SDL_Rect CurrentWindow*/
  13.782 -//If CurrentWindow has change, move the viewport
  13.783 -if((overlay->hwdata->CurrentWindow.x != dstrect->x) ||
  13.784 -  (overlay->hwdata->CurrentWindow.y != dstrect->y) ||
  13.785 -  (overlay->hwdata->CurrentWindow.w != dstrect->w) ||
  13.786 -  (overlay->hwdata->CurrentWindow.h != dstrect->h))
  13.787 -{
  13.788 -		if(overlay->hwdata->State == OVERLAY_STATE_UNINIT)
  13.789 -		return -1;
  13.790 +        overlay->hwdata->props.flags |= Pg_SCALER_PROP_SCALER_ENABLE;
  13.791 +        overlay->hwdata->scaler_on = 1;
  13.792  
  13.793 -	overlay->hwdata->CurrentWindow.x = dstrect->x;
  13.794 -  	overlay->hwdata->CurrentWindow.y = dstrect->y;
  13.795 -  	overlay->hwdata->CurrentWindow.w = dstrect->w;
  13.796 -  	overlay->hwdata->CurrentWindow.h = dstrect->h;
  13.797 +        PtGetAbsPosition(window, &pos.x, &pos.y);
  13.798 +        overlay->hwdata->CurrentWindow.pos.x = pos.x + dstrect->x;
  13.799 +        overlay->hwdata->CurrentWindow.pos.y = pos.y + dstrect->y;
  13.800 +        overlay->hwdata->CurrentWindow.size.w = dstrect->w;
  13.801 +        overlay->hwdata->CurrentWindow.size.h = dstrect->h;
  13.802  
  13.803 -	overlay->hwdata->props.viewport.ul.x = overlay->hwdata->CurrentWindow.x;
  13.804 -	overlay->hwdata->props.viewport.ul.y = overlay->hwdata->CurrentWindow.y;
  13.805 -	//Next line MIGHT have x and y reversed!!!!!!!!!!!!
  13.806 -	overlay->hwdata->props.viewport.lr.x = overlay->hwdata->CurrentWindow.x +overlay->hwdata->CurrentWindow.w;
  13.807 -	overlay->hwdata->props.viewport.lr.y = overlay->hwdata->CurrentWindow.y + overlay->hwdata->CurrentWindow.h;
  13.808 +        PhAreaToRect(&overlay->hwdata->CurrentWindow, &overlay->hwdata->props.viewport);
  13.809  
  13.810 -	
  13.811 -     rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
  13.812 +        rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
  13.813  
  13.814 -	switch(rtncode)
  13.815 -	{
  13.816 -	case -1:
  13.817 -		SDL_SetError("PgConfigScalerChannel failed\n");
  13.818 -		SDL_FreeYUVOverlay(overlay);
  13.819 -		return(0);
  13.820 -   		break;
  13.821 -	case 1:
  13.822 -		grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
  13.823 -		break;
  13.824 -	case 0:
  13.825 -	default:
  13.826 -   		break;
  13.827 -	}
  13.828 -}
  13.829 +        switch(rtncode)
  13.830 +        {
  13.831 +            case -1:
  13.832 +                     SDL_SetError("PgConfigScalerChannel failed\n");
  13.833 +                     SDL_FreeYUVOverlay(overlay);
  13.834 +                     return (0);
  13.835 +            case 1:
  13.836 +                     grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
  13.837 +                     break;
  13.838 +            case 0:
  13.839 +            default:
  13.840 +                     break;
  13.841 +        }
  13.842 +    }
  13.843  
  13.844 +    if (!overlay->hwdata->locked)
  13.845 +    {
  13.846 +        overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
  13.847 +        if (overlay->hwdata->current == -1)
  13.848 +        {
  13.849 +            SDL_SetError("PgNextVideoFrame failed\n");
  13.850 +            SDL_FreeYUVOverlay(overlay);
  13.851 +            return 0;
  13.852 +        }
  13.853 +        if (overlay->hwdata->current == 0)
  13.854 +            overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
  13.855 +        else
  13.856 +            overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
  13.857  
  13.858 -//JB the X11 file did this. We do this in SDL_unlock, we need to confirm that lock and unlock are called for each frame!
  13.859 -//	XvShmPutImage(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
  13.860 -//	              hwdata->image, 0, 0, overlay->w, overlay->h,
  13.861 -//	              dstrect->x, dstrect->y, dstrect->w, dstrect->h, False);	           
  13.862 -/*  This is what this call is
  13.863 -int XvShmPutImage (
  13.864 -   Display *dpy,
  13.865 -   XvPortID port,
  13.866 -   Drawable d,
  13.867 -   GC gc,
  13.868 -   XvImage *image,
  13.869 -   int src_x,
  13.870 -   int src_y,
  13.871 -   unsigned int src_w,
  13.872 -   unsigned int src_h,
  13.873 -   int dest_x, 
  13.874 -   int dest_y,
  13.875 -   unsigned int dest_w,
  13.876 -   unsigned int dest_h,
  13.877 -   Bool send_event
  13.878 -)
  13.879 -*/
  13.880 -
  13.881 -	return(0);
  13.882 +        if (overlay->planes > 0)
  13.883 +        {
  13.884 +            overlay->pitches[0] = overlay->hwdata->channel->yplane1->pitch;
  13.885 +            overlay->pixels[0]  = overlay->hwdata->CurrentFrameData->Y;
  13.886 +        }
  13.887 +        if (overlay->planes > 1)
  13.888 +        {
  13.889 +            overlay->pitches[1] = overlay->hwdata->channel->uplane1->pitch;
  13.890 +            overlay->pixels[1]  = overlay->hwdata->CurrentFrameData->U;
  13.891 +        }
  13.892 +        if (overlay->planes > 2)
  13.893 +        {
  13.894 +            overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
  13.895 +            overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
  13.896 +        }
  13.897 +    }
  13.898 +        
  13.899 +    return 0;
  13.900  }
  13.901  
  13.902  void ph_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
  13.903  {
  13.904 -	//struct private_yuvhwdata *hwdata;
  13.905 +    if (overlay == NULL)
  13.906 +        return;
  13.907  
  13.908 -	if(overlay == NULL)
  13.909 -		return;
  13.910 +    if (overlay->hwdata == NULL)
  13.911 +        return;
  13.912 +
  13.913 +    /* it is need for some buggy drivers, that can't hide overlay before */
  13.914 +    /* freeing buffer, so we got trash on the srceen                     */
  13.915 +    overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_SCALER_ENABLE;
  13.916 +    PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
  13.917 +
  13.918 +    overlay->hwdata->scaler_on = 0;
  13.919 +    overlay->hwdata->State = OVERLAY_STATE_UNINIT;
  13.920 +
  13.921 +    if (overlay->hwdata->channel != NULL)
  13.922 +    {
  13.923 +        PgDestroyVideoChannel(overlay->hwdata->channel);
  13.924 +        overlay->hwdata->channel = NULL;
  13.925 +        return;
  13.926 +    }	
  13.927 +
  13.928 +    overlay->hwdata->CurrentFrameData = NULL;  
  13.929  	
  13.930 -	if(overlay->hwdata == NULL)
  13.931 -		return;
  13.932 -	
  13.933 -	overlay->hwdata->State = OVERLAY_STATE_UNINIT;
  13.934 -
  13.935 -	if( overlay->hwdata->channel == NULL )
  13.936 -	{
  13.937 -		return;
  13.938 -	}	
  13.939 -
  13.940 -	PgDestroyVideoChannel(overlay->hwdata->channel);
  13.941 -
  13.942 -	overlay->hwdata->channel = NULL;
  13.943 -	overlay->hwdata->CurrentFrameData = NULL;  
  13.944 -	
  13.945 -	free(overlay->hwdata->FrameData0);
  13.946 -	free(overlay->hwdata->FrameData1);
  13.947 -	overlay->hwdata->FrameData0 = NULL;
  13.948 -	overlay->hwdata->FrameData1 = NULL;
  13.949 -	free(overlay->hwdata);
  13.950 -
  13.951 +    free(overlay->hwdata->FrameData0);
  13.952 +    free(overlay->hwdata->FrameData1);
  13.953 +    overlay->hwdata->FrameData0 = NULL;
  13.954 +    overlay->hwdata->FrameData1 = NULL;
  13.955 +    free(overlay->hwdata);
  13.956  }
    14.1 --- a/src/video/photon/SDL_phyuv_c.h	Mon Jan 20 01:37:07 2003 +0000
    14.2 +++ b/src/video/photon/SDL_phyuv_c.h	Mon Jan 20 01:38:37 2003 +0000
    14.3 @@ -31,11 +31,7 @@
    14.4  #include "SDL_ph_video.h"
    14.5  
    14.6  extern SDL_Overlay *ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display);
    14.7 -
    14.8  extern int ph_LockYUVOverlay(_THIS, SDL_Overlay *overlay);
    14.9 -
   14.10  extern void ph_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay);
   14.11 -
   14.12  extern int ph_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
   14.13 -
   14.14  extern void ph_FreeYUVOverlay(_THIS, SDL_Overlay *overlay);