OSDN Git Service

5befaa0fb58eb5eedc03c3615c6a5b65b436f3b8
[android-x86/external-libdrm.git] / libkms / api.c
1 /**************************************************************************
2  *
3  * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24  * USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27
28
29 #include "config.h"
30 #include <errno.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include "internal.h"
34
35 int kms_create(int fd, struct kms_driver **out)
36 {
37         return linux_create(fd, out);
38 }
39
40 int kms_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
41 {
42         switch (key) {
43         case KMS_BO_TYPE:
44                 break;
45         default:
46                 return -EINVAL;
47         }
48         return kms->get_prop(kms, key, out);
49 }
50
51 int kms_destroy(struct kms_driver **kms)
52 {
53         if (!(*kms))
54                 return 0;
55
56         free(*kms);
57         *kms = NULL;
58         return 0;
59 }
60
61 int kms_bo_create(struct kms_driver *kms, const unsigned *attr, struct kms_bo **out)
62 {
63         unsigned width = 0;
64         unsigned height = 0;
65         enum kms_bo_type type = KMS_BO_TYPE_SCANOUT_X8R8G8B8;
66         int i;
67
68         for (i = 0; attr[i];) {
69                 unsigned key = attr[i++];
70                 unsigned value = attr[i++];
71
72                 switch (key) {
73                 case KMS_WIDTH:
74                         width = value;
75                         break;
76                 case KMS_HEIGHT:
77                         height = value;
78                         break;
79                 case KMS_BO_TYPE:
80                         type = value;
81                         break;
82                 default:
83                         return -EINVAL;
84                 }
85         }
86
87         if (width == 0 || height == 0)
88                 return -EINVAL;
89
90         /* XXX sanity check type */
91
92         if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8 &&
93             (width != 64 || height != 64))
94                 return -EINVAL;
95
96         return kms->bo_create(kms, width, height, type, attr, out);
97 }
98
99 int kms_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
100 {
101         switch (key) {
102         case KMS_PITCH:
103                 *out = bo->pitch;
104                 break;
105         case KMS_HANDLE:
106                 *out = bo->handle;
107                 break;
108         default:
109                 return -EINVAL;
110         }
111
112         return 0;
113 }
114
115 int kms_bo_map(struct kms_bo *bo, void **out)
116 {
117         return bo->kms->bo_map(bo, out);
118 }
119
120 int kms_bo_unmap(struct kms_bo *bo)
121 {
122         return bo->kms->bo_unmap(bo);
123 }
124
125 int kms_bo_destroy(struct kms_bo **bo)
126 {
127         int ret;
128
129         if (!(*bo))
130                 return 0;
131
132         ret = (*bo)->kms->bo_destroy(*bo);
133         if (ret)
134                 return ret;
135
136         *bo = NULL;
137         return 0;
138 }