va.c 34.8 KB
Newer Older
Waldo Bastian's avatar
Waldo Bastian committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

Gwenole Beauchesne's avatar
Gwenole Beauchesne committed
25
#define _GNU_SOURCE 1
Waldo Bastian's avatar
Waldo Bastian committed
26 27 28
#include "va.h"
#include "va_backend.h"

Austin Yuan's avatar
Austin Yuan committed
29
#include <assert.h>
Waldo Bastian's avatar
Waldo Bastian committed
30 31
#include <stdarg.h>
#include <stdio.h>
32
#include <stdlib.h>
Waldo Bastian's avatar
Waldo Bastian committed
33 34 35
#include <string.h>
#include <dlfcn.h>
#include <unistd.h>
Austin Yuan's avatar
Austin Yuan committed
36

37

38
#define DRIVER_INIT_FUNC	"__vaDriverInit_0_31"
Waldo Bastian's avatar
Waldo Bastian committed
39

Waldo Bastian's avatar
Waldo Bastian committed
40 41
#define DRIVER_EXTENSION	"_drv_video.so"

Austin Yuan's avatar
Austin Yuan committed
42 43 44
#define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
#define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }

Waldo Bastian's avatar
Waldo Bastian committed
45 46 47
#define ASSERT		assert
#define CHECK_VTABLE(s, ctx, func) if (!va_checkVtable(ctx->vtable.va##func, #func)) s = VA_STATUS_ERROR_UNKNOWN;
#define CHECK_MAXIMUM(s, ctx, var) if (!va_checkMaximum(ctx->max_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
Waldo Bastian's avatar
Waldo Bastian committed
48
#define CHECK_STRING(s, ctx, var) if (!va_checkString(ctx->str_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
Waldo Bastian's avatar
Waldo Bastian committed
49

Austin Yuan's avatar
Austin Yuan committed
50 51 52 53 54 55
extern int trace_flag;
#define VA_TRACE(trace_func,...)                \
    if (trace_flag) {                           \
        va_TraceMsg("========%s========\n", __func__);   \
        trace_func(__VA_ARGS__);                \
    }
Waldo Bastian's avatar
Waldo Bastian committed
56

57 58 59
static int vaDisplayIsValid(VADisplay dpy)
{
  VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
60
  return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
61
}
Waldo Bastian's avatar
Waldo Bastian committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

static void va_errorMessage(const char *msg, ...)
{
    va_list args;

    fprintf(stderr, "libva error: ");
    va_start(args, msg);
    vfprintf(stderr, msg, args);
    va_end(args);
}

static void va_infoMessage(const char *msg, ...)
{
    va_list args;

    fprintf(stderr, "libva: ");
    va_start(args, msg);
    vfprintf(stderr, msg, args);
    va_end(args);
}

static Bool va_checkVtable(void *ptr, char *function)
{
    if (!ptr)
    {
        va_errorMessage("No valid vtable entry for va%s\n", function);
        return False;
    }
    return True;
}

static Bool va_checkMaximum(int value, char *variable)
{
    if (!value)
    {
        va_errorMessage("Failed to define max_%s in init\n", variable);
        return False;
    }
    return True;
}

Waldo Bastian's avatar
Waldo Bastian committed
103 104 105 106 107 108 109 110 111 112
static Bool va_checkString(const char* value, char *variable)
{
    if (!value)
    {
        va_errorMessage("Failed to define str_%s in init\n", variable);
        return False;
    }
    return True;
}

Austin Yuan's avatar
Austin Yuan committed
113
static VAStatus va_getDriverName(VADisplay dpy, char **driver_name)
Waldo Bastian's avatar
Waldo Bastian committed
114
{
Austin Yuan's avatar
Austin Yuan committed
115
    VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
116

117
    return pDisplayContext->vaGetDriverName(pDisplayContext, driver_name);
Waldo Bastian's avatar
Waldo Bastian committed
118 119
}

Austin Yuan's avatar
Austin Yuan committed
120
static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
Waldo Bastian's avatar
Waldo Bastian committed
121
{
Austin Yuan's avatar
Austin Yuan committed
122
    VADriverContextP ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
123
    VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
124
    char *search_path = NULL;
Waldo Bastian's avatar
Waldo Bastian committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138
    char *saveptr;
    char *driver_dir;
    
    if (geteuid() == getuid())
    {
        /* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
        search_path = getenv("LIBVA_DRIVERS_PATH");
        if (!search_path)
        {
            search_path = getenv("LIBGL_DRIVERS_PATH");
        }
    }
    if (!search_path)
    {
139
        search_path = VA_DRIVERS_PATH;
Waldo Bastian's avatar
Waldo Bastian committed
140 141
    }

142 143
    search_path = strdup((const char *)search_path);
    driver_dir = strtok_r((const char *)search_path, ":", &saveptr);
Waldo Bastian's avatar
Waldo Bastian committed
144 145 146 147 148 149
    while(driver_dir)
    {
        void *handle = NULL;
        char *driver_path = (char *) malloc( strlen(driver_dir) +
                                             strlen(driver_name) +
                                             strlen(DRIVER_EXTENSION) + 2 );
Austin Yuan's avatar
Austin Yuan committed
150 151 152 153
        strncpy( driver_path, driver_dir, strlen(driver_dir) + 1);
        strncat( driver_path, "/", strlen("/") );
        strncat( driver_path, driver_name, strlen(driver_name) );
        strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
Waldo Bastian's avatar
Waldo Bastian committed
154 155 156
        
        va_infoMessage("Trying to open %s\n", driver_path);

Austin Yuan's avatar
Austin Yuan committed
157
        handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
Waldo Bastian's avatar
Waldo Bastian committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
        if (!handle)
        {
            /* Don't give errors for non-existing files */
            if (0 == access( driver_path, F_OK))
            {	
                va_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
            }
        }
        else
        {
            VADriverInit init_func;
            init_func = (VADriverInit) dlsym(handle, DRIVER_INIT_FUNC);
            if (!init_func)
            {
                va_errorMessage("%s has no function %s\n", driver_path, DRIVER_INIT_FUNC);
                dlclose(handle);
            }
            else
            {
                vaStatus = (*init_func)(ctx);

                if (VA_STATUS_SUCCESS == vaStatus)
                {
                    CHECK_MAXIMUM(vaStatus, ctx, profiles);
                    CHECK_MAXIMUM(vaStatus, ctx, entrypoints);
                    CHECK_MAXIMUM(vaStatus, ctx, attributes);
                    CHECK_MAXIMUM(vaStatus, ctx, image_formats);
                    CHECK_MAXIMUM(vaStatus, ctx, subpic_formats);
Waldo Bastian's avatar
Waldo Bastian committed
186
                    CHECK_MAXIMUM(vaStatus, ctx, display_attributes);
Waldo Bastian's avatar
Waldo Bastian committed
187
                    CHECK_STRING(vaStatus, ctx, vendor);
Waldo Bastian's avatar
Waldo Bastian committed
188 189 190 191 192
                    CHECK_VTABLE(vaStatus, ctx, Terminate);
                    CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles);
                    CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints);
                    CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes);
                    CHECK_VTABLE(vaStatus, ctx, CreateConfig);
Waldo Bastian's avatar
Waldo Bastian committed
193
                    CHECK_VTABLE(vaStatus, ctx, DestroyConfig);
Waldo Bastian's avatar
Waldo Bastian committed
194 195
                    CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes);
                    CHECK_VTABLE(vaStatus, ctx, CreateSurfaces);
