src/video/photon/SDL_phyuv.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. grab_ptrs2
  2. ph_CreateYUVOverlay
  3. ph_LockYUVOverlay
  4. ph_UnlockYUVOverlay
  5. ph_DisplayYUVOverlay
  6. ph_FreeYUVOverlay

   1 /*
   2     SDL - Simple DirectMedia Layer
   3     Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
   4 
   5     This library is free software; you can redistribute it and/or
   6     modify it under the terms of the GNU Library General Public
   7     License as published by the Free Software Foundation; either
   8     version 2 of the License, or (at your option) any later version.
   9 
  10     This library is distributed in the hope that it will be useful,
  11     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13     Library General Public License for more details.
  14 
  15     You should have received a copy of the GNU Library General Public
  16     License along with this library; if not, write to the Free
  17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18 
  19     Sam Lantinga
  20     slouken@devolution.com
  21 */
  22 
  23 #ifdef SAVE_RCSID
  24 static char rcsid =
  25  "@(#) $Id: SDL_phyuv.c,v 1.1.2.11 2001/02/10 07:20:07 hercules Exp $";
  26 #endif
  27 
  28 /* This is the QNX Realtime Platform version for SDL YUV video overlays */
  29 
  30 #include <stdlib.h>
  31 #include <string.h>
  32 //#include <ncurses.h> //only for bool
  33 #ifndef bool
  34 #define bool char
  35 #define TRUE 1
  36 #define FALSE 0
  37 #endif
  38 #include <errno.h>
  39 
  40 #include <Ph.h>
  41 #include <Pt.h>
  42 
  43 #include "SDL_error.h"
  44 #include "SDL_video.h"
  45 #include "SDL_phyuv_c.h"
  46 #include "SDL_yuvfuncs.h"
  47 
  48 #if 0  //just for reference
  49 /* YUV data formats                     FourCC             Layout               H sample (YUV)  V sample (YUV)  BPP */
  50 #define Pg_VIDEO_FORMAT_IYU1            0x31555949      /* U2Y2Y2V2Y2Y2         144             111             12  */
  51 #define Pg_VIDEO_FORMAT_IYU2            0x32555949      /* U4Y4V4U4Y4V4         111             111             24  */
  52 #define Pg_VIDEO_FORMAT_UYVY            0x59565955      /* U8Y8V8Y8             122             111             16  */
  53 #define Pg_VIDEO_FORMAT_YUY2            0x32595559      /* Y8U8Y8V8             122             111             16  */
  54 #define Pg_VIDEO_FORMAT_YVYU            0x55595659      /* Y8V8Y8U8             122             111             16  */
  55 #define Pg_VIDEO_FORMAT_V422            0x56343232      /* V8Y8U8Y8             122             111             16  */
  56 #define Pg_VIDEO_FORMAT_CLJR            0x524a4c43      /* V6U6Y5Y5Y5Y5         133             111             8   */
  57 #define Pg_VIDEO_FORMAT_YVU9            0x39555659      /* Planar YVU           144             144             9   */
  58 #define Pg_VIDEO_FORMAT_YV12            0x32315659      /* Planar YUV           122             122             12  */
  59 
  60 /* There seems to be no FourCC that matches this */
  61 #define Pg_VIDEO_FORMAT_YUV420          0x00000100      /* Planar YUV           122             111             16  */
  62 
  63 /* These formats are the same as YV12, except the U and V planes do not have to contiguously follow the Y plane */
  64 /* but they're all the same to us, since we always have 3 plane pointers */
  65 #define Pg_VIDEO_FORMAT_CLPL    Pg_VIDEO_FORMAT_YV12    /* Cirrus Logic Planar format */
  66 #define Pg_VIDEO_FORMAT_VBPL    Pg_VIDEO_FORMAT_YV12    /* VooDoo Banshee planar format */
  67 
  68 #define SDL_YV12_OVERLAY        0x32315659      /* Planar mode: Y + V + U */
  69 #define SDL_IYUV_OVERLAY        0x56555949      /* Planar mode: Y + U + V */
  70 #define SDL_YUY2_OVERLAY        0x32595559      /* Packed mode: Y0+U0+Y1+V0 */
  71 #define SDL_UYVY_OVERLAY        0x59565955      /* Packed mode: U0+Y0+V0+Y1 */
  72 #define SDL_YVYU_OVERLAY        0x55595659      /* Packed mode: Y0+V0+Y1+U0 */
  73 
  74 #endif 
  75 
  76 
  77 #define OVERLAY_STATE_UNINIT  0
  78 #define OVERLAY_STATE_ACTIVE 1
  79 
  80 /* The functions used to manipulate software video overlays */
  81 static struct private_yuvhwfuncs ph_yuvfuncs = {
  82         ph_LockYUVOverlay,
  83         ph_UnlockYUVOverlay,
  84         ph_DisplayYUVOverlay,
  85         ph_FreeYUVOverlay
  86 };
  87 
  88 
  89 typedef struct {
  90   int id;
  91   int width, height;
  92   int data_size;              /* bytes */
  93   int num_planes;
  94   int *pitches;               /* bytes */
  95   int *offsets;               /* bytes */
  96   char *data;
  97   void *obdata;     
  98 } XvImage;
  99 
 100 
 101 struct private_yuvhwdata {
 102         XvImage *image; 
 103         FRAMEDATA *CurrentFrameData;
 104         FRAMEDATA *FrameData0;
 105         FRAMEDATA *FrameData1;
 106         PgScalerProps_t props;
 107         PgScalerCaps_t          caps;
 108         PgVideoChannel_t *channel;
 109         SDL_Rect CurrentWindow;
 110         long format;
 111         int screen_width;
 112         int screen_height ;
 113         int screen_bpp ;    //2
 114         bool planar;
 115         bool scaler_on ;
 116         int current;
 117         long YStride;
 118         long VStride;
 119         long UStride;
 120         long chromakey;
 121         unsigned long State;
 122         long flags;
 123 };
 124 
 125 extern PgVideoChannel_t * PgCreateVideoChannel(unsigned type, unsigned flags);
 126 extern int PgGetScalerCapabilities( PgVideoChannel_t *channel, int format_index, PgScalerCaps_t *vcaps );
 127 extern int PgConfigScalerChannel(PgVideoChannel_t *channel, PgScalerProps_t *props);
 128 extern void PgDestroyVideoChannel(PgVideoChannel_t *channel);
 129 extern PgColor_t PgGetOverlayChromaColor(void);
 130 
 131 void
 132 grab_ptrs2(PgVideoChannel_t *channel, FRAMEDATA *Frame0, FRAMEDATA *Frame1 )
     /* [<][>][^][v][top][bottom][index][help] */
 133 {
 134 
 135         /* Buffers have moved; re-obtain the pointers */
 136         Frame0->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane1);
 137         Frame1->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane2);
 138         Frame0->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane1);
 139         Frame1->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane2);
 140         Frame0->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane1);
 141         Frame1->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane2);
 142 
 143 }
 144 
 145 SDL_Overlay *ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
     /* [<][>][^][v][top][bottom][index][help] */
 146 {
 147         SDL_Overlay *overlay;
 148         struct private_yuvhwdata *hwdata;
 149         int xv_port;
 150         int rtncode;
 151 //      PhRect_t rect;
 152 //      PhSysInfo_t info;
 153 //      PhRegion_t region;
 154 //      short x, y;
 155         PtArg_t argt;
 156         int i =0;
 157 //      bool bCont = TRUE;
 158         int Priority[20];
 159         int Type[20];
 160         int entries, select, highest;
 161 
 162         PhDCSetCurrent(0);  //Need to set draw context to window esp. if we we in Offscreeen mode
 163 
 164         /* Create the overlay structure */
 165         overlay = (SDL_Overlay *)malloc(sizeof *overlay);
 166         if ( overlay == NULL ) {
 167                 SDL_OutOfMemory();
 168                 return(NULL);
 169         }
 170         memset(overlay, 0, (sizeof *overlay));
 171 
 172         /* Fill in the basic members */
 173         overlay->format = format;
 174         overlay->w = width;
 175         overlay->h = height;
 176         
 177         /* Set up the YUV surface function structure */
 178         overlay->hwfuncs = &ph_yuvfuncs;
 179 
 180         /* Create the pixel data and lookup tables */
 181         hwdata = (struct private_yuvhwdata *)malloc(sizeof *hwdata);
 182         overlay->hwdata = hwdata;
 183         if ( hwdata == NULL ) {
 184                 SDL_OutOfMemory();
 185                 SDL_FreeYUVOverlay(overlay);
 186                 return(NULL);
 187         }
 188         
 189                 if (overlay->hwdata->channel == NULL)
 190         {
 191         
 192   
 193                 if ((overlay->hwdata->channel = PgCreateVideoChannel(Pg_VIDEO_CHANNEL_SCALER,0)) == NULL) 
 194                 {
 195                         SDL_SetError("Create channel failed:%s\n", strerror( errno ));
 196                         free(overlay->hwdata);
 197                         free(overlay);
 198                         return(NULL);
 199                 }
 200 #if 0
 201                 overlay->hwdata->caps.size = sizeof (overlay->hwdata->caps);
 202                 PgGetScalerCapabilities(overlay->hwdata->channel, 0, &(overlay->hwdata->caps));
 203                 if (overlay->hwdata->caps.flags & Pg_SCALER_CAP_DOUBLE_BUFFER)
 204                         overlay->hwdata->props.flags |= Pg_SCALER_PROP_DOUBLE_BUFFER;
 205 #endif  
 206         }
 207 
 208 overlay->hwdata->CurrentWindow.x = 0;
 209 overlay->hwdata->CurrentWindow.y = 0;
 210 overlay->hwdata->CurrentWindow.w = 320;
 211 overlay->hwdata->CurrentWindow.h = 240;
 212 
 213 
 214 
 215 overlay->hwdata->State = OVERLAY_STATE_UNINIT;
 216 
 217 overlay->hwdata->screen_bpp = 2;
 218 overlay->hwdata->scaler_on = FALSE;
 219 
 220 overlay->hwdata->screen_width = 1024;
 221 overlay->hwdata->screen_height  = 768;
 222 
 223 overlay->hwdata->FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA)));
 224 overlay->hwdata->FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA)));
 225 
 226 overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps);
 227 
 228 
 229 //Note you really don't need to do this for SDL as you are given a format, but this is a good example
 230 
 231 xv_port = -1;
 232 i=0;
 233         
 234 while(PgGetScalerCapabilities(overlay->hwdata->channel, i++, &(overlay->hwdata->caps)) == 0) 
 235 {
 236 
 237                 if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YV12) //in SDL
 238                 {
 239                         
 240                         Priority[i-1] = 0;
 241                         Type[i-1] = Pg_VIDEO_FORMAT_YV12;
 242                         if(format == Pg_VIDEO_FORMAT_YV12)
 243                         {
 244                                 overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YV12;
 245                                 xv_port = 1; //supported
 246                                 Priority[i-1] = 100; //force selected
 247                         }
 248                         
 249                 }
 250                 else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YVU9) //in SDL
 251                 {
 252                         
 253                         Priority[i-1] = 0;
 254                         Type[i-1] = Pg_VIDEO_FORMAT_YVU9;                       
 255                         if(format == Pg_VIDEO_FORMAT_YVU9)
 256                         {
 257                                 overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YVU9;
 258                                 xv_port = 1; //supported
 259                                 Priority[i-1] = 100; //force selected
 260                         }
 261                         
 262                 }
 263 #if 0 //this part of SDL is YUV specific
 264                 else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_RGB555)
 265                 {
 266                         
 267                         Priority[i-1] = 3;
 268                         Type[i-1] = Pg_VIDEO_FORMAT_RGB555;                     
 269                 }
 270                 else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_RGB565)
 271                 {
 272                         
 273                         Priority[i-1] =  2;
 274                         Type[i-1] = Pg_VIDEO_FORMAT_RGB565;                     
 275                 }
 276                 else if(overlay->hwdata->caps.format == Pg_VIDEO_FORMAT_RGB8888)
 277                 {
 278                         
 279                         Priority[i-1] = 1;
 280                         Type[i-1] = Pg_VIDEO_FORMAT_RGB8888;                    
 281                 }
 282 #endif
 283                 else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_IYU1)
 284                 {
 285                         
 286                         Priority[i-1] = 0;
 287                         Type[i-1] = Pg_VIDEO_FORMAT_IYU1;
 288                         
 289                 }
 290                 else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_IYU2)
 291                 {
 292                         
 293                         Priority[i-1] = 0;
 294                         Type[i-1] = Pg_VIDEO_FORMAT_IYU2;                       
 295                 }
 296 
 297                 else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_UYVY) //in SDL
 298                 {
 299                         
 300                         Priority[i-1] = 7;
 301                         Type[i-1] = Pg_VIDEO_FORMAT_UYVY;
 302                         if(format == Pg_VIDEO_FORMAT_UYVY)
 303                         {
 304                                 overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_UYVY;
 305                                 xv_port = 1; //supported
 306                                 Priority[i-1] = 100; //force selected
 307                         }
 308                         
 309                 }
 310                 else if(overlay->hwdata->caps.format == Pg_VIDEO_FORMAT_YUY2) //in SDL
 311                 {
 312                         
 313                         Priority[i-1] = 8;
 314                         Type[i-1] = Pg_VIDEO_FORMAT_YUY2;                       
 315                         if(format == Pg_VIDEO_FORMAT_YUY2)
 316                         {
 317                                 overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YUY2;
 318                                 xv_port = 1; //supported
 319                                 Priority[i-1] = 100; //force selected
 320                         }
 321                         
 322                 }
 323                 else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YVYU) //in SDL
 324                 {
 325                         
 326                         Priority[i-1] = 4;
 327                         Type[i-1] = Pg_VIDEO_FORMAT_YVYU;       
 328                         
 329                         if(format == Pg_VIDEO_FORMAT_YVYU)
 330                         {
 331                                 overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YVYU;
 332                                 xv_port = 1; //supported
 333                                 Priority[i-1] = 100; //force selected
 334                                 
 335                         }
 336                 
 337                 }
 338                 else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_V422)
 339                 {
 340                         
 341                         Priority[i-1] = 5;
 342                         Type[i-1] = Pg_VIDEO_FORMAT_V422;                       
 343                 }               
 344                 else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_CLJR)
 345                 {
 346                         
 347                         Priority[i-1] = 6;
 348                         Type[i-1] = Pg_VIDEO_FORMAT_CLJR;               
 349                 }       
 350                 else
 351                 {
 352                 
 353                 Priority[i-1] = 0;
 354                 }
 355                         
 356 overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps);
 357 }
 358 
 359         if ( xv_port == -1 )
 360         {
 361                 SDL_SetError("No available video ports for requested format");
 362                 return(NULL);
 363         }
 364  
 365 //Pick the highest priority format
 366 entries = i -2;
 367 highest = Priority[0]; //make first entry top at begining
 368 select = 0;
 369 
 370 for (i = 1; i < entries; i++)
 371 {
 372 
 373 
 374    if(Priority[i] > highest)
 375    {
 376       highest = Priority[i];
 377       select  = i;
 378    }
 379 } 
 380 
 381  
 382  
 383  overlay->hwdata->caps.size = sizeof (overlay->hwdata->caps     );
 384 PgGetScalerCapabilities(overlay->hwdata->channel, select, &(overlay->hwdata->caps));
 385 overlay->hwdata->props.format = overlay->hwdata->caps.format ;
 386 
 387     overlay->hwdata->format = overlay->hwdata->props.format;  //to make easier for apps to use
 388 
 389 
 390         overlay->hwdata->props.size = sizeof (overlay->hwdata->props);
 391     overlay->hwdata->props.src_dim.w = width;   
 392     overlay->hwdata->props.src_dim.h = height;   
 393         
 394         overlay->hwdata->chromakey = PgGetOverlayChromaColor();
 395 
 396         // Set chromakey in video widget so we can see overlay data
 397         /* I don't know where the container widget is!!!, I guess it is in hidden->window*/
 398         
 399         PtEnter(0);
 400         PtSetArg( &argt, Pt_ARG_FILL_COLOR, overlay->hwdata->chromakey, 0 );
 401         PtSetResources( window, 1, &argt ); 
 402         PtLeave(0);
 403 
 404 
 405         fflush( stderr );
 406 
 407         overlay->hwdata->props.viewport.ul.x = overlay->hwdata->CurrentWindow.x;
 408         overlay->hwdata->props.viewport.ul.y = overlay->hwdata->CurrentWindow.y;
 409         //Next line MIGHT have x and y reversed!!!!!!!!!!!!
 410         overlay->hwdata->props.viewport.lr.x = overlay->hwdata->CurrentWindow.x +overlay->hwdata->CurrentWindow.w;
 411         overlay->hwdata->props.viewport.lr.y = overlay->hwdata->CurrentWindow.y + overlay->hwdata->CurrentWindow.h;
 412                 
 413 
 414 
 415         overlay->hwdata->props.flags =
 416             ~Pg_SCALER_PROP_SCALER_ENABLE | Pg_SCALER_PROP_DOUBLE_BUFFER ;
 417 
 418         if (overlay->hwdata->chromakey) {
 419                 overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
 420                 overlay->hwdata->props.color_key = overlay->hwdata->chromakey;
 421                 overlay->hwdata->props.color_key_mask = 0xffffff;
 422         } 
 423         else
 424         {
 425                 overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_CHROMA_ENABLE;
 426         }
 427 
 428 
 429         overlay->hwdata->scaler_on = FALSE;
 430 
 431 
 432 
 433  rtncode =    PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));       
 434         switch(rtncode)
 435         {
 436         case -1:
 437                 SDL_SetError("PgConfigScalerChannel failed\n");
 438                 SDL_FreeYUVOverlay(overlay);
 439                 return(NULL);
 440                 break;
 441         case 1:
 442                 grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
 443                 break;
 444         case 0:
 445         default:
 446                 break;
 447         }
 448 
 449 
 450         grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
 451 
 452 if(overlay->hwdata->channel->yplane1 != NULL)                   
 453         overlay->hwdata->YStride = overlay->hwdata->channel->yplane1->pitch;
 454 if(overlay->hwdata->channel->uplane1 != NULL)                   
 455         overlay->hwdata->UStride = overlay->hwdata->channel->uplane1->pitch;
 456 if(overlay->hwdata->channel->vplane1 != NULL)                   
 457         overlay->hwdata->VStride = overlay->hwdata->channel->vplane1->pitch;
 458 
 459 
 460         overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
 461 
 462 
 463 
 464         if (overlay->hwdata->current == -1)
 465         {
 466                 SDL_SetError("PgNextFrame failed, bailing out\n");
 467                 SDL_FreeYUVOverlay(overlay);
 468                 return(NULL);
 469         }
 470         
 471         //set current frame for double buffering
 472         if(overlay->hwdata->current == 0)
 473         {
 474                 overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
 475         }
 476         else
 477         {
 478                 overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
 479         }
 480     
 481         overlay->hwdata->State = OVERLAY_STATE_ACTIVE;
 482 
 483 
 484         /* We're all done.. */
 485         return(overlay);
 486 }
 487 
 488 int ph_LockYUVOverlay(_THIS, SDL_Overlay *overlay)
     /* [<][>][^][v][top][bottom][index][help] */
 489 {
 490 //int rtncode;
 491 
 492 if(overlay == NULL)
 493    return 0;
 494 
 495 //set current frame for double buffering
 496         if(overlay->hwdata->current == 0)
 497         {
 498                 overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
 499         }
 500         else
 501         {
 502                 overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
 503         }
 504 
 505         //Lock gets the pointer and passes it to the app. The app writes all yuv data into overlay->pixels
 506 //Note this is defined as Uint8 **pixels;                               /* Read-write */        
 507         overlay->pixels = &overlay->hwdata->CurrentFrameData->Y; 
 508         overlay->pitches  = &overlay->hwdata->YStride;
 509                 
 510         return(0);
 511 }
 512 
 513 void ph_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay)
     /* [<][>][^][v][top][bottom][index][help] */
 514 {
 515 int rtncode;
 516 
 517 if(overlay == NULL)
 518    return ;
 519 
 520                 if(overlay->hwdata->scaler_on == FALSE) 
 521                 {
 522                         
 523                 
 524                 overlay->hwdata->props.flags |= Pg_SCALER_PROP_SCALER_ENABLE;
 525         rtncode =PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
 526                 switch(rtncode)
 527                         {
 528                                 case -1:
 529                                         SDL_SetError("PgConfigScalerChannel failed\n");
 530                                         SDL_FreeYUVOverlay(overlay);
 531                                         break;
 532                                 case 1:
 533                                         grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
 534                                         overlay->hwdata->scaler_on = TRUE;
 535                                         break;
 536                                 case 0:
 537                                         default:
 538                                         overlay->hwdata->scaler_on = TRUE;
 539                                         break;
 540                         }
 541 //This would be the best place to draw chromakey but we do not have a SDL_Surface in the args
 542 //This means we might see a chromakey flicker at startup
 543                 }
 544                 overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
 545 
 546 
 547         if (overlay->hwdata->current == -1) {
 548                 SDL_SetError("PgNextVideoFrame failed\n");
 549                 SDL_FreeYUVOverlay(overlay);    
 550                 return; 
 551         }
 552 
 553         overlay->pixels = NULL;
 554 }
 555 
 556 int ph_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
     /* [<][>][^][v][top][bottom][index][help] */
 557 {
 558 int rtncode;
 559 
 560 if(overlay == NULL)
 561    return 0;
 562 
 563 
 564         /*SDL_Rect CurrentWindow*/
 565 //If CurrentWindow has change, move the viewport
 566 if((overlay->hwdata->CurrentWindow.x != dstrect->x) ||
 567   (overlay->hwdata->CurrentWindow.y != dstrect->y) ||
 568   (overlay->hwdata->CurrentWindow.w != dstrect->w) ||
 569   (overlay->hwdata->CurrentWindow.h != dstrect->h))
 570 {
 571                 if(overlay->hwdata->State == OVERLAY_STATE_UNINIT)
 572                 return -1;
 573 
 574         overlay->hwdata->CurrentWindow.x = dstrect->x;
 575         overlay->hwdata->CurrentWindow.y = dstrect->y;
 576         overlay->hwdata->CurrentWindow.w = dstrect->w;
 577         overlay->hwdata->CurrentWindow.h = dstrect->h;
 578 
 579         overlay->hwdata->props.viewport.ul.x = overlay->hwdata->CurrentWindow.x;
 580         overlay->hwdata->props.viewport.ul.y = overlay->hwdata->CurrentWindow.y;
 581         //Next line MIGHT have x and y reversed!!!!!!!!!!!!
 582         overlay->hwdata->props.viewport.lr.x = overlay->hwdata->CurrentWindow.x +overlay->hwdata->CurrentWindow.w;
 583         overlay->hwdata->props.viewport.lr.y = overlay->hwdata->CurrentWindow.y + overlay->hwdata->CurrentWindow.h;
 584 
 585         
 586      rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
 587 
 588         switch(rtncode)
 589         {
 590         case -1:
 591                 SDL_SetError("PgConfigScalerChannel failed\n");
 592                 SDL_FreeYUVOverlay(overlay);
 593                 return(0);
 594                 break;
 595         case 1:
 596                 grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
 597                 break;
 598         case 0:
 599         default:
 600                 break;
 601         }
 602 }
 603 
 604 
 605 //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!
 606 //      XvShmPutImage(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
 607 //                    hwdata->image, 0, 0, overlay->w, overlay->h,
 608 //                    dstrect->x, dstrect->y, dstrect->w, dstrect->h, False);              
 609 /*  This is what this call is
 610 int XvShmPutImage (
 611    Display *dpy,
 612    XvPortID port,
 613    Drawable d,
 614    GC gc,
 615    XvImage *image,
 616    int src_x,
 617    int src_y,
 618    unsigned int src_w,
 619    unsigned int src_h,
 620    int dest_x, 
 621    int dest_y,
 622    unsigned int dest_w,
 623    unsigned int dest_h,
 624    Bool send_event
 625 )
 626 */
 627 
 628         return(0);
 629 }
 630 
 631 void ph_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
     /* [<][>][^][v][top][bottom][index][help] */
 632 {
 633         //struct private_yuvhwdata *hwdata;
 634 
 635         if(overlay == NULL)
 636                 return;
 637         
 638         if(overlay->hwdata == NULL)
 639                 return;
 640         
 641         overlay->hwdata->State = OVERLAY_STATE_UNINIT;
 642 
 643         if( overlay->hwdata->channel == NULL )
 644         {
 645                 return;
 646         }       
 647 
 648         PgDestroyVideoChannel(overlay->hwdata->channel);
 649 
 650         overlay->hwdata->channel = NULL;
 651         overlay->hwdata->CurrentFrameData = NULL;  
 652         
 653         free(overlay->hwdata->FrameData0);
 654         free(overlay->hwdata->FrameData1);
 655         overlay->hwdata->FrameData0 = NULL;
 656         overlay->hwdata->FrameData1 = NULL;
 657         free(overlay->hwdata);
 658 
 659 }

/* [<][>][^][v][top][bottom][index][help] */