Commit c4a03c10 authored by Ren Zhaohan's avatar Ren Zhaohan

libva backend

parent 24914b55
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 \
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++
LOCAL_COPY_HEADERS_TO := libva/va
LOCAL_COPY_HEADERS := \
va.h \
va_backend.h \
va_version.h.in \
x11/va_dricommon.h \
va_android.h
LOCAL_MODULE := libva_android
......
......@@ -23,9 +23,10 @@
*/
#define _GNU_SOURCE 1
#include "../va.h"
#include "../va_backend.h"
#include "../va_android.h"
#include "va.h"
#include "va_backend.h"
#include "va_android.h"
#include "x11/va_dricommon.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
......@@ -34,10 +35,44 @@
#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 open_device (char *dev_name)
{
struct stat st;
int fd;
if (-1 == stat (dev_name, &st))
{
printf ("Cannot identify '%s': %d, %s\n",
dev_name, errno, strerror (errno));
return -1;
}
if (!S_ISCHR (st.st_mode))
{
printf ("%s is no device\n", dev_name);
return -1;
}
fd = open (dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);
if (-1 == fd)
{
fprintf (stderr, "Cannot open '%s': %d, %s\n",
dev_name, errno, strerror (errno));
return -1;
}
return fd;
}
static int va_DisplayContextIsValid (
VADisplayContextP pDisplayContext
)
......@@ -78,7 +113,7 @@ static VAStatus va_DisplayContextGetDriverName (
unsigned int device_id;
char driver_name[64];
} devices[] = {
{ 0x8086, 0x4100, "android" },
{ 0x8086, 0x4100, "psb" },
};
if (driver_name)
......@@ -111,13 +146,27 @@ VADisplay vaGetDisplay (
pDisplayContext = pDisplayContext->pNext;
}
if (!dpy)
{
/* create new entry */
VADriverContextP pDriverContext;
struct dri_state *dri_state;
pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext));
pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext));
if (pDisplayContext && pDriverContext)
dri_state = (struct dri_state*)calloc(1, sizeof(*dri_state));
/* assgin necessary dri_state struct variable */
dri_state->driConnectedFlag = VA_DRI2;
dri_state->fd = open_device(DEVICE_NAME);
dri_state->createDrawable = NULL;
dri_state->destroyDrawable = NULL;
dri_state->swapBuffer = NULL;
dri_state->getRenderingBuffer = NULL;
dri_state->close = NULL;
if (pDisplayContext && pDriverContext && dri_state)
{
pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
......@@ -128,6 +177,7 @@ VADisplay vaGetDisplay (
pDisplayContext->vaDestroy = va_DisplayContextDestroy;
pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
pDisplayContexts = pDisplayContext;
pDriverContext->dri_state = dri_state;
dpy = (VADisplay)pDisplayContext;
}
else
......@@ -136,13 +186,14 @@ VADisplay vaGetDisplay (
free(pDisplayContext);
if (pDriverContext)
free(pDriverContext);
if (dri_state)
free(dri_state);
}
}
return dpy;
}
#define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
#define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
......@@ -155,7 +206,8 @@ static int vaDisplayIsValid(VADisplay dpy)
VAStatus vaPutSurface (
VADisplay dpy,
VASurfaceID surface,
Surface *draw, /* Android Surface/Window */
//Surface *draw, /* Android Surface/Window */
void *draw,
short srcx,
short srcy,
unsigned short srcw,
......@@ -178,3 +230,4 @@ VAStatus vaPutSurface (
destx, desty, destw, desth,
cliprects, number_cliprects, flags );
}
......@@ -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 */
......
......@@ -1789,6 +1789,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,16 +2,16 @@
#define _VA_ANDROID_H_
#include <va/va.h>
#ifdef __cplusplus
extern "C" {
#endif
//#define Surface void
/*
* Returns a suitable VADisplay for VA API
*/
VADisplay vaGetDisplay (
void *dpy
Display *dpy
);
/*
......@@ -25,7 +25,8 @@ VADisplay vaGetDisplay (
VAStatus vaPutSurface (
VADisplay dpy,
VASurfaceID surface,
Surface *draw, /* Android Window/Surface */
//Surface *draw, /* Android Window/Surface */
void* draw,
short srcx,
short srcy,
unsigned short srcw,
......@@ -38,7 +39,6 @@ VAStatus vaPutSurface (
unsigned int number_cliprects, /* number of clip rects in the clip list */
unsigned int flags /* PutSurface flags */
);
#ifdef __cplusplus
}
#endif
......
......@@ -30,15 +30,18 @@
#define _VA_BACKEND_H_
#include <va/va.h>
#ifndef ANDROID
#include <X11/Xlib.h>
#endif
#include <linux/videodev2.h>
#include <ui/Surface.h>
class Surface;
typedef struct VADriverContext *VADriverContextP;
typedef struct VADisplayContext *VADisplayContextP;
#ifdef ANDROID
#define Surface void
#endif
struct VADriverVTable
{
VAStatus (*vaTerminate) ( VADriverContextP ctx );
......@@ -182,7 +185,11 @@ struct VADriverVTable
VAStatus (*vaPutSurface) (
VADriverContextP ctx,
VASurfaceID surface,
#ifdef ANDROID
Surface* draw, /* X Drawable */
#else
Drawable draw,
#endif
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