Waldo Bastian's avatar
Waldo Bastian committed
196
                    CHECK_VTABLE(vaStatus, ctx, DestroySurfaces);
Waldo Bastian's avatar
Waldo Bastian committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
                    CHECK_VTABLE(vaStatus, ctx, CreateContext);
                    CHECK_VTABLE(vaStatus, ctx, DestroyContext);
                    CHECK_VTABLE(vaStatus, ctx, CreateBuffer);
                    CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements);
                    CHECK_VTABLE(vaStatus, ctx, MapBuffer);
                    CHECK_VTABLE(vaStatus, ctx, UnmapBuffer);
                    CHECK_VTABLE(vaStatus, ctx, DestroyBuffer);
                    CHECK_VTABLE(vaStatus, ctx, BeginPicture);
                    CHECK_VTABLE(vaStatus, ctx, RenderPicture);
                    CHECK_VTABLE(vaStatus, ctx, EndPicture);
                    CHECK_VTABLE(vaStatus, ctx, SyncSurface);
                    CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus);
                    CHECK_VTABLE(vaStatus, ctx, PutSurface);
                    CHECK_VTABLE(vaStatus, ctx, QueryImageFormats);
                    CHECK_VTABLE(vaStatus, ctx, CreateImage);
212
                    CHECK_VTABLE(vaStatus, ctx, DeriveImage);
Waldo Bastian's avatar
Waldo Bastian committed
213
                    CHECK_VTABLE(vaStatus, ctx, DestroyImage);
Waldo Bastian's avatar
Waldo Bastian committed
214
                    CHECK_VTABLE(vaStatus, ctx, SetImagePalette);
Waldo Bastian's avatar
Waldo Bastian committed
215 216 217 218 219 220 221 222 223
                    CHECK_VTABLE(vaStatus, ctx, GetImage);
                    CHECK_VTABLE(vaStatus, ctx, PutImage);
                    CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats);
                    CHECK_VTABLE(vaStatus, ctx, CreateSubpicture);
                    CHECK_VTABLE(vaStatus, ctx, DestroySubpicture);
                    CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage);
                    CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey);
                    CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha);
                    CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture);
Waldo Bastian's avatar
Waldo Bastian committed
224
                    CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture);
Waldo Bastian's avatar
Waldo Bastian committed
225 226 227
                    CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes);
                    CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes);
                    CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes);
Waldo Bastian's avatar
Waldo Bastian committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
                }
                if (VA_STATUS_SUCCESS != vaStatus)
                {
                    va_errorMessage("%s init failed\n", driver_path);
                    dlclose(handle);
                }
                if (VA_STATUS_SUCCESS == vaStatus)
                {
                    ctx->handle = handle;
                }
                free(driver_path);
                break;
            }
        }
        free(driver_path);
        
        driver_dir = strtok_r(NULL, ":", &saveptr);
    }
    
    free(search_path);    
    
    return vaStatus;
}

252 253
VAPrivFunc vaGetLibFunc(VADisplay dpy, const char *func)
{
Austin Yuan's avatar
Austin Yuan committed
254 255
    VADriverContextP ctx;
    if( !vaDisplayIsValid(dpy) )
256
        return NULL;
Austin Yuan's avatar
Austin Yuan committed
257
    ctx = CTX(dpy);
258 259 260 261 262 263 264

    if (NULL == ctx->handle)
        return NULL;
        
    return (VAPrivFunc) dlsym(ctx->handle, func);
}

Waldo Bastian's avatar
Waldo Bastian committed
265 266 267 268 269 270 271 272 273 274

/*
 * Returns a short english description of error_status
 */
