src/video/photon/SDL_phyuv.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 19 May 2002 19:54:01 +0000
changeset 370 ba72f259bc88
parent 297 f6ffac90895c
child 380 bce7171e7a85
permissions -rw-r--r--
Date: Sat, 18 May 2002 17:40:53 +0300
From: Mike Gorchak <mike@malva.ua>
Subject: New QNX patches

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