Convert RGBx/RGBA into non-NV12 format
authorXiang, Haihao <haihao.xiang@intel.com>
Tue, 20 Aug 2013 14:02:09 +0000 (22:02 +0800)
committerXiang, Haihao <haihao.xiang@intel.com>
Mon, 9 Sep 2013 07:02:52 +0000 (15:02 +0800)
It is the combined conversions of RGBx/RGBA->NV12 and NV12->non-NV12.
It would be better to implement RGBx/RGBA->YUV444 and YUV444->non-444 later

Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
src/i965_post_processing.c

index bf1f7e1..23865bf 100755 (executable)
@@ -1100,6 +1100,22 @@ pp_get_surface_fourcc(VADriverContextP ctx, const struct i965_surface *surface)
 }
 
 static void
+pp_get_surface_size(VADriverContextP ctx, const struct i965_surface *surface, int *width, int *height)
+{
+    if (surface->type == I965_SURFACE_TYPE_IMAGE) {
+        struct object_image *obj_image = (struct object_image *)surface->base;
+
+        *width = obj_image->image.width;
+        *height = obj_image->image.height;
+    } else {
+        struct object_surface *obj_surface = (struct object_surface *)surface->base;
+
+        *width = obj_surface->orig_width;
+        *height = obj_surface->orig_height;
+    }
+}
+
+static void
 pp_set_surface_tiling(struct i965_surface_state *ss, unsigned int tiling)
 {
     switch (tiling) {
@@ -4777,6 +4793,13 @@ i965_post_processing(
 }       
 
 static VAStatus
+i965_image_pl2_processing(VADriverContextP ctx,
+                          const struct i965_surface *src_surface,
+                          const VARectangle *src_rect,
+                          struct i965_surface *dst_surface,
+                          const VARectangle *dst_rect);
+
+static VAStatus
 i965_image_pl1_rgbx_processing(VADriverContextP ctx,
                                const struct i965_surface *src_surface,
                                const VARectangle *src_rect,
@@ -4795,14 +4818,51 @@ i965_image_pl1_rgbx_processing(VADriverContextP ctx,
                                       dst_rect,
                                       PP_RGBX_LOAD_SAVE_NV12,
                                       NULL);
+        intel_batchbuffer_flush(pp_context->batch);
+
+        return VA_STATUS_SUCCESS;
     } else {
-        assert(0);
-        return VA_STATUS_ERROR_UNKNOWN;
-    }
+        VAStatus status;
+        VASurfaceID out_surface_id = VA_INVALID_SURFACE;
+        struct object_surface *obj_surface = NULL;
+        struct i965_surface tmp_surface;
+        int width, height;
 
-    intel_batchbuffer_flush(pp_context->batch);
+        pp_get_surface_size(ctx, dst_surface, &width, &height);
+        status = i965_CreateSurfaces(ctx,
+                                     width,
+                                     height,
+                                     VA_RT_FORMAT_YUV420,
+                                     1,
+                                     &out_surface_id);
+        assert(status == VA_STATUS_SUCCESS);
+        obj_surface = SURFACE(out_surface_id);
+        assert(obj_surface);
+        i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC('N', 'V', '1', '2'), SUBSAMPLE_YUV420);
 
-    return VA_STATUS_SUCCESS;
+        tmp_surface.base = (struct object_base *)obj_surface;
+        tmp_surface.type = I965_SURFACE_TYPE_SURFACE;
+        tmp_surface.flags = I965_SURFACE_FLAG_FRAME;
+
+        status = i965_image_pl1_rgbx_processing(ctx,
+                                                src_surface,
+                                                src_rect,
+                                                &tmp_surface,
+                                                dst_rect);
+
+        if (status == VA_STATUS_SUCCESS)
+            status = i965_image_pl2_processing(ctx,
+                                               &tmp_surface,
+                                               dst_rect,
+                                               dst_surface,
+                                               dst_rect);
+
+        i965_DestroySurfaces(ctx,
+                             &out_surface_id,
+                             1);
+
+        return status;
+    }
 }
 
 static VAStatus
@@ -4907,8 +4967,7 @@ i965_image_pl2_processing(VADriverContextP ctx,
                                                  PP_NV12_LOAD_SAVE_RGBX,
                                                  NULL);
     } else {
-        assert(0);
-        return VA_STATUS_ERROR_UNKNOWN;
+        return VA_STATUS_ERROR_UNIMPLEMENTED;
     }
 
     intel_batchbuffer_flush(pp_context->batch);