Ticket #1667: updaterect.patch

File updaterect.patch, 4.3 KB (added by Marton Balint, 14 years ago)
  • ffplay.c

    diff --git a/ffplay.c b/ffplay.c
    index c6cf880..90c18f4 100644
    a b typedef struct VideoState {  
    234234#if !CONFIG_AVFILTER
    235235    struct SwsContext *img_convert_ctx;
    236236#endif
     237    SDL_Rect last_display_rect;
    237238
    238239    char filename[1024];
    239240    int width, height, xleft, ytop;
    static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block, int *seria  
    449450}
    450451
    451452static inline void fill_rectangle(SDL_Surface *screen,
    452                                   int x, int y, int w, int h, int color)
     453                                  int x, int y, int w, int h, int color, int update)
    453454{
    454455    SDL_Rect rect;
    455456    rect.x = x;
    static inline void fill_rectangle(SDL_Surface *screen,  
    457458    rect.w = w;
    458459    rect.h = h;
    459460    SDL_FillRect(screen, &rect, color);
     461    if (update && w > 0 && h > 0)
     462        SDL_UpdateRect(screen, x, y, w, h);
     463}
     464
     465/* draw only the border of a rectangle */
     466static void fill_border(int xleft, int ytop, int width, int height, int x, int y, int w, int h, int color, int update)
     467{
     468    int w1, w2, h1, h2;
     469
     470    /* fill the background */
     471    w1 = x;
     472    if (w1 < 0)
     473        w1 = 0;
     474    w2 = width - (x + w);
     475    if (w2 < 0)
     476        w2 = 0;
     477    h1 = y;
     478    if (h1 < 0)
     479        h1 = 0;
     480    h2 = height - (y + h);
     481    if (h2 < 0)
     482        h2 = 0;
     483    fill_rectangle(screen,
     484                   xleft, ytop,
     485                   w1, height,
     486                   color, update);
     487    fill_rectangle(screen,
     488                   xleft + width - w2, ytop,
     489                   w2, height,
     490                   color, update);
     491    fill_rectangle(screen,
     492                   xleft + w1, ytop,
     493                   width - w1 - w2, h1,
     494                   color, update);
     495    fill_rectangle(screen,
     496                   xleft + w1, ytop + height - h2,
     497                   width - w1 - w2, h2,
     498                   color, update);
    460499}
    461500
    462501#define ALPHA_BLEND(a, oldp, newp, s)\
    static void video_image_display(VideoState *is)  
    759798        calculate_display_rect(&rect, is->xleft, is->ytop, is->width, is->height, vp);
    760799
    761800        SDL_DisplayYUVOverlay(vp->bmp, &rect);
     801
     802        if (rect.x != is->last_display_rect.x || rect.y != is->last_display_rect.y || rect.w != is->last_display_rect.w || rect.h != is->last_display_rect.h || is->force_refresh) {
     803            int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
     804            fill_border(is->xleft, is->ytop, is->width, is->height, rect.x, rect.y, rect.w, rect.h, bgcolor, 1);
     805            is->last_display_rect = rect;
     806        }
    762807    }
    763808}
    764809
    static void video_audio_display(VideoState *s)  
    824869    if (s->show_mode == SHOW_MODE_WAVES) {
    825870        fill_rectangle(screen,
    826871                       s->xleft, s->ytop, s->width, s->height,
    827                        bgcolor);
     872                       bgcolor, 0);
    828873
    829874        fgcolor = SDL_MapRGB(screen->format, 0xff, 0xff, 0xff);
    830875
    static void video_audio_display(VideoState *s)  
    845890                }
    846891                fill_rectangle(screen,
    847892                               s->xleft + x, ys, 1, y,
    848                                fgcolor);
     893                               fgcolor, 0);
    849894                i += channels;
    850895                if (i >= SAMPLE_ARRAY_SIZE)
    851896                    i -= SAMPLE_ARRAY_SIZE;
    static void video_audio_display(VideoState *s)  
    858903            y = s->ytop + ch * h;
    859904            fill_rectangle(screen,
    860905                           s->xleft, y, s->width, 1,
    861                            fgcolor);
     906                           fgcolor, 0);
    862907        }
    863908        SDL_UpdateRect(screen, s->xleft, s->ytop, s->width, s->height);
    864909    } else {
    static void video_audio_display(VideoState *s)  
    896941
    897942                fill_rectangle(screen,
    898943                            s->xpos, s->height-y, 1, 1,
    899                             fgcolor);
     944                            fgcolor, 0);
    900945            }
    901946        }
    902947        SDL_UpdateRect(screen, s->xpos, s->ytop, 1, s->height);
    static void toggle_audio_display(VideoState *is)  
    28282873    is->show_mode = (is->show_mode + 1) % SHOW_MODE_NB;
    28292874    fill_rectangle(screen,
    28302875                is->xleft, is->ytop, is->width, is->height,
    2831                 bgcolor);
    2832     SDL_UpdateRect(screen, is->xleft, is->ytop, is->width, is->height);
     2876                bgcolor, 1);
    28332877}
    28342878
    28352879/* handle an event sent by the GUI */