commit 446cd618ec79c55e0044c7bdd565a66a768d0e6e
Author: Gwenole Beauchesne <gbeauchesne@splitted-desktop.com>
Date:   Wed Nov 4 13:16:34 2009 +0000

    [G45] Implement vaGetImage() for full-sized surface readback.

diff --git a/i965_drv_video/i965_drv_video.c b/i965_drv_video/i965_drv_video.c
index ad51b6c..80c61ca 100644
--- a/i965_drv_video/i965_drv_video.c
+++ b/i965_drv_video/i965_drv_video.c
@@ -1481,7 +1481,54 @@ i965_GetImage(VADriverContextP ctx,
               unsigned int height,
               VAImageID image)
 {
-    return VA_STATUS_SUCCESS;
+    struct i965_driver_data *i965 = i965_driver_data(ctx);
+    struct i965_render_state *render_state = &i965->render_state;
+
+    struct object_surface *obj_surface = SURFACE(surface);
+    if (!obj_surface)
+        return VA_STATUS_ERROR_INVALID_SURFACE;
+
+    struct object_image *obj_image = IMAGE(image);
+    if (!obj_image)
+        return VA_STATUS_ERROR_INVALID_IMAGE;
+
+    /* XXX: we only support full-size surface readback */
+    if (x != 0 ||
+        y != 0 ||
+        width != obj_surface->width ||
+        height != obj_surface->height)
+        return VA_STATUS_ERROR_INVALID_PARAMETER;
+
+    /* XXX: we only support 1:1 image copies */
+    if (width != obj_image->image.width ||
+        height != obj_image->image.height)
+        return VA_STATUS_ERROR_INVALID_PARAMETER;
+
+    VAStatus va_status;
+    void *image_data = NULL;
+
+    va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
+    if (va_status != VA_STATUS_SUCCESS)
+        return va_status;
+
+    dri_bo_map(obj_surface->bo, 0);
+
+    switch (obj_image->image.format.fourcc) {
+    case VA_FOURCC('Y','V','1','2'): /* YV12 is native format here */
+        if (render_state->interleaved_uv)
+            goto operation_failed;
+        memcpy(image_data, obj_surface->bo->virtual, obj_surface->bo->size);
+        break;
+    default:
+    operation_failed:
+        va_status = VA_STATUS_ERROR_OPERATION_FAILED;
+        break;
+    }
+
+    dri_bo_unmap(obj_surface->bo);
+
+    i965_UnmapBuffer(ctx, obj_image->image.buf);
+    return va_status;
 }
 
 VAStatus 
