Commit 1f4d9627 authored by Austin Yuan's avatar Austin Yuan

Merge branch 'va_backend' into PO

Conflicts:
	va/android/va_android.c
	va/va_android.h
	va/va_backend.h
Signed-off-by: default avatarAustin Yuan <shengquan.yuan@gmail.com>
parents be467652 c4a03c10
LOCAL_PATH:= $(call my-dir)
LIBVA_MINOR_VERSION := 31
LIBVA_MAJOR_VERSION := 0
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
android/va_android.c
va.c \
va_trace.c \
android/va_android.c \
android/drmtest.c \
LOCAL_CFLAGS += -DHAVE_CONFIG_H \
-DIN_LIBVA \
-DANDROID \
LOCAL_C_INCLUDES += \
$(TOPDIR)kernel/include \
$(TARGET_OUT_HEADERS)/libva \
$(TOPDIR)kernel/include/drm
LOCAL_CC := g++
$(TOPDIR)kernel/include/drm
LOCAL_COPY_HEADERS_TO := libva/va
......@@ -21,6 +26,7 @@ LOCAL_COPY_HEADERS := \
va.h \
va_backend.h \
va_version.h.in \
x11/va_dricommon.h \
va_android.h
LOCAL_MODULE := libva_android
......
......@@ -55,7 +55,7 @@ static int is_master(int fd)
}
/** Open the first DRM device matching the criteria */
int drm_open_matching(const char *pci_glob, int flags)
int drm_open_matching(const char *pci_glob, int flags, int *device_id)
{
struct udev *udev;
struct udev_enumerate *e;
......@@ -64,10 +64,13 @@ int drm_open_matching(const char *pci_glob, int flags)
const char *pci_id, *path;
int fd;
*device_id = ~0;
udev = udev_new();
if (udev == NULL) {
fprintf(stderr, "failed to initialize udev context\n");
abort();
//abort();
return -1;
}
fd = -1;
......@@ -97,13 +100,16 @@ int drm_open_matching(const char *pci_glob, int flags)
}
udev_enumerate_unref(e);
udev_unref(udev);
*device_id = pci_id;
return fd;
}
int drm_open_any(void)
{
int fd = drm_open_matching("*:*", 0);
int dev_id;
int fd = drm_open_matching("*:*", 0, &dev_id);
if (fd < 0) {
fprintf(stderr, "failed to open any drm device\n");
......@@ -116,9 +122,9 @@ int drm_open_any(void)
/**
* Open the first DRM device we can find where we end up being the master.
*/
int drm_open_any_master(void)
int drm_open_any_master(int *device_id)
{
int fd = drm_open_matching("*:*", DRM_TEST_MASTER);
int fd = drm_open_matching("*:*", DRM_TEST_MASTER, device_id);
if (fd < 0) {
fprintf(stderr, "failed to open any drm device\n");
......
......@@ -36,5 +36,5 @@
#define DRM_TEST_MASTER 0x01
int drm_open_any(void);
int drm_open_any_master(void);
int drm_open_matching(const char *pci_glob, int flags);
int drm_open_any_master(int *device_id);
int drm_open_matching(const char *pci_glob, int flags, int *device_id);
......@@ -26,7 +26,7 @@
#include "va.h"
#include "va_backend.h"
#include "va_android.h"
#include "va_dricommon.h"
#include "va_dricommon.h" /* needs some helper functions from this file */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
......@@ -35,11 +35,15 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <errno.h>
#define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; }
#define DEVICE_NAME "/dev/dri/card0"
static VADisplayContextP pDisplayContexts = NULL;
static int va_DisplayContextIsValid (
VADisplayContextP pDisplayContext
)
......@@ -86,21 +90,20 @@ static VAStatus va_DisplayContextGetDriverName (
VADriverContextP ctx = pDisplayContext->pDriverContext;
struct dri_state *dri_state = (struct dri_state *)ctx->dri_state;
char *driver_name_env;
int dev_id;
struct {
unsigned int verndor_id;
unsigned int device_id;
int verndor_id;
int device_id;
char driver_name[64];
} devices[] = {
{ 0x8086, 0x4100, "pvr" },
{ 0x8086, 0x0310, "pvr" },
{ 0x0, 0x0, "\0" },
};
memset(dri_state, 0, sizeof(*dri_state));
dri_state->fd = drm_open_any_master();
if (dri_state->fd < 0) {
fprintf(stderr, "open DRM device by udev failed, try /dev/dri/card0\n");
dri_state->fd = open("/dev/dri/card0", O_RDWR);
}
dri_state->fd = drm_open_any_master(&dev_id);
if (dri_state->fd < 0) {
fprintf(stderr,"can't open DRM devices\n");
......@@ -108,14 +111,24 @@ static VAStatus va_DisplayContextGetDriverName (
}
if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL
&& geteuid() == getuid())
{
&& geteuid() == getuid()) {
/* don't allow setuid apps to use LIBVA_DRIVER_NAME */
*driver_name = strdup(driver_name_env);
return VA_STATUS_SUCCESS;
} else /* TBD: other vendor driver names */
*driver_name = strdup(devices[0].driver_name);
} else { /* TBD: other vendor driver names */
int i=0;
while ((devices[i].device_id !=0) &&
(devices[i].device_id != dev_id))
i++;
if (devices[i].device_id != 0)
*driver_name = strdup(devices[0].driver_name);
else {
fprintf(stderr,"device (0x%04x) is not supported\n", dev_id);
return VA_STATUS_ERROR_UNKNOWN;
}
}
dri_state->driConnectedFlag = VA_DUMMY;
......@@ -144,6 +157,7 @@ VADisplay vaGetDisplay (
pDisplayContext = pDisplayContext->pNext;
}
if (!dpy)
{
/* create new entry */
......@@ -152,7 +166,6 @@ VADisplay vaGetDisplay (
pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext));
pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext));
dri_state = calloc(1, sizeof(*dri_state));
if (pDisplayContext && pDriverContext && dri_state)
{
pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
......@@ -181,7 +194,6 @@ VADisplay vaGetDisplay (
return dpy;
}
#define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
#define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
......@@ -214,36 +226,9 @@ VAStatus vaPutSurface (
CHECK_DISPLAY(dpy);
ctx = CTX(dpy);
return ctx->vtable.vaPutSurface( ctx, surface, draw, srcx, srcy, srcw, srch,
return ctx->vtable.vaPutSurface( ctx, surface, (void *)draw, srcx, srcy, srcw, srch,
destx, desty, destw, desth,
cliprects, number_cliprects, flags );
}
VAStatus vaPutSurfaceBuf (
VADisplay dpy,
VASurfaceID surface,
Drawable draw, /* Android Surface/Window */
unsigned char* data,
int* data_len,
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 */
unsigned int flags /* de-interlacing flags */
)
{
VADriverContextP ctx;
CHECK_DISPLAY(dpy);
ctx = CTX(dpy);
return ctx->vtable.vaPutSurfaceBuf( ctx, surface, draw, data, data_len, srcx, srcy, srcw, srch,
destx, desty, destw, desth, cliprects, number_cliprects, flags );
}
#endif
......@@ -25,6 +25,7 @@
#define _GNU_SOURCE 1
#include "va.h"
#include "va_backend.h"
#include "config.h"
#include <assert.h>
#include <stdarg.h>
......@@ -54,6 +55,10 @@ extern int trace_flag;
trace_func(__VA_ARGS__); \
}
#define VA_MAJOR_VERSION (0)
#define VA_MINOR_VERSION (31)
#define VA_VERSION_S "0.31.1"
static int vaDisplayIsValid(VADisplay dpy)
{
VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
......@@ -153,8 +158,11 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
va_infoMessage("Trying to open %s\n", driver_path);
#ifndef ANDROID
handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
#else
handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL);
#endif
if (!handle)
{
/* Don't give errors for non-existing files */
......
......@@ -1804,6 +1804,17 @@ VAStatus vaSetDisplayAttributes (
int num_attributes
);
#ifdef ANDROID
#define Display unsigned int
#define Drawable unsigned int
#define XID unsigned int
#define Bool int
#define Status int
#define True 1
#define False 0
#define Xfree(ptr) free((ptr))
#endif
#ifdef __cplusplus
}
#endif
......
......@@ -2,22 +2,18 @@
#define _VA_ANDROID_H_
#include <va/va.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Returns a suitable VADisplay for VA API
*/
VADisplay vaGetDisplay (
void *dpy
void *android_dpy
);
#ifdef ANDROID
#if ANDROID
#include <ui/Surface.h>
class Surface;
......@@ -45,26 +41,6 @@ VAStatus vaPutSurface (
unsigned int number_cliprects, /* number of clip rects in the clip list */
unsigned int flags /* PutSurface flags */
);
VAStatus vaPutSurfaceBuf (
VADriverContextP ctx,
VASurfaceID surface,
Drawable draw, /* X Drawable */
unsigned char* data,
int* data_len,
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 */
unsigned int flags /* de-interlacing flags */
);
#endif
#ifdef __cplusplus
......
......@@ -30,12 +30,18 @@
#define _VA_BACKEND_H_
#include <va/va.h>
#ifndef ANDROID
#include <X11/Xlib.h>
#endif
#include <linux/videodev2.h>
typedef struct VADriverContext *VADriverContextP;
typedef struct VADisplayContext *VADisplayContextP;
#ifdef ANDROID
#define Surface void
#endif
struct VADriverVTable
{
VAStatus (*vaTerminate) ( VADriverContextP ctx );
......@@ -179,7 +185,7 @@ struct VADriverVTable
VAStatus (*vaPutSurface) (
VADriverContextP ctx,
VASurfaceID surface,
void* draw, /* X Drawable */
void * draw, /* Drawable of window system */
short srcx,
short srcy,
unsigned short srcw,
......
#ifndef _VA_DRICOMMON_H_
#define _VA_DRICOMMON_H_
#ifndef ANDROID
#include <X11/Xlib.h>
#endif
#include <xf86drm.h>
#include <drm.h>
#include <drm_sarea.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment