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 \
--- /dev/null
- int drm_open_matching(const char *pci_glob, int flags)
+/*
+ * Copyright © 2007 Intel Corporation
+ *
+ * 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, sublicense,
+ * 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 NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ *
+ * Authors:
+ * Eric Anholt <eric@anholt.net>
+ *
+ */
+
+#include <string.h>
+#include <fcntl.h>
+#include <fnmatch.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include "drmtest.h"
+
+#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
+#include <libudev.h>
+
+static int is_master(int fd)
+{
+ drm_client_t client;
+ int ret;
+
+ /* Check that we're the only opener and authed. */
+ client.idx = 0;
+ ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
+ assert (ret == 0);
+ if (!client.auth)
+ return 0;
+ client.idx = 1;
+ ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
+ if (ret != -1 || errno != EINVAL)
+ return 0;
+
+ return 1;
+}
+
+/** Open the first DRM device matching the criteria */
- abort();
++int drm_open_matching(const char *pci_glob, int flags, int *device_id)
+{
+ struct udev *udev;
+ struct udev_enumerate *e;
+ struct udev_device *device, *parent;
+ struct udev_list_entry *entry;
+ 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();
++ return -1;
+ }
+
+ fd = -1;
+ e = udev_enumerate_new(udev);
+ udev_enumerate_add_match_subsystem(e, "drm");
+ udev_enumerate_scan_devices(e);
+ udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
+ path = udev_list_entry_get_name(entry);
+ device = udev_device_new_from_syspath(udev, path);
+ parent = udev_device_get_parent(device);
+ /* Filter out KMS output devices. */
+ if (strcmp(udev_device_get_subsystem(parent), "pci") != 0)
+ continue;
+ pci_id = udev_device_get_property_value(parent, "PCI_ID");
+ if (fnmatch(pci_glob, pci_id, 0) != 0)
+ continue;
+ fd = open(udev_device_get_devnode(device), O_RDWR);
+ if (fd < 0)
+ continue;
+ if ((flags & DRM_TEST_MASTER) && !is_master(fd)) {
+ close(fd);
+ fd = -1;
+ continue;
+ }
+
+ break;
+ }
+ udev_enumerate_unref(e);
+ udev_unref(udev);
- int fd = drm_open_matching("*:*", 0);
++ *device_id = pci_id;
++
+ return fd;
+}
+
+int drm_open_any(void)
+{
- int drm_open_any_master(void)
++ int dev_id;
++
++ int fd = drm_open_matching("*:*", 0, &dev_id);
+
+ if (fd < 0) {
+ fprintf(stderr, "failed to open any drm device\n");
+ //abort();
+ }
+
+ return fd;
+}
+
+/**
+ * Open the first DRM device we can find where we end up being the master.
+ */
- int fd = drm_open_matching("*:*", DRM_TEST_MASTER);
++int drm_open_any_master(int *device_id)
+{
++ int fd = drm_open_matching("*:*", DRM_TEST_MASTER, device_id);
+
+ if (fd < 0) {
+ fprintf(stderr, "failed to open any drm device\n");
+ //abort();
+ }
+
+ return fd;
+
+}
--- /dev/null
- int drm_open_any_master(void);
- int drm_open_matching(const char *pci_glob, int flags);
+/*
+ * Copyright © 2007 Intel Corporation
+ *
+ * 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, sublicense,
+ * 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 NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ *
+ * Authors:
+ * Eric Anholt <eric@anholt.net>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <assert.h>
+#include <errno.h>
+
+#include "xf86drm.h"
+
+#define DRM_TEST_MASTER 0x01
+
+int drm_open_any(void);
++int drm_open_any_master(int *device_id);
++int drm_open_matching(const char *pci_glob, int flags, int *device_id);
#include "va.h"
#include "va_backend.h"
#include "va_android.h"
- #include "va_dricommon.h"
-#include "x11/va_dricommon.h"
++#include "va_dricommon.h" /* needs some helper functions from this file */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
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
)
VADisplayContextP pDisplayContext,
char **driver_name
)
-{
+{
+ 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, "psb" },
+ { 0x8086, 0x4100, "pvr" },
++ { 0x8086, 0x0310, "pvr" },
++ { 0x0, 0x0, "\0" },
};
- if (driver_name)
- *driver_name = NULL;
-
- *driver_name = strdup(devices[0].driver_name);
+ 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");
+ return VA_STATUS_ERROR_UNKNOWN;
+ }
+
+ 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;
return VA_STATUS_SUCCESS;
}
/* create new entry */
VADriverContextP pDriverContext;
struct dri_state *dri_state;
-
pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext));
pDriverContext = (VADriverContextP)calloc(1, sizeof(*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;
-
+ dri_state = calloc(1, sizeof(*dri_state));
-
if (pDisplayContext && pDriverContext && dri_state)
{
pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
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
extern "C" {
#endif
-
-//#define Surface void
/*
* Returns a suitable VADisplay for VA API
*/
VADisplay vaGetDisplay (
- void *dpy
- Display *dpy
++ void *android_dpy
);
- #ifdef ANDROID
-
++#if ANDROID
+#include <ui/Surface.h>
+class Surface;
+
/*
* Output rendering
* Following is the rendering interface for X windows,
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
}
#endif
VAStatus (*vaPutSurface) (
VADriverContextP ctx,
VASurfaceID surface,
- void* draw, /* X Drawable */
- #ifdef ANDROID
- Surface* draw, /* X Drawable */
- #else
- Drawable draw,
- #endif
++ void * draw, /* Drawable of window system */
short srcx,
short srcy,
unsigned short srcw,