Back to index

libdrm  2.4.37
api.c
Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
00021  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
00022  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
00023  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
00024  * USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00028 
00029 #include "config.h"
00030 #include <errno.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include "internal.h"
00034 
00035 int kms_create(int fd, struct kms_driver **out)
00036 {
00037        return linux_create(fd, out);
00038 }
00039 
00040 int kms_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
00041 {
00042        switch (key) {
00043        case KMS_BO_TYPE:
00044               break;
00045        default:
00046               return -EINVAL;
00047        }
00048        return kms->get_prop(kms, key, out);
00049 }
00050 
00051 int kms_destroy(struct kms_driver **kms)
00052 {
00053        if (!(*kms))
00054               return 0;
00055 
00056        free(*kms);
00057        *kms = NULL;
00058        return 0;
00059 }
00060 
00061 int kms_bo_create(struct kms_driver *kms, const unsigned *attr, struct kms_bo **out)
00062 {
00063        unsigned width = 0;
00064        unsigned height = 0;
00065        enum kms_bo_type type = KMS_BO_TYPE_SCANOUT_X8R8G8B8;
00066        int i;
00067 
00068        for (i = 0; attr[i];) {
00069               unsigned key = attr[i++];
00070               unsigned value = attr[i++];
00071 
00072               switch (key) {
00073               case KMS_WIDTH:
00074                      width = value;
00075                      break;
00076               case KMS_HEIGHT:
00077                      height = value;
00078                      break;
00079               case KMS_BO_TYPE:
00080                      type = value;
00081                      break;
00082               default:
00083                      return EINVAL;
00084               }
00085        }
00086 
00087        if (width == 0 || height == 0)
00088               return -EINVAL;
00089 
00090        /* XXX sanity check type */
00091 
00092        if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8 &&
00093            (width != 64 || height != 64))
00094               return -EINVAL;
00095 
00096        return kms->bo_create(kms, width, height, type, attr, out);
00097 }
00098 
00099 int kms_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
00100 {
00101        switch (key) {
00102        case KMS_PITCH:
00103               *out = bo->pitch;
00104               break;
00105        case KMS_HANDLE:
00106               *out = bo->handle;
00107               break;
00108        default:
00109               return -EINVAL;
00110        }
00111 
00112        return 0;
00113 }
00114 
00115 int kms_bo_map(struct kms_bo *bo, void **out)
00116 {
00117        return bo->kms->bo_map(bo, out);
00118 }
00119 
00120 int kms_bo_unmap(struct kms_bo *bo)
00121 {
00122        return bo->kms->bo_unmap(bo);
00123 }
00124 
00125 int kms_bo_destroy(struct kms_bo **bo)
00126 {
00127        int ret;
00128 
00129        if (!(*bo))
00130               return 0;
00131 
00132        ret = (*bo)->kms->bo_destroy(*bo);
00133        if (ret)
00134               return ret;
00135 
00136        *bo = NULL;
00137        return 0;
00138 }