8440b2c6ae3bbe8791472afb83d3dadec404a495
2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Benjamin Franzke <benjaminfranzke@googlemail.com>
36 #include <sys/types.h>
45 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
47 struct gbm_device
*devices
[16];
49 static int device_num
= 0;
52 gbm_device_get_fd(struct gbm_device
*gbm
)
57 /* FIXME: maybe superfluous, use udev subclass from the fd? */
58 GBM_EXPORT
const char *
59 gbm_device_get_backend_name(struct gbm_device
*gbm
)
65 gbm_device_is_format_supported(struct gbm_device
*gbm
,
66 enum gbm_bo_format format
,
69 return gbm
->is_format_supported(gbm
, format
, usage
);
73 gbm_device_destroy(struct gbm_device
*gbm
)
76 if (gbm
->refcount
== 0)
80 GBM_EXPORT
struct gbm_device
*
81 _gbm_mesa_get_device(int fd
)
83 struct gbm_device
*gbm
= NULL
;
88 if (fd
< 0 || fstat(fd
, &buf
) < 0 || !S_ISCHR(buf
.st_mode
)) {
89 fprintf(stderr
, "_gbm_mesa_get_device: invalid fd: %d\n", fd
);
93 for (i
= 0; i
< device_num
; ++i
) {
94 dev
= devices
[i
]->stat
.st_rdev
;
95 if (major(dev
) == major(buf
.st_rdev
) &&
96 minor(dev
) == minor(buf
.st_rdev
)) {
106 GBM_EXPORT
struct gbm_device
*
107 gbm_create_device(int fd
)
109 struct gbm_device
*gbm
= NULL
;
112 if (fd
< 0 || fstat(fd
, &buf
) < 0 || !S_ISCHR(buf
.st_mode
)) {
113 fprintf(stderr
, "gbm_create_device: invalid fd: %d\n", fd
);
118 memset(devices
, 0, sizeof devices
);
120 gbm
= _gbm_create_device(fd
);
124 gbm
->dummy
= gbm_create_device
;
128 if (device_num
< ARRAY_SIZE(devices
)-1)
129 devices
[device_num
++] = gbm
;
134 GBM_EXPORT
unsigned int
135 gbm_bo_get_width(struct gbm_bo
*bo
)
140 GBM_EXPORT
unsigned int
141 gbm_bo_get_height(struct gbm_bo
*bo
)
147 gbm_bo_get_pitch(struct gbm_bo
*bo
)
152 GBM_EXPORT
union gbm_bo_handle
153 gbm_bo_get_handle(struct gbm_bo
*bo
)
159 gbm_bo_destroy(struct gbm_bo
*bo
)
161 bo
->gbm
->bo_destroy(bo
);
164 GBM_EXPORT
struct gbm_bo
*
165 gbm_bo_create(struct gbm_device
*gbm
,
166 uint32_t width
, uint32_t height
,
167 enum gbm_bo_format format
, uint32_t usage
)
169 if (width
== 0 || height
== 0)
172 if (usage
& GBM_BO_USE_CURSOR_64X64
&&
173 (width
!= 64 || height
!= 64))
176 return gbm
->bo_create(gbm
, width
, height
, format
, usage
);
179 GBM_EXPORT
struct gbm_bo
*
180 gbm_bo_create_from_egl_image(struct gbm_device
*gbm
,
181 void *egl_dpy
, void *egl_image
,
182 uint32_t width
, uint32_t height
,
185 if (width
== 0 || height
== 0)
188 return gbm
->bo_create_from_egl_image(gbm
, egl_dpy
, egl_image
,
189 width
, height
, usage
);