src/video/ps2gs/SDL_gsyuv.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/src/video/ps2gs/SDL_gsyuv.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/src/video/ps2gs/SDL_gsyuv.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -64,7 +64,7 @@
     1.4  };
     1.5  
     1.6  static int
     1.7 -power_of_2 (int value)
     1.8 +power_of_2(int value)
     1.9  {
    1.10      int shift;
    1.11  
    1.12 @@ -75,8 +75,8 @@
    1.13  }
    1.14  
    1.15  SDL_Overlay *
    1.16 -GS_CreateYUVOverlay (_THIS, int width, int height, Uint32 format,
    1.17 -                     SDL_Surface * display)
    1.18 +GS_CreateYUVOverlay(_THIS, int width, int height, Uint32 format,
    1.19 +                    SDL_Surface * display)
    1.20  {
    1.21      SDL_Overlay *overlay;
    1.22      struct private_yuvhwdata *hwdata;
    1.23 @@ -92,13 +92,13 @@
    1.24  
    1.25      /* We can only decode blocks of 16x16 pixels */
    1.26      if ((width & 15) || (height & 15)) {
    1.27 -        SDL_SetError ("Overlay width/height must be multiples of 16");
    1.28 +        SDL_SetError("Overlay width/height must be multiples of 16");
    1.29          return (NULL);
    1.30      }
    1.31      /* Make sure the image isn't too large for a single DMA transfer */
    1.32      if (((width / 16) * (height / 16)) > MAX_MACROBLOCKS) {
    1.33 -        SDL_SetError ("Overlay too large (maximum size: %d pixels)",
    1.34 -                      MAX_MACROBLOCKS * 16 * 16);
    1.35 +        SDL_SetError("Overlay too large (maximum size: %d pixels)",
    1.36 +                     MAX_MACROBLOCKS * 16 * 16);
    1.37          return (NULL);
    1.38      }
    1.39  
    1.40 @@ -111,17 +111,17 @@
    1.41          /* Supported planar YUV format */
    1.42          break;
    1.43      default:
    1.44 -        SDL_SetError ("Unsupported YUV format");
    1.45 +        SDL_SetError("Unsupported YUV format");
    1.46          return (NULL);
    1.47      }
    1.48  
    1.49      /* Create the overlay structure */
    1.50 -    overlay = (SDL_Overlay *) SDL_malloc (sizeof *overlay);
    1.51 +    overlay = (SDL_Overlay *) SDL_malloc(sizeof *overlay);
    1.52      if (overlay == NULL) {
    1.53 -        SDL_OutOfMemory ();
    1.54 +        SDL_OutOfMemory();
    1.55          return (NULL);
    1.56      }
    1.57 -    SDL_memset (overlay, 0, (sizeof *overlay));
    1.58 +    SDL_memset(overlay, 0, (sizeof *overlay));
    1.59  
    1.60      /* Fill in the basic members */
    1.61      overlay->format = format;
    1.62 @@ -133,18 +133,18 @@
    1.63      overlay->hw_overlay = 1;
    1.64  
    1.65      /* Create the pixel data */
    1.66 -    hwdata = (struct private_yuvhwdata *) SDL_malloc (sizeof *hwdata);
    1.67 +    hwdata = (struct private_yuvhwdata *) SDL_malloc(sizeof *hwdata);
    1.68      overlay->hwdata = hwdata;
    1.69      if (hwdata == NULL) {
    1.70 -        SDL_FreeYUVOverlay (overlay);
    1.71 -        SDL_OutOfMemory ();
    1.72 +        SDL_FreeYUVOverlay(overlay);
    1.73 +        SDL_OutOfMemory();
    1.74          return (NULL);
    1.75      }
    1.76      hwdata->ipu_fd = -1;
    1.77 -    hwdata->pixels = (Uint8 *) SDL_malloc (width * height * 2);
    1.78 +    hwdata->pixels = (Uint8 *) SDL_malloc(width * height * 2);
    1.79      if (hwdata->pixels == NULL) {
    1.80 -        SDL_FreeYUVOverlay (overlay);
    1.81 -        SDL_OutOfMemory ();
    1.82 +        SDL_FreeYUVOverlay(overlay);
    1.83 +        SDL_OutOfMemory();
    1.84          return (NULL);
    1.85      }
    1.86      hwdata->macroblocks = (width / 16) * (height / 16);
    1.87 @@ -175,10 +175,10 @@
    1.88         simplicity we'll support only one.  Opening the IPU more
    1.89         than once will fail with EBUSY.
    1.90       */
    1.91 -    hwdata->ipu_fd = open ("/dev/ps2ipu", O_RDWR);
    1.92 +    hwdata->ipu_fd = open("/dev/ps2ipu", O_RDWR);
    1.93      if (hwdata->ipu_fd < 0) {
    1.94 -        SDL_FreeYUVOverlay (overlay);
    1.95 -        SDL_SetError ("Playstation 2 IPU busy");
    1.96 +        SDL_FreeYUVOverlay(overlay);
    1.97 +        SDL_SetError("Playstation 2 IPU busy");
    1.98          return (NULL);
    1.99      }
   1.100  
   1.101 @@ -187,14 +187,14 @@
   1.102      map_offset = (mapped_len + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
   1.103      hwdata->dma_len = hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8) +
   1.104          width * height * bpp +
   1.105 -        hwdata->macroblocks * (16 * sizeof (long long)) +
   1.106 -        12 * sizeof (long long);
   1.107 -    hwdata->dma_mem = mmap (0, hwdata->dma_len, PROT_READ | PROT_WRITE,
   1.108 -                            MAP_SHARED, memory_fd, map_offset);
   1.109 +        hwdata->macroblocks * (16 * sizeof(long long)) +
   1.110 +        12 * sizeof(long long);
   1.111 +    hwdata->dma_mem = mmap(0, hwdata->dma_len, PROT_READ | PROT_WRITE,
   1.112 +                           MAP_SHARED, memory_fd, map_offset);
   1.113      if (hwdata->dma_mem == MAP_FAILED) {
   1.114          hwdata->ipu_imem = (caddr_t) 0;
   1.115 -        SDL_FreeYUVOverlay (overlay);
   1.116 -        SDL_SetError ("Unable to map %d bytes for DMA", hwdata->dma_len);
   1.117 +        SDL_FreeYUVOverlay(overlay);
   1.118 +        SDL_SetError("Unable to map %d bytes for DMA", hwdata->dma_len);
   1.119          return (NULL);
   1.120      }
   1.121      hwdata->ipu_imem = hwdata->dma_mem;
   1.122 @@ -205,11 +205,11 @@
   1.123      /* Allocate memory for the DMA packets */
   1.124      hwdata->plist.num = hwdata->macroblocks * 4 + 1;
   1.125      hwdata->plist.packet =
   1.126 -        (struct ps2_packet *) SDL_malloc (hwdata->plist.num *
   1.127 -                                          sizeof (struct ps2_packet));
   1.128 +        (struct ps2_packet *) SDL_malloc(hwdata->plist.num *
   1.129 +                                         sizeof(struct ps2_packet));
   1.130      if (!hwdata->plist.packet) {
   1.131 -        SDL_FreeYUVOverlay (overlay);
   1.132 -        SDL_OutOfMemory ();
   1.133 +        SDL_FreeYUVOverlay(overlay);
   1.134 +        SDL_OutOfMemory();
   1.135          return (NULL);
   1.136      }
   1.137      pnum = 0;
   1.138 @@ -227,7 +227,7 @@
   1.139          for (w = width / 16; w; --w) {
   1.140              /* The head tag */
   1.141              packet[pnum].ptr = &tags[0];
   1.142 -            packet[pnum].len = 10 * sizeof (*tags);
   1.143 +            packet[pnum].len = 10 * sizeof(*tags);
   1.144              ++pnum;
   1.145              tags[0] = 4 | (1LL << 60);  /* GIFtag */
   1.146              tags[1] = 0x0e;     /* A+D */
   1.147 @@ -245,7 +245,7 @@
   1.148              tags[9] = PS2_GS_TRXDIR;
   1.149              /* Now the actual image data */
   1.150              packet[pnum].ptr = &tags[10];
   1.151 -            packet[pnum].len = 2 * sizeof (*tags);
   1.152 +            packet[pnum].len = 2 * sizeof(*tags);
   1.153              ++pnum;
   1.154              tags[10] = ((16 * 16 * bpp) >> 4) | (2LL << 58);
   1.155              tags[11] = 0;
   1.156 @@ -253,7 +253,7 @@
   1.157              packet[pnum].len = 16 * 16 * bpp;
   1.158              ++pnum;
   1.159              packet[pnum].ptr = &tags[12];
   1.160 -            packet[pnum].len = 2 * sizeof (*tags);
   1.161 +            packet[pnum].len = 2 * sizeof(*tags);
   1.162              ++pnum;
   1.163              tags[12] = (0 >> 4) | (1 << 15) | (2LL << 58);
   1.164              tags[13] = 0;
   1.165 @@ -268,25 +268,25 @@
   1.166  
   1.167      /* Set up the texture memory area for the video */
   1.168      tex_packet.ptr = tags;
   1.169 -    tex_packet.len = 8 * sizeof (*tags);
   1.170 +    tex_packet.len = 8 * sizeof(*tags);
   1.171      tags[0] = 3 | (1LL << 60);  /* GIFtag */
   1.172      tags[1] = 0x0e;             /* A+D */
   1.173      tags[2] = ((screen_image.y + screen_image.h) * screen_image.w) / 64 +
   1.174          ((unsigned long long) fbw << 14) +
   1.175          ((unsigned long long) psm << 20) +
   1.176 -        ((unsigned long long) power_of_2 (width) << 26) +
   1.177 -        ((unsigned long long) power_of_2 (height) << 30) +
   1.178 +        ((unsigned long long) power_of_2(width) << 26) +
   1.179 +        ((unsigned long long) power_of_2(height) << 30) +
   1.180          ((unsigned long long) 1 << 34) + ((unsigned long long) 1 << 35);
   1.181      tags[3] = PS2_GS_TEX0_1;
   1.182      tags[4] = (1 << 5) + (1 << 6);
   1.183      tags[5] = PS2_GS_TEX1_1;
   1.184      tags[6] = 0;
   1.185      tags[7] = PS2_GS_TEXFLUSH;
   1.186 -    ioctl (console_fd, PS2IOC_SEND, &tex_packet);
   1.187 +    ioctl(console_fd, PS2IOC_SEND, &tex_packet);
   1.188  
   1.189      /* Set up the tags for scaling the image */
   1.190      packet[pnum].ptr = tags;
   1.191 -    packet[pnum].len = 12 * sizeof (*tags);
   1.192 +    packet[pnum].len = 12 * sizeof(*tags);
   1.193      ++pnum;
   1.194      tags[0] = 5 | (1LL << 60);  /* GIFtag */
   1.195      tags[1] = 0x0e;             /* A+D */
   1.196 @@ -310,20 +310,20 @@
   1.197  }
   1.198  
   1.199  int
   1.200 -GS_LockYUVOverlay (_THIS, SDL_Overlay * overlay)
   1.201 +GS_LockYUVOverlay(_THIS, SDL_Overlay * overlay)
   1.202  {
   1.203      return (0);
   1.204  }
   1.205  
   1.206  void
   1.207 -GS_UnlockYUVOverlay (_THIS, SDL_Overlay * overlay)
   1.208 +GS_UnlockYUVOverlay(_THIS, SDL_Overlay * overlay)
   1.209  {
   1.210      return;
   1.211  }
   1.212  
   1.213  int
   1.214 -GS_DisplayYUVOverlay (_THIS, SDL_Overlay * overlay, SDL_Rect * src,
   1.215 -                      SDL_Rect * dst)
   1.216 +GS_DisplayYUVOverlay(_THIS, SDL_Overlay * overlay, SDL_Rect * src,
   1.217 +                     SDL_Rect * dst)
   1.218  {
   1.219      struct private_yuvhwdata *hwdata;
   1.220      __u32 cmd;
   1.221 @@ -350,7 +350,7 @@
   1.222          Cr = (Uint32 *) overlay->pixels[2];
   1.223          Cb = (Uint32 *) overlay->pixels[1];
   1.224      default:
   1.225 -        SDL_SetError ("Unsupported YUV format in blit (?)");
   1.226 +        SDL_SetError("Unsupported YUV format in blit (?)");
   1.227          return (-1);
   1.228      }
   1.229      dstp = (Uint32 *) hwdata->ipu_imem;
   1.230 @@ -397,37 +397,37 @@
   1.231  
   1.232      /* Send the macroblock data to the IPU */
   1.233  #ifdef DEBUG_YUV
   1.234 -    fprintf (stderr, "Sending data to IPU..\n");
   1.235 +    fprintf(stderr, "Sending data to IPU..\n");
   1.236  #endif
   1.237      packet.ptr = hwdata->ipu_imem;
   1.238      packet.len = hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8);
   1.239 -    ioctl (hwdata->ipu_fd, PS2IOC_SENDA, &packet);
   1.240 +    ioctl(hwdata->ipu_fd, PS2IOC_SENDA, &packet);
   1.241  
   1.242      /* Trigger the DMA to the IPU for conversion */
   1.243  #ifdef DEBUG_YUV
   1.244 -    fprintf (stderr, "Trigging conversion command\n");
   1.245 +    fprintf(stderr, "Trigging conversion command\n");
   1.246  #endif
   1.247      cmd = (7 << 28) + hwdata->macroblocks;
   1.248      if (screen_image.psm == PS2_GS_PSMCT16) {
   1.249          cmd += (1 << 27) +      /* Output RGB 555 */
   1.250              (1 << 26);          /* Dither output */
   1.251      }
   1.252 -    ioctl (hwdata->ipu_fd, PS2IOC_SIPUCMD, &cmd);
   1.253 +    ioctl(hwdata->ipu_fd, PS2IOC_SIPUCMD, &cmd);
   1.254  
   1.255      /* Retrieve the converted image from the IPU */
   1.256  #ifdef DEBUG_YUV
   1.257 -    fprintf (stderr, "Retrieving data from IPU..\n");
   1.258 +    fprintf(stderr, "Retrieving data from IPU..\n");
   1.259  #endif
   1.260      packet.ptr = hwdata->ipu_omem;
   1.261      packet.len = overlay->w * overlay->h *
   1.262          this->screen->format->BytesPerPixel;
   1.263 -    ioctl (hwdata->ipu_fd, PS2IOC_RECV, &packet);
   1.264 +    ioctl(hwdata->ipu_fd, PS2IOC_RECV, &packet);
   1.265  
   1.266  #ifdef DEBUG_YUV
   1.267 -    fprintf (stderr, "Copying image to screen..\n");
   1.268 +    fprintf(stderr, "Copying image to screen..\n");
   1.269  #endif
   1.270      /* Wait for previous DMA to complete */
   1.271 -    ioctl (console_fd, PS2IOC_SENDQCT, 1);
   1.272 +    ioctl(console_fd, PS2IOC_SENDQCT, 1);
   1.273  
   1.274      /* Send the current image to the screen and scale it */
   1.275      screen = this->screen;
   1.276 @@ -442,29 +442,29 @@
   1.277      x += (unsigned int) dst->w;
   1.278      y += (unsigned int) dst->h;
   1.279      *hwdata->stretch_x2y2 = (x * 16) + ((y * 16) << 16);
   1.280 -    return ioctl (console_fd, PS2IOC_SENDL, &hwdata->plist);
   1.281 +    return ioctl(console_fd, PS2IOC_SENDL, &hwdata->plist);
   1.282  }
   1.283  
   1.284  void
   1.285 -GS_FreeYUVOverlay (_THIS, SDL_Overlay * overlay)
   1.286 +GS_FreeYUVOverlay(_THIS, SDL_Overlay * overlay)
   1.287  {
   1.288      struct private_yuvhwdata *hwdata;
   1.289  
   1.290      hwdata = overlay->hwdata;
   1.291      if (hwdata) {
   1.292          if (hwdata->ipu_fd >= 0) {
   1.293 -            close (hwdata->ipu_fd);
   1.294 +            close(hwdata->ipu_fd);
   1.295          }
   1.296          if (hwdata->dma_mem) {
   1.297 -            munmap (hwdata->dma_mem, hwdata->dma_len);
   1.298 +            munmap(hwdata->dma_mem, hwdata->dma_len);
   1.299          }
   1.300          if (hwdata->plist.packet) {
   1.301 -            SDL_free (hwdata->plist.packet);
   1.302 +            SDL_free(hwdata->plist.packet);
   1.303          }
   1.304          if (hwdata->pixels) {
   1.305 -            SDL_free (hwdata->pixels);
   1.306 +            SDL_free(hwdata->pixels);
   1.307          }
   1.308 -        SDL_free (hwdata);
   1.309 +        SDL_free(hwdata);
   1.310      }
   1.311  }
   1.312