const char *vaErrorStr(VAStatus error_status)
{
    switch(error_status)
    {
        case VA_STATUS_SUCCESS:
            return "success (no error)";
275 276
        case VA_STATUS_ERROR_OPERATION_FAILED:
            return "operation failed";
Waldo Bastian's avatar
Waldo Bastian committed
277 278
        case VA_STATUS_ERROR_ALLOCATION_FAILED:
            return "resource allocation failed";
279 280
        case VA_STATUS_ERROR_INVALID_DISPLAY:
            return "invalid VADisplay";
Waldo Bastian's avatar
Waldo Bastian committed
281 282 283 284 285 286 287 288
        case VA_STATUS_ERROR_INVALID_CONFIG:
            return "invalid VAConfigID";
        case VA_STATUS_ERROR_INVALID_CONTEXT:
            return "invalid VAContextID";
        case VA_STATUS_ERROR_INVALID_SURFACE:
            return "invalid VASurfaceID";
        case VA_STATUS_ERROR_INVALID_BUFFER:
            return "invalid VABufferID";
289 290 291 292
        case VA_STATUS_ERROR_INVALID_IMAGE:
            return "invalid VAImageID";
        case VA_STATUS_ERROR_INVALID_SUBPICTURE:
            return "invalid VASubpictureID";
Waldo Bastian's avatar
Waldo Bastian committed
293 294 295 296 297 298 299 300 301 302 303 304
        case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
            return "attribute not supported";
        case VA_STATUS_ERROR_MAX_NUM_EXCEEDED:
            return "list argument exceeds maximum number";
        case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
            return "the requested VAProfile is not supported";
        case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
            return "the requested VAEntryPoint is not supported";
        case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
            return "the requested RT Format is not supported";
        case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
            return "the requested VABufferType is not supported";
305 306 307 308 309 310 311 312
        case VA_STATUS_ERROR_SURFACE_BUSY:
            return "surface is in use";
        case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
            return "flag not supported";
        case VA_STATUS_ERROR_INVALID_PARAMETER:
            return "invalid parameter";
        case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
            return "resolution not supported";
313 314
        case VA_STATUS_ERROR_UNIMPLEMENTED:
            return "the requested function is not implemented";
315 316
        case VA_STATUS_ERROR_SURFACE_IN_DISPLAYING:
            return "surface is in displaying (may by overlay)" ;
Waldo Bastian's avatar
Waldo Bastian committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
        case VA_STATUS_ERROR_UNKNOWN:
            return "unknown libva error";
    }
    return "unknown libva error / description missing";
}
      
