src/video/photon/SDL_phyuv.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1643 51038e80ae59
child 1668 4da1ee79c9af
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
    34 
    34 
    35 #define OVERLAY_STATE_UNINIT 0
    35 #define OVERLAY_STATE_UNINIT 0
    36 #define OVERLAY_STATE_ACTIVE 1
    36 #define OVERLAY_STATE_ACTIVE 1
    37 
    37 
    38 /* The functions are used to manipulate software video overlays */
    38 /* The functions are used to manipulate software video overlays */
    39 static struct private_yuvhwfuncs ph_yuvfuncs =
    39 static struct private_yuvhwfuncs ph_yuvfuncs = {
    40 {
       
    41     ph_LockYUVOverlay,
    40     ph_LockYUVOverlay,
    42     ph_UnlockYUVOverlay,
    41     ph_UnlockYUVOverlay,
    43     ph_DisplayYUVOverlay,
    42     ph_DisplayYUVOverlay,
    44     ph_FreeYUVOverlay
    43     ph_FreeYUVOverlay
    45 };
    44 };
    46 
    45 
    47 int grab_ptrs2(PgVideoChannel_t* channel, FRAMEDATA* Frame0, FRAMEDATA* Frame1)
    46 int
       
    47 grab_ptrs2 (PgVideoChannel_t * channel, FRAMEDATA * Frame0,
       
    48             FRAMEDATA * Frame1)
    48 {
    49 {
    49     int planes = 0;
    50     int planes = 0;
    50 
    51 
    51     /* Buffers have moved; re-obtain the pointers */
    52     /* Buffers have moved; re-obtain the pointers */
    52     Frame0->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane1);
    53     Frame0->Y = (unsigned char *) PdGetOffscreenContextPtr (channel->yplane1);
    53     Frame1->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane2);
    54     Frame1->Y = (unsigned char *) PdGetOffscreenContextPtr (channel->yplane2);
    54     Frame0->U = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane1);
    55     Frame0->U = (unsigned char *) PdGetOffscreenContextPtr (channel->vplane1);
    55     Frame1->U = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane2);
    56     Frame1->U = (unsigned char *) PdGetOffscreenContextPtr (channel->vplane2);
    56     Frame0->V = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane1);
    57     Frame0->V = (unsigned char *) PdGetOffscreenContextPtr (channel->uplane1);
    57     Frame1->V = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane2);
    58     Frame1->V = (unsigned char *) PdGetOffscreenContextPtr (channel->uplane2);
    58 
    59 
    59     if (Frame0->Y)
    60     if (Frame0->Y)
    60         planes++;
    61         planes++;
    61 
    62 
    62     if (Frame0->U)
    63     if (Frame0->U)
    66         planes++;
    67         planes++;
    67 
    68 
    68     return planes;
    69     return planes;
    69 }
    70 }
    70 
    71 
    71 SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface* display)
    72 SDL_Overlay *
       
    73 ph_CreateYUVOverlay (_THIS, int width, int height, Uint32 format,
       
    74                      SDL_Surface * display)
    72 {
    75 {
    73     SDL_Overlay* overlay;
    76     SDL_Overlay *overlay;
    74     struct private_yuvhwdata* hwdata;
    77     struct private_yuvhwdata *hwdata;
    75     int vidport;
    78     int vidport;
    76     int rtncode;
    79     int rtncode;
    77     int planes;
    80     int planes;
    78     int i=0;
    81     int i = 0;
    79     PhPoint_t pos;
    82     PhPoint_t pos;
    80 
    83 
    81     /* Create the overlay structure */
    84     /* Create the overlay structure */
    82     overlay = SDL_calloc(1, sizeof(SDL_Overlay));
    85     overlay = SDL_calloc (1, sizeof (SDL_Overlay));
    83 
    86 
    84     if (overlay == NULL)
    87     if (overlay == NULL) {
    85     {
    88         SDL_OutOfMemory ();
    86         SDL_OutOfMemory();
       
    87         return NULL;
    89         return NULL;
    88     }
    90     }
    89 
    91 
    90     /* Fill in the basic members */
    92     /* Fill in the basic members */
    91     overlay->format = format;
    93     overlay->format = format;
    92     overlay->w = width;
    94     overlay->w = width;
    93     overlay->h = height;
    95     overlay->h = height;
    94     overlay->hwdata = NULL;
    96     overlay->hwdata = NULL;
    95 	
    97 
    96     /* Set up the YUV surface function structure */
    98     /* Set up the YUV surface function structure */
    97     overlay->hwfuncs = &ph_yuvfuncs;
    99     overlay->hwfuncs = &ph_yuvfuncs;
    98 
   100 
    99     /* Create the pixel data and lookup tables */
   101     /* Create the pixel data and lookup tables */
   100     hwdata = SDL_calloc(1, sizeof(struct private_yuvhwdata));
   102     hwdata = SDL_calloc (1, sizeof (struct private_yuvhwdata));
   101 
   103 
   102     if (hwdata == NULL)
   104     if (hwdata == NULL) {
   103     {
   105         SDL_OutOfMemory ();
   104         SDL_OutOfMemory();
   106         SDL_FreeYUVOverlay (overlay);
   105         SDL_FreeYUVOverlay(overlay);
       
   106         return NULL;
   107         return NULL;
   107     }
   108     }
   108 
   109 
   109     overlay->hwdata = hwdata;
   110     overlay->hwdata = hwdata;
   110 
   111 
   111     PhDCSetCurrent(0);
   112     PhDCSetCurrent (0);
   112     if (overlay->hwdata->channel == NULL)
   113     if (overlay->hwdata->channel == NULL) {
   113     {
   114         if ((overlay->hwdata->channel =
   114         if ((overlay->hwdata->channel = PgCreateVideoChannel(Pg_VIDEO_CHANNEL_SCALER, 0)) == NULL)
   115              PgCreateVideoChannel (Pg_VIDEO_CHANNEL_SCALER, 0)) == NULL) {
   115         {
   116             SDL_SetError
   116             SDL_SetError("ph_CreateYUVOverlay(): Create channel failed: %s\n", strerror(errno));
   117                 ("ph_CreateYUVOverlay(): Create channel failed: %s\n",
   117             SDL_FreeYUVOverlay(overlay);
   118                  strerror (errno));
       
   119             SDL_FreeYUVOverlay (overlay);
   118             return NULL;
   120             return NULL;
   119 
   121 
   120         }
   122         }
   121     }
   123     }
   122 
   124 
   123     overlay->hwdata->forcedredraw=0;
   125     overlay->hwdata->forcedredraw = 0;
   124 
   126 
   125     PtGetAbsPosition(window, &pos.x, &pos.y);
   127     PtGetAbsPosition (window, &pos.x, &pos.y);
   126     overlay->hwdata->CurrentWindowPos.x = pos.x;
   128     overlay->hwdata->CurrentWindowPos.x = pos.x;
   127     overlay->hwdata->CurrentWindowPos.y = pos.y;
   129     overlay->hwdata->CurrentWindowPos.y = pos.y;
   128     overlay->hwdata->CurrentViewPort.pos.x = 0;
   130     overlay->hwdata->CurrentViewPort.pos.x = 0;
   129     overlay->hwdata->CurrentViewPort.pos.y = 0;
   131     overlay->hwdata->CurrentViewPort.pos.y = 0;
   130     overlay->hwdata->CurrentViewPort.size.w = width;
   132     overlay->hwdata->CurrentViewPort.size.w = width;
   131     overlay->hwdata->CurrentViewPort.size.h = height;
   133     overlay->hwdata->CurrentViewPort.size.h = height;
   132     overlay->hwdata->State = OVERLAY_STATE_UNINIT;
   134     overlay->hwdata->State = OVERLAY_STATE_UNINIT;
   133     overlay->hwdata->FrameData0 = (FRAMEDATA *) SDL_calloc(1, sizeof(FRAMEDATA));
   135     overlay->hwdata->FrameData0 =
   134     overlay->hwdata->FrameData1 = (FRAMEDATA *) SDL_calloc(1, sizeof(FRAMEDATA));
   136         (FRAMEDATA *) SDL_calloc (1, sizeof (FRAMEDATA));
       
   137     overlay->hwdata->FrameData1 =
       
   138         (FRAMEDATA *) SDL_calloc (1, sizeof (FRAMEDATA));
   135 
   139 
   136     vidport = -1;
   140     vidport = -1;
   137     i=0;
   141     i = 0;
   138     
   142 
   139     overlay->hwdata->ischromakey=0;
   143     overlay->hwdata->ischromakey = 0;
   140 
   144 
   141     do {
   145     do {
   142         SDL_memset(&overlay->hwdata->caps, 0x00, sizeof(PgScalerCaps_t));
   146         SDL_memset (&overlay->hwdata->caps, 0x00, sizeof (PgScalerCaps_t));
   143         overlay->hwdata->caps.size = sizeof(PgScalerCaps_t);
   147         overlay->hwdata->caps.size = sizeof (PgScalerCaps_t);
   144         rtncode = PgGetScalerCapabilities(overlay->hwdata->channel, i, &overlay->hwdata->caps);
   148         rtncode =
   145         if (rtncode==0)
   149             PgGetScalerCapabilities (overlay->hwdata->channel, i,
   146         { 
   150                                      &overlay->hwdata->caps);
   147             if (overlay->hwdata->caps.format==format)
   151         if (rtncode == 0) {
   148             {
   152             if (overlay->hwdata->caps.format == format) {
   149                if ((overlay->hwdata->caps.flags & Pg_SCALER_CAP_DST_CHROMA_KEY) == Pg_SCALER_CAP_DST_CHROMA_KEY)
   153                 if ((overlay->hwdata->caps.
   150                {
   154                      flags & Pg_SCALER_CAP_DST_CHROMA_KEY) ==
   151                    overlay->hwdata->ischromakey=1;
   155                     Pg_SCALER_CAP_DST_CHROMA_KEY) {
   152                }
   156                     overlay->hwdata->ischromakey = 1;
   153                vidport=1;
   157                 }
   154                break;
   158                 vidport = 1;
       
   159                 break;
   155             }
   160             }
   156         }
   161         } else {
   157         else
   162             break;
   158         {
       
   159            break;
       
   160         }
   163         }
   161         i++;
   164         i++;
   162     } while(1);
   165     }
   163 
   166     while (1);
   164 
   167 
   165     if (vidport == -1)
   168 
   166     {
   169     if (vidport == -1) {
   167         SDL_SetError("No available video ports for requested format\n");
   170         SDL_SetError ("No available video ports for requested format\n");
   168         SDL_FreeYUVOverlay(overlay);
   171         SDL_FreeYUVOverlay (overlay);
   169         return NULL;
   172         return NULL;
   170     }
   173     }
   171 
   174 
   172     overlay->hwdata->format = format;
   175     overlay->hwdata->format = format;
   173     overlay->hwdata->props.format = format;
   176     overlay->hwdata->props.format = format;
   174     overlay->hwdata->props.size = sizeof(PgScalerProps_t);
   177     overlay->hwdata->props.size = sizeof (PgScalerProps_t);
   175     overlay->hwdata->props.src_dim.w = width;
   178     overlay->hwdata->props.src_dim.w = width;
   176     overlay->hwdata->props.src_dim.h = height;
   179     overlay->hwdata->props.src_dim.h = height;
   177 
   180 
   178     /* overlay->hwdata->chromakey = PgGetOverlayChromaColor(); */
   181     /* overlay->hwdata->chromakey = PgGetOverlayChromaColor(); */
   179     overlay->hwdata->chromakey = PgRGB(12, 6, 12); /* very dark pink color */
   182     overlay->hwdata->chromakey = PgRGB (12, 6, 12);     /* very dark pink color */
   180     overlay->hwdata->props.color_key = overlay->hwdata->chromakey;
   183     overlay->hwdata->props.color_key = overlay->hwdata->chromakey;
   181 
   184 
   182     PhAreaToRect(&overlay->hwdata->CurrentViewPort, &overlay->hwdata->props.viewport);
   185     PhAreaToRect (&overlay->hwdata->CurrentViewPort,
       
   186                   &overlay->hwdata->props.viewport);
   183 
   187 
   184     overlay->hwdata->props.flags = Pg_SCALER_PROP_DOUBLE_BUFFER;
   188     overlay->hwdata->props.flags = Pg_SCALER_PROP_DOUBLE_BUFFER;
   185 
   189 
   186     if ((overlay->hwdata->ischromakey)&&(overlay->hwdata->chromakey))
   190     if ((overlay->hwdata->ischromakey) && (overlay->hwdata->chromakey)) {
   187     {
       
   188         overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
   191         overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
   189         overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_SPECIFY_KEY_MASK;
   192         overlay->hwdata->props.flags |=
   190     } 
   193             Pg_SCALER_PROP_CHROMA_SPECIFY_KEY_MASK;
   191     else
   194     } else {
   192     {
       
   193         overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_CHROMA_ENABLE;
   195         overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_CHROMA_ENABLE;
   194     }
   196     }
   195 
   197 
   196     rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &overlay->hwdata->props);
   198     rtncode =
   197 
   199         PgConfigScalerChannel (overlay->hwdata->channel,
   198     switch(rtncode)
   200                                &overlay->hwdata->props);
   199     {
   201 
   200         case -1: SDL_SetError("PgConfigScalerChannel failed\n");
   202     switch (rtncode) {
   201                  SDL_FreeYUVOverlay(overlay);
   203     case -1:
   202                  return NULL;
   204         SDL_SetError ("PgConfigScalerChannel failed\n");
   203         case 1:
   205         SDL_FreeYUVOverlay (overlay);
   204         case 0:
   206         return NULL;
   205         default:
   207     case 1:
   206                  break;
   208     case 0:
   207     }
   209     default:
   208 
   210         break;
   209     planes = grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   211     }
   210 
   212 
   211     if(overlay->hwdata->channel->yplane1 != NULL)
   213     planes =
       
   214         grab_ptrs2 (overlay->hwdata->channel, overlay->hwdata->FrameData0,
       
   215                     overlay->hwdata->FrameData1);
       
   216 
       
   217     if (overlay->hwdata->channel->yplane1 != NULL)
   212         overlay->hwdata->YStride = overlay->hwdata->channel->yplane1->pitch;
   218         overlay->hwdata->YStride = overlay->hwdata->channel->yplane1->pitch;
   213     if(overlay->hwdata->channel->vplane1 != NULL)
   219     if (overlay->hwdata->channel->vplane1 != NULL)
   214         overlay->hwdata->UStride = overlay->hwdata->channel->vplane1->pitch;
   220         overlay->hwdata->UStride = overlay->hwdata->channel->vplane1->pitch;
   215     if(overlay->hwdata->channel->uplane1 != NULL)
   221     if (overlay->hwdata->channel->uplane1 != NULL)
   216         overlay->hwdata->VStride = overlay->hwdata->channel->uplane1->pitch;
   222         overlay->hwdata->VStride = overlay->hwdata->channel->uplane1->pitch;
   217 
   223 
   218     /* check for the validness of all planes */
   224     /* check for the validness of all planes */
   219     if ((overlay->hwdata->channel->yplane1 == NULL) &&
   225     if ((overlay->hwdata->channel->yplane1 == NULL) &&
   220         (overlay->hwdata->channel->uplane1 == NULL) &&
   226         (overlay->hwdata->channel->uplane1 == NULL) &&
   221         (overlay->hwdata->channel->vplane1 == NULL))
   227         (overlay->hwdata->channel->vplane1 == NULL)) {
   222     {
   228         SDL_FreeYUVOverlay (overlay);
   223        SDL_FreeYUVOverlay(overlay);
   229         SDL_SetError ("PgConfigScaler() returns all planes equal NULL\n");
   224        SDL_SetError("PgConfigScaler() returns all planes equal NULL\n");
   230         return NULL;
   225        return NULL;
       
   226     }
   231     }
   227 /*
   232 /*
   228     overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
   233     overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
   229 
   234 
   230     if (overlay->hwdata->current==0)
   235     if (overlay->hwdata->current==0)
   242     overlay->hwdata->locked = 1;
   247     overlay->hwdata->locked = 1;
   243 */
   248 */
   244 
   249 
   245     /* Find the pitch and offset values for the overlay */
   250     /* Find the pitch and offset values for the overlay */
   246     overlay->planes = planes;
   251     overlay->planes = planes;
   247     overlay->pitches = SDL_calloc(overlay->planes, sizeof(Uint16));
   252     overlay->pitches = SDL_calloc (overlay->planes, sizeof (Uint16));
   248     overlay->pixels  = SDL_calloc(overlay->planes, sizeof(Uint8*));
   253     overlay->pixels = SDL_calloc (overlay->planes, sizeof (Uint8 *));
   249     if (!overlay->pitches || !overlay->pixels)
   254     if (!overlay->pitches || !overlay->pixels) {
   250     {
   255         SDL_OutOfMemory ();
   251         SDL_OutOfMemory();
   256         SDL_FreeYUVOverlay (overlay);
   252         SDL_FreeYUVOverlay(overlay);
   257         return (NULL);
   253         return(NULL);
   258     }
   254     }
   259 
   255 
   260     if (overlay->planes > 0) {
   256     if (overlay->planes > 0)
       
   257     {
       
   258         overlay->pitches[0] = overlay->hwdata->channel->yplane1->pitch;
   261         overlay->pitches[0] = overlay->hwdata->channel->yplane1->pitch;
   259         overlay->pixels[0]  = overlay->hwdata->CurrentFrameData->Y;
   262         overlay->pixels[0] = overlay->hwdata->CurrentFrameData->Y;
   260     }
   263     }
   261     if (overlay->planes > 1)
   264     if (overlay->planes > 1) {
   262     {
       
   263         overlay->pitches[1] = overlay->hwdata->channel->vplane1->pitch;
   265         overlay->pitches[1] = overlay->hwdata->channel->vplane1->pitch;
   264         overlay->pixels[1]  = overlay->hwdata->CurrentFrameData->U;
   266         overlay->pixels[1] = overlay->hwdata->CurrentFrameData->U;
   265     }
   267     }
   266     if (overlay->planes > 2)
   268     if (overlay->planes > 2) {
   267     {
       
   268         overlay->pitches[2] = overlay->hwdata->channel->uplane1->pitch;
   269         overlay->pitches[2] = overlay->hwdata->channel->uplane1->pitch;
   269         overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
   270         overlay->pixels[2] = overlay->hwdata->CurrentFrameData->V;
   270     }
   271     }
   271 
   272 
   272     overlay->hwdata->State = OVERLAY_STATE_ACTIVE;
   273     overlay->hwdata->State = OVERLAY_STATE_ACTIVE;
   273     overlay->hwdata->scaler_on = 0;
   274     overlay->hwdata->scaler_on = 0;
   274     overlay->hw_overlay = 1;
   275     overlay->hw_overlay = 1;
   275 
   276 
   276     current_overlay=overlay;
   277     current_overlay = overlay;
   277 
   278 
   278     return overlay;
   279     return overlay;
   279 }
   280 }
   280 
   281 
   281 int ph_LockYUVOverlay(_THIS, SDL_Overlay* overlay)
   282 int
       
   283 ph_LockYUVOverlay (_THIS, SDL_Overlay * overlay)
   282 {
   284 {
   283     if (overlay == NULL)
   285     if (overlay == NULL) {
   284     {
       
   285         return -1;
   286         return -1;
   286     }
   287     }
   287 
   288 
   288     overlay->hwdata->locked = 1;
   289     overlay->hwdata->locked = 1;
   289 
   290 
   319         overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
   320         overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
   320         overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
   321         overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
   321     }
   322     }
   322 */
   323 */
   323 
   324 
   324     return(0);
   325     return (0);
   325 }
   326 }
   326 
   327 
   327 void ph_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay)
   328 void
       
   329 ph_UnlockYUVOverlay (_THIS, SDL_Overlay * overlay)
   328 {
   330 {
   329     if (overlay == NULL)
   331     if (overlay == NULL) {
   330     {
       
   331         return;
   332         return;
   332     }
   333     }
   333 
   334 
   334     overlay->hwdata->locked = 0;
   335     overlay->hwdata->locked = 0;
   335 }
   336 }
   336 
   337 
   337 int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst)
   338 int
       
   339 ph_DisplayYUVOverlay (_THIS, SDL_Overlay * overlay, SDL_Rect * src,
       
   340                       SDL_Rect * dst)
   338 {
   341 {
   339     int rtncode;
   342     int rtncode;
   340     PhPoint_t pos;
   343     PhPoint_t pos;
   341     SDL_Rect backrect;
   344     SDL_Rect backrect;
   342     PhRect_t windowextent;
   345     PhRect_t windowextent;
   343     int winchanged=0;
   346     int winchanged = 0;
   344 
   347 
   345     if ((overlay == NULL) || (overlay->hwdata==NULL))
   348     if ((overlay == NULL) || (overlay->hwdata == NULL)) {
   346     {
       
   347         return -1;
   349         return -1;
   348     }
   350     }
   349 
   351 
   350     if (overlay->hwdata->State == OVERLAY_STATE_UNINIT)
   352     if (overlay->hwdata->State == OVERLAY_STATE_UNINIT) {
   351     {
       
   352         return -1;
   353         return -1;
   353     }
   354     }
   354 
   355 
   355     PtGetAbsPosition(window, &pos.x, &pos.y);
   356     PtGetAbsPosition (window, &pos.x, &pos.y);
   356     if ((pos.x!=overlay->hwdata->CurrentWindowPos.x) ||
   357     if ((pos.x != overlay->hwdata->CurrentWindowPos.x) ||
   357         (pos.y!=overlay->hwdata->CurrentWindowPos.y))
   358         (pos.y != overlay->hwdata->CurrentWindowPos.y)) {
   358     {
   359         winchanged = 1;
   359        winchanged=1;
   360         overlay->hwdata->CurrentWindowPos.x = pos.x;
   360        overlay->hwdata->CurrentWindowPos.x=pos.x;
   361         overlay->hwdata->CurrentWindowPos.y = pos.y;
   361        overlay->hwdata->CurrentWindowPos.y=pos.y;
       
   362     }
   362     }
   363 
   363 
   364     /* If CurrentViewPort position/size has been changed, then move/resize the viewport */
   364     /* If CurrentViewPort position/size has been changed, then move/resize the viewport */
   365     if ((overlay->hwdata->CurrentViewPort.pos.x != dst->x) ||
   365     if ((overlay->hwdata->CurrentViewPort.pos.x != dst->x) ||
   366         (overlay->hwdata->CurrentViewPort.pos.y != dst->y) ||
   366         (overlay->hwdata->CurrentViewPort.pos.y != dst->y) ||
   367         (overlay->hwdata->CurrentViewPort.size.w != dst->w) ||
   367         (overlay->hwdata->CurrentViewPort.size.w != dst->w) ||
   368         (overlay->hwdata->CurrentViewPort.size.h != dst->h) ||
   368         (overlay->hwdata->CurrentViewPort.size.h != dst->h) ||
   369         (overlay->hwdata->scaler_on==0) || (winchanged==1) ||
   369         (overlay->hwdata->scaler_on == 0) || (winchanged == 1) ||
   370         (overlay->hwdata->forcedredraw==1))
   370         (overlay->hwdata->forcedredraw == 1)) {
   371     {
   371 
   372 
   372         if (overlay->hwdata->ischromakey == 1) {
   373         if (overlay->hwdata->ischromakey==1)
       
   374         {
       
   375             /* restore screen behind the overlay/chroma color. */
   373             /* restore screen behind the overlay/chroma color. */
   376             backrect.x=overlay->hwdata->CurrentViewPort.pos.x;
   374             backrect.x = overlay->hwdata->CurrentViewPort.pos.x;
   377             backrect.y=overlay->hwdata->CurrentViewPort.pos.y;
   375             backrect.y = overlay->hwdata->CurrentViewPort.pos.y;
   378             backrect.w=overlay->hwdata->CurrentViewPort.size.w;
   376             backrect.w = overlay->hwdata->CurrentViewPort.size.w;
   379             backrect.h=overlay->hwdata->CurrentViewPort.size.h;
   377             backrect.h = overlay->hwdata->CurrentViewPort.size.h;
   380             this->UpdateRects(this, 1, &backrect);
   378             this->UpdateRects (this, 1, &backrect);
   381 
   379 
   382             /* Draw the new rectangle of the chroma color at the viewport position */
   380             /* Draw the new rectangle of the chroma color at the viewport position */
   383             PgSetFillColor(overlay->hwdata->chromakey);
   381             PgSetFillColor (overlay->hwdata->chromakey);
   384             PgDrawIRect(dst->x, dst->y, dst->x+dst->w-1, dst->y+dst->h-1, Pg_DRAW_FILL);
   382             PgDrawIRect (dst->x, dst->y, dst->x + dst->w - 1,
   385             PgFlush();
   383                          dst->y + dst->h - 1, Pg_DRAW_FILL);
       
   384             PgFlush ();
   386         }
   385         }
   387 
   386 
   388         overlay->hwdata->props.flags |= Pg_SCALER_PROP_SCALER_ENABLE;
   387         overlay->hwdata->props.flags |= Pg_SCALER_PROP_SCALER_ENABLE;
   389         overlay->hwdata->scaler_on = 1;
   388         overlay->hwdata->scaler_on = 1;
   390 
   389 
   391         PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, PtWidgetRid(window), &windowextent);
   390         PhWindowQueryVisible (Ph_QUERY_CONSOLE, 0, PtWidgetRid (window),
   392         overlay->hwdata->CurrentViewPort.pos.x = pos.x-windowextent.ul.x+dst->x;
   391                               &windowextent);
   393         overlay->hwdata->CurrentViewPort.pos.y = pos.y-windowextent.ul.y+dst->y;
   392         overlay->hwdata->CurrentViewPort.pos.x =
       
   393             pos.x - windowextent.ul.x + dst->x;
       
   394         overlay->hwdata->CurrentViewPort.pos.y =
       
   395             pos.y - windowextent.ul.y + dst->y;
   394         overlay->hwdata->CurrentViewPort.size.w = dst->w;
   396         overlay->hwdata->CurrentViewPort.size.w = dst->w;
   395         overlay->hwdata->CurrentViewPort.size.h = dst->h;
   397         overlay->hwdata->CurrentViewPort.size.h = dst->h;
   396         PhAreaToRect(&overlay->hwdata->CurrentViewPort, &overlay->hwdata->props.viewport);
   398         PhAreaToRect (&overlay->hwdata->CurrentViewPort,
       
   399                       &overlay->hwdata->props.viewport);
   397         overlay->hwdata->CurrentViewPort.pos.x = dst->x;
   400         overlay->hwdata->CurrentViewPort.pos.x = dst->x;
   398         overlay->hwdata->CurrentViewPort.pos.y = dst->y;
   401         overlay->hwdata->CurrentViewPort.pos.y = dst->y;
   399 
   402 
   400         rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
   403         rtncode =
   401 
   404             PgConfigScalerChannel (overlay->hwdata->channel,
   402         switch(rtncode)
   405                                    &(overlay->hwdata->props));
   403         {
   406 
   404             case -1:
   407         switch (rtncode) {
   405                      SDL_SetError("PgConfigScalerChannel() function failed\n");
   408         case -1:
   406                      SDL_FreeYUVOverlay(overlay);
   409             SDL_SetError ("PgConfigScalerChannel() function failed\n");
   407                      return -1;
   410             SDL_FreeYUVOverlay (overlay);
   408             case 1:
   411             return -1;
   409                      grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   412         case 1:
   410                      break;
   413             grab_ptrs2 (overlay->hwdata->channel,
   411             case 0:
   414                         overlay->hwdata->FrameData0,
   412             default:
   415                         overlay->hwdata->FrameData1);
   413                      break;
   416             break;
       
   417         case 0:
       
   418         default:
       
   419             break;
   414         }
   420         }
   415     }
   421     }
   416 
   422 
   417 
   423 
   418 /*
   424 /*
   450             overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
   456             overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
   451             overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
   457             overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
   452         }
   458         }
   453     }
   459     }
   454 */
   460 */
   455         
   461 
   456     return 0;
   462     return 0;
   457 }
   463 }
   458 
   464 
   459 void ph_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
   465 void
       
   466 ph_FreeYUVOverlay (_THIS, SDL_Overlay * overlay)
   460 {
   467 {
   461     SDL_Rect backrect;
   468     SDL_Rect backrect;
   462 
   469 
   463     if (overlay == NULL)
   470     if (overlay == NULL) {
   464     {
       
   465         return;
   471         return;
   466     }
   472     }
   467 
   473 
   468     if (overlay->hwdata == NULL)
   474     if (overlay->hwdata == NULL) {
   469     {
       
   470         return;
   475         return;
   471     }
   476     }
   472 
   477 
   473     current_overlay=NULL;
   478     current_overlay = NULL;
   474 
   479 
   475     /* restore screen behind the overlay/chroma color. */
   480     /* restore screen behind the overlay/chroma color. */
   476     backrect.x=overlay->hwdata->CurrentViewPort.pos.x;
   481     backrect.x = overlay->hwdata->CurrentViewPort.pos.x;
   477     backrect.y=overlay->hwdata->CurrentViewPort.pos.y;
   482     backrect.y = overlay->hwdata->CurrentViewPort.pos.y;
   478     backrect.w=overlay->hwdata->CurrentViewPort.size.w;
   483     backrect.w = overlay->hwdata->CurrentViewPort.size.w;
   479     backrect.h=overlay->hwdata->CurrentViewPort.size.h;
   484     backrect.h = overlay->hwdata->CurrentViewPort.size.h;
   480     this->UpdateRects(this, 1, &backrect);
   485     this->UpdateRects (this, 1, &backrect);
   481 
   486 
   482     /* it is need for some buggy drivers, that can't hide overlay before */
   487     /* it is need for some buggy drivers, that can't hide overlay before */
   483     /* freeing buffer, so we got trash on the srceen                     */
   488     /* freeing buffer, so we got trash on the srceen                     */
   484     overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_SCALER_ENABLE;
   489     overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_SCALER_ENABLE;
   485     PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
   490     PgConfigScalerChannel (overlay->hwdata->channel,
       
   491                            &(overlay->hwdata->props));
   486 
   492 
   487     overlay->hwdata->scaler_on = 0;
   493     overlay->hwdata->scaler_on = 0;
   488     overlay->hwdata->State = OVERLAY_STATE_UNINIT;
   494     overlay->hwdata->State = OVERLAY_STATE_UNINIT;
   489 
   495 
   490     if (overlay->hwdata->channel != NULL)
   496     if (overlay->hwdata->channel != NULL) {
   491     {
   497         PgDestroyVideoChannel (overlay->hwdata->channel);
   492         PgDestroyVideoChannel(overlay->hwdata->channel);
       
   493         overlay->hwdata->channel = NULL;
   498         overlay->hwdata->channel = NULL;
   494         return;
   499         return;
   495     }	
   500     }
   496 
   501 
   497     overlay->hwdata->CurrentFrameData = NULL;  
   502     overlay->hwdata->CurrentFrameData = NULL;
   498 	
   503 
   499     SDL_free(overlay->hwdata->FrameData0);
   504     SDL_free (overlay->hwdata->FrameData0);
   500     SDL_free(overlay->hwdata->FrameData1);
   505     SDL_free (overlay->hwdata->FrameData1);
   501     overlay->hwdata->FrameData0 = NULL;
   506     overlay->hwdata->FrameData0 = NULL;
   502     overlay->hwdata->FrameData1 = NULL;
   507     overlay->hwdata->FrameData1 = NULL;
   503     SDL_free(overlay->hwdata);
   508     SDL_free (overlay->hwdata);
   504 }
   509 }
       
   510 
       
   511 /* vi: set ts=4 sw=4 expandtab: */