aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob Bornecrantz2009-11-24 10:54:10 -0600
committerJakob Bornecrantz2009-12-04 09:11:55 -0600
commit8c0571a73399c372644c8d92a136a474f3e05d48 (patch)
tree1067f940118c64267f4a0bfe49b04e9f4971e94d /libkms/api.c
parent28eae30689610faa0fe043ab869587e7699e82bf (diff)
downloadexternal-libdrm-8c0571a73399c372644c8d92a136a474f3e05d48.tar.gz
external-libdrm-8c0571a73399c372644c8d92a136a474f3e05d48.tar.xz
external-libdrm-8c0571a73399c372644c8d92a136a474f3e05d48.zip
libkms: Add libkms
Diffstat (limited to 'libkms/api.c')
-rw-r--r--libkms/api.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/libkms/api.c b/libkms/api.c
new file mode 100644
index 00000000..f15ee70b
--- /dev/null
+++ b/libkms/api.c
@@ -0,0 +1,124 @@
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 <errno.h>
30#include <stdlib.h>
31#include <string.h>
32#include "internal.h"
33
34int kms_create(int fd, struct kms_driver **out)
35{
36 return vmwgfx_create(fd, out);
37}
38
39int kms_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
40{
41 switch (key) {
42 case KMS_MAX_SCANOUT_WIDTH:
43 case KMS_MAX_SCANOUT_HEIGHT:
44 case KMS_MIN_SCANOUT_WIDTH:
45 case KMS_MIN_SCANOUT_HEIGHT:
46 case KMS_MAX_CURSOR_WIDTH:
47 case KMS_MAX_CURSOR_HEIGHT:
48 case KMS_MIN_CURSOR_WIDTH:
49 case KMS_MIN_CURSOR_HEIGHT:
50 break;
51 default:
52 return -EINVAL;
53 }
54 return kms->get_prop(kms, key, out);
55}
56
57int kms_destroy(struct kms_driver *kms)
58{
59 free(kms);
60 return 0;
61}
62
63int kms_bo_create(struct kms_driver *kms, const unsigned *attr, struct kms_bo **out)
64{
65 unsigned width = 0;
66 unsigned height = 0;
67 enum kms_bo_type type = KMS_BO_TYPE_SCANOUT;
68 int i;
69
70 for (i = 0; attr[i];) {
71 unsigned key = attr[i++];
72 unsigned value = attr[i++];
73
74 switch (key) {
75 case KMS_WIDTH:
76 width = value;
77 break;
78 case KMS_HEIGHT:
79 height = value;
80 break;
81 case KMS_BO_TYPE:
82 type = value;
83 break;
84 default:
85 return EINVAL;
86 }
87 }
88
89 if (width == 0 || height == 0)
90 return -EINVAL;
91
92 return kms->bo_create(kms, width, height, type, attr, out);
93}
94
95int kms_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
96{
97 switch (key) {
98 case KMS_PITCH:
99 *out = bo->pitch;
100 break;
101 case KMS_HANDLE:
102 *out = bo->handle;
103 break;
104 default:
105 return -EINVAL;
106 }
107
108 return 0;
109}
110
111int kms_bo_map(struct kms_bo *bo, void **out)
112{
113 return bo->kms->bo_map(bo, out);
114}
115
116int kms_bo_unmap(struct kms_bo *bo)
117{
118 return bo->kms->bo_unmap(bo);
119}
120
121int kms_bo_destroy(struct kms_bo *bo)
122{
123 return bo->kms->bo_destroy(bo);
124}