Home | History | Annotate | Download | only in va
      1 /**************************************************************************
      2  *
      3  * Copyright 2010 Thomas Balling Srensen & Orasanu Lucian.
      4  * All Rights Reserved.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the
      8  * "Software"), to deal in the Software without restriction, including
      9  * without limitation the rights to use, copy, modify, merge, publish,
     10  * distribute, sub license, and/or sell copies of the Software, and to
     11  * permit persons to whom the Software is furnished to do so, subject to
     12  * the following conditions:
     13  *
     14  * The above copyright notice and this permission notice (including the
     15  * next paragraph) shall be included in all copies or substantial portions
     16  * of the Software.
     17  *
     18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
     21  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
     22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     25  *
     26  **************************************************************************/
     27 
     28 #include <va/va.h>
     29 #include <va/va_backend.h>
     30 
     31 #include "pipe/p_format.h"
     32 
     33 #include "util/u_memory.h"
     34 #include "util/u_format.h"
     35 #include "util/u_debug.h"
     36 
     37 #include "va_private.h"
     38 
     39 typedef struct  {
     40    enum pipe_format pipe_format;
     41    VAImageFormat       va_format;
     42 } va_image_formats_supported_t;
     43 
     44 static const va_image_formats_supported_t va_image_formats_supported[VA_MAX_IMAGE_FORMATS_SUPPORTED] =
     45 {
     46    { PIPE_FORMAT_B8G8R8A8_UNORM,
     47       { VA_FOURCC('B','G','R','A'), VA_LSB_FIRST, 32, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }},
     48    { PIPE_FORMAT_R8G8B8A8_UNORM,
     49       { VA_FOURCC_RGBA, VA_LSB_FIRST, 32, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }}
     50 };
     51 
     52 VAStatus
     53 vlVaQueryImageFormats(VADriverContextP ctx, VAImageFormat *format_list, int *num_formats)
     54 {
     55    if (!ctx)
     56       return VA_STATUS_ERROR_INVALID_CONTEXT;
     57 
     58    if (!(format_list && num_formats))
     59       return VA_STATUS_ERROR_UNKNOWN;
     60 
     61    int n = 0;
     62 
     63    num_formats[0] = VA_MAX_IMAGE_FORMATS_SUPPORTED;
     64 
     65    /* Query supported formats */
     66    for (n = 0; n < VA_MAX_IMAGE_FORMATS_SUPPORTED; n++) {
     67       format_list[n] = va_image_formats_supported[n].va_format;
     68    }
     69 
     70    return VA_STATUS_SUCCESS;
     71 }
     72 
     73 VAStatus
     74 vlVaCreateImage(VADriverContextP ctx, VAImageFormat *format, int width, int height, VAImage *image)
     75 {
     76    if (!ctx)
     77       return VA_STATUS_ERROR_INVALID_CONTEXT;
     78 
     79    if(!format)
     80       return VA_STATUS_ERROR_UNKNOWN;
     81 
     82    if (!(width && height))
     83       return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
     84 
     85    if (!vlCreateHTAB())
     86       return VA_STATUS_ERROR_UNKNOWN;
     87 
     88    switch (format->fourcc) {
     89    case VA_FOURCC('B','G','R','A'):
     90       VA_INFO("Creating BGRA image of size %dx%d\n",width,height);
     91       break;
     92    case VA_FOURCC_RGBA:
     93       VA_INFO("Creating RGBA image of size %dx%d\n",width,height);
     94       break;
     95    default:
     96       VA_ERROR("Couldn't create image of type %0x08\n",format->fourcc);
     97       return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
     98    }
     99 
    100    VA_INFO("Image %p created successfully\n",format);
    101 
    102    return VA_STATUS_SUCCESS;
    103 }
    104 
    105 VAStatus
    106 vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image)
    107 {
    108    if (!ctx)
    109       return VA_STATUS_ERROR_INVALID_CONTEXT;
    110 
    111    return VA_STATUS_ERROR_UNIMPLEMENTED;
    112 }
    113 
    114 VAStatus
    115 vlVaDestroyImage(VADriverContextP ctx, VAImageID image)
    116 {
    117    if (!ctx)
    118       return VA_STATUS_ERROR_INVALID_CONTEXT;
    119 
    120    return VA_STATUS_ERROR_UNIMPLEMENTED;
    121 }
    122 
    123 VAStatus
    124 vlVaSetImagePalette(VADriverContextP ctx, VAImageID image, unsigned char *palette)
    125 {
    126    if (!ctx)
    127       return VA_STATUS_ERROR_INVALID_CONTEXT;
    128 
    129    return VA_STATUS_ERROR_UNIMPLEMENTED;
    130 }
    131 
    132 VAStatus
    133 vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y,
    134              unsigned int width, unsigned int height, VAImageID image)
    135 {
    136    if (!ctx)
    137       return VA_STATUS_ERROR_INVALID_CONTEXT;
    138 
    139    return VA_STATUS_ERROR_UNIMPLEMENTED;
    140 }
    141 
    142 VAStatus
    143 vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image,
    144              int src_x, int src_y, unsigned int src_width, unsigned int src_height,
    145              int dest_x, int dest_y, unsigned int dest_width, unsigned int dest_height)
    146 {
    147    if (!ctx)
    148       return VA_STATUS_ERROR_INVALID_CONTEXT;
    149 
    150    return VA_STATUS_ERROR_UNIMPLEMENTED;
    151 }
    152