st/va: added internal storage for VAImage and BGRA format
authorMichael Varga <Michael.Varga@amd.com>
Mon, 3 Nov 2014 16:35:28 +0000 (10:35 -0600)
committerLeo Liu <leo.liu@amd.com>
Wed, 19 Nov 2014 14:29:11 +0000 (09:29 -0500)
When calling vaCreateImage() an internal copy of VAImage is maintained
since the allocation of "image" may not be guaranteed to live long enough.

Signed-off-by: Michael Varga <Michael.Varga@amd.com>
src/gallium/state_trackers/va/image.c
src/gallium/state_trackers/va/va_private.h

index a30155e26c973246394830e1f0af978de5679e29..022240df84f9045583d272cc06b05a64b599e47b 100644 (file)
@@ -44,6 +44,7 @@ static const VAImageFormat formats[VL_VA_MAX_IMAGE_FORMATS] =
    {VA_FOURCC('Y','V','1','2')},
    {VA_FOURCC('Y','U','Y','V')},
    {VA_FOURCC('U','Y','V','Y')},
+   {VA_FOURCC('B','G','R','A')}
 };
 
 static void
@@ -93,7 +94,9 @@ vlVaQueryImageFormats(VADriverContextP ctx, VAImageFormat *format_list, int *num
 VAStatus
 vlVaCreateImage(VADriverContextP ctx, VAImageFormat *format, int width, int height, VAImage *image)
 {
+   VAStatus status;
    vlVaDriver *drv;
+   VAImage *img;
    int w, h;
 
    if (!ctx)
@@ -104,50 +107,66 @@ vlVaCreateImage(VADriverContextP ctx, VAImageFormat *format, int width, int heig
 
    drv = VL_VA_DRIVER(ctx);
 
-   image->image_id = handle_table_add(drv->htab, image);
-   image->format = *format;
-   image->width = width;
-   image->height = height;
+   img = CALLOC(1, sizeof(VAImage));
+   if (!img)
+      return VA_STATUS_ERROR_ALLOCATION_FAILED;
+   img->image_id = handle_table_add(drv->htab, img);
+
+   img->format = *format;
+   img->width = width;
+   img->height = height;
    w = align(width, 2);
    h = align(width, 2);
 
    switch (format->fourcc) {
    case VA_FOURCC('N','V','1','2'):
-      image->num_planes = 2;
-      image->pitches[0] = w;
-      image->offsets[0] = 0;
-      image->pitches[1] = w;
-      image->offsets[1] = w * h;
-      image->data_size  = w * h * 3 / 2;
+      img->num_planes = 2;
+      img->pitches[0] = w;
+      img->offsets[0] = 0;
+      img->pitches[1] = w;
+      img->offsets[1] = w * h;
+      img->data_size  = w * h * 3 / 2;
       break;
 
    case VA_FOURCC('I','4','2','0'):
    case VA_FOURCC('Y','V','1','2'):
-      image->num_planes = 3;
-      image->pitches[0] = w;
-      image->offsets[0] = 0;
-      image->pitches[1] = w / 2;
-      image->offsets[1] = w * h;
-      image->pitches[2] = w / 2;
-      image->offsets[2] = w * h * 5 / 4;
-      image->data_size  = w * h * 3 / 2;
+      img->num_planes = 3;
+      img->pitches[0] = w;
+      img->offsets[0] = 0;
+      img->pitches[1] = w / 2;
+      img->offsets[1] = w * h;
+      img->pitches[2] = w / 2;
+      img->offsets[2] = w * h * 5 / 4;
+      img->data_size  = w * h * 3 / 2;
       break;
 
    case VA_FOURCC('U','Y','V','Y'):
    case VA_FOURCC('Y','U','Y','V'):
-      image->num_planes = 1;
-      image->pitches[0] = w * 2;
-      image->offsets[0] = 0;
-      image->data_size  = w * h * 2;
+      img->num_planes = 1;
+      img->pitches[0] = w * 2;
+      img->offsets[0] = 0;
+      img->data_size  = w * h * 2;
+      break;
+
+   case VA_FOURCC('B','G','R','A'):
+      img->num_planes = 1;
+      img->pitches[0] = w * 4;
+      img->offsets[0] = 0;
+      img->data_size  = w * h * 4;
       break;
 
    default:
       return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
    }
 
-   return vlVaCreateBuffer(ctx, 0, VAImageBufferType,
-                           align(image->data_size, 16),
-                           1, NULL, &image->buf);
+   status =  vlVaCreateBuffer(ctx, 0, VAImageBufferType,
+                           align(img->data_size, 16),
+                           1, NULL, &img->buf);
+   if (status != VA_STATUS_SUCCESS)
+      return status;
+   *image = *img;
+
+   return status;
 }
 
 VAStatus
@@ -172,6 +191,7 @@ vlVaDestroyImage(VADriverContextP ctx, VAImageID image)
       return VA_STATUS_ERROR_INVALID_IMAGE;
 
    handle_table_remove(VL_VA_DRIVER(ctx)->htab, image);
+   FREE(vaimage);
    return vlVaDestroyBuffer(ctx, vaimage->buf);
 }
 
index 7d2fc24ca71bde3665d723f018406a8773d2eb17..f250f74d2efc6e9bf580d88c8b28bcb927398270 100644 (file)
@@ -44,7 +44,7 @@
 #define VL_VA_DRIVER(ctx) ((vlVaDriver *)ctx->pDriverData)
 #define VL_VA_PSCREEN(ctx) (VL_VA_DRIVER(ctx)->vscreen->pscreen)
 
-#define VL_VA_MAX_IMAGE_FORMATS 5
+#define VL_VA_MAX_IMAGE_FORMATS 6
 
 static inline enum pipe_video_chroma_format
 ChromaToPipe(int format)
@@ -76,6 +76,8 @@ YCbCrToPipe(unsigned format)
       return PIPE_FORMAT_YUYV;
    case VA_FOURCC('U','Y','V','Y'):
       return PIPE_FORMAT_UYVY;
+   case VA_FOURCC('B','G','R','A'):
+      return PIPE_FORMAT_B8G8R8A8_UNORM;
    default:
       assert(0);
       return PIPE_FORMAT_NONE;