VAStatus vaInitialize (
    VADisplay dpy,
    int *major_version,	 /* out */
    int *minor_version 	 /* out */
)
{
  char *driver_name = NULL;
  VAStatus vaStatus;
  
Austin Yuan's avatar
Austin Yuan committed
332
  CHECK_DISPLAY(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
333

Austin Yuan's avatar
Austin Yuan committed
334
  va_TraceInit();
Waldo Bastian's avatar
Waldo Bastian committed
335

336
  va_infoMessage("libva version %s\n", VA_VERSION_S);
Austin Yuan's avatar
Austin Yuan committed
337 338

  vaStatus = va_getDriverName(dpy, &driver_name);
Waldo Bastian's avatar
Waldo Bastian committed
339 340 341 342
  va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
  
  if (VA_STATUS_SUCCESS == vaStatus)
  {
Austin Yuan's avatar
Austin Yuan committed
343
      vaStatus = va_openDriver(dpy, driver_name);
Waldo Bastian's avatar
Waldo Bastian committed
344 345
      va_infoMessage("va_openDriver() returns %d\n", vaStatus);
      
Waldo Bastian's avatar
Waldo Bastian committed
346 347
      *major_version = VA_MAJOR_VERSION;
      *minor_version = VA_MINOR_VERSION;
Waldo Bastian's avatar
Waldo Bastian committed
348 349 350
  }

  if (driver_name)
Austin Yuan's avatar
Austin Yuan committed
351
      free(driver_name);
Waldo Bastian's avatar
Waldo Bastian committed
352 353 354 355 356 357 358 359 360 361 362 363
  return vaStatus;
}


/*
 * After this call, all library internal resources will be cleaned up
 */ 
VAStatus vaTerminate (
    VADisplay dpy
)
{
  VAStatus vaStatus = VA_STATUS_SUCCESS;
Austin Yuan's avatar
Austin Yuan committed
364 365 366 367 368
  VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
  VADriverContextP old_ctx;

  CHECK_DISPLAY(dpy);
  old_ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
369 370 371 372 373 374 375 376 377

  if (old_ctx->handle)
  {
      vaStatus = old_ctx->vtable.vaTerminate(old_ctx);
      dlclose(old_ctx->handle);
      old_ctx->handle = NULL;
  }

  if (VA_STATUS_SUCCESS == vaStatus)
Austin Yuan's avatar
Austin Yuan committed
378
      pDisplayContext->vaDestroy(pDisplayContext);
Austin Yuan's avatar
Austin Yuan committed
379 380 381

  va_TraceEnd();

Waldo Bastian's avatar
Waldo Bastian committed
382 383 384
  return vaStatus;
}

Waldo Bastian's avatar
Waldo Bastian committed
385 386 387 388 389 390 391 392 393 394 395 396
/*
 * vaQueryVendorString returns a pointer to a zero-terminated string
 * describing some aspects of the VA implemenation on a specific
 * hardware accelerator. The format of the returned string is:
 * <vendorname>-<major_version>-<minor_version>-<addtional_info>
 * e.g. for the Intel GMA500 implementation, an example would be:
 * "IntelGMA500-1.0-0.2-patch3
 */
const char *vaQueryVendorString (
    VADisplay dpy
)
{
Austin Yuan's avatar
Austin Yuan committed
397
  if( !vaDisplayIsValid(dpy) )
Waldo Bastian's avatar
Waldo Bastian committed
398 399
      return NULL;
  
Austin Yuan's avatar
Austin Yuan committed
400
  return CTX(dpy)->str_vendor;
Waldo Bastian's avatar
Waldo Bastian committed
401 402 403
}


Waldo Bastian's avatar
Waldo Bastian committed
404 405 406 407 408
/* Get maximum number of profiles supported by the implementation */
int vaMaxNumProfiles (
    VADisplay dpy
)
{
Austin Yuan's avatar
Austin Yuan committed
409
  if( !vaDisplayIsValid(dpy) )
Waldo Bastian's avatar
Waldo Bastian committed
410
      return 0;
Waldo Bastian's avatar
Waldo Bastian committed
411
  
Austin Yuan's avatar
Austin Yuan committed
412
  return CTX(dpy)->max_profiles;
Waldo Bastian's avatar
Waldo Bastian committed
413 414 415 416 417 418 419
}

/* Get maximum number of entrypoints supported by the implementation */
int vaMaxNumEntrypoints (
    VADisplay dpy
)
{
Austin Yuan's avatar
Austin Yuan committed
420
  if( !vaDisplayIsValid(dpy) )
Waldo Bastian's avatar
Waldo Bastian committed
421
      return 0;
Waldo Bastian's avatar
Waldo Bastian committed
422
  
Austin Yuan's avatar
Austin Yuan committed
423
  return CTX(dpy)->max_entrypoints;
Waldo Bastian's avatar
Waldo Bastian committed
424 425 426 427 428 429 430 431
}


/* Get maximum number of attributs supported by the implementation */
int vaMaxNumConfigAttributes (
    VADisplay dpy
)
{
Austin Yuan's avatar
Austin Yuan committed
432
  if( !vaDisplayIsValid(dpy) )
Waldo Bastian's avatar
Waldo Bastian committed
433
      return 0;
Waldo Bastian's avatar
Waldo Bastian committed
434
  
Austin Yuan's avatar
Austin Yuan committed
435
  return CTX(dpy)->max_attributes;
Waldo Bastian's avatar
Waldo Bastian committed
436 437 438 439 440 441 442 443 444
}

VAStatus vaQueryConfigEntrypoints (
    VADisplay dpy,
    VAProfile profile,
    VAEntrypoint *entrypoints,	/* out */
    int *num_entrypoints	/* out */
)
{
Austin Yuan's avatar
Austin Yuan committed
445 446 447
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
448 449 450 451

  return ctx->vtable.vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
}

Waldo Bastian's avatar
Waldo Bastian committed
452
VAStatus vaGetConfigAttributes (
Waldo Bastian's avatar
Waldo Bastian committed
453 454 455 456 457 458 459
    VADisplay dpy,
    VAProfile profile,
    VAEntrypoint entrypoint,
    VAConfigAttrib *attrib_list, /* in/out */
    int num_attribs
)
{
Austin Yuan's avatar
Austin Yuan committed
460 461 462
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
463

Waldo Bastian's avatar
Waldo Bastian committed
464
  return ctx->vtable.vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
Waldo Bastian's avatar
Waldo Bastian committed
465 466 467 468 469 470 471 472
}

VAStatus vaQueryConfigProfiles (
    VADisplay dpy,
    VAProfile *profile_list,	/* out */
    int *num_profiles		/* out */
)
{
Austin Yuan's avatar
Austin Yuan committed
473 474 475
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
476 477 478 479 480 481 482 483 484 485 486 487 488

  return ctx->vtable.vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
}

VAStatus vaCreateConfig (
    VADisplay dpy,
    VAProfile profile, 
    VAEntrypoint entrypoint, 
    VAConfigAttrib *attrib_list,
    int num_attribs,
    VAConfigID *config_id /* out */
)
{
Austin Yuan's avatar
Austin Yuan committed
489 490 491
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
492

Austin Yuan's avatar
Austin Yuan committed
493
  VA_TRACE(va_TraceCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
Waldo Bastian's avatar
Waldo Bastian committed
494 495 496
  return ctx->vtable.vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
}

Waldo Bastian's avatar
Waldo Bastian committed
497 498 499 500 501
VAStatus vaDestroyConfig (
    VADisplay dpy,
    VAConfigID config_id
)
{
Austin Yuan's avatar
Austin Yuan committed
502 503 504
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
505 506 507 508 509

  return ctx->vtable.vaDestroyConfig ( ctx, config_id );
}

VAStatus vaQueryConfigAttributes (
Waldo Bastian's avatar
Waldo Bastian committed
510 511 512 513 514 515 516 517
    VADisplay dpy,
    VAConfigID config_id, 
    VAProfile *profile, 	/* out */
    VAEntrypoint *entrypoint, 	/* out */
    VAConfigAttrib *attrib_list,/* out */
    int *num_attribs		/* out */
)
{
Austin Yuan's avatar
Austin Yuan committed
518 519 520
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
521

Waldo Bastian's avatar
Waldo Bastian committed
522
  return ctx->vtable.vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
Waldo Bastian's avatar
Waldo Bastian committed
523 524 525 526 527 528 529 530
}

VAStatus vaCreateSurfaces (
    VADisplay dpy,
    int width,
    int height,
    int format,
    int num_surfaces,
Waldo Bastian's avatar
Waldo Bastian committed
531
    VASurfaceID *surfaces	/* out */
Waldo Bastian's avatar
Waldo Bastian committed
532 533
)
{
Austin Yuan's avatar
Austin Yuan committed
534 535 536
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
537

Austin Yuan's avatar
Austin Yuan committed
538
  VA_TRACE(va_TraceCreateSurface, dpy, width, height, format, num_surfaces, surfaces);
Waldo Bastian's avatar
Waldo Bastian committed
539 540 541
  return ctx->vtable.vaCreateSurfaces( ctx, width, height, format, num_surfaces, surfaces );
}

Austin Yuan's avatar
Austin Yuan committed
542

Waldo Bastian's avatar
Waldo Bastian committed
543
VAStatus vaDestroySurfaces (
Waldo Bastian's avatar
Waldo Bastian committed
544
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
545
    VASurfaceID *surface_list,
Waldo Bastian's avatar
Waldo Bastian committed
546 547 548
    int num_surfaces
)
{
Austin Yuan's avatar
Austin Yuan committed
549 550 551
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
552

Waldo Bastian's avatar
Waldo Bastian committed
553
  return ctx->vtable.vaDestroySurfaces( ctx, surface_list, num_surfaces );
Waldo Bastian's avatar
Waldo Bastian committed
554 555 556 557 558 559 560 561
}

VAStatus vaCreateContext (
    VADisplay dpy,
    VAConfigID config_id,
    int picture_width,
    int picture_height,
    int flag,
Waldo Bastian's avatar
Waldo Bastian committed
562
    VASurfaceID *render_targets,
Waldo Bastian's avatar
Waldo Bastian committed
563
    int num_render_targets,
Waldo Bastian's avatar
Waldo Bastian committed
564
    VAContextID *context		/* out */
Waldo Bastian's avatar
Waldo Bastian committed
565 566
)
{
Austin Yuan's avatar
Austin Yuan committed
567 568 569
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
570

Austin Yuan's avatar
Austin Yuan committed
571
  VA_TRACE(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
Waldo Bastian's avatar
Waldo Bastian committed
572 573 574 575 576 577
  return ctx->vtable.vaCreateContext( ctx, config_id, picture_width, picture_height,
                                      flag, render_targets, num_render_targets, context );
}

VAStatus vaDestroyContext (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
578
    VAContextID context
Waldo Bastian's avatar
Waldo Bastian committed
579 580
)
{
Austin Yuan's avatar
Austin Yuan committed
581 582 583
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
584 585 586 587 588 589

  return ctx->vtable.vaDestroyContext( ctx, context );
}

VAStatus vaCreateBuffer (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
590 591 592 593 594 595
    VAContextID context,	/* in */
    VABufferType type,		/* in */
    unsigned int size,		/* in */
    unsigned int num_elements,	/* in */
    void *data,			/* in */
    VABufferID *buf_id		/* out */
Waldo Bastian's avatar
Waldo Bastian committed
596 597
)
{
Austin Yuan's avatar
Austin Yuan committed
598 599 600
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
601

Waldo Bastian's avatar
Waldo Bastian committed
602
  return ctx->vtable.vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
Waldo Bastian's avatar
Waldo Bastian committed
603 604 605 606 607 608 609 610
}

VAStatus vaBufferSetNumElements (
    VADisplay dpy,
    VABufferID buf_id,	/* in */
    unsigned int num_elements /* in */
)
{
Austin Yuan's avatar
Austin Yuan committed
611 612 613
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
614 615 616 617 618 619 620 621 622 623 624

  return ctx->vtable.vaBufferSetNumElements( ctx, buf_id, num_elements );
}


VAStatus vaMapBuffer (
    VADisplay dpy,
    VABufferID buf_id,	/* in */
    void **pbuf 	/* out */
)
{
Austin Yuan's avatar
Austin Yuan committed
625 626 627
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
628 629 630 631 632 633 634 635 636

  return ctx->vtable.vaMapBuffer( ctx, buf_id, pbuf );
}

VAStatus vaUnmapBuffer (
    VADisplay dpy,
    VABufferID buf_id	/* in */
)
{
Austin Yuan's avatar
Austin Yuan committed
637 638 639
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
640 641 642 643 644 645 646 647 648

  return ctx->vtable.vaUnmapBuffer( ctx, buf_id );
}

VAStatus vaDestroyBuffer (
    VADisplay dpy,
    VABufferID buffer_id
)
{
Austin Yuan's avatar
Austin Yuan committed
649 650 651
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
652 653 654 655

  return ctx->vtable.vaDestroyBuffer( ctx, buffer_id );
}

Austin Yuan's avatar
Austin Yuan committed
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
VAStatus vaBufferInfo (
    VADisplay dpy,
    VAContextID context,	/* in */
    VABufferID buf_id,		/* in */
    VABufferType *type,		/* out */
    unsigned int *size,		/* out */
    unsigned int *num_elements	/* out */
)
{
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);

  if (ctx->vtable.vaBufferInfo)
      return ctx->vtable.vaBufferInfo( ctx, context, buf_id, type, size, num_elements );
  else
      return VA_STATUS_ERROR_UNIMPLEMENTED;
}

Waldo Bastian's avatar
Waldo Bastian committed
675 676
VAStatus vaBeginPicture (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
677 678
    VAContextID context,
    VASurfaceID render_target
Waldo Bastian's avatar
Waldo Bastian committed
679 680
)
{
Austin Yuan's avatar
Austin Yuan committed
681 682 683
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
684

Austin Yuan's avatar
Austin Yuan committed
685
  VA_TRACE(va_TraceBeginPicture, ctx, context, render_target);
Waldo Bastian's avatar
Waldo Bastian committed
686 687 688 689 690
  return ctx->vtable.vaBeginPicture( ctx, context, render_target );
}

VAStatus vaRenderPicture (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
691
    VAContextID context,
Waldo Bastian's avatar
Waldo Bastian committed
692 693 694 695
    VABufferID *buffers,
    int num_buffers
)
{
Austin Yuan's avatar
Austin Yuan committed
696 697 698
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
699

Austin Yuan's avatar
Austin Yuan committed
700
  VA_TRACE(va_TraceRenderPicture, dpy, context, buffers, num_buffers);
Waldo Bastian's avatar
Waldo Bastian committed
701 702 703 704 705
  return ctx->vtable.vaRenderPicture( ctx, context, buffers, num_buffers );
}

VAStatus vaEndPicture (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
706
    VAContextID context
Waldo Bastian's avatar
Waldo Bastian committed
707 708
)
{
Austin Yuan's avatar
Austin Yuan committed
709 710 711
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
712

Austin Yuan's avatar
Austin Yuan committed
713
  VA_TRACE(va_TraceEndPicture, dpy, context);
Waldo Bastian's avatar
Waldo Bastian committed
714 715 716 717 718
  return ctx->vtable.vaEndPicture( ctx, context );
}

VAStatus vaSyncSurface (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
719
    VASurfaceID render_target
Waldo Bastian's avatar
Waldo Bastian committed
720 721
)
{
Austin Yuan's avatar
Austin Yuan committed
722 723 724
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
725

726
  return ctx->vtable.vaSyncSurface( ctx, render_target );
Waldo Bastian's avatar
Waldo Bastian committed
727 728 729 730
}

VAStatus vaQuerySurfaceStatus (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
731
    VASurfaceID render_target,
Waldo Bastian's avatar
Waldo Bastian committed
732 733 734
    VASurfaceStatus *status	/* out */
)
{
Austin Yuan's avatar
Austin Yuan committed
735 736 737
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
738

Waldo Bastian's avatar
Waldo Bastian committed
739
  return ctx->vtable.vaQuerySurfaceStatus( ctx, render_target, status );
Waldo Bastian's avatar
Waldo Bastian committed
740 741 742 743
}

VAStatus vaPutSurface (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
744
    VASurfaceID surface,
Waldo Bastian's avatar
Waldo Bastian committed
745 746 747 748 749 750 751 752 753 754 755
    Drawable draw, /* X Drawable */
    short srcx,
    short srcy,
    unsigned short srcw,
    unsigned short srch,
    short destx,
    short desty,
    unsigned short destw,
    unsigned short desth,
    VARectangle *cliprects, /* client supplied clip list */
    unsigned int number_cliprects, /* number of clip rects in the clip list */
Waldo Bastian's avatar
Waldo Bastian committed
756
    unsigned int flags /* de-interlacing flags */
Waldo Bastian's avatar
Waldo Bastian committed
757 758
)
{
Austin Yuan's avatar
Austin Yuan committed
759 760 761
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
762 763 764 765 766 767 768 769 770 771 772

  return ctx->vtable.vaPutSurface( ctx, surface, draw, srcx, srcy, srcw, srch,
                                   destx, desty, destw, desth,
                                   cliprects, number_cliprects, flags );
}

/* Get maximum number of image formats supported by the implementation */
int vaMaxNumImageFormats (
    VADisplay dpy
)
{
Austin Yuan's avatar
Austin Yuan committed
773
  if( !vaDisplayIsValid(dpy) )
Waldo Bastian's avatar
Waldo Bastian committed
774
      return 0;
Waldo Bastian's avatar
Waldo Bastian committed
775
  
Austin Yuan's avatar
Austin Yuan committed
776
  return CTX(dpy)->max_image_formats;
Waldo Bastian's avatar
Waldo Bastian committed
777 778 779 780 781 782 783 784
}

VAStatus vaQueryImageFormats (
    VADisplay dpy,
    VAImageFormat *format_list,	/* out */
    int *num_formats		/* out */
)
{
Austin Yuan's avatar
Austin Yuan committed
785 786 787
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807

  return ctx->vtable.vaQueryImageFormats ( ctx, format_list, num_formats);
}

/* 
 * The width and height fields returned in the VAImage structure may get 
 * enlarged for some YUV formats. The size of the data buffer that needs
 * to be allocated will be given in the "data_size" field in VAImage.
 * Image data is not allocated by this function.  The client should
 * allocate the memory and fill in the VAImage structure's data field
 * after looking at "data_size" returned from the library.
 */
VAStatus vaCreateImage (
    VADisplay dpy,
    VAImageFormat *format,
    int width,
    int height,
    VAImage *image	/* out */
)
{
Austin Yuan's avatar
Austin Yuan committed
808 809 810
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
811 812 813 814 815 816 817 818 819

  return ctx->vtable.vaCreateImage ( ctx, format, width, height, image);
}

/*
 * Should call DestroyImage before destroying the surface it is bound to
 */
VAStatus vaDestroyImage (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
820
    VAImageID image
Waldo Bastian's avatar
Waldo Bastian committed
821 822
)
{
Austin Yuan's avatar
Austin Yuan committed
823 824 825
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
826 827 828 829

  return ctx->vtable.vaDestroyImage ( ctx, image);
}

Waldo Bastian's avatar
Waldo Bastian committed
830 831 832 833 834 835
VAStatus vaSetImagePalette (
    VADisplay dpy,
    VAImageID image,
    unsigned char *palette
)
{
Austin Yuan's avatar
Austin Yuan committed
836 837 838
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
839 840 841 842

  return ctx->vtable.vaSetImagePalette ( ctx, image, palette);
}

Waldo Bastian's avatar
Waldo Bastian committed
843 844 845 846 847 848
/*
 * Retrieve surface data into a VAImage
 * Image must be in a format supported by the implementation
 */
VAStatus vaGetImage (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
849
    VASurfaceID surface,
Waldo Bastian's avatar
Waldo Bastian committed
850 851 852 853
    int x,	/* coordinates of the upper left source pixel */
    int y,
    unsigned int width, /* width and height of the region */
    unsigned int height,
Waldo Bastian's avatar
Waldo Bastian committed
854
    VAImageID image
Waldo Bastian's avatar
Waldo Bastian committed
855 856
)
{
Austin Yuan's avatar
Austin Yuan committed
857 858 859
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
860 861 862 863 864 865 866 867 868

  return ctx->vtable.vaGetImage ( ctx, surface, x, y, width, height, image);
}

/*
 * Copy data from a VAImage to a surface
 * Image must be in a format supported by the implementation
 */
VAStatus vaPutImage (
869 870 871 872 873 874 875 876 877 878 879 880 881
    VADisplay dpy,
    VASurfaceID surface,
    VAImageID image,
    int src_x,
    int src_y,
    unsigned int src_width,
    unsigned int src_height,
    int dest_x,
    int dest_y,
    unsigned int dest_width,
    unsigned int dest_height
)
{
Austin Yuan's avatar
Austin Yuan committed
882 883 884
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
885

886
  return ctx->vtable.vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
}

/*
 * Derive an VAImage from an existing surface.
 * This interface will derive a VAImage and corresponding image buffer from
 * an existing VA Surface. The image buffer can then be mapped/unmapped for
 * direct CPU access. This operation is only possible on implementations with
 * direct rendering capabilities and internal surface formats that can be
 * represented with a VAImage. When the operation is not possible this interface
 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
 * to using vaCreateImage + vaPutImage to accomplish the same task in an
 * indirect manner.
 *
 * Implementations should only return success when the resulting image buffer
 * would be useable with vaMap/Unmap.
 *
 * When directly accessing a surface special care must be taken to insure
 * proper synchronization with the graphics hardware. Clients should call
 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
 * rendering or currently being displayed by an overlay.
 *
 * Additionally nothing about the contents of a surface should be assumed
 * following a vaPutSurface. Implementations are free to modify the surface for
 * scaling or subpicture blending within a call to vaPutImage.
 *
 * Calls to vaPutImage or vaGetImage using the same surface from which the image
 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
 * vaGetImage with other surfaces is supported.
 *
 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
 * image and image buffer structures will be destroyed; however, the underlying
 * surface will remain unchanged until freed with vaDestroySurfaces.
 */
VAStatus vaDeriveImage (
    VADisplay dpy,
    VASurfaceID surface,
    VAImage *image	/* out */
)
{
Austin Yuan's avatar
Austin Yuan committed
926 927 928
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
929 930 931 932 933

  return ctx->vtable.vaDeriveImage ( ctx, surface, image );
}


Waldo Bastian's avatar
Waldo Bastian committed
934 935 936 937 938
/* Get maximum number of subpicture formats supported by the implementation */
int vaMaxNumSubpictureFormats (
    VADisplay dpy
)
{
Austin Yuan's avatar
Austin Yuan committed
939
  if( !vaDisplayIsValid(dpy) )
Waldo Bastian's avatar
Waldo Bastian committed
940
      return 0;
Waldo Bastian's avatar
Waldo Bastian committed
941
  
Austin Yuan's avatar
Austin Yuan committed
942
  return CTX(dpy)->max_subpic_formats;
Waldo Bastian's avatar
Waldo Bastian committed
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
}

/* 
 * Query supported subpicture formats 
 * The caller must provide a "format_list" array that can hold at
 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag 
 * for each format to indicate additional capabilities for that format. The actual 
 * number of formats returned in "format_list" is returned in "num_formats".
 */
VAStatus vaQuerySubpictureFormats (
    VADisplay dpy,
    VAImageFormat *format_list,	/* out */
    unsigned int *flags,	/* out */
    unsigned int *num_formats	/* out */
)
{
Austin Yuan's avatar
Austin Yuan committed
959 960 961
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
962 963 964 965 966 967 968 969 970

  return ctx->vtable.vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
}

/* 
 * Subpictures are created with an image associated. 
 */
VAStatus vaCreateSubpicture (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
971 972
    VAImageID image,
    VASubpictureID *subpicture	/* out */
Waldo Bastian's avatar
Waldo Bastian committed
973 974
)
{
Austin Yuan's avatar
Austin Yuan committed
975 976 977
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
978 979 980 981 982 983 984 985 986

  return ctx->vtable.vaCreateSubpicture ( ctx, image, subpicture );
}

/*
 * Destroy the subpicture before destroying the image it is assocated to
 */
VAStatus vaDestroySubpicture (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
987
    VASubpictureID subpicture
Waldo Bastian's avatar
Waldo Bastian committed
988 989
)
{
Austin Yuan's avatar
Austin Yuan committed
990 991 992
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
993 994 995 996 997 998

  return ctx->vtable.vaDestroySubpicture ( ctx, subpicture);
}

VAStatus vaSetSubpictureImage (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
999 1000
    VASubpictureID subpicture,
    VAImageID image
Waldo Bastian's avatar
Waldo Bastian committed
1001 1002
)
{
Austin Yuan's avatar
Austin Yuan committed
1003 1004 1005
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016

  return ctx->vtable.vaSetSubpictureImage ( ctx, subpicture, image);
}


/*
 * If chromakey is enabled, then the area where the source value falls within
 * the chromakey [min, max] range is transparent
 */
VAStatus vaSetSubpictureChromakey (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
1017
    VASubpictureID subpicture,
Waldo Bastian's avatar
Waldo Bastian committed
1018
    unsigned int chromakey_min,
Waldo Bastian's avatar
Waldo Bastian committed
1019 1020
    unsigned int chromakey_max,
    unsigned int chromakey_mask
Waldo Bastian's avatar
Waldo Bastian committed
1021 1022
)
{
Austin Yuan's avatar
Austin Yuan committed
1023 1024 1025
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
1026

Waldo Bastian's avatar
Waldo Bastian committed
1027
  return ctx->vtable.vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
Waldo Bastian's avatar
Waldo Bastian committed
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
}


/*
 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and 
 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
 * the overall alpha is per-pixel alpha multiplied by the global alpha
 */
VAStatus vaSetSubpictureGlobalAlpha (
    VADisplay dpy,
Waldo Bastian's avatar
Waldo Bastian committed
1038
    VASubpictureID subpicture,
Waldo Bastian's avatar
Waldo Bastian committed
1039 1040 1041
    float global_alpha 
)
{
Austin Yuan's avatar
Austin Yuan committed
1042 1043 1044
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056

  return ctx->vtable.vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
}

/*
  vaAssociateSubpicture associates the subpicture with the target_surface.
  It defines the region mapping between the subpicture and the target 
  surface through source and destination rectangles (with the same width and height).
  Both will be displayed at the next call to vaPutSurface.  Additional
  associations before the call to vaPutSurface simply overrides the association.
*/
VAStatus vaAssociateSubpicture (
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
    VADisplay dpy,
    VASubpictureID subpicture,
    VASurfaceID *target_surfaces,
    int num_surfaces,
    short src_x, /* upper left offset in subpicture */
    short src_y,
    unsigned short src_width,
    unsigned short src_height,
    short dest_x, /* upper left offset in surface */
    short dest_y,
    unsigned short dest_width,
    unsigned short dest_height,
    /*
     * whether to enable chroma-keying or global-alpha
     * see VA_SUBPICTURE_XXX values
     */
    unsigned int flags
)
{
Austin Yuan's avatar
Austin Yuan committed
1076 1077 1078
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
1079

1080
  return ctx->vtable.vaAssociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height, flags );
1081 1082
}

Waldo Bastian's avatar
Waldo Bastian committed
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
/*
 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
 */
VAStatus vaDeassociateSubpicture (
    VADisplay dpy,
    VASubpictureID subpicture,
    VASurfaceID *target_surfaces,
    int num_surfaces
)
{
Austin Yuan's avatar
Austin Yuan committed
1093 1094 1095
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
1096 1097

  return ctx->vtable.vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
Waldo Bastian's avatar
Waldo Bastian committed
1098 1099
}

Waldo Bastian's avatar
Waldo Bastian committed
1100

Waldo Bastian's avatar
Waldo Bastian committed
1101 1102 1103 1104 1105
/* Get maximum number of display attributes supported by the implementation */
int vaMaxNumDisplayAttributes (
    VADisplay dpy
)
{
Austin Yuan's avatar
Austin Yuan committed
1106
  if( !vaDisplayIsValid(dpy) )
Waldo Bastian's avatar
Waldo Bastian committed
1107
      return 0;
Waldo Bastian's avatar
Waldo Bastian committed
1108
  
Austin Yuan's avatar
Austin Yuan committed
1109
  return CTX(dpy)->max_display_attributes;
Waldo Bastian's avatar
Waldo Bastian committed
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
}

/* 
 * Query display attributes 
 * The caller must provide a "attr_list" array that can hold at
 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
 * returned in "attr_list" is returned in "num_attributes".
 */
VAStatus vaQueryDisplayAttributes (
    VADisplay dpy,
    VADisplayAttribute *attr_list,	/* out */
    int *num_attributes			/* out */
)
{
Austin Yuan's avatar
Austin Yuan committed
1124 1125 1126
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142

  return ctx->vtable.vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
}

/* 
 * Get display attributes 
 * This function returns the current attribute values in "attr_list".
 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
 * from vaQueryDisplayAttributes() can have their values retrieved.  
 */
VAStatus vaGetDisplayAttributes (
    VADisplay dpy,
    VADisplayAttribute *attr_list,	/* in/out */
    int num_attributes
)
{
Austin Yuan's avatar
Austin Yuan committed
1143 1144 1145
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161

  return ctx->vtable.vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
}

/* 
 * Set display attributes 
 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
 * from vaQueryDisplayAttributes() can be set.  If the attribute is not settable or 
 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
 */
VAStatus vaSetDisplayAttributes (
    VADisplay dpy,
    VADisplayAttribute *attr_list,
    int num_attributes
)
{
Austin Yuan's avatar
Austin Yuan committed
1162 1163 1164
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
1165 1166 1167 1168

  return ctx->vtable.vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
}

1169 1170 1171 1172 1173 1174 1175 1176
/* Wrap a CI (camera imaging) frame as a VA surface to share captured video between camear
 * and VA encode. With frame_id, VA driver need to call CI interfaces to get the information
 * of the frame, and to determine if the frame can be wrapped as a VA surface
 *
 * Application should make sure the frame is idle before the frame is passed into VA stack
 * and also a vaSyncSurface should be called before application tries to access the frame
 * from CI stack
 */
1177 1178 1179 1180
VAStatus vaCreateSurfaceFromCIFrame (
    VADisplay dpy,
    unsigned long frame_id,
    VASurfaceID *surface	/* out */
Waldo Bastian's avatar
Waldo Bastian committed
1181 1182
)
{
Austin Yuan's avatar
Austin Yuan committed
1183 1184 1185
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);
Waldo Bastian's avatar
Waldo Bastian committed
1186

1187 1188 1189
  if (ctx->vtable.vaCreateSurfaceFromCIFrame)
      return ctx->vtable.vaCreateSurfaceFromCIFrame( ctx, frame_id, surface );
  else
Austin Yuan's avatar
Austin Yuan committed
1190
      return VA_STATUS_ERROR_UNIMPLEMENTED;
Waldo Bastian's avatar
Waldo Bastian committed
1191 1192
}

