OSDN Git Service

drm mode: fix drmIoctl wrapper
[android-x86/external-libdrm.git] / libkms / api.c
index f15ee70..4a05f3d 100644 (file)
@@ -26,6 +26,7 @@
  **************************************************************************/
 
 
+#include "config.h"
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 
 int kms_create(int fd, struct kms_driver **out)
 {
-       return vmwgfx_create(fd, out);
+       return linux_create(fd, out);
 }
 
 int kms_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
 {
        switch (key) {
-       case KMS_MAX_SCANOUT_WIDTH:
-       case KMS_MAX_SCANOUT_HEIGHT:
-       case KMS_MIN_SCANOUT_WIDTH:
-       case KMS_MIN_SCANOUT_HEIGHT:
-       case KMS_MAX_CURSOR_WIDTH:
-       case KMS_MAX_CURSOR_HEIGHT:
-       case KMS_MIN_CURSOR_WIDTH:
-       case KMS_MIN_CURSOR_HEIGHT:
+       case KMS_BO_TYPE:
                break;
        default:
                return -EINVAL;
@@ -54,9 +48,13 @@ int kms_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
        return kms->get_prop(kms, key, out);
 }
 
-int kms_destroy(struct kms_driver *kms)
+int kms_destroy(struct kms_driver **kms)
 {
-       free(kms);
+       if (!(*kms))
+               return 0;
+
+       free(*kms);
+       *kms = NULL;
        return 0;
 }
 
@@ -64,7 +62,7 @@ int kms_bo_create(struct kms_driver *kms, const unsigned *attr, struct kms_bo **
 {
        unsigned width = 0;
        unsigned height = 0;
-       enum kms_bo_type type = KMS_BO_TYPE_SCANOUT;
+       enum kms_bo_type type = KMS_BO_TYPE_SCANOUT_X8R8G8B8;
        int i;
 
        for (i = 0; attr[i];) {
@@ -89,6 +87,12 @@ int kms_bo_create(struct kms_driver *kms, const unsigned *attr, struct kms_bo **
        if (width == 0 || height == 0)
                return -EINVAL;
 
+       /* XXX sanity check type */
+
+       if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8 &&
+           (width != 64 || height != 64))
+               return -EINVAL;
+
        return kms->bo_create(kms, width, height, type, attr, out);
 }
 
@@ -118,7 +122,17 @@ int kms_bo_unmap(struct kms_bo *bo)
        return bo->kms->bo_unmap(bo);
 }
 
-int kms_bo_destroy(struct kms_bo *bo)
+int kms_bo_destroy(struct kms_bo **bo)
 {
-       return bo->kms->bo_destroy(bo);
+       int ret;
+
+       if (!(*bo))
+               return 0;
+
+       ret = (*bo)->kms->bo_destroy(*bo);
+       if (ret)
+               return ret;
+
+       *bo = NULL;
+       return 0;
 }