OSDN Git Service

Merge branch 'va_backend' into PO
authorAustin Yuan <shengquan.yuan@gmail.com>
Wed, 28 Apr 2010 23:20:56 +0000 (07:20 +0800)
committerAustin Yuan <shengquan.yuan@gmail.com>
Wed, 28 Apr 2010 23:20:56 +0000 (07:20 +0800)
Conflicts:
va/android/va_android.c
va/va_android.h
va/va_backend.h

Signed-off-by: Austin Yuan <shengquan.yuan@gmail.com>
1  2 
va/Android.mk
va/android/drmtest.c
va/android/drmtest.h
va/android/va_android.c
va/va.h
va/va_android.h
va/va_backend.h
va/x11/va_dricommon.h

diff --cc va/Android.mk
@@@ -3,10 -6,13 +6,14 @@@ LIBVA_MAJOR_VERSION := 
  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 \
index 3a8bd0d,0000000..85be50a
mode 100644,000000..100644
--- /dev/null
@@@ -1,130 -1,0 +1,136 @@@
- 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;
 +
 +}
index 55bb446,0000000..875b03f
mode 100644,000000..100644
--- /dev/null
@@@ -1,40 -1,0 +1,40 @@@
- 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);
@@@ -26,7 -26,7 +26,7 @@@
  #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
  )
@@@ -82,42 -106,20 +86,51 @@@ static VAStatus va_DisplayContextGetDri
      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;
  }
@@@ -149,10 -152,20 +163,9 @@@ VADisplay vaGetDisplay 
        /* 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;          
@@@ -214,36 -226,8 +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
diff --cc va/va.h
Simple merge
diff --cc va/va_android.h
@@@ -8,19 -6,14 +6,17 @@@
  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, 
@@@ -45,28 -39,6 +41,8 @@@ 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
  }
  #endif
diff --cc va/va_backend.h
@@@ -179,7 -185,11 +185,7 @@@ struct VADriverVTabl
        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,
Simple merge