1193

1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
/* Wrap a V4L2 buffer as a VA surface, so that V4L2 camera, VA encode
 * can share the data without copy
 * The VA driver should query the camera device from v4l2_fd to see
 * if camera device memory/buffer can be wrapped into a VA surface
 * Buffer information is passed in by v4l2_fmt and v4l2_buf structure,
 * VA driver also needs do further check if the buffer can meet encode
 * hardware requirement, such as dimension, fourcc, stride, etc
 *
 * Application should make sure the buffer is idle before the frame into VA stack
 * and also a vaSyncSurface should be called before application tries to access the frame
 * from V4L2 stack
 */
VAStatus vaCreateSurfaceFromV4L2Buf(
Austin Yuan's avatar
Austin Yuan committed
1207
    VADisplay dpy,
1208 1209 1210 1211
    int v4l2_fd,         /* file descriptor of V4L2 device */
    struct v4l2_format *v4l2_fmt,       /* format of V4L2 */
    struct v4l2_buffer *v4l2_buf,       /* V4L2 buffer */
    VASurfaceID *surface	       /* out */
Austin Yuan's avatar
Austin Yuan committed
1212 1213 1214 1215 1216 1217
)
{
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);

1218 1219
  if (ctx->vtable.vaCreateSurfaceFromV4L2Buf) 
      return ctx->vtable.vaCreateSurfaceFromV4L2Buf( ctx, v4l2_fd, v4l2_fmt, v4l2_buf, surface );
