src/video/ps2gs/SDL_gsyuv.c
changeset 1895 c121d94672cb
parent 1838 3d138844ceab
child 2859 99210400e8b9
     1.1 --- a/src/video/ps2gs/SDL_gsyuv.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/src/video/ps2gs/SDL_gsyuv.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -27,435 +27,445 @@
     1.4  #include <unistd.h>
     1.5  #include <sys/ioctl.h>
     1.6  #include <sys/mman.h>
     1.7 -#include <asm/page.h>		/* For definition of PAGE_SIZE */
     1.8 +#include <asm/page.h>           /* For definition of PAGE_SIZE */
     1.9  
    1.10  #include "SDL_video.h"
    1.11  #include "SDL_gsyuv_c.h"
    1.12  #include "../SDL_yuvfuncs.h"
    1.13  
    1.14  /* The maximum number of 16x16 pixel block converted at once */
    1.15 -#define MAX_MACROBLOCKS	1024	/* 2^10 macroblocks at once */
    1.16 +#define MAX_MACROBLOCKS	1024    /* 2^10 macroblocks at once */
    1.17  
    1.18  /* The functions used to manipulate video overlays */
    1.19  static struct private_yuvhwfuncs gs_yuvfuncs = {
    1.20 -	GS_LockYUVOverlay,
    1.21 -	GS_UnlockYUVOverlay,
    1.22 -	GS_DisplayYUVOverlay,
    1.23 -	GS_FreeYUVOverlay
    1.24 +    GS_LockYUVOverlay,
    1.25 +    GS_UnlockYUVOverlay,
    1.26 +    GS_DisplayYUVOverlay,
    1.27 +    GS_FreeYUVOverlay
    1.28  };
    1.29  
    1.30 -struct private_yuvhwdata {
    1.31 -	int ipu_fd;
    1.32 -	Uint8 *pixels;
    1.33 -	int macroblocks;
    1.34 -	int dma_len;
    1.35 -	caddr_t dma_mem;
    1.36 -	caddr_t ipu_imem;
    1.37 -	caddr_t ipu_omem;
    1.38 -	caddr_t dma_tags;
    1.39 -	unsigned long long *stretch_x1y1;
    1.40 -	unsigned long long *stretch_x2y2;
    1.41 -	struct ps2_plist plist;
    1.42 +struct private_yuvhwdata
    1.43 +{
    1.44 +    int ipu_fd;
    1.45 +    Uint8 *pixels;
    1.46 +    int macroblocks;
    1.47 +    int dma_len;
    1.48 +    caddr_t dma_mem;
    1.49 +    caddr_t ipu_imem;
    1.50 +    caddr_t ipu_omem;
    1.51 +    caddr_t dma_tags;
    1.52 +    unsigned long long *stretch_x1y1;
    1.53 +    unsigned long long *stretch_x2y2;
    1.54 +    struct ps2_plist plist;
    1.55  
    1.56 -	/* These are just so we don't have to allocate them separately */
    1.57 -	Uint16 pitches[3];
    1.58 -	Uint8 *planes[3];
    1.59 +    /* These are just so we don't have to allocate them separately */
    1.60 +    Uint16 pitches[3];
    1.61 +    Uint8 *planes[3];
    1.62  };
    1.63  
    1.64 -static int power_of_2(int value)
    1.65 +static int
    1.66 +power_of_2(int value)
    1.67  {
    1.68 -	int shift;
    1.69 +    int shift;
    1.70  
    1.71 -	for ( shift = 0; (1<<shift) < value; ++shift ) {
    1.72 -		/* Keep looking */ ;
    1.73 -	}
    1.74 -	return(shift);
    1.75 +    for (shift = 0; (1 << shift) < value; ++shift) {
    1.76 +        /* Keep looking */ ;
    1.77 +    }
    1.78 +    return (shift);
    1.79  }
    1.80  
    1.81 -SDL_Overlay *GS_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
    1.82 +SDL_Overlay *
    1.83 +GS_CreateYUVOverlay(_THIS, int width, int height, Uint32 format,
    1.84 +                    SDL_Surface * display)
    1.85  {
    1.86 -	SDL_Overlay *overlay;
    1.87 -	struct private_yuvhwdata *hwdata;
    1.88 -	int map_offset;
    1.89 -	unsigned long long *tags;
    1.90 -	caddr_t base;
    1.91 -	int bpp;
    1.92 -	int fbp, fbw, psm;
    1.93 -	int x, y, w, h;
    1.94 -	int pnum;
    1.95 -	struct ps2_packet *packet;
    1.96 -	struct ps2_packet tex_packet;
    1.97 +    SDL_Overlay *overlay;
    1.98 +    struct private_yuvhwdata *hwdata;
    1.99 +    int map_offset;
   1.100 +    unsigned long long *tags;
   1.101 +    caddr_t base;
   1.102 +    int bpp;
   1.103 +    int fbp, fbw, psm;
   1.104 +    int x, y, w, h;
   1.105 +    int pnum;
   1.106 +    struct ps2_packet *packet;
   1.107 +    struct ps2_packet tex_packet;
   1.108  
   1.109 -	/* We can only decode blocks of 16x16 pixels */
   1.110 -	if ( (width & 15) || (height & 15) ) {
   1.111 -		SDL_SetError("Overlay width/height must be multiples of 16");
   1.112 -		return(NULL);
   1.113 -	}
   1.114 -	/* Make sure the image isn't too large for a single DMA transfer */
   1.115 -	if ( ((width/16) * (height/16)) > MAX_MACROBLOCKS ) {
   1.116 -		SDL_SetError("Overlay too large (maximum size: %d pixels)",
   1.117 -		             MAX_MACROBLOCKS * 16 * 16);
   1.118 -		return(NULL);
   1.119 -	}
   1.120 +    /* We can only decode blocks of 16x16 pixels */
   1.121 +    if ((width & 15) || (height & 15)) {
   1.122 +        SDL_SetError("Overlay width/height must be multiples of 16");
   1.123 +        return (NULL);
   1.124 +    }
   1.125 +    /* Make sure the image isn't too large for a single DMA transfer */
   1.126 +    if (((width / 16) * (height / 16)) > MAX_MACROBLOCKS) {
   1.127 +        SDL_SetError("Overlay too large (maximum size: %d pixels)",
   1.128 +                     MAX_MACROBLOCKS * 16 * 16);
   1.129 +        return (NULL);
   1.130 +    }
   1.131  
   1.132 -	/* Double-check the requested format.  For simplicity, we'll only
   1.133 -	   support planar YUV formats.
   1.134 -	 */
   1.135 -	switch (format) {
   1.136 -	    case SDL_YV12_OVERLAY:
   1.137 -	    case SDL_IYUV_OVERLAY:
   1.138 -		/* Supported planar YUV format */
   1.139 -		break;
   1.140 -	    default:
   1.141 -		SDL_SetError("Unsupported YUV format");
   1.142 -		return(NULL);
   1.143 -	}
   1.144 +    /* Double-check the requested format.  For simplicity, we'll only
   1.145 +       support planar YUV formats.
   1.146 +     */
   1.147 +    switch (format) {
   1.148 +    case SDL_YV12_OVERLAY:
   1.149 +    case SDL_IYUV_OVERLAY:
   1.150 +        /* Supported planar YUV format */
   1.151 +        break;
   1.152 +    default:
   1.153 +        SDL_SetError("Unsupported YUV format");
   1.154 +        return (NULL);
   1.155 +    }
   1.156  
   1.157 -	/* Create the overlay structure */
   1.158 -	overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay);
   1.159 -	if ( overlay == NULL ) {
   1.160 -		SDL_OutOfMemory();
   1.161 -		return(NULL);
   1.162 -	}
   1.163 -	SDL_memset(overlay, 0, (sizeof *overlay));
   1.164 +    /* Create the overlay structure */
   1.165 +    overlay = (SDL_Overlay *) SDL_malloc(sizeof *overlay);
   1.166 +    if (overlay == NULL) {
   1.167 +        SDL_OutOfMemory();
   1.168 +        return (NULL);
   1.169 +    }
   1.170 +    SDL_memset(overlay, 0, (sizeof *overlay));
   1.171  
   1.172 -	/* Fill in the basic members */
   1.173 -	overlay->format = format;
   1.174 -	overlay->w = width;
   1.175 -	overlay->h = height;
   1.176 +    /* Fill in the basic members */
   1.177 +    overlay->format = format;
   1.178 +    overlay->w = width;
   1.179 +    overlay->h = height;
   1.180  
   1.181 -	/* Set up the YUV surface function structure */
   1.182 -	overlay->hwfuncs = &gs_yuvfuncs;
   1.183 -	overlay->hw_overlay = 1;
   1.184 +    /* Set up the YUV surface function structure */
   1.185 +    overlay->hwfuncs = &gs_yuvfuncs;
   1.186 +    overlay->hw_overlay = 1;
   1.187  
   1.188 -	/* Create the pixel data */
   1.189 -	hwdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *hwdata);
   1.190 -	overlay->hwdata = hwdata;
   1.191 -	if ( hwdata == NULL ) {
   1.192 -		SDL_FreeYUVOverlay(overlay);
   1.193 -		SDL_OutOfMemory();
   1.194 -		return(NULL);
   1.195 -	}
   1.196 -	hwdata->ipu_fd = -1;
   1.197 -	hwdata->pixels = (Uint8 *)SDL_malloc(width*height*2);
   1.198 -	if ( hwdata->pixels == NULL ) {
   1.199 -		SDL_FreeYUVOverlay(overlay);
   1.200 -		SDL_OutOfMemory();
   1.201 -		return(NULL);
   1.202 -	}
   1.203 -	hwdata->macroblocks = (width/16) * (height/16);
   1.204 +    /* Create the pixel data */
   1.205 +    hwdata = (struct private_yuvhwdata *) SDL_malloc(sizeof *hwdata);
   1.206 +    overlay->hwdata = hwdata;
   1.207 +    if (hwdata == NULL) {
   1.208 +        SDL_FreeYUVOverlay(overlay);
   1.209 +        SDL_OutOfMemory();
   1.210 +        return (NULL);
   1.211 +    }
   1.212 +    hwdata->ipu_fd = -1;
   1.213 +    hwdata->pixels = (Uint8 *) SDL_malloc(width * height * 2);
   1.214 +    if (hwdata->pixels == NULL) {
   1.215 +        SDL_FreeYUVOverlay(overlay);
   1.216 +        SDL_OutOfMemory();
   1.217 +        return (NULL);
   1.218 +    }
   1.219 +    hwdata->macroblocks = (width / 16) * (height / 16);
   1.220  
   1.221 -	/* Find the pitch and offset values for the overlay */
   1.222 -	overlay->pitches = hwdata->pitches;
   1.223 -	overlay->pixels = hwdata->planes;
   1.224 -	switch (format) {
   1.225 -	    case SDL_YV12_OVERLAY:
   1.226 -	    case SDL_IYUV_OVERLAY:
   1.227 -		overlay->pitches[0] = overlay->w;
   1.228 -		overlay->pitches[1] = overlay->pitches[0] / 2;
   1.229 -		overlay->pitches[2] = overlay->pitches[0] / 2;
   1.230 -	        overlay->pixels[0] = hwdata->pixels;
   1.231 -	        overlay->pixels[1] = overlay->pixels[0] +
   1.232 -		                     overlay->pitches[0] * overlay->h;
   1.233 -	        overlay->pixels[2] = overlay->pixels[1] +
   1.234 -		                     overlay->pitches[1] * overlay->h / 2;
   1.235 -		overlay->planes = 3;
   1.236 -		break;
   1.237 -	    default:
   1.238 -		/* We should never get here (caught above) */
   1.239 -		break;
   1.240 -	}
   1.241 +    /* Find the pitch and offset values for the overlay */
   1.242 +    overlay->pitches = hwdata->pitches;
   1.243 +    overlay->pixels = hwdata->planes;
   1.244 +    switch (format) {
   1.245 +    case SDL_YV12_OVERLAY:
   1.246 +    case SDL_IYUV_OVERLAY:
   1.247 +        overlay->pitches[0] = overlay->w;
   1.248 +        overlay->pitches[1] = overlay->pitches[0] / 2;
   1.249 +        overlay->pitches[2] = overlay->pitches[0] / 2;
   1.250 +        overlay->pixels[0] = hwdata->pixels;
   1.251 +        overlay->pixels[1] = overlay->pixels[0] +
   1.252 +            overlay->pitches[0] * overlay->h;
   1.253 +        overlay->pixels[2] = overlay->pixels[1] +
   1.254 +            overlay->pitches[1] * overlay->h / 2;
   1.255 +        overlay->planes = 3;
   1.256 +        break;
   1.257 +    default:
   1.258 +        /* We should never get here (caught above) */
   1.259 +        break;
   1.260 +    }
   1.261  
   1.262 -	/* Theoretically we could support several concurrent decode
   1.263 -	   streams queueing up on the same file descriptor, but for
   1.264 -	   simplicity we'll support only one.  Opening the IPU more
   1.265 -	   than once will fail with EBUSY.
   1.266 -	*/
   1.267 -	hwdata->ipu_fd = open("/dev/ps2ipu", O_RDWR);
   1.268 -	if ( hwdata->ipu_fd < 0 ) {
   1.269 -		SDL_FreeYUVOverlay(overlay);
   1.270 -		SDL_SetError("Playstation 2 IPU busy");
   1.271 -		return(NULL);
   1.272 -	}
   1.273 +    /* Theoretically we could support several concurrent decode
   1.274 +       streams queueing up on the same file descriptor, but for
   1.275 +       simplicity we'll support only one.  Opening the IPU more
   1.276 +       than once will fail with EBUSY.
   1.277 +     */
   1.278 +    hwdata->ipu_fd = open("/dev/ps2ipu", O_RDWR);
   1.279 +    if (hwdata->ipu_fd < 0) {
   1.280 +        SDL_FreeYUVOverlay(overlay);
   1.281 +        SDL_SetError("Playstation 2 IPU busy");
   1.282 +        return (NULL);
   1.283 +    }
   1.284  
   1.285 -	/* Allocate a DMA area for pixel conversion */
   1.286 -	bpp = this->screen->format->BytesPerPixel;
   1.287 -	map_offset = (mapped_len + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
   1.288 -	hwdata->dma_len = hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8) +
   1.289 -	                  width * height * bpp +
   1.290 -	                  hwdata->macroblocks * (16 * sizeof(long long)) +
   1.291 -	                  12 * sizeof(long long);
   1.292 -	hwdata->dma_mem = mmap(0, hwdata->dma_len, PROT_READ|PROT_WRITE,
   1.293 -	                       MAP_SHARED, memory_fd, map_offset);
   1.294 -	if ( hwdata->dma_mem == MAP_FAILED ) {
   1.295 -		hwdata->ipu_imem = (caddr_t)0;
   1.296 -		SDL_FreeYUVOverlay(overlay);
   1.297 -		SDL_SetError("Unable to map %d bytes for DMA", hwdata->dma_len);
   1.298 -		return(NULL);
   1.299 -	}
   1.300 -	hwdata->ipu_imem = hwdata->dma_mem;
   1.301 -	hwdata->ipu_omem = hwdata->ipu_imem +
   1.302 -	                   hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8);
   1.303 -	hwdata->dma_tags = hwdata->ipu_omem + width * height * bpp;
   1.304 +    /* Allocate a DMA area for pixel conversion */
   1.305 +    bpp = this->screen->format->BytesPerPixel;
   1.306 +    map_offset = (mapped_len + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
   1.307 +    hwdata->dma_len = hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8) +
   1.308 +        width * height * bpp +
   1.309 +        hwdata->macroblocks * (16 * sizeof(long long)) +
   1.310 +        12 * sizeof(long long);
   1.311 +    hwdata->dma_mem = mmap(0, hwdata->dma_len, PROT_READ | PROT_WRITE,
   1.312 +                           MAP_SHARED, memory_fd, map_offset);
   1.313 +    if (hwdata->dma_mem == MAP_FAILED) {
   1.314 +        hwdata->ipu_imem = (caddr_t) 0;
   1.315 +        SDL_FreeYUVOverlay(overlay);
   1.316 +        SDL_SetError("Unable to map %d bytes for DMA", hwdata->dma_len);
   1.317 +        return (NULL);
   1.318 +    }
   1.319 +    hwdata->ipu_imem = hwdata->dma_mem;
   1.320 +    hwdata->ipu_omem = hwdata->ipu_imem +
   1.321 +        hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8);
   1.322 +    hwdata->dma_tags = hwdata->ipu_omem + width * height * bpp;
   1.323  
   1.324 -	/* Allocate memory for the DMA packets */
   1.325 -	hwdata->plist.num = hwdata->macroblocks * 4 + 1;
   1.326 -	hwdata->plist.packet = (struct ps2_packet *)SDL_malloc(
   1.327 -	                       hwdata->plist.num*sizeof(struct ps2_packet));
   1.328 -	if ( ! hwdata->plist.packet ) {
   1.329 -		SDL_FreeYUVOverlay(overlay);
   1.330 -		SDL_OutOfMemory();
   1.331 -		return(NULL);
   1.332 -	}
   1.333 -	pnum = 0;
   1.334 -	packet = hwdata->plist.packet;
   1.335 +    /* Allocate memory for the DMA packets */
   1.336 +    hwdata->plist.num = hwdata->macroblocks * 4 + 1;
   1.337 +    hwdata->plist.packet =
   1.338 +        (struct ps2_packet *) SDL_malloc(hwdata->plist.num *
   1.339 +                                         sizeof(struct ps2_packet));
   1.340 +    if (!hwdata->plist.packet) {
   1.341 +        SDL_FreeYUVOverlay(overlay);
   1.342 +        SDL_OutOfMemory();
   1.343 +        return (NULL);
   1.344 +    }
   1.345 +    pnum = 0;
   1.346 +    packet = hwdata->plist.packet;
   1.347  
   1.348 -	/* Set up the tags to send the image to the screen */
   1.349 -	tags = (unsigned long long *)hwdata->dma_tags;
   1.350 -	base = hwdata->ipu_omem;
   1.351 -	fbp = screen_image.fbp;
   1.352 -	fbw = screen_image.fbw;
   1.353 -	psm = screen_image.psm;
   1.354 -	y = screen_image.y + screen_image.h;	/* Offscreen video memory */
   1.355 -	for ( h=height/16; h; --h ) {
   1.356 -		x = 0;			/* Visible video memory */
   1.357 -		for ( w=width/16; w; --w ) {
   1.358 -			/* The head tag */
   1.359 -			packet[pnum].ptr = &tags[0];
   1.360 -			packet[pnum].len = 10 * sizeof(*tags);
   1.361 -			++pnum;
   1.362 -			tags[0] = 4 | (1LL << 60);	/* GIFtag */
   1.363 -			tags[1] = 0x0e;			/* A+D */
   1.364 -			tags[2] = ((unsigned long long)fbp << 32) |
   1.365 -			          ((unsigned long long)fbw << 48) |
   1.366 -			          ((unsigned long long)psm << 56);
   1.367 -			tags[3] = PS2_GS_BITBLTBUF;
   1.368 -			tags[4] = ((unsigned long long)x << 32) |
   1.369 -			          ((unsigned long long)y << 48);
   1.370 -			tags[5] = PS2_GS_TRXPOS;
   1.371 -			tags[6] = (unsigned long long)16 |
   1.372 -			          ((unsigned long long)16 << 32);
   1.373 -			tags[7] = PS2_GS_TRXREG;
   1.374 -			tags[8] = 0;
   1.375 -			tags[9] = PS2_GS_TRXDIR;
   1.376 -			/* Now the actual image data */
   1.377 -			packet[pnum].ptr = &tags[10];
   1.378 -			packet[pnum].len = 2 * sizeof(*tags);
   1.379 -			++pnum;
   1.380 -			tags[10] = ((16*16*bpp) >> 4) | (2LL << 58);
   1.381 -			tags[11] = 0;
   1.382 -			packet[pnum].ptr = (void *)base;
   1.383 -			packet[pnum].len = 16 * 16 * bpp;
   1.384 -			++pnum;
   1.385 -			packet[pnum].ptr = &tags[12];
   1.386 -			packet[pnum].len = 2 * sizeof(*tags);
   1.387 -			++pnum;
   1.388 -			tags[12] = (0 >> 4) | (1 << 15) | (2LL << 58);
   1.389 -			tags[13] = 0;
   1.390 +    /* Set up the tags to send the image to the screen */
   1.391 +    tags = (unsigned long long *) hwdata->dma_tags;
   1.392 +    base = hwdata->ipu_omem;
   1.393 +    fbp = screen_image.fbp;
   1.394 +    fbw = screen_image.fbw;
   1.395 +    psm = screen_image.psm;
   1.396 +    y = screen_image.y + screen_image.h;        /* Offscreen video memory */
   1.397 +    for (h = height / 16; h; --h) {
   1.398 +        x = 0;                  /* Visible video memory */
   1.399 +        for (w = width / 16; w; --w) {
   1.400 +            /* The head tag */
   1.401 +            packet[pnum].ptr = &tags[0];
   1.402 +            packet[pnum].len = 10 * sizeof(*tags);
   1.403 +            ++pnum;
   1.404 +            tags[0] = 4 | (1LL << 60);  /* GIFtag */
   1.405 +            tags[1] = 0x0e;     /* A+D */
   1.406 +            tags[2] = ((unsigned long long) fbp << 32) |
   1.407 +                ((unsigned long long) fbw << 48) |
   1.408 +                ((unsigned long long) psm << 56);
   1.409 +            tags[3] = PS2_GS_BITBLTBUF;
   1.410 +            tags[4] = ((unsigned long long) x << 32) |
   1.411 +                ((unsigned long long) y << 48);
   1.412 +            tags[5] = PS2_GS_TRXPOS;
   1.413 +            tags[6] = (unsigned long long) 16 |
   1.414 +                ((unsigned long long) 16 << 32);
   1.415 +            tags[7] = PS2_GS_TRXREG;
   1.416 +            tags[8] = 0;
   1.417 +            tags[9] = PS2_GS_TRXDIR;
   1.418 +            /* Now the actual image data */
   1.419 +            packet[pnum].ptr = &tags[10];
   1.420 +            packet[pnum].len = 2 * sizeof(*tags);
   1.421 +            ++pnum;
   1.422 +            tags[10] = ((16 * 16 * bpp) >> 4) | (2LL << 58);
   1.423 +            tags[11] = 0;
   1.424 +            packet[pnum].ptr = (void *) base;
   1.425 +            packet[pnum].len = 16 * 16 * bpp;
   1.426 +            ++pnum;
   1.427 +            packet[pnum].ptr = &tags[12];
   1.428 +            packet[pnum].len = 2 * sizeof(*tags);
   1.429 +            ++pnum;
   1.430 +            tags[12] = (0 >> 4) | (1 << 15) | (2LL << 58);
   1.431 +            tags[13] = 0;
   1.432  
   1.433 -			tags += 16;
   1.434 -			base += 16 * 16 * bpp;
   1.435 +            tags += 16;
   1.436 +            base += 16 * 16 * bpp;
   1.437  
   1.438 -			x += 16;
   1.439 -		}
   1.440 -		y += 16;
   1.441 -	}
   1.442 +            x += 16;
   1.443 +        }
   1.444 +        y += 16;
   1.445 +    }
   1.446  
   1.447 -	/* Set up the texture memory area for the video */
   1.448 -	tex_packet.ptr = tags;
   1.449 -	tex_packet.len = 8 * sizeof(*tags);
   1.450 -	tags[0] = 3 | (1LL << 60);	/* GIFtag */
   1.451 -	tags[1] = 0x0e;			/* A+D */
   1.452 -	tags[2] = ((screen_image.y + screen_image.h) * screen_image.w) / 64 +
   1.453 -	          ((unsigned long long)fbw << 14) +
   1.454 -	          ((unsigned long long)psm << 20) +
   1.455 -	          ((unsigned long long)power_of_2(width) << 26) +
   1.456 -	          ((unsigned long long)power_of_2(height) << 30) +
   1.457 -	          ((unsigned long long)1 << 34) +
   1.458 -	          ((unsigned long long)1 << 35);
   1.459 -	tags[3] = PS2_GS_TEX0_1;
   1.460 -	tags[4] = (1 << 5) + (1 << 6);
   1.461 -	tags[5] = PS2_GS_TEX1_1;
   1.462 -	tags[6] = 0;
   1.463 -	tags[7] = PS2_GS_TEXFLUSH;
   1.464 -	ioctl(console_fd, PS2IOC_SEND, &tex_packet);
   1.465 +    /* Set up the texture memory area for the video */
   1.466 +    tex_packet.ptr = tags;
   1.467 +    tex_packet.len = 8 * sizeof(*tags);
   1.468 +    tags[0] = 3 | (1LL << 60);  /* GIFtag */
   1.469 +    tags[1] = 0x0e;             /* A+D */
   1.470 +    tags[2] = ((screen_image.y + screen_image.h) * screen_image.w) / 64 +
   1.471 +        ((unsigned long long) fbw << 14) +
   1.472 +        ((unsigned long long) psm << 20) +
   1.473 +        ((unsigned long long) power_of_2(width) << 26) +
   1.474 +        ((unsigned long long) power_of_2(height) << 30) +
   1.475 +        ((unsigned long long) 1 << 34) + ((unsigned long long) 1 << 35);
   1.476 +    tags[3] = PS2_GS_TEX0_1;
   1.477 +    tags[4] = (1 << 5) + (1 << 6);
   1.478 +    tags[5] = PS2_GS_TEX1_1;
   1.479 +    tags[6] = 0;
   1.480 +    tags[7] = PS2_GS_TEXFLUSH;
   1.481 +    ioctl(console_fd, PS2IOC_SEND, &tex_packet);
   1.482  
   1.483 -	/* Set up the tags for scaling the image */
   1.484 -	packet[pnum].ptr = tags;
   1.485 -	packet[pnum].len = 12 * sizeof(*tags);
   1.486 -	++pnum;
   1.487 -	tags[0] = 5 | (1LL << 60);	/* GIFtag */
   1.488 -	tags[1] = 0x0e;			/* A+D */
   1.489 -	tags[2] = 6 + (1 << 4) + (1 << 8);
   1.490 -	tags[3] = PS2_GS_PRIM;
   1.491 -	tags[4] = ((unsigned long long)0 * 16) +
   1.492 -	           (((unsigned long long)0 * 16) << 16);
   1.493 -	tags[5] = PS2_GS_UV;
   1.494 -	tags[6] = 0; /* X1, Y1 */
   1.495 -	tags[7] = PS2_GS_XYZ2;
   1.496 -	hwdata->stretch_x1y1 = &tags[6];
   1.497 -	tags[8] = ((unsigned long long)overlay->w * 16) +
   1.498 -	           (((unsigned long long)overlay->h * 16) << 16);
   1.499 -	tags[9] = PS2_GS_UV;
   1.500 -	tags[10] = 0; /* X2, Y2 */
   1.501 -	tags[11] = PS2_GS_XYZ2;
   1.502 -	hwdata->stretch_x2y2 = &tags[10];
   1.503 +    /* Set up the tags for scaling the image */
   1.504 +    packet[pnum].ptr = tags;
   1.505 +    packet[pnum].len = 12 * sizeof(*tags);
   1.506 +    ++pnum;
   1.507 +    tags[0] = 5 | (1LL << 60);  /* GIFtag */
   1.508 +    tags[1] = 0x0e;             /* A+D */
   1.509 +    tags[2] = 6 + (1 << 4) + (1 << 8);
   1.510 +    tags[3] = PS2_GS_PRIM;
   1.511 +    tags[4] = ((unsigned long long) 0 * 16) +
   1.512 +        (((unsigned long long) 0 * 16) << 16);
   1.513 +    tags[5] = PS2_GS_UV;
   1.514 +    tags[6] = 0;                /* X1, Y1 */
   1.515 +    tags[7] = PS2_GS_XYZ2;
   1.516 +    hwdata->stretch_x1y1 = &tags[6];
   1.517 +    tags[8] = ((unsigned long long) overlay->w * 16) +
   1.518 +        (((unsigned long long) overlay->h * 16) << 16);
   1.519 +    tags[9] = PS2_GS_UV;
   1.520 +    tags[10] = 0;               /* X2, Y2 */
   1.521 +    tags[11] = PS2_GS_XYZ2;
   1.522 +    hwdata->stretch_x2y2 = &tags[10];
   1.523  
   1.524 -	/* We're all done.. */
   1.525 -	return(overlay);
   1.526 +    /* We're all done.. */
   1.527 +    return (overlay);
   1.528  }
   1.529  
   1.530 -int GS_LockYUVOverlay(_THIS, SDL_Overlay *overlay)
   1.531 +int
   1.532 +GS_LockYUVOverlay(_THIS, SDL_Overlay * overlay)
   1.533  {
   1.534 -	return(0);
   1.535 +    return (0);
   1.536  }
   1.537  
   1.538 -void GS_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay)
   1.539 +void
   1.540 +GS_UnlockYUVOverlay(_THIS, SDL_Overlay * overlay)
   1.541  {
   1.542 -	return;
   1.543 +    return;
   1.544  }
   1.545  
   1.546 -int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
   1.547 +int
   1.548 +GS_DisplayYUVOverlay(_THIS, SDL_Overlay * overlay, SDL_Rect * src,
   1.549 +                     SDL_Rect * dst)
   1.550  {
   1.551 -	struct private_yuvhwdata *hwdata;
   1.552 -	__u32 cmd;
   1.553 -	struct ps2_packet packet;
   1.554 -	int h, w, i;
   1.555 -	Uint32 *lum, *Cr, *Cb;
   1.556 -	int lum_pitch;
   1.557 -	int crb_pitch;
   1.558 -	Uint32 *lum_src, *Cr_src, *Cb_src;
   1.559 -	Uint32 *srcp, *dstp;
   1.560 -	unsigned int x, y;
   1.561 -	SDL_Surface *screen;
   1.562 +    struct private_yuvhwdata *hwdata;
   1.563 +    __u32 cmd;
   1.564 +    struct ps2_packet packet;
   1.565 +    int h, w, i;
   1.566 +    Uint32 *lum, *Cr, *Cb;
   1.567 +    int lum_pitch;
   1.568 +    int crb_pitch;
   1.569 +    Uint32 *lum_src, *Cr_src, *Cb_src;
   1.570 +    Uint32 *srcp, *dstp;
   1.571 +    unsigned int x, y;
   1.572 +    SDL_Surface *screen;
   1.573  
   1.574 -	/* Find out where the various portions of the image are */
   1.575 -	hwdata = overlay->hwdata;
   1.576 -	switch (overlay->format) {
   1.577 -	    case SDL_YV12_OVERLAY:
   1.578 -		lum = (Uint32 *)overlay->pixels[0];
   1.579 -		Cr =  (Uint32 *)overlay->pixels[1];
   1.580 -		Cb =  (Uint32 *)overlay->pixels[2];
   1.581 -		break;
   1.582 -	    case SDL_IYUV_OVERLAY:
   1.583 -		lum = (Uint32 *)overlay->pixels[0];
   1.584 -		Cr =  (Uint32 *)overlay->pixels[2];
   1.585 -		Cb =  (Uint32 *)overlay->pixels[1];
   1.586 -	    default:
   1.587 -		SDL_SetError("Unsupported YUV format in blit (?)");
   1.588 -		return(-1);
   1.589 -	}
   1.590 -	dstp = (Uint32 *)hwdata->ipu_imem;
   1.591 -	lum_pitch = overlay->w/4;
   1.592 -	crb_pitch = (overlay->w/2)/4;
   1.593 +    /* Find out where the various portions of the image are */
   1.594 +    hwdata = overlay->hwdata;
   1.595 +    switch (overlay->format) {
   1.596 +    case SDL_YV12_OVERLAY:
   1.597 +        lum = (Uint32 *) overlay->pixels[0];
   1.598 +        Cr = (Uint32 *) overlay->pixels[1];
   1.599 +        Cb = (Uint32 *) overlay->pixels[2];
   1.600 +        break;
   1.601 +    case SDL_IYUV_OVERLAY:
   1.602 +        lum = (Uint32 *) overlay->pixels[0];
   1.603 +        Cr = (Uint32 *) overlay->pixels[2];
   1.604 +        Cb = (Uint32 *) overlay->pixels[1];
   1.605 +    default:
   1.606 +        SDL_SetError("Unsupported YUV format in blit (?)");
   1.607 +        return (-1);
   1.608 +    }
   1.609 +    dstp = (Uint32 *) hwdata->ipu_imem;
   1.610 +    lum_pitch = overlay->w / 4;
   1.611 +    crb_pitch = (overlay->w / 2) / 4;
   1.612  
   1.613 -	/* Copy blocks of 16x16 pixels to the DMA area */
   1.614 -	for ( h=overlay->h/16; h; --h ) {
   1.615 -		lum_src = lum;
   1.616 -		Cr_src = Cr;
   1.617 -		Cb_src = Cb;
   1.618 -		for ( w=overlay->w/16; w; --w ) {
   1.619 -			srcp = lum_src;
   1.620 -			for ( i=0; i<16; ++i ) {
   1.621 -				dstp[0] = srcp[0];
   1.622 -				dstp[1] = srcp[1];
   1.623 -				dstp[2] = srcp[2];
   1.624 -				dstp[3] = srcp[3];
   1.625 -				srcp += lum_pitch;
   1.626 -				dstp += 4;
   1.627 -			}
   1.628 -			srcp = Cb_src;
   1.629 -			for ( i=0; i<8; ++i ) {
   1.630 -				dstp[0] = srcp[0];
   1.631 -				dstp[1] = srcp[1];
   1.632 -				srcp += crb_pitch;
   1.633 -				dstp += 2;
   1.634 -			}
   1.635 -			srcp = Cr_src;
   1.636 -			for ( i=0; i<8; ++i ) {
   1.637 -				dstp[0] = srcp[0];
   1.638 -				dstp[1] = srcp[1];
   1.639 -				srcp += crb_pitch;
   1.640 -				dstp += 2;
   1.641 -			}
   1.642 -			lum_src += 16 / 4;
   1.643 -			Cb_src += 8 / 4;
   1.644 -			Cr_src += 8 / 4;
   1.645 -		}
   1.646 -		lum += lum_pitch * 16;
   1.647 -		Cr += crb_pitch * 8;
   1.648 -		Cb += crb_pitch * 8;
   1.649 -	}
   1.650 +    /* Copy blocks of 16x16 pixels to the DMA area */
   1.651 +    for (h = overlay->h / 16; h; --h) {
   1.652 +        lum_src = lum;
   1.653 +        Cr_src = Cr;
   1.654 +        Cb_src = Cb;
   1.655 +        for (w = overlay->w / 16; w; --w) {
   1.656 +            srcp = lum_src;
   1.657 +            for (i = 0; i < 16; ++i) {
   1.658 +                dstp[0] = srcp[0];
   1.659 +                dstp[1] = srcp[1];
   1.660 +                dstp[2] = srcp[2];
   1.661 +                dstp[3] = srcp[3];
   1.662 +                srcp += lum_pitch;
   1.663 +                dstp += 4;
   1.664 +            }
   1.665 +            srcp = Cb_src;
   1.666 +            for (i = 0; i < 8; ++i) {
   1.667 +                dstp[0] = srcp[0];
   1.668 +                dstp[1] = srcp[1];
   1.669 +                srcp += crb_pitch;
   1.670 +                dstp += 2;
   1.671 +            }
   1.672 +            srcp = Cr_src;
   1.673 +            for (i = 0; i < 8; ++i) {
   1.674 +                dstp[0] = srcp[0];
   1.675 +                dstp[1] = srcp[1];
   1.676 +                srcp += crb_pitch;
   1.677 +                dstp += 2;
   1.678 +            }
   1.679 +            lum_src += 16 / 4;
   1.680 +            Cb_src += 8 / 4;
   1.681 +            Cr_src += 8 / 4;
   1.682 +        }
   1.683 +        lum += lum_pitch * 16;
   1.684 +        Cr += crb_pitch * 8;
   1.685 +        Cb += crb_pitch * 8;
   1.686 +    }
   1.687  
   1.688 -	/* Send the macroblock data to the IPU */
   1.689 +    /* Send the macroblock data to the IPU */
   1.690  #ifdef DEBUG_YUV
   1.691 -	fprintf(stderr, "Sending data to IPU..\n");
   1.692 +    fprintf(stderr, "Sending data to IPU..\n");
   1.693  #endif
   1.694 -	packet.ptr = hwdata->ipu_imem;
   1.695 -	packet.len = hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8);
   1.696 -	ioctl(hwdata->ipu_fd, PS2IOC_SENDA, &packet);
   1.697 +    packet.ptr = hwdata->ipu_imem;
   1.698 +    packet.len = hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8);
   1.699 +    ioctl(hwdata->ipu_fd, PS2IOC_SENDA, &packet);
   1.700  
   1.701 -	/* Trigger the DMA to the IPU for conversion */
   1.702 +    /* Trigger the DMA to the IPU for conversion */
   1.703  #ifdef DEBUG_YUV
   1.704 -	fprintf(stderr, "Trigging conversion command\n");
   1.705 +    fprintf(stderr, "Trigging conversion command\n");
   1.706  #endif
   1.707 -	cmd = (7 << 28) + hwdata->macroblocks;
   1.708 -	if ( screen_image.psm == PS2_GS_PSMCT16 ) {
   1.709 -		cmd += (1 << 27) +	/* Output RGB 555 */
   1.710 -		       (1 << 26);	/* Dither output */
   1.711 -	}
   1.712 -	ioctl(hwdata->ipu_fd, PS2IOC_SIPUCMD, &cmd);
   1.713 +    cmd = (7 << 28) + hwdata->macroblocks;
   1.714 +    if (screen_image.psm == PS2_GS_PSMCT16) {
   1.715 +        cmd += (1 << 27) +      /* Output RGB 555 */
   1.716 +            (1 << 26);          /* Dither output */
   1.717 +    }
   1.718 +    ioctl(hwdata->ipu_fd, PS2IOC_SIPUCMD, &cmd);
   1.719  
   1.720 -	/* Retrieve the converted image from the IPU */
   1.721 +    /* Retrieve the converted image from the IPU */
   1.722  #ifdef DEBUG_YUV
   1.723 -	fprintf(stderr, "Retrieving data from IPU..\n");
   1.724 +    fprintf(stderr, "Retrieving data from IPU..\n");
   1.725  #endif
   1.726 -	packet.ptr = hwdata->ipu_omem;
   1.727 -	packet.len = overlay->w * overlay->h *
   1.728 -	             this->screen->format->BytesPerPixel;
   1.729 -	ioctl(hwdata->ipu_fd, PS2IOC_RECV, &packet);
   1.730 +    packet.ptr = hwdata->ipu_omem;
   1.731 +    packet.len = overlay->w * overlay->h *
   1.732 +        this->screen->format->BytesPerPixel;
   1.733 +    ioctl(hwdata->ipu_fd, PS2IOC_RECV, &packet);
   1.734  
   1.735  #ifdef DEBUG_YUV
   1.736 -	fprintf(stderr, "Copying image to screen..\n");
   1.737 +    fprintf(stderr, "Copying image to screen..\n");
   1.738  #endif
   1.739 -	/* Wait for previous DMA to complete */
   1.740 -	ioctl(console_fd, PS2IOC_SENDQCT, 1);
   1.741 +    /* Wait for previous DMA to complete */
   1.742 +    ioctl(console_fd, PS2IOC_SENDQCT, 1);
   1.743  
   1.744 -	/* Send the current image to the screen and scale it */
   1.745 -	screen = this->screen;
   1.746 -	x = (unsigned int)dst->x;
   1.747 -	y = (unsigned int)dst->y;
   1.748 -	if ( screen->offset ) {
   1.749 -		x += (screen->offset % screen->pitch) /
   1.750 -		     screen->format->BytesPerPixel;
   1.751 -		y += (screen->offset / screen->pitch);
   1.752 -	}
   1.753 -	y += screen_image.y;
   1.754 -	*hwdata->stretch_x1y1 = (x * 16) + ((y * 16) << 16);
   1.755 -	x += (unsigned int)dst->w;
   1.756 -	y += (unsigned int)dst->h;
   1.757 -	*hwdata->stretch_x2y2 = (x * 16) + ((y * 16) << 16);
   1.758 -	return ioctl(console_fd, PS2IOC_SENDL, &hwdata->plist);
   1.759 +    /* Send the current image to the screen and scale it */
   1.760 +    screen = this->screen;
   1.761 +    x = (unsigned int) dst->x;
   1.762 +    y = (unsigned int) dst->y;
   1.763 +    if (screen->offset) {
   1.764 +        x += (screen->offset % screen->pitch) / screen->format->BytesPerPixel;
   1.765 +        y += (screen->offset / screen->pitch);
   1.766 +    }
   1.767 +    y += screen_image.y;
   1.768 +    *hwdata->stretch_x1y1 = (x * 16) + ((y * 16) << 16);
   1.769 +    x += (unsigned int) dst->w;
   1.770 +    y += (unsigned int) dst->h;
   1.771 +    *hwdata->stretch_x2y2 = (x * 16) + ((y * 16) << 16);
   1.772 +    return ioctl(console_fd, PS2IOC_SENDL, &hwdata->plist);
   1.773  }
   1.774  
   1.775 -void GS_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
   1.776 +void
   1.777 +GS_FreeYUVOverlay(_THIS, SDL_Overlay * overlay)
   1.778  {
   1.779 -	struct private_yuvhwdata *hwdata;
   1.780 +    struct private_yuvhwdata *hwdata;
   1.781  
   1.782 -	hwdata = overlay->hwdata;
   1.783 -	if ( hwdata ) {
   1.784 -		if ( hwdata->ipu_fd >= 0 ) {
   1.785 -			close(hwdata->ipu_fd);
   1.786 -		}
   1.787 -		if ( hwdata->dma_mem ) {
   1.788 -			munmap(hwdata->dma_mem, hwdata->dma_len);
   1.789 -		}
   1.790 -		if ( hwdata->plist.packet ) {
   1.791 -			SDL_free(hwdata->plist.packet);
   1.792 -		}
   1.793 -		if ( hwdata->pixels ) {
   1.794 -			SDL_free(hwdata->pixels);
   1.795 -		}
   1.796 -		SDL_free(hwdata);
   1.797 -	}
   1.798 +    hwdata = overlay->hwdata;
   1.799 +    if (hwdata) {
   1.800 +        if (hwdata->ipu_fd >= 0) {
   1.801 +            close(hwdata->ipu_fd);
   1.802 +        }
   1.803 +        if (hwdata->dma_mem) {
   1.804 +            munmap(hwdata->dma_mem, hwdata->dma_len);
   1.805 +        }
   1.806 +        if (hwdata->plist.packet) {
   1.807 +            SDL_free(hwdata->plist.packet);
   1.808 +        }
   1.809 +        if (hwdata->pixels) {
   1.810 +            SDL_free(hwdata->pixels);
   1.811 +        }
   1.812 +        SDL_free(hwdata);
   1.813 +    }
   1.814  }
   1.815 +
   1.816 +/* vi: set ts=4 sw=4 expandtab: */