st/va: properly set stride and offset in vlVaDeriveImage
authorJulien Isorce <jisorce@oblong.com>
Tue, 23 Apr 2019 21:30:06 +0000 (14:30 -0700)
committerJulien Isorce <julien.isorce@gmail.com>
Tue, 30 Apr 2019 17:53:12 +0000 (17:53 +0000)
Using the new resource_get_info function.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=110443
Signed-off-by: Julien Isorce <jisorce@oblong.com>
Reviewed-by: Leo Liu <leo.liu@amd.com>
src/gallium/state_trackers/va/image.c

index f7e0db08961513886958bcd74419cdc5e404feb0..491c2d82858a84ee37ca12a25b4e944f37c4d18d 100644 (file)
@@ -197,10 +197,13 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image)
    vlVaSurface *surf;
    vlVaBuffer *img_buf;
    VAImage *img;
+   struct pipe_screen *screen;
    struct pipe_surface **surfaces;
    int w;
    int h;
    int i;
+   unsigned stride = 0;
+   unsigned offset = 0;
 
    if (!ctx)
       return VA_STATUS_ERROR_INVALID_CONTEXT;
@@ -210,6 +213,11 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image)
    if (!drv)
       return VA_STATUS_ERROR_INVALID_CONTEXT;
 
+   screen = VL_VA_PSCREEN(ctx);
+
+   if (!screen)
+      return VA_STATUS_ERROR_INVALID_CONTEXT;
+
    surf = handle_table_get(drv->htab, surface);
 
    if (!surf || !surf->buffer)
@@ -242,38 +250,45 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image)
       }
    }
 
+   mtx_lock(&drv->mutex);
+   screen->resource_get_info(screen, surfaces[0]->texture, &stride, &offset);
+   if (!stride)
+      offset = 0;
+
    switch (img->format.fourcc) {
    case VA_FOURCC('U','Y','V','Y'):
    case VA_FOURCC('Y','U','Y','V'):
-      img->num_planes = 1;
-      img->pitches[0] = w * 2;
-      img->offsets[0] = 0;
-      img->data_size  = w * h * 2;
+      assert(stride >= (w * 2));
+      img->pitches[0] = stride > 0 ? stride : w * 2;
       break;
 
    case VA_FOURCC('B','G','R','A'):
    case VA_FOURCC('R','G','B','A'):
    case VA_FOURCC('B','G','R','X'):
    case VA_FOURCC('R','G','B','X'):
-      img->num_planes = 1;
-      img->pitches[0] = w * 4;
-      img->offsets[0] = 0;
-      img->data_size  = w * h * 4;
+      assert(stride >= (w * 4));
+      img->pitches[0] = stride > 0 ? stride : w * 4;
       break;
 
    default:
-      /* VaDeriveImage is designed for contiguous planes. */
+      /* VaDeriveImage only supports contiguous planes. But there is now a
+         more generic api vlVaExportSurfaceHandle. */
       FREE(img);
+      mtx_unlock(&drv->mutex);
       return VA_STATUS_ERROR_OPERATION_FAILED;
    }
 
+   img->num_planes = 1;
+   img->offsets[0] = offset;
+   img->data_size  = img->pitches[0] * h;
+
    img_buf = CALLOC(1, sizeof(vlVaBuffer));
    if (!img_buf) {
       FREE(img);
+      mtx_unlock(&drv->mutex);
       return VA_STATUS_ERROR_ALLOCATION_FAILED;
    }
 
-   mtx_lock(&drv->mutex);
    img->image_id = handle_table_add(drv->htab, img);
 
    img_buf->type = VAImageBufferType;