1220 1221
  else
      return VA_STATUS_ERROR_UNKNOWN;
Austin Yuan's avatar
Austin Yuan committed
1222 1223
}

1224 1225 1226 1227
/* It is a debug interface, and isn't exported in core VAAPI
 * It is used to dump surface data into system memory
 * Application should explicitly call free to release the buffer memory
 */
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247

VAStatus vaCopySurfaceToBuffer(VADisplay dpy,
    VASurfaceID surface,
    unsigned int *fourcc, /* following are output argument */
    unsigned int *luma_stride,
    unsigned int *chroma_u_stride,
    unsigned int *chroma_v_stride,
    unsigned int *luma_offset,
    unsigned int *chroma_u_offset,
    unsigned int *chroma_v_offset,
    void **buffer 
)
{
  VADriverContextP ctx;
  CHECK_DISPLAY(dpy);
  ctx = CTX(dpy);

  if (ctx->vtable.vaCopySurfaceToBuffer)
      return ctx->vtable.vaCopySurfaceToBuffer( ctx, surface, fourcc, luma_stride, chroma_u_stride, chroma_v_stride, luma_offset, chroma_u_offset, chroma_v_offset, buffer);
  else
Austin Yuan's avatar
Austin Yuan committed
1248
      return VA_STATUS_ERROR_UNIMPLEMENTED;
1249
}