Ticket #1801: mplayer_vdpau-hack.diff

File mplayer_vdpau-hack.diff, 9.1 KB (added by h.mth@…, 16 years ago)

vdpau eosd efficiency hack

  • libvo/vo_vdpau.c

    old new  
    7272        mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] %s: %s\n", \
    7373               message, vdp_get_error_string(vdp_st));
    7474
     75/* Round up to the next power of two */
     76#define ROUND_POT(x) pow(2, ceil(log(x)/log(2)))
     77
    7578/* number of video and output surfaces */
    7679#define NUM_OUTPUT_SURFACES                3
    7780#define MAX_VIDEO_SURFACES                 50
    … …  
    7982/* number of palette entries */
    8083#define PALETTE_SIZE 256
    8184
    82 /* Initial maximum number of EOSD surfaces */
    83 #define EOSD_SURFACES_INITIAL 512
     85/* Initial maximum number of EOSD render targets */
     86#define EOSD_TARGETS_INITIAL 512
     87
     88/* Size of the surfaces the EOSD bitmaps will be placed into */
     89#define EOSD_SURFACE_SIZE 512
    8490
    8591/*
    8692 * Global variable declaration - VDPAU specific
    … …  
    188194// Pool of surfaces
    189195struct {
    190196    VdpBitmapSurface surface;
    191     int w;
    192     int h;
    193     char in_use;
     197    int w, h;
     198    int x, y;
     199    int max_y;
    194200} *eosd_surfaces;
    195201
    196202// List of surfaces to be rendered
    … …  
    202208} *eosd_targets;
    203209
    204210static int eosd_render_count;
    205 static int eosd_surface_count;
     211static int eosd_surfaces_size;
     212static int eosd_targets_size;
    206213
    207214// Video equalizer
    208215static VdpProcamp procamp;
    … …  
    617624    for (i = 0; i <= NUM_OUTPUT_SURFACES; i++)
    618625        output_surfaces[i] = VDP_INVALID_HANDLE;
    619626    vdp_device = VDP_INVALID_HANDLE;
    620     for (i = 0; i < eosd_surface_count; i++)
     627    for (i = 0; i < eosd_surfaces_size; i++)
    621628        eosd_surfaces[i].surface = VDP_INVALID_HANDLE;
    622629    output_surface_width = output_surface_height = -1;
    623630    eosd_render_count = 0;
    … …  
    857864static void generate_eosd(EOSD_ImageList *imgs)
    858865{
    859866    VdpStatus vdp_st;
    860     VdpRect destRect;
     867    VdpRect dest_rect;
    861868    int j, found;
    862869    ASS_Image *img = imgs->imgs;
    863870    ASS_Image *i;
    … …  
    870877    if (!img)
    871878        return;
    872879
    873     if (imgs->changed == 1)
    874         goto eosd_skip_upload;
    875 
    876     for (j = 0; j < eosd_surface_count; j++)
    877         eosd_surfaces[j].in_use = 0;
     880    if (imgs->changed != 1) {
     881    for (j = 0; j < eosd_surfaces_size; j++) {
     882        eosd_surfaces[j].x = 0;
     883        eosd_surfaces[j].y = 0;
     884        eosd_surfaces[j].max_y = 0;
     885    }
    878886
    879887    for (i = img; i; i = i->next) {
    880         // Try to reuse a suitable surface
     888        // Find surface with enough free space
    881889        found = -1;
    882         for (j = 0; j < eosd_surface_count; j++) {
    883             if (eosd_surfaces[j].surface != VDP_INVALID_HANDLE && !eosd_surfaces[j].in_use &&
    884                 eosd_surfaces[j].w >= i->w && eosd_surfaces[j].h >= i->h) {
     890        for (j = 0; j < eosd_surfaces_size; j++) {
     891            if ((eosd_surfaces[j].y + i->h < eosd_surfaces[j].h && eosd_surfaces[j].x + i->w < eosd_surfaces[j].w)
     892                || (eosd_surfaces[j].max_y + i->h < eosd_surfaces[j].h)) {
    885893                found = j;
    886894                break;
    887895            }
    888896        }
    889         // None found, allocate a new surface
     897        // No free space; allocate a new surface
    890898        if (found < 0) {
    891             for (j = 0; j < eosd_surface_count; j++) {
    892                 if (!eosd_surfaces[j].in_use) {
    893                     if (eosd_surfaces[j].surface != VDP_INVALID_HANDLE)
    894                         vdp_bitmap_surface_destroy(eosd_surfaces[j].surface);
    895                     found = j;
    896                     break;
    897                 }
    898             }
    899             // Allocate new space for surface/target arrays
    900             if (found < 0) {
    901                 j = found = eosd_surface_count;
    902                 eosd_surface_count = eosd_surface_count ? eosd_surface_count*2 : EOSD_SURFACES_INITIAL;
    903                 eosd_surfaces = realloc(eosd_surfaces, eosd_surface_count * sizeof(*eosd_surfaces));
    904                 eosd_targets  = realloc(eosd_targets,  eosd_surface_count * sizeof(*eosd_targets));
    905                 for (j = found; j < eosd_surface_count; j++) {
    906                     eosd_surfaces[j].surface = VDP_INVALID_HANDLE;
    907                     eosd_surfaces[j].in_use = 0;
    908                 }
    909             }
     899            found = eosd_surfaces_size;
     900            eosd_surfaces = realloc(eosd_surfaces, ++eosd_surfaces_size * sizeof(*eosd_surfaces));
     901            eosd_surfaces[found].w = (i->w <= EOSD_SURFACE_SIZE) ? EOSD_SURFACE_SIZE : ROUND_POT(i->w);
     902            eosd_surfaces[found].h = (i->h <= EOSD_SURFACE_SIZE) ? EOSD_SURFACE_SIZE : ROUND_POT(i->h);
     903            eosd_surfaces[found].x = eosd_surfaces[found].y = 0;
     904            eosd_surfaces[found].max_y = 0;
     905            printf("allocate %d (%dx%d)\n", found, eosd_surfaces[found].w, eosd_surfaces[found].h);
    910906            vdp_st = vdp_bitmap_surface_create(vdp_device, VDP_RGBA_FORMAT_A8,
    911                 i->w, i->h, VDP_TRUE, &eosd_surfaces[found].surface);
     907                eosd_surfaces[found].w, eosd_surfaces[found].h, VDP_TRUE, &eosd_surfaces[found].surface);
    912908            CHECK_ST_WARNING("EOSD: error when creating surface")
    913             eosd_surfaces[found].w = i->w;
    914             eosd_surfaces[found].h = i->h;
    915909        }
    916         eosd_surfaces[found].in_use = 1;
     910        // Allocate new space for targets, if needed
     911        if (eosd_render_count >= eosd_targets_size) {
     912            eosd_targets_size = eosd_targets_size ? eosd_targets_size*2 : EOSD_TARGETS_INITIAL;
     913            eosd_targets = realloc(eosd_targets, eosd_targets_size * sizeof(*eosd_targets));
     914        }
     915        // Set up render target
     916        if ((eosd_surfaces[found].x + i->w) > eosd_surfaces[found].w) {
     917            eosd_surfaces[found].y = eosd_surfaces[found].max_y;
     918            eosd_surfaces[found].x = 0;
     919        }
     920        dest_rect.x0 = eosd_surfaces[found].x;
     921        dest_rect.y0 = eosd_surfaces[found].y;
     922        dest_rect.x1 = dest_rect.x0 + i->w;
     923        dest_rect.y1 = dest_rect.y0 + i->h;
     924        eosd_surfaces[found].max_y = FFMAX(eosd_surfaces[found].max_y, eosd_surfaces[found].y + i->h);
     925        eosd_surfaces[found].x += i->w;
     926        // Render destination and color
    917927        eosd_targets[eosd_render_count].surface = eosd_surfaces[found].surface;
    918         destRect.x0 = 0;
    919         destRect.y0 = 0;
    920         destRect.x1 = i->w;
    921         destRect.y1 = i->h;
    922         vdp_st = vdp_bitmap_surface_putbits_native(eosd_targets[eosd_render_count].surface,
    923             (const void *) &i->bitmap, &i->stride, &destRect);
     928        eosd_targets[eosd_render_count].source.x0 = dest_rect.x0;
     929        eosd_targets[eosd_render_count].source.y0 = dest_rect.y0;
     930        eosd_targets[eosd_render_count].source.x1 = dest_rect.x1;
     931        eosd_targets[eosd_render_count].source.y1 = dest_rect.y1;
     932        eosd_targets[eosd_render_count].color.alpha = 1.0 - ((i->color >> 0) & 0xff) / 255.0;
     933        eosd_targets[eosd_render_count].color.blue  = ((i->color >>  8) & 0xff) / 255.0;
     934        eosd_targets[eosd_render_count].color.green = ((i->color >> 16) & 0xff) / 255.0;
     935        eosd_targets[eosd_render_count].color.red   = ((i->color >> 24) & 0xff) / 255.0;
     936        vdp_st = vdp_bitmap_surface_putbits_native(eosd_surfaces[found].surface,
     937            (const void *) &i->bitmap, &i->stride, &dest_rect);
    924938        CHECK_ST_WARNING("EOSD: putbits failed")
    925939        eosd_render_count++;
    926940    }
     941    }
    927942
    928 eosd_skip_upload:
    929943    eosd_render_count = 0;
    930     for (i = img; i; i = i->next) {
    931         // Render dest, color, etc.
    932         eosd_targets[eosd_render_count].color.alpha = 1.0 - ((i->color >>  0) & 0xff) / 255.0;
    933         eosd_targets[eosd_render_count].color.blue  =       ((i->color >>  8) & 0xff) / 255.0;
    934         eosd_targets[eosd_render_count].color.green =       ((i->color >> 16) & 0xff) / 255.0;
    935         eosd_targets[eosd_render_count].color.red   =       ((i->color >> 24) & 0xff) / 255.0;
     944    for(i = img; i; i = i->next) {
    936945        eosd_targets[eosd_render_count].dest.x0     =        i->dst_x;
    937946        eosd_targets[eosd_render_count].dest.y0     =        i->dst_y;
    938947        eosd_targets[eosd_render_count].dest.x1     = i->w + i->dst_x;
    939948        eosd_targets[eosd_render_count].dest.y1     = i->h + i->dst_y;
    940         eosd_targets[eosd_render_count].source.x0   = 0;
    941         eosd_targets[eosd_render_count].source.y0   = 0;
    942         eosd_targets[eosd_render_count].source.x1   = i->w;
    943         eosd_targets[eosd_render_count].source.y1   = i->h;
    944949        eosd_render_count++;
    945950    }
    946951}
    … …  
    11351140        CHECK_ST_WARNING("Error when calling vdp_output_surface_destroy")
    11361141    }
    11371142
    1138     for (i = 0; i<eosd_surface_count; i++) {
    1139         if (eosd_surfaces[i].surface != VDP_INVALID_HANDLE) {
    1140             vdp_st = vdp_bitmap_surface_destroy(eosd_surfaces[i].surface);
    1141             CHECK_ST_WARNING("Error when calling vdp_bitmap_surface_destroy")
    1142         }
    1143         eosd_surfaces[i].surface = VDP_INVALID_HANDLE;
     1143    for (i = 0; i < eosd_surfaces_size; i++) {
     1144        vdp_st = vdp_bitmap_surface_destroy(eosd_surfaces[i].surface);
     1145        CHECK_ST_WARNING("Error when calling vdp_bitmap_surface_destroy")
    11441146    }
    11451147
    11461148    vdp_st = vdp_device_destroy(vdp_device);
    … …  
    12681270    index_data = NULL;
    12691271    index_data_size = 0;
    12701272
    1271     eosd_surface_count = eosd_render_count = 0;
     1273    eosd_surfaces_size = eosd_targets_size = eosd_render_count = 0;
    12721274    eosd_surfaces = NULL;
    12731275    eosd_targets  = NULL;
    12741276