render: prepare for display attributes.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Wed, 29 Aug 2012 15:27:25 +0000 (17:27 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Thu, 20 Sep 2012 09:05:57 +0000 (11:05 +0200)
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
(cherry picked from commit 8dda3077e56d95c937e92ee6d6964fe6a22e9fd0)

src/i965_drv_video.c
src/i965_drv_video.h

index 7b5ab7e..7c8e30c 100755 (executable)
@@ -33,6 +33,7 @@
 #endif
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <string.h>
 #include <assert.h>
 
@@ -106,6 +107,10 @@ enum {
     I965_SURFACETYPE_INDEXED
 };
 
+/* List of supported display attributes */
+static const VADisplayAttribute i965_display_attributes[] = {
+};
+
 /* List of supported image formats */
 typedef struct {
     unsigned int        type;
@@ -1922,6 +1927,52 @@ i965_QuerySurfaceStatus(VADriverContextP ctx,
     return VA_STATUS_SUCCESS;
 }
 
+static VADisplayAttribute *
+get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
+{
+    struct i965_driver_data * const i965 = i965_driver_data(ctx);
+    unsigned int i;
+
+    if (!i965->display_attributes)
+        return NULL;
+
+    for (i = 0; i < i965->num_display_attributes; i++) {
+        if (i965->display_attributes[i].type == type)
+            return &i965->display_attributes[i];
+    }
+    return NULL;
+}
+
+static bool
+i965_display_attributes_init(VADriverContextP ctx)
+{
+    struct i965_driver_data * const i965 = i965_driver_data(ctx);
+
+    i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
+    i965->display_attributes = malloc(
+        i965->num_display_attributes * sizeof(i965->display_attributes[0]));
+    if (!i965->display_attributes)
+        return false;
+
+    memcpy(
+        i965->display_attributes,
+        i965_display_attributes,
+        sizeof(i965_display_attributes)
+    );
+    return true;
+}
+
+static void
+i965_display_attributes_terminate(VADriverContextP ctx)
+{
+    struct i965_driver_data * const i965 = i965_driver_data(ctx);
+
+    if (i965->display_attributes) {
+        free(i965->display_attributes);
+        i965->display_attributes = NULL;
+        i965->num_display_attributes = 0;
+    }
+}
 
 /* 
  * Query display attributes 
@@ -1930,12 +1981,19 @@ i965_QuerySurfaceStatus(VADriverContextP ctx,
  * returned in "attr_list" is returned in "num_attributes".
  */
 VAStatus 
-i965_QueryDisplayAttributes(VADriverContextP ctx,
-                            VADisplayAttribute *attr_list,    /* out */
-                            int *num_attributes)              /* out */
+i965_QueryDisplayAttributes(
+    VADriverContextP    ctx,
+    VADisplayAttribute *attribs,        /* out */
+    int                *num_attribs_ptr /* out */
+)
 {
-    if (num_attributes)
-        *num_attributes = 0;
+    const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
+
+    if (attribs && num_attribs > 0)
+        memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
+
+    if (num_attribs_ptr)
+        *num_attribs_ptr = num_attribs;
 
     return VA_STATUS_SUCCESS;
 }
@@ -1947,12 +2005,27 @@ i965_QueryDisplayAttributes(VADriverContextP ctx,
  * from vaQueryDisplayAttributes() can have their values retrieved.  
  */
 VAStatus 
-i965_GetDisplayAttributes(VADriverContextP ctx,
-                          VADisplayAttribute *attr_list,    /* in/out */
-                          int num_attributes)
+i965_GetDisplayAttributes(
+    VADriverContextP    ctx,
+    VADisplayAttribute *attribs,        /* inout */
+    int                 num_attribs     /* in */
+)
 {
-    /* TODO */
-    return VA_STATUS_ERROR_UNIMPLEMENTED;
+    int i;
+
+    for (i = 0; i < num_attribs; i++) {
+        VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
+
+        src_attrib = get_display_attribute(ctx, dst_attrib->type);
+        if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
+            dst_attrib->min_value = src_attrib->min_value;
+            dst_attrib->max_value = src_attrib->max_value;
+            dst_attrib->value     = src_attrib->value;
+        }
+        else
+            dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
+    }
+    return VA_STATUS_SUCCESS;
 }
 
 /* 
@@ -1962,12 +2035,32 @@ i965_GetDisplayAttributes(VADriverContextP ctx,
  * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
  */
 VAStatus 
-i965_SetDisplayAttributes(VADriverContextP ctx,
-                          VADisplayAttribute *attr_list,
-                          int num_attributes)
+i965_SetDisplayAttributes(
+    VADriverContextP    ctx,
+    VADisplayAttribute *attribs,        /* in */
+    int                 num_attribs     /* in */
+)
 {
-    /* TODO */
-    return VA_STATUS_ERROR_UNIMPLEMENTED;
+    int i;
+
+    for (i = 0; i < num_attribs; i++) {
+        VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
+
+        dst_attrib = get_display_attribute(ctx, src_attrib->type);
+        if (!dst_attrib)
+            return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
+
+        if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
+            continue;
+
+        if (src_attrib->value < dst_attrib->min_value ||
+            src_attrib->value > dst_attrib->max_value)
+            return VA_STATUS_ERROR_INVALID_PARAMETER;
+
+        dst_attrib->value = src_attrib->value;
+        /* XXX: track modified attributes through timestamps */
+    }
+    return VA_STATUS_SUCCESS;
 }
 
 VAStatus 
@@ -2001,6 +2094,9 @@ i965_Init(VADriverContextP ctx)
 
     i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER);
 
+    if (!i965_display_attributes_init(ctx))
+        return VA_STATUS_ERROR_UNKNOWN;
+
     if (i965_post_processing_init(ctx) == False)
         return VA_STATUS_ERROR_UNKNOWN;
 
@@ -3374,6 +3470,8 @@ i965_Terminate(VADriverContextP ctx)
     if (i965_post_processing_terminate(ctx) == False)
         return VA_STATUS_ERROR_UNKNOWN;
 
+    i965_display_attributes_terminate(ctx);
+
     i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
     i965_destroy_heap(&i965->image_heap, i965_destroy_image);
     i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
@@ -3842,7 +3940,7 @@ VA_DRIVER_INIT_FUNC(  VADriverContextP ctx )
     ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
     ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
     ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
-    ctx->max_display_attributes = I965_MAX_DISPLAY_ATTRIBUTES;
+    ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
 
     vtable->vaTerminate = i965_Terminate;
     vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
index 9515a49..89ce906 100644 (file)
@@ -45,7 +45,6 @@
 #define I965_MAX_CONFIG_ATTRIBUTES              10
 #define I965_MAX_IMAGE_FORMATS                  10
 #define I965_MAX_SUBPIC_FORMATS                 4
-#define I965_MAX_DISPLAY_ATTRIBUTES             4
 
 #define INTEL_STR_DRIVER_VENDOR                 "Intel"
 #define INTEL_STR_DRIVER_NAME                   "i965"
@@ -273,6 +272,9 @@ struct i965_driver_data
     struct i965_render_state render_state;
     void *pp_context;
     char va_vendor[256];
+    VADisplayAttribute *display_attributes;
+    unsigned int num_display_attributes;
     
     VAContextID current_context_id;