Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / gallium / targets / gbm / gbm.c
1 /*
2  * Copyright © 2011 Intel Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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.
23  *
24  * Authors:
25  *    Benjamin Franzke <benjaminfranzke@googlemail.com>
26  */
27
28 #include "util/u_inlines.h"
29
30 #include "gbm_gallium_drmint.h"
31 #include "pipe_loader.h"
32
33 static struct pipe_screen *
34 create_drm_screen(const char *name, int fd)
35 {
36    struct pipe_module *pmod = get_pipe_module(name);
37  
38    return (pmod && pmod->drmdd && pmod->drmdd->create_screen) ?
39       pmod->drmdd->create_screen(fd) : NULL;
40 }
41
42 int
43 gallium_screen_create(struct gbm_gallium_drm_device *gdrm)
44 {
45    gdrm->base.driver_name = drm_fd_get_screen_name(gdrm->base.base.fd);
46    if (gdrm->base.driver_name == NULL)
47       return -1;
48
49    gdrm->screen = create_drm_screen(gdrm->base.driver_name, gdrm->base.base.fd);
50    if (gdrm->screen == NULL) {
51       debug_printf("failed to load driver: %s\n", gdrm->base.driver_name);
52       return -1;
53    };
54
55    return 0;
56 }
57
58 GBM_EXPORT struct gbm_backend gbm_backend = {
59    .backend_name = "gallium_drm",
60    .create_device = gbm_gallium_drm_device_create